-
Notifications
You must be signed in to change notification settings - Fork 96
/
TooltipHandler.cs
117 lines (95 loc) · 2.16 KB
/
TooltipHandler.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
108
109
110
111
112
113
114
115
116
117
#region license
/* [Scientific Committee on Advanced Navigation]
* S.C.A.N. Satellite
*
* TooltipHandler - Script to control tooltip activation
*
* Copyright (c)2013 damny;
* Copyright (c)2014 technogeeky <technogeeky@gmail.com>;
* Copyright (c)2014 DMagic
* Copyright (c)2014 (Your Name Here) <your email here>; see LICENSE.txt for licensing details.
*/
#endregion
using System;
using System.Collections.Generic;
using SCANsat.Unity.Unity;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
namespace SCANsat.Unity
{
public class TooltipHandler : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{
[SerializeField, TextArea(2, 10)]
private string m_TooltipName = "";
[SerializeField]
private bool m_IsActive = true;
[SerializeField]
private bool m_HelpTip = false;
[SerializeField]
private GameObject _prefab = null;
[SerializeField]
private string _tooltipText = "";
private Canvas _canvas;
private SCAN_Tooltip _tooltip;
private float _scale;
public string TooltipName
{
get { return m_TooltipName; }
}
public Canvas _Canvas
{
set { _canvas = value; }
}
public GameObject Prefab
{
set { _prefab = value; }
}
public float Scale
{
set { _scale = value; }
}
public bool IsActive
{
set { m_IsActive = value; }
}
public bool HelpTip
{
get { return m_HelpTip; }
}
public string TooltipText
{
set { _tooltipText = value; }
}
public void OnPointerEnter(PointerEventData eventData)
{
if (!m_IsActive)
return;
OpenTooltip();
}
public void OnPointerExit(PointerEventData eventData)
{
if (!m_IsActive)
return;
CloseTooltip();
}
private void OpenTooltip()
{
if (_prefab == null || _canvas == null)
return;
_tooltip = Instantiate(_prefab).GetComponent<SCAN_Tooltip>();
if (_tooltip == null)
return;
_tooltip.transform.SetParent(_canvas.transform, false);
_tooltip.transform.SetAsLastSibling();
_tooltip.Setup(_canvas, _tooltipText, _scale);
}
private void CloseTooltip()
{
if (_tooltip == null)
return;
_tooltip.gameObject.SetActive(false);
Destroy(_tooltip.gameObject);
}
}
}