Mercurial > hg > Game > Games
comparison Orchestland/Assets/OVR/Scripts/Util/OVRUGUI.cs @ 1:f7675884f2a1
Add Orchestland project
author | Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 17 Jul 2015 23:09:20 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:347d21cdfc22 | 1:f7675884f2a1 |
---|---|
1 /************************************************************************************ | |
2 | |
3 Copyright : Copyright 2014 Oculus VR, LLC. All Rights reserved. | |
4 | |
5 Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License"); | |
6 you may not use the Oculus VR Rift SDK except in compliance with the License, | |
7 which is provided at the time of installation or download, or which | |
8 otherwise accompanies this software in either electronic or hard copy form. | |
9 | |
10 You may obtain a copy of the License at | |
11 | |
12 http://www.oculusvr.com/licenses/LICENSE-3.2 | |
13 | |
14 Unless required by applicable law or agreed to in writing, the Oculus VR SDK | |
15 distributed under the License is distributed on an "AS IS" BASIS, | |
16 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
17 See the License for the specific language governing permissions and | |
18 limitations under the License. | |
19 | |
20 ************************************************************************************/ | |
21 | |
22 // Use the Unity new GUI with Unity 4.6 or above. | |
23 #if UNITY_4_6 || UNITY_5_0 | |
24 #define USE_NEW_GUI | |
25 #endif | |
26 | |
27 using UnityEngine; | |
28 #if USE_NEW_GUI | |
29 using UnityEngine.UI; | |
30 # endif | |
31 using System.Collections; | |
32 | |
33 //------------------------------------------------------------------------------------- | |
34 /// <summary> | |
35 /// Class for Unity new GUI built in 4.6 | |
36 /// </summary> | |
37 public class OVRUGUI | |
38 { | |
39 #if USE_NEW_GUI | |
40 | |
41 #region UIGameObject | |
42 private static GameObject NewGUIManager; | |
43 private static GameObject RiftPresent; | |
44 private static GameObject LowPersistence; | |
45 private static GameObject VisionMode; | |
46 private static GameObject FPS; | |
47 private static GameObject Prediction; | |
48 private static GameObject IPD; | |
49 private static GameObject FOV; | |
50 private static GameObject Height; | |
51 private static GameObject SpeedRotationMutipler; | |
52 private static GameObject DeviceDetection; | |
53 private static GameObject ResolutionEyeTexture; | |
54 private static GameObject Latencies; | |
55 #endregion | |
56 | |
57 #region VRVariables | |
58 [HideInInspector] | |
59 public static string strRiftPresent = null; | |
60 [HideInInspector] | |
61 public static string strLPM = null; //"LowPersistenceMode: ON"; | |
62 [HideInInspector] | |
63 public static string strVisionMode = null;//"Vision Enabled: ON"; | |
64 [HideInInspector] | |
65 public static string strFPS = null;//"FPS: 0"; | |
66 [HideInInspector] | |
67 public static string strIPD = null;//"IPD: 0.000"; | |
68 [HideInInspector] | |
69 public static string strPrediction = null;//"Pred: OFF"; | |
70 [HideInInspector] | |
71 public static string strFOV = null;//"FOV: 0.0f"; | |
72 [HideInInspector] | |
73 public static string strHeight = null;//"Height: 0.0f"; | |
74 [HideInInspector] | |
75 public static string strSpeedRotationMultipler = null;//"Spd. X: 0.0f Rot. X: 0.0f"; | |
76 [HideInInspector] | |
77 public static OVRPlayerController PlayerController = null; | |
78 [HideInInspector] | |
79 public static OVRCameraRig CameraController = null; | |
80 //[HideInInspector] | |
81 //public static string strDeviceDetection = null;// Device attach / detach | |
82 [HideInInspector] | |
83 public static string strResolutionEyeTexture = null;// "Resolution : {0} x {1}" | |
84 [HideInInspector] | |
85 public static string strLatencies = null;// Device attach / detach | |
86 #endregion | |
87 | |
88 [HideInInspector] | |
89 public static bool InitUIComponent = false; | |
90 private static float offsetY = 55.0f; | |
91 private static bool isInited = false; | |
92 private static int numOfGUI = 0; | |
93 private static GameObject text; | |
94 | |
95 /// <summary> | |
96 /// It's for rift present GUI | |
97 /// </summary> | |
98 public static void RiftPresentGUI(GameObject GUIMainOBj) | |
99 { | |
100 RiftPresent = ComponentComposition(RiftPresent); | |
101 RiftPresent.transform.parent = GUIMainOBj.transform; | |
102 RiftPresent.name = "RiftPresent"; | |
103 RectTransform r = RiftPresent.GetComponent<RectTransform>(); | |
104 r.localPosition = new Vector3(0.0f, 0.0f, 0.0f); | |
105 r.localScale = new Vector3(1.0f, 1.0f, 1.0f); | |
106 r.localEulerAngles = Vector3.zero; | |
107 | |
108 Text t = RiftPresent.GetComponentInChildren<Text>(); | |
109 t.text = strRiftPresent; | |
110 t.fontSize = 20; | |
111 } | |
112 | |
113 /// <summary> | |
114 /// It's for rift present GUI | |
115 /// </summary> | |
116 public static void UpdateGUI() | |
117 { | |
118 if (InitUIComponent && !isInited) | |
119 { | |
120 InitUIComponents(); | |
121 } | |
122 | |
123 UpdateVariable(); | |
124 } | |
125 | |
126 | |
127 /// <summary> | |
128 /// Update VR Variables | |
129 /// </summary> | |
130 static void UpdateVariable() | |
131 { | |
132 NewGUIManager.transform.localPosition = new Vector3(0.0f, 100.0f, 0.0f); | |
133 | |
134 if (!string.IsNullOrEmpty(strLPM)) | |
135 LowPersistence.GetComponentInChildren<Text>().text = strLPM; | |
136 if (!string.IsNullOrEmpty(strVisionMode)) | |
137 VisionMode.GetComponentInChildren<Text>().text = strVisionMode; | |
138 if (!string.IsNullOrEmpty(strFPS)) | |
139 FPS.GetComponentInChildren<Text>().text = strFPS; | |
140 if (!string.IsNullOrEmpty(strPrediction)) | |
141 Prediction.GetComponentInChildren<Text>().text = strPrediction; | |
142 if (!string.IsNullOrEmpty(strIPD)) | |
143 IPD.GetComponentInChildren<Text>().text = strIPD; | |
144 if (!string.IsNullOrEmpty(strFOV)) | |
145 FOV.GetComponentInChildren<Text>().text = strFOV; | |
146 if (!string.IsNullOrEmpty(strResolutionEyeTexture)) | |
147 ResolutionEyeTexture.GetComponentInChildren<Text>().text = strResolutionEyeTexture; | |
148 if (!string.IsNullOrEmpty(strLatencies)) | |
149 Latencies.GetComponentInChildren<Text>().text = strLatencies; | |
150 | |
151 if (PlayerController != null) | |
152 { | |
153 if (!string.IsNullOrEmpty(strHeight)) | |
154 Height.GetComponentInChildren<Text>().text = strHeight; | |
155 if (!string.IsNullOrEmpty(strSpeedRotationMultipler)) | |
156 SpeedRotationMutipler.GetComponentInChildren<Text>().text = strSpeedRotationMultipler; | |
157 } | |
158 } | |
159 | |
160 /// <summary> | |
161 /// Initialize UI GameObjects | |
162 /// </summary> | |
163 static void InitUIComponents() | |
164 { | |
165 float posY = 0.0f; | |
166 int fontSize = 20; | |
167 | |
168 NewGUIManager = new GameObject(); | |
169 NewGUIManager.name = "GUIManager"; | |
170 NewGUIManager.transform.parent = GameObject.Find("OVRGUIMain").transform; | |
171 NewGUIManager.transform.localPosition = Vector3.zero; | |
172 NewGUIManager.transform.localEulerAngles = Vector3.zero; | |
173 NewGUIManager.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f); | |
174 | |
175 // Print out for Low Persistence Mode | |
176 if (!string.IsNullOrEmpty(strLPM)) | |
177 { | |
178 LowPersistence = UIObjectManager(LowPersistence, "LowPersistence", posY -= offsetY, strLPM, fontSize); | |
179 } | |
180 | |
181 // Print out for VisionMode | |
182 if (!string.IsNullOrEmpty(strVisionMode)) | |
183 { | |
184 VisionMode = UIObjectManager(VisionMode, "VisionMode", posY -= offsetY, strVisionMode, fontSize); | |
185 } | |
186 | |
187 // Print out for FPS | |
188 if (!string.IsNullOrEmpty(strFPS)) | |
189 { | |
190 FPS = UIObjectManager(FPS, "FPS", posY -= offsetY, strFPS, fontSize); | |
191 } | |
192 | |
193 // Print out for Prediction | |
194 if (!string.IsNullOrEmpty(strPrediction)) | |
195 { | |
196 Prediction = UIObjectManager(Prediction, "Prediction", posY -= offsetY, strPrediction, fontSize); | |
197 } | |
198 | |
199 // Print out for IPD | |
200 if (!string.IsNullOrEmpty(strIPD)) | |
201 { | |
202 IPD = UIObjectManager(IPD, "IPD", posY -= offsetY, strIPD, fontSize); | |
203 } | |
204 | |
205 // Print out for FOV | |
206 if (!string.IsNullOrEmpty(strFOV)) | |
207 { | |
208 FOV = UIObjectManager(FOV, "FOV", posY -= offsetY, strFOV, fontSize); | |
209 } | |
210 | |
211 if (PlayerController != null) | |
212 { | |
213 // Print out for Height | |
214 if (!string.IsNullOrEmpty(strHeight)) | |
215 { | |
216 Height = UIObjectManager(Height, "Height", posY -= offsetY, strHeight, fontSize); | |
217 } | |
218 | |
219 // Print out for Speed Rotation Multiplier | |
220 if (!string.IsNullOrEmpty(strSpeedRotationMultipler)) | |
221 { | |
222 SpeedRotationMutipler = UIObjectManager(SpeedRotationMutipler, "SpeedRotationMutipler", posY -= offsetY, strSpeedRotationMultipler, fontSize); | |
223 } | |
224 } | |
225 | |
226 // Print out for Resoulution of Eye Texture | |
227 if (!string.IsNullOrEmpty(strResolutionEyeTexture)) | |
228 { | |
229 ResolutionEyeTexture = UIObjectManager(ResolutionEyeTexture, "Resolution", posY -= offsetY, strResolutionEyeTexture, fontSize); | |
230 } | |
231 | |
232 // Print out for Latency | |
233 if (!string.IsNullOrEmpty(strLatencies)) | |
234 { | |
235 Latencies = UIObjectManager(Latencies, "Latency", posY -= offsetY, strLatencies, 17); | |
236 posY = 0.0f; | |
237 } | |
238 | |
239 InitUIComponent = false; | |
240 isInited = true; | |
241 | |
242 } | |
243 | |
244 static GameObject UIObjectManager(GameObject gameObject, string name, float posY, string text, int fontSize) | |
245 { | |
246 gameObject = ComponentComposition(gameObject); | |
247 gameObject.name = name; | |
248 gameObject.transform.parent = NewGUIManager.transform; | |
249 | |
250 RectTransform r = gameObject.GetComponent<RectTransform>(); | |
251 r.localPosition = new Vector3(0.0f, posY -= offsetY, 0.0f); | |
252 | |
253 Text t = gameObject.GetComponentInChildren<Text>(); | |
254 t.text = text; | |
255 t.fontSize = fontSize; | |
256 gameObject.transform.localEulerAngles = Vector3.zero; | |
257 | |
258 r.localScale = new Vector3(1.0f, 1.0f, 1.0f); | |
259 | |
260 return gameObject; | |
261 | |
262 } | |
263 | |
264 /// <summary> | |
265 /// Component composition | |
266 /// </summary> | |
267 /// <returns> Composed game object. </returns> | |
268 static GameObject ComponentComposition(GameObject GO) | |
269 { | |
270 GO = new GameObject(); | |
271 GO.AddComponent<RectTransform>(); | |
272 GO.AddComponent<CanvasRenderer>(); | |
273 GO.AddComponent<Image>(); | |
274 GO.GetComponent<RectTransform>().sizeDelta = new Vector2(350f, 50f); | |
275 GO.GetComponent<Image>().color = new Color(7f / 255f, 45f / 255f, 71f / 255f, 200f / 255f); | |
276 | |
277 text = new GameObject(); | |
278 text.AddComponent<RectTransform>(); | |
279 text.AddComponent<CanvasRenderer>(); | |
280 text.AddComponent<Text>(); | |
281 text.GetComponent<RectTransform>().sizeDelta = new Vector2(350f, 50f); | |
282 text.GetComponent<Text>().font = (Font)Resources.Load("DINPro-Bold"); | |
283 text.GetComponent<Text>().alignment = TextAnchor.MiddleCenter; | |
284 | |
285 text.transform.parent = GO.transform; | |
286 text.name = "TextBox"; | |
287 | |
288 return GO; | |
289 } | |
290 | |
291 #endif | |
292 } |