Tanoda
MiscLogicManager.cs
Go to the documentation of this file.
1using System;
2using System.Collections;
3using System.Collections.Generic;
4using System.Text;
5using GILES;
6using GILES.Interface;
7using NaughtyAttributes;
8using UnityEngine;
10#if !UNITY_WEBGL
11using Valve.VR;
12using Valve.VR.InteractionSystem;
13#endif
14
15public class MiscLogicManager : pb_MonoBehaviourSingleton<MiscLogicManager>
16{
17 public enum CurrentMode
18 {
19
20 Training,
21 Exam,
22 Optimization
23 }
24
25 public bool LowMemoryMode = false;
26
27 public CurrentMode mode = CurrentMode.Training;
28
29 public GameObject[] right, left;
30 public GameObject[] teleport;
31 public GameObject handPicker;
32 public bool UseItemCollision = false;
33
35 public UnityEvent onDobotMode, onVarjoFound;
36//#if UNITY_EDITOR
37 [SerializeField] private bool EditorForceVarjo = false;
38//#endif
39
40 IEnumerator Start()
41 {
42 mode = (CurrentMode)SavedUser.instance.TrainingType;
43 if (SavedUser.instance.courseType == SavedUser.CourseType.Dobot)
44 {
45 onDobotMode?.Invoke();
46 }
47 yield return new WaitForSeconds(0.5f);
48
49 while (LoadingManager.instance.isLoading)
50 {
51 yield return new WaitForEndOfFrame();
52 }
53
54 var player = GameObject.Find("Player");
55 while (!player)
56 {
57 yield return new WaitForSeconds(0.1f);
58 player = GameObject.Find("Player");
59 }
60
61 if (SavedUser.instance.handTracking > 0)
62 {
63 if (SavedUser.instance.handTracking == 1)
64 {
65 if (left != null)
66 foreach (var o in left)
67 {
68 o.SetActive(false);
69 }
70 }
71 else
72 {
73 if (right != null)
74 foreach (var o in right)
75 {
76 o.SetActive(false);
77 }
78 }
79 }
80#if !UNITY_WEBGL
81 var model = new StringBuilder(128);
82 var manufacturer = new StringBuilder(128);
83 ETrackedPropertyError error = ETrackedPropertyError.TrackedProp_Success;
84 for (uint i = 0; i < 17; i++)
85 {
86 model.Clear();
87 manufacturer.Clear();
88
89 if (OpenVR.System != null)
90 {
91 OpenVR.System.GetStringTrackedDeviceProperty(i, ETrackedDeviceProperty.Prop_ModelNumber_String,
92 model,
93 128, ref error);
94 OpenVR.System.GetStringTrackedDeviceProperty(i, ETrackedDeviceProperty.Prop_ManufacturerName_String,
95 manufacturer,
96 128, ref error);
97 var deviceclass = OpenVR.System.GetTrackedDeviceClass(i);
98
99 if (deviceclass == ETrackedDeviceClass.HMD && manufacturer.ToString() == "Varjo" && model.ToString() == "hedy")
100 {
101 handPicker.SetActive(false);
102 onVarjoFound?.Invoke();
103 SavedUser.instance?.SetVarjoBool(true);
104 break;
105 }
106 }
107 }
108#endif
109
110 pb_Scene.instance.EnablePhysics();
111
112 onLoadingFinished?.Invoke();
113 pb_Hierarchy.instance.RebuildInspector();
114 yield return new WaitForEndOfFrame();
115#if !UNITY_WEBGL
116 var allTcd = pb_Scene.instance.transform.GetComponentsInChildren<ThrowableCanDisable>();
118 foreach (var tcd in allTcd)
119 {
120 tcd.ResetPosition();
121 }
122#endif
123//#if UNITY_EDITOR
124 if (EditorForceVarjo)
125 {
126 handPicker.SetActive(false);
127 onVarjoFound?.Invoke();
128 SavedUser.instance?.SetVarjoBool(true);
129 }
130//#endif
131 GC.Collect();
132 }
133
135 {
136 handPicker?.SetActive(false);
137 GameObject.Find("SteamVR_Tracker")?.SetActive(false);
138 }
139
140 internal bool canTeleport = true;
141 public void CanUseTeleport(bool value)
142 {
143 canTeleport = value;
144 if (teleport != null)
145 {
146 foreach (var o in teleport)
147 {
148 o.SetActive(value);
149 }
150 }
151 }
152
153 public void SetTeleportSize()
154 {
156 pb_SelectionHandle.instance.SetTool(Tool.Scale);
157 }
158
159 public void SetTeleportSize(Vector3 size)
160 {
161 if(teleport[0])
162 teleport[0].transform.localScale = size;
163 }
164
165 public Vector3 GetTeleportSize()
166 {
167 return teleport[0] ? teleport[0].transform.localScale : Vector3.zero;
168 }
169
170 public void LevelFailed(float time = 0.0f)
171 {
172#if !DANA
173 VRPopupManager.instance.SetText(Macro.T("LEVEL_FAILED") + (time == 0.0f ? "" : "\n" + Macro.T("YOUR_TIME")+ ": " + Mathf.FloorToInt(time / 60).ToString("D2") + ":" + (time % 60).ToString("00.00").Replace(',', '.')));
174#else
175 VRPopupManager.instance.SetText("LEVEL FAILED!","-", "-", "-","-");
176#endif
177 VRPopupManager.instance.ShowPopup();
178 VRPopupManager.instance.HideAfter(5.0f);
179 OnEnded?.Invoke();
180 }
181 [Button]
182 public void LevelEnded(float time = 0.0f, float accuracy = 0.0f, float focus = 0.0f, float performance = 0.0f)
183 {
184#if !DANA
185 VRPopupManager.instance.SetText(Macro.T("LEVEL_ENDED") + (time == 0.0f ? "" : "\n" + Macro.T("YOUR_TIME") + ": " + Mathf.FloorToInt(time / 60).ToString("D2") + ":" + (time % 60).ToString("00.00").Replace(',', '.')));
186#else
187 VRPopupManager.instance.SetText("LEVEL ENDED!",
188 Mathf.FloorToInt(time / 60).ToString("D2") + ":" + (time % 60).ToString("00.00").Replace(',', '.'),
189 Mathf.FloorToInt(accuracy).ToString("D0") + "%",
190 Mathf.FloorToInt(focus).ToString("D0") + "%",
191 Mathf.FloorToInt(performance).ToString("D0") + "%"); //Az idő eredmények helyett, fókusz, hatékonyság, és összesített teljesítmény szerepel
192#endif
193
194 //Mathf.FloorToInt(myBestTime / 60).ToString("D2") + ":" + (myBestTime % 60).ToString("00.00").Replace(',', '.'),
195 //Mathf.FloorToInt(bestTime / 60).ToString("D2") + ":" + (bestTime % 60).ToString("00.00").Replace(',', '.'),
196 //Mathf.FloorToInt(avgTime / 60).ToString("D2") + ":" + (avgTime % 60).ToString("00.00").Replace(',', '.'));
197
198 VRPopupManager.instance.ShowPopup();
199 //VRPopupManager.instance.HideAfter(5.0f);
200 TurnOnReplayButton();
201 OnEnded?.Invoke();
202 }
203
204 public UnityEvent OnEnded = new UnityEvent();
205
206 public bool previewLock = false;
207
208 private static void TurnOnReplayButton()
209 {
210#if !UNITY_WEBGL
211 var iris = GameObject.Find("iris_position_helper");
212 if (!iris) return;
213 var replay = iris.transform.GetComponentsInChildren<InteractableHoverEvents>(true);
214 foreach (var interactableHoverEventse in replay)
215 {
216 if (interactableHoverEventse.name == "ReplayPOI")
217 {
218 interactableHoverEventse.gameObject.SetActive(true);
219 }
220 }
221#endif
222 }
223
224 public void OffsetEditorHelper(Transform attachPoint, GameObject objectToGrab, OffsetHolder offsetHolder, Canvas canvas, Canvas canvasOffsetEditor, bool editingLeft)
225 {
226 StartCoroutine(offsetEditorHelper(attachPoint, objectToGrab, offsetHolder, canvas, canvasOffsetEditor, editingLeft));
227 }
228 public void OffsetEditorHelper(Transform attachPoint, GameObject objectToGrab, GameObjectAction offsetHolder, Canvas canvas, Canvas canvasOffsetEditor, bool editingLeft)
229 {
230 StartCoroutine(offsetEditorHelper(attachPoint, objectToGrab, offsetHolder, canvas, canvasOffsetEditor, editingLeft));
231 }
232
233 private IEnumerator offsetEditorHelper(Transform attachPoint, GameObject objectToGrab, OffsetHolder offsetHolder, Canvas canvas, Canvas canvasOffsetEditor, bool editingLeft)
234 {
235 attachPoint.transform.SetParent(objectToGrab.transform, true);
236 yield return null;
237
238 if (editingLeft)
239 {
240 offsetHolder.LeftOffset = attachPoint.localPosition;
241 offsetHolder.LeftRotation = attachPoint.localRotation.eulerAngles;
242 }
243 else
244 {
245 offsetHolder.Offset = attachPoint.localPosition;
246 offsetHolder.Rotation = attachPoint.localRotation.eulerAngles;
247 }
248
249 if (attachPoint.gameObject != null) Destroy(attachPoint.gameObject);
250
252
253 canvas.enabled = true;
254 canvasOffsetEditor.enabled = false;
255 }
256
257 private IEnumerator offsetEditorHelper(Transform attachPoint, GameObject objectToGrab, GameObjectAction offsetHolder, Canvas canvas, Canvas canvasOffsetEditor, bool editingLeft)
258 {
259 attachPoint.transform.SetParent(objectToGrab.transform, true);
260 yield return null;
261
262 if (editingLeft)
263 {
264 offsetHolder.LeftOffset = attachPoint.localPosition;
265 offsetHolder.LeftRotation = attachPoint.localRotation.eulerAngles;
266 }
267 else
268 {
269 offsetHolder.Offset = attachPoint.localPosition;
270 offsetHolder.Rotation = attachPoint.localRotation.eulerAngles;
271 }
272
273 if (attachPoint.gameObject != null) Destroy(attachPoint.gameObject);
274
276
277 canvas.enabled = true;
278 canvasOffsetEditor.enabled = false;
279 }
280
281
282}
UnityEngine.UI.Button Button
Definition: Pointer.cs:7
static void SetSelection(IEnumerable< GameObject > selection)
Definition: pb_Selection.cs:92
static void Clear()
Definition: pb_Selection.cs:61
Definition: Macro.cs:12
static string T(string key)
Definition: Macro.cs:19
static void cacheAllTCD()
Definition: Macro.cs:430
UnityEvent onDobotMode
void CanUseTeleport(bool value)
GameObject handPicker
Vector3 GetTeleportSize()
void OffsetEditorHelper(Transform attachPoint, GameObject objectToGrab, OffsetHolder offsetHolder, Canvas canvas, Canvas canvasOffsetEditor, bool editingLeft)
void LevelFailed(float time=0.0f)
void SetTeleportSize(Vector3 size)
void LevelEnded(float time=0.0f, float accuracy=0.0f, float focus=0.0f, float performance=0.0f)
GameObject[] teleport
GameObject[] left
GameObject[] right
UnityEvent onVarjoFound
Callback onLoadingFinished
void OffsetEditorHelper(Transform attachPoint, GameObject objectToGrab, GameObjectAction offsetHolder, Canvas canvas, Canvas canvasOffsetEditor, bool editingLeft)
Vector3 Offset
Definition: OffsetHolder.cs:7
Vector3 LeftRotation
Definition: OffsetHolder.cs:10
Vector3 Rotation
Definition: OffsetHolder.cs:8
Vector3 LeftOffset
Definition: OffsetHolder.cs:9
delegate void Callback()
Tool
Definition: pb_Enum.cs:24