-
Notifications
You must be signed in to change notification settings - Fork 95
Expand file tree
/
Copy pathTestTooltips.cs
More file actions
143 lines (121 loc) · 4.39 KB
/
Copy pathTestTooltips.cs
File metadata and controls
143 lines (121 loc) · 4.39 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
using Unity.TouchFramework;
using UnityEngine;
using UnityEngine.InputSystem;
using Random = UnityEngine.Random;
namespace Packages.com.unity.Samples
{
enum PopUpType
{
Tooltip,
ModalPopup,
Notification,
BigNotification,
}
public class TestTooltips : MonoBehaviour
{
#pragma warning disable CS0649
[SerializeField]
PopUpType m_TestType;
[SerializeField]
RectTransform m_RectPopUp;
[SerializeField]
PopUpManager m_PopUpManager;
[SerializeField]
Sprite[] m_Icons;
#pragma warning restore CS0649
Vector3 m_position;
void OnGUI()
{
GUILayout.Label("Press [SPACE] to display tooltips.");
}
void Update()
{
if (Keyboard.current.spaceKey.wasReleasedThisFrame)
{
switch (m_TestType)
{
case PopUpType.Notification:
NotificationTest();
break;
case PopUpType.Tooltip:
TooltipTest();
break;
case PopUpType.BigNotification:
BigNotificationTest();
break;
case PopUpType.ModalPopup:
ModalPopup();
break;
}
}
}
void NotificationTest()
{
// Get custom struct from manager
var data = m_PopUpManager.GetNotificationData();
// The Notification has an icon and a different default position
bool hasIcon = (Random.value > 0.5f && m_Icons != null && m_Icons.Length > 0);
var icon = hasIcon ? m_Icons[Mathf.FloorToInt(Random.value * 10e3f) % m_Icons.Length] : null;
data.icon = icon;
data.text = "Notification text";
// Send back the modified struct
m_PopUpManager.DisplayNotification(data);
}
void TooltipTest()
{
// Get custom struct from manager
var data = m_PopUpManager.GetTooltipData();
// Modify the struct
// The tooltip has an icon and an arrow that points the coordinate you put in data.worldPosition
data.text = "This tool helps you";
bool hasIcon = (Random.value > 0.5f && m_Icons != null && m_Icons.Length > 0);
var icon = hasIcon ? m_Icons[Mathf.FloorToInt(Random.value * 10e3f) % m_Icons.Length] : null;
data.icon = icon;
// Sets position to the pointer
RectTransformUtility.ScreenPointToWorldPointInRectangle(
m_RectPopUp, Mouse.current.position.ReadValue(), null, out var worldposition);
data.worldPosition = worldposition;
// Send back the modified struct
m_PopUpManager.DisplayTooltip(data);
}
void BigNotificationTest()
{
// Get custom struct from manager
var data = m_PopUpManager.GetBigNotificationData();
// Modify the struct
// The big tooltip does not have an icon, but it has a title and a larger text field
data.title = "The Title";
data.text = "You can write the description in this textbox.";
// Send back the modified struct
m_PopUpManager.DisplayBigNotification(data);
}
void ModalPopup()
{
// Get custom struct from manager
var data = m_PopUpManager.GetModalPopUpData();
// The dialog modal is a bit more complex.
// Title + text like the big tooltip
data.title = "Alert";
data.text = "This needs user confirmation";
// Button and callback configuration
data.positiveText = "Ok";
data.positiveCallback = PositiveAction;
// Negative button optional
bool hasNegativeAction = Random.value > 0.5f;
if (hasNegativeAction)
{
data.negativeText = "No, thanks";
data.negativeCallback = NegativeAction;
}
m_PopUpManager.DisplayModalPopUp(data);
}
void NegativeAction()
{
Debug.Log("User canceled action");
}
void PositiveAction()
{
Debug.Log("User confirmed action");
}
}
}