Tanoda
TutorialManager.cs
Go to the documentation of this file.
1using System;
2using System.Collections;
3using System.Collections.Generic;
4using System.IO;
5using GILES;
6using GILES.Interface;
7using NaughtyAttributes;
8using UnityEngine;
9using UnityEngine.UI;
10using UnityEngine.SceneManagement;
11using System.Diagnostics;
12#if !UNITY_WEBGL
13using Valve.VR;
14using Valve.VR.InteractionSystem;
15using ViveHandTracking;
16#endif
17
18public class TutorialManager : MonoBehaviour
19{
20 public GameObject player, cube, Table, clone, target;
21 Vector3 playerOriginalPos, playerOriginalRot;
22 bool isHighlight = false;
23 bool first = false;
24 bool second = false;
25 bool third = false;
26 bool fourth = false;
27 bool rotated = false;
28 bool activated = false;
29 bool once = false;
30 bool attachedToHand;
31 private GameObject ProgressCanvas;
32 internal float holdTime = 2.0f;
33 private float currTime;
35 private bool inProgress= false;
36 private Transform originalProgressParent;
37 private Camera VRCamera;
38 private float realTime = 0.0f;
39 bool endOfProcess = false;
40#if DANA
41 public void Start()
42 {
43 ProgressCanvas = GameObject.Find("Canvas_ProgressBar").gameObject;
44 ProgressCanvas.GetComponentInChildren<Image>(true).fillAmount = 0;
45 currTime = holdTime * 2;
46 endOfProcess = false;
47 originalProgressParent = ProgressCanvas.transform.parent;
48 VRCamera = GameObject.Find("VRCamera")?.GetComponent<Camera>();
49 if (!VRCamera) //ha nincs vr, ne legyen null
50 VRCamera = Camera.current;
51 }
52 private void Update()
53 {
54#if !UNITY_WEBGL
55 var playerHands = Player.instance.hands;
56 Image Progress = ProgressCanvas.GetComponentInChildren<Image>(true);
57 List<bool> atph = new List<bool>();
58 foreach (var hand in playerHands)
59 {
60 var hh = hand.GetComponent<HackedHand>();
61 if (hh && hh.attachedToHand) atph.Add(true);
62 else if (hh && hh.realToolInHand) atph.Add(true);
63 }
64 if (attachedToHand)
65 {
66 StartCoroutine(LookAtCanvas());
67 if (!first && !once)
68 {
69 once = true;
70 speak("Miután megfogtuk az alkatrészt, a felvillanó kék modell jelzi, hogy hova kell tennünk azt.");
71 }
72 if (first && second && InGoodPos())
73 {
74 inProgress = true;
75 activated = true;
76 currTime -= Time.deltaTime;
77 ProgressCanvas.transform.SetParent(cube.transform, true);
78 if (!rotated)
79 {
80 ProgressCanvas.transform.localPosition = new Vector3(0, 0, 0);
81 ProgressCanvas.transform.position = ProgressCanvas.transform.position + new Vector3(0, 0.2f, 0);
82
83 rotated = true;
84 }
85
86 StartCoroutine(ProgressBar(holdTime, Progress, ProgressCanvas));
87 }
88 if (first && second && !InGoodPos())
89 {
90
91 inProgress = false;
92 ProgressCanvas.transform.GetChild(0).gameObject.SetActive(false);
93 }
95 return;
96 }
97 if (first && !second && !cube.GetComponent<TwoHandGrab>() && !once)
98 {
99 once = true;
100 StartCoroutine(latePreview(true));
101 speak("Amennyiben a modellünk körül két kezet látunk, az azt jelenti, hogy két kézzel kell megfognunk. Miután megfogtuk tegyük ezt is a helyére.");
102
103 }
104 if (first && second && !third && !once)
105 {
106 once = true;
107 speak("Szerszámok használatakor egy zöld modell fogja jelezni, hogy hol kell használnunk azt. A szerszámokat használat után vissza kell raknunk a helyükre, ezt jelzi a kék modell.");
108 if (cube.GetComponent<TwoHandGrab>())
109 {
110 Destroy(cube.GetComponent<TwoHandGrab>());
111 }
112 StartCoroutine(latePreview());
113 }
114 if (first && second && third && !once)
115 {
116 speak("A bemutató véget ért, a Start gomb megnyomásával tudjuk a jelenetet indítani!");
117 clone.SetActive(false);
118 target.SetActive(false);
119 once = true;
120 FinishTutorial();
121
122 }
123 if (atph.Count > 0)
124 {
125 attachedToHand = true;
126 MatChange(cube, true);
127 if (!first)
128 {
130 CubeHighlight(clone, new Vector3(40.9840012f, 1.11800003f, 0.569999993f));
131 FollowMe.Instance?.StartFollowing(clone.transform.position, clone);
132 }
133 if (first && !second)
134 {
136 CubeHighlight(clone, new Vector3(42.73f, 1.11800003f, 0.569999993f));
137 FollowMe.Instance?.StartFollowing(clone.transform.position, clone);
138 }
139 if (first && second)
140 {
141 speak("Amennyiben utasítást kapunk rá, a szerszámot egy bizonyos ideig kell a cél területen tartani. Azt , hogy meddig kell a helyén tartanunk, egy folyamat jelző sáv fogja jelezni. Akkor kell kivenni a szerszámot a cél pozícióból, amikor a jelző sáv eléri a zöldet, ellenkező esetben büntetést kapunk.");
143 CubeHighlight(target, new Vector3(41.97f, 1.525f, 0.569999993f));
144 FollowMe.Instance?.StartFollowing(clone.transform.position, clone);
145 }
146
147 }
148
149#endif
150 }
151 [Button]
152 public void StartTutorial()
153 {
154#if !UNITY_WEBGL
155 if (playerOriginalPos == null)
156 {
157 playerOriginalPos = player.transform.position;
158 playerOriginalRot = player.transform.eulerAngles;
159 }
160 player.transform.position = new Vector3(42.5f, 0, 0);
161 cube.SetActive(true);
162 Table.SetActive(true);
163 MatChange(cube);
164 clone.SetActive(true);
165 cube.GetComponent<ThrowableCanDisable>().enabled = true;
167 FollowMe.Instance?.StartFollowing(cube.transform.position, cube);
168
169 //tartCoroutine(LateSpeak("A folyamat elindítása után, ilyen hangutasítások fogják jelezni számunkra, hogy mit kell csinálnunk. Amennyiben messze vagyunk a céltól, a hangutasításon kívül egy kék szellem fogja jelezni, hogy merre kell mennünk. A kéken villogó modellt kell megfognunk."));
170 //StartCoroutine(LateStart());
171 speak("A folyamat elindítása után, ilyen hangutasítások fogják jelezni számunkra, hogy mit kell csinálnunk. Amennyiben messze vagyunk a céltól, a hangutasításon kívül egy kék szellem fogja jelezni, hogy merre kell mennünk. A kéken villogó modellt kell megfognunk.");
172 //MatChange(cube);
173
174 //cube.SetActive(true);
175 //Table.SetActive(true);
176 //clone.SetActive(true);
177 //PreviewHand.Instance?.EnterOffsetEditor(cube, "-", Vector3.zero, Vector3.zero);
178 //FollowMe.Instance?.StartFollowing(cube.transform.position, cube);
179#endif
180 }
181
182 IEnumerator LateStart()
183 {
184 while (!endOfProcess)
185 {
186 yield return null;
187 }
188#if !UNITY_WEBGL
189
190 MatChange(cube);
191 clone.SetActive(true);
192 cube.GetComponent<ThrowableCanDisable>().enabled = true;
194 FollowMe.Instance?.StartFollowing(cube.transform.position, cube);
195#endif
196 }
197 public void speak(string textToSpeak, string selectedLanguage = "hu-HU")
198 {
199#if DANA
200 var proc = VoiceTTS.Speak(textToSpeak, selectedLanguage);
201 BlurTheScene.Instance.showBlur(proc, textToSpeak);
202 StartCoroutine(waiter(proc));
203#endif
204 }
205 public IEnumerator waiter(Process p)
206 {
207 while (!p.HasExited)
208 {
209 yield return null;
210 }
212 endOfProcess = true;
213 yield return null;
214
215 }
216 IEnumerator LateSpeak(string textToSpeak, string selectedLanguage = "hu-HU")
217 {
218 yield return new WaitForSeconds(1);
219#if DANA
220 var proc = VoiceTTS.Speak(textToSpeak, selectedLanguage);
221 BlurTheScene.Instance.showBlur(proc, textToSpeak);
222 StartCoroutine(waiter(proc));
223#endif
224 }
225 private IEnumerator latePreview(bool twohand = false)
226 {
227 yield return new WaitForSeconds(0.5f);
228#if !UNITY_WEBGL
229 if (twohand && !cube.GetComponent<TwoHandGrab>()) cube.AddComponent<TwoHandGrab>();
230 MatChange(cube);
232 FollowMe.Instance?.StartFollowing(cube.transform.position, cube);
233#endif
234 }
235 public void CubeHighlight(GameObject obj ,Vector3 TargetPos)
236 {
237 isHighlight = true;
238
239 obj.transform.position = TargetPos;
240 obj.SetActive(true);
241
242 }
243 [Button]
244 public void FinishTutorial()
245 {
246 player.transform.position = playerOriginalPos;
247 //player.transform.eulerAngles = playerOriginalRot;
249 cube.SetActive(false);
250 Table.SetActive(false);
251 clone.SetActive(false);
252 target.SetActive(false);
253 var StartCanvas = FindObjectOfType<StartCanvas>(true).canvas;
254 StartCanvas.SetActive(true);
255 GetComponent<TutorialManager>().enabled = false;
256
257 }
258
259 private bool InGoodPos()
260 {
261 Vector3 local;
262 var targetPosition = target.transform.localPosition;
263 local = target.transform.InverseTransformPoint(cube.transform.position);
264 if (Math.Abs(local.x) > 0.1f) return false;
265 if (Math.Abs(local.y) > 0.1f) return false;
266 if (Math.Abs(local.z) > 0.1f) return false;
267
268 return true;
269 }
270 private void MatChange(GameObject go, bool changeMat = false)
271 {
272 var mrs = go.GetComponentsInChildren<MeshRenderer>();
273
274 foreach (var meshRenderer in mrs)
275 {
276 var list = new List<Material>();
277 for (var i = 0; i < meshRenderer.materials.Length; i++) list.Add(changeMat ? originalHighlight : highlightMaterial);
278 meshRenderer.materials = list.ToArray();
279
280 }
281 }
282
283 private IEnumerator ProgressBar(float value, Image progressImage, GameObject progressCanvas)
284 {
285 float time = realTime;
286 float fill = 0;
287 float deltaTime = 0;
288 progressCanvas.transform.GetChild(0).gameObject.SetActive(true);
289 //progressImage.fillAmount = 0;
290 Color yellow = new Color(250 / 255f, 250 / 255f, 6 / 255f);
291 Color red = new Color(250 / 255f, 13 / 255f, 6 / 255f);
292 Color green = new Color(11 / 255f, 250 / 255f, 6 / 255f);
293 //progressImage.color = yellow;
294 while (inProgress && progressImage.fillAmount < 1)
295 {
296 time += Time.deltaTime;
297 if (progressImage.fillAmount <= 0.30f)
298 {
299 progressImage.color = yellow;
300
301 }
302
303 fill = progressImage.fillAmount - 0.3f;
304 if (progressImage.fillAmount >= 0.30f && progressImage.fillAmount <= 0.36f)
305 {
306 progressImage.color = Color.Lerp(yellow, green, fill / 0.06f);
307 }
308 fill = progressImage.fillAmount - 0.58f;
309 if (progressImage.fillAmount >= 0.58f && progressImage.fillAmount <= 0.64f)
310 {
311 progressImage.color = Color.Lerp(green, red, fill / 0.06f);
312 }
313
314 if (progressImage.fillAmount <= 0.36f)
315 {
316 progressImage.fillAmount = Mathf.Lerp(0, 0.36f, time / ((value) * 0.9f));
317
318 }
319 deltaTime = time - ((value) * 0.9f);
320 if (progressImage.fillAmount >= 0.36f && progressImage.fillAmount <= 0.64f)
321 {
322 progressImage.fillAmount = Mathf.Lerp(0.36f, 0.64f, deltaTime / (value * 2 * 0.1f));
323 }
324 deltaTime = time - ((value) * 1.1f);
325 if (progressImage.fillAmount >= 0.64f)
326 {
327 progressImage.fillAmount = Mathf.Lerp(0.64f, 1, deltaTime / ((value * 2) - (value * 1.1f)));
328 }
329
330 yield return null;
331 }
332 realTime = time;
333
334 }
335
336 private IEnumerator LookAtCanvas()
337 {
338 while (activated)
339 {
340 ProgressCanvas.transform.LookAt(VRCamera.transform);
341 yield return null;
342 }
343 }
344 public void actionCounter()
345 {
346 attachedToHand = false;
347 once = false;
348 if (!first)
349 {
350 first = true;
351 return;
352 }
353 if (!second)
354 {
355 second = true;
356 return;
357 }
358 ProgressCanvas.transform.SetParent(originalProgressParent);
359 if (!third)
360 {
361 third = true;
362 return;
363 }
364
365 }
366#endif
367}
Es.InkPainter.Math Math
Definition: PaintTest.cs:7
UnityEngine.UI.Button Button
Definition: Pointer.cs:7
System.Drawing.Image Image
Definition: TestScript.cs:37
UnityEngine.Color Color
Definition: TestScript.cs:32
void showBlur(Process p, string text)
Definition: BlurTheScene.cs:57
static BlurTheScene Instance
Definition: BlurTheScene.cs:17
void hideBlur()
Definition: BlurTheScene.cs:66
void StopFollowing()
Definition: FollowMe.cs:28
void StartFollowing(Vector3 EndPosition, GameObject TargetObject)
Definition: FollowMe.cs:35
static FollowMe Instance
Definition: FollowMe.cs:19
void hideHandPreview(GameObject objectToGrab)
Definition: PreviewHand.cs:73
void EnterOffsetEditor(GameObject objectToGrab, ActionObject action, Vector3 TargetPos, Vector3 TargetRot)
Definition: PreviewHand.cs:40
static PreviewHand Instance
Definition: PreviewHand.cs:16
GameObject canvas
Definition: StartCanvas.cs:11
Material highlightMaterial
GameObject target
GameObject Table
Material originalHighlight
GameObject clone
GameObject player