프로젝트

일반

사용자정보

통계
| 개정판:

t1 / TFDContents / Assets / KinectDemos / InteractionDemo / Scripts / GuiWindowScript.cs @ 3

이력 | 보기 | 이력해설 | 다운로드 (3.31 KB)

1
using UnityEngine;
2
using System.Collections;
3

    
4
public class GuiWindowScript : MonoBehaviour 
5
{
6
	[Tooltip("GUI-Window rectangle in screen coordinates (pixels).")]
7
	public Rect guiWindowRect = new Rect(-140, 40, 140, 420);
8
	[Tooltip("GUI-Window skin (optional).")]
9
	public GUISkin guiSkin;
10

    
11
	// public parameters
12
	[Tooltip("Reference to the plane below the draggable objects.")]
13
	public GameObject planeObj = null;
14
	[Tooltip("Whether the window is currently invisible or not.")]
15
	public bool hiddenWindow = false;
16
	
17
	private bool resetObjectsClicked = false;
18
	private bool hideWindowClicked = false;
19
	private bool isGravityOn = true;
20
	private bool isPlaneOn = true;
21
	private bool isControlMouseOn = true;
22

    
23
	private string label1Text = string.Empty;
24
	private string label2Text = string.Empty;
25

    
26

    
27
	void Start()
28
	{
29
		planeObj = GameObject.Find("Plane");
30
	}
31

    
32

    
33
	private void ShowGuiWindow(int windowID) 
34
	{
35
		GUILayout.BeginVertical();
36

    
37
		GUILayout.Space(30);
38
		isPlaneOn = GUILayout.Toggle(isPlaneOn, "Plane On");
39
		SetPlaneVisible(isPlaneOn);
40

    
41
		GUILayout.Space(30);
42
		isGravityOn = GUILayout.Toggle(isGravityOn, "Gravity On");
43
		SetGravity(isGravityOn);
44
		
45
		GUILayout.Space(30);
46
		isControlMouseOn = GUILayout.Toggle(isControlMouseOn, "Control Mouse");
47
		SetMouseControl(isControlMouseOn);
48
		
49
		GUILayout.FlexibleSpace();
50
		
51
		resetObjectsClicked = GUILayout.Button("Reset Objects");
52
		if(resetObjectsClicked)
53
		{
54
			//label1Text = "Resetting objects...";
55
			ResetObjects(resetObjectsClicked);
56
		}
57

    
58
		GUILayout.Label(label1Text);
59

    
60
		hideWindowClicked = GUILayout.Button("Hide Options");
61
		if(hideWindowClicked)
62
		{
63
			//label2Text = "Hiding options window...";
64
			HideWindow(hideWindowClicked);
65
		}
66
		
67
		GUILayout.Label(label2Text);
68
		GUILayout.EndVertical();
69
		
70
		// Make the window draggable.
71
		GUI.DragWindow();
72
	}
73
	
74
	
75
	void OnGUI()
76
	{
77
		if(!hiddenWindow)
78
		{
79
			Rect windowRect = guiWindowRect;
80
			if(windowRect.x < 0)
81
				windowRect.x += Screen.width;
82
			if(windowRect.y < 0)
83
				windowRect.y += Screen.height;
84
			
85
			GUI.skin = guiSkin;
86
			guiWindowRect = GUI.Window(1, windowRect, ShowGuiWindow, "Options");
87
		}
88
	}
89

    
90

    
91
	// set gravity on or off
92
	private void SetGravity(bool gravityOn)
93
	{
94
		GrabDropScript compGrabDrop = GetComponent<GrabDropScript>();
95

    
96
		if(compGrabDrop != null && compGrabDrop.useGravity != gravityOn)
97
		{
98
			compGrabDrop.useGravity = gravityOn;
99
		}
100
	}
101

    
102
	// make plane visible or not
103
	private void SetPlaneVisible(bool planeOn)
104
	{
105
		if(planeObj && planeObj.activeInHierarchy != planeOn)
106
		{
107
			planeObj.SetActive(planeOn);
108
		}
109
	}
110

    
111
	// turn off or on mouse-cursor control
112
	private void SetMouseControl(bool controlMouseOn)
113
	{
114
		InteractionManager manager = InteractionManager.Instance;
115

    
116
		if(manager && manager.IsInteractionInited())
117
		{
118
			if(manager.controlMouseCursor != controlMouseOn)
119
			{
120
				manager.controlMouseCursor = controlMouseOn;
121
			}
122
		}
123
	}
124

    
125
	// reset objects if needed
126
	private void ResetObjects(bool resetObjs)
127
	{
128
		if(resetObjs)
129
		{
130
			GrabDropScript compGrabDrop = GetComponent<GrabDropScript>();
131
			
132
			if(compGrabDrop != null)
133
			{
134
				compGrabDrop.resetObjects = true;
135
			}
136
		}
137
	}
138

    
139
	// hide options window
140
	private void HideWindow(bool hideWin)
141
	{
142
		if(hideWin)
143
		{
144
			hiddenWindow = true;
145
		}
146
	}
147
	
148

    
149
}