Nextrek
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
|
//----------------------------------------------
// NGUI: Next-Gen UI kit
// Copyright © 2011-2013 Tasharen Entertainment
//----------------------------------------------
using UnityEngine;
/// <summary>
/// Sample script showing how easy it is to implement a standard button that swaps sprites.
/// </summary>
[AddComponentMenu("NGUI/UI/Image Button")]
public class UIImageButton : MonoBehaviour
{
public UISprite target;
public string normalSprite;
public string hoverSprite;
public string pressedSprite;
public string disabledSprite;
public bool isEnabled
{
get
{
Collider col = collider;
return col && col.enabled;
}
set
{
Collider col = collider;
if (!col) return;
if (col.enabled != value)
{
col.enabled = value;
UpdateImage();
}
}
}
void OnEnable ()
{
if (target == null) target = GetComponentInChildren<UISprite>();
UpdateImage();
}
void UpdateImage()
{
if (target != null)
{
if (isEnabled)
{
target.spriteName = UICamera.IsHighlighted(gameObject) ? hoverSprite : normalSprite;
}
else
{
target.spriteName = disabledSprite;
}
target.MakePixelPerfect();
}
}
void OnHover (bool isOver)
{
if (isEnabled && target != null)
{
target.spriteName = isOver ? hoverSprite : normalSprite;
target.MakePixelPerfect();
}
}
void OnPress (bool pressed)
{
if (pressed)
{
target.spriteName = pressedSprite;
target.MakePixelPerfect();
}
else UpdateImage();
}
}
|
Revision |
Author |
Commited |
Message |
83
|
FMMortaroli
|
Tue 13 May, 2014 11:32:51 +0000 |
|