-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
CreditsGhost.cs
107 lines (87 loc) 路 2.89 KB
/
CreditsGhost.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using AdrianMiasik.Components.Base;
using UnityEngine;
using UnityEngine.EventSystems;
namespace AdrianMiasik.Components.Specific
{
/// <summary>
/// A <see cref="TimerProgress"/> inheritor used for displaying the authors name of the app. Intended to minimize
/// after a couple seconds via the base class.
/// </summary>
// public class CreditsBubble : TimerProgress, IPointerEnterHandler, IPointerExitHandler, IColorHook
public class CreditsGhost : Ghost, IPointerEnterHandler, IPointerExitHandler
{
[SerializeField] private RectTransform m_self;
[SerializeField] private SimpleTimer m_timer;
private bool isPointerHovering;
private bool lockInteraction;
private float cachedWidthPercentage;
private float cachedRightOffsetPixels;
public override void Initialize(PomodoroTimer pomodoroTimer, bool updateColors = true)
{
base.Initialize(pomodoroTimer, updateColors);
// Cache
cachedWidthPercentage = m_self.anchorMax.x;
cachedRightOffsetPixels = m_self.offsetMax.x;
// Setup
m_timer.m_onComplete.AddListener(OnTimerComplete);
m_timer.Initialize(3);
Lock();
}
private void OnTimerComplete()
{
if (!isPointerHovering && !Timer.IsAboutPageOpen())
{
if (!Timer.IsSidebarOpen())
{
FadeOut();
}
}
if (!Timer.IsAboutPageOpen())
{
Unlock();
}
}
public void Lock()
{
lockInteraction = true;
}
public void Unlock()
{
lockInteraction = false;
}
public void OnPointerEnter(PointerEventData eventData)
{
isPointerHovering = true;
if (lockInteraction)
{
return;
}
FadeIn();
}
public void OnPointerExit(PointerEventData eventData)
{
isPointerHovering = false;
if (lockInteraction)
{
return;
}
FadeOut();
}
public void SetWidth(float desiredWidthPercentage)
{
m_self.anchorMax = new Vector2(desiredWidthPercentage, m_self.anchorMax.y);
}
public void SetRightOffset(float rightOffsetInPixels)
{
m_self.offsetMax = new Vector2(rightOffsetInPixels, m_self.offsetMax.y);
}
public void ResetWidth()
{
m_self.anchorMax = new Vector2(cachedWidthPercentage, m_self.anchorMax.y);
}
public void ResetRightOffset()
{
m_self.offsetMax = new Vector2(cachedRightOffsetPixels, m_self.offsetMax.y);
}
}
}