-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathUIButtonScale.cs
83 lines (71 loc) · 1.61 KB
/
UIButtonScale.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
using UnityEngine;
[AddComponentMenu("NGUI/Interaction/Button Scale")]
public class UIButtonScale : MonoBehaviour
{
public Transform tweenTarget;
public Vector3 hover = new Vector3(1.1f, 1.1f, 1.1f);
public Vector3 pressed = new Vector3(1.05f, 1.05f, 1.05f);
public float duration = 0.2f;
private Vector3 mScale;
private bool mStarted;
private void Start()
{
if (!mStarted)
{
mStarted = true;
if (tweenTarget == null)
{
tweenTarget = base.transform;
}
mScale = tweenTarget.localScale;
}
}
private void OnEnable()
{
if (mStarted)
{
OnHover(UICamera.IsHighlighted(base.gameObject));
}
}
private void OnDisable()
{
if (mStarted && tweenTarget != null)
{
TweenScale component = tweenTarget.GetComponent<TweenScale>();
if (component != null)
{
component.value = mScale;
component.enabled = false;
}
}
}
private void OnPress(bool isPressed)
{
if (base.enabled)
{
if (!mStarted)
{
Start();
}
TweenScale.Begin(tweenTarget.gameObject, duration, isPressed ? Vector3.Scale(mScale, pressed) : ((!UICamera.IsHighlighted(base.gameObject)) ? mScale : Vector3.Scale(mScale, hover))).method = UITweener.Method.EaseInOut;
}
}
private void OnHover(bool isOver)
{
if (base.enabled)
{
if (!mStarted)
{
Start();
}
TweenScale.Begin(tweenTarget.gameObject, duration, (!isOver) ? mScale : Vector3.Scale(mScale, hover)).method = UITweener.Method.EaseInOut;
}
}
private void OnSelect(bool isSelected)
{
if (base.enabled && (!isSelected || UICamera.currentScheme == UICamera.ControlScheme.Controller))
{
OnHover(isSelected);
}
}
}