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;
using System.Collections.Generic;
/// <summary>
/// Attaching this script to a widget makes it react to key events such as tab, up, down, etc.
/// </summary>
[RequireComponent(typeof(Collider))]
[AddComponentMenu("NGUI/Interaction/Button Keys")]
public class UIButtonKeys : MonoBehaviour
{
public bool startsSelected = false;
public UIButtonKeys selectOnClick;
public UIButtonKeys selectOnUp;
public UIButtonKeys selectOnDown;
public UIButtonKeys selectOnLeft;
public UIButtonKeys selectOnRight;
void OnEnable ()
{
if (startsSelected)
{
if (UICamera.selectedObject == null || !NGUITools.GetActive(UICamera.selectedObject))
{
UICamera.selectedObject = gameObject;
UICamera.Notify(gameObject, "OnHover", true);
}
}
}
void OnKey (KeyCode key)
{
if (enabled && NGUITools.GetActive(gameObject))
{
switch (key)
{
case KeyCode.LeftArrow:
if (selectOnLeft != null) UICamera.selectedObject = selectOnLeft.gameObject;
break;
case KeyCode.RightArrow:
if (selectOnRight != null) UICamera.selectedObject = selectOnRight.gameObject;
break;
case KeyCode.UpArrow:
if (selectOnUp != null) UICamera.selectedObject = selectOnUp.gameObject;
break;
case KeyCode.DownArrow:
if (selectOnDown != null) UICamera.selectedObject = selectOnDown.gameObject;
break;
case KeyCode.Tab:
if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
{
if (selectOnLeft != null) UICamera.selectedObject = selectOnLeft.gameObject;
else if (selectOnUp != null) UICamera.selectedObject = selectOnUp.gameObject;
else if (selectOnDown != null) UICamera.selectedObject = selectOnDown.gameObject;
else if (selectOnRight != null) UICamera.selectedObject = selectOnRight.gameObject;
}
else
{
if (selectOnRight != null) UICamera.selectedObject = selectOnRight.gameObject;
else if (selectOnDown != null) UICamera.selectedObject = selectOnDown.gameObject;
else if (selectOnUp != null) UICamera.selectedObject = selectOnUp.gameObject;
else if (selectOnLeft != null) UICamera.selectedObject = selectOnLeft.gameObject;
}
break;
}
}
}
void OnClick ()
{
if (enabled && selectOnClick != null)
{
UICamera.selectedObject = selectOnClick.gameObject;
}
}
}
|
Revision |
Author |
Commited |
Message |
83
|
FMMortaroli
|
Tue 13 May, 2014 11:32:51 +0000 |
|