-
Notifications
You must be signed in to change notification settings - Fork 96
/
TextHandler.cs
113 lines (92 loc) · 2.36 KB
/
TextHandler.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
#region license
/* [Scientific Committee on Advanced Navigation]
* S.C.A.N. Satellite
*
* TextHandler - Script for handling Text object replacement with Text Mesh Pro
*
* 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 UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;
using UnityEngine.EventSystems;
namespace SCANsat.Unity
{
public class TextHandler : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IScrollHandler
{
[SerializeField]
private bool m_Outline = false;
[SerializeField]
private float m_OutlineWidth = 0;
[SerializeField]
private bool m_Highlighter = false;
[SerializeField]
private Color m_HighlightColor = Color.white;
public class OnTextEvent : UnityEvent<string> { }
public class OnColorEvent : UnityEvent<Color> { }
public class OnFontEvent : UnityEvent<int> { }
private OnTextEvent _onTextUpdate = new OnTextEvent();
private OnColorEvent _onColorUpdate = new OnColorEvent();
private OnFontEvent _onFontChange = new OnFontEvent();
private Vector2 _preferredSize = new Vector2();
private Color _normalColor = Color.white;
private ScrollRect scroller;
public void SetNormalColor(Color c)
{
_normalColor = c;
}
public void SetScroller(ScrollRect s)
{
scroller = s;
}
public bool Outline
{
get { return m_Outline; }
}
public float OutlineWidth
{
get { return m_OutlineWidth; }
}
public Vector2 PreferredSize
{
get { return _preferredSize; }
set { _preferredSize = value; }
}
public UnityEvent<string> OnTextUpdate
{
get { return _onTextUpdate; }
}
public UnityEvent<Color> OnColorUpdate
{
get { return _onColorUpdate; }
}
public UnityEvent<int> OnFontChange
{
get { return _onFontChange; }
}
public void OnPointerEnter(PointerEventData eventData)
{
if (!m_Highlighter)
return;
OnColorUpdate.Invoke(m_HighlightColor);
}
public void OnPointerExit(PointerEventData eventData)
{
if (!m_Highlighter)
return;
OnColorUpdate.Invoke(_normalColor);
}
public void OnScroll(PointerEventData eventData)
{
if (scroller == null)
return;
scroller.OnScroll(eventData);
}
}
}