Tanoda
GazeRestarter.cs
Go to the documentation of this file.
1using System.Collections;
2using System.Collections.Generic;
3using GILES;
4using UnityEngine;
6using UnityEngine.SceneManagement;
7
8public class GazeRestarter : MonoBehaviour
9{
10 public GameObject[] hide;
11 private float percent = 0.05f;
12 private MeshRenderer mr;
13 private Material mat;
14 public bool done = false;
15 public static GazeRestarter instance;
16
17 public UnityEvent OnStart;
18
19 private IEnumerator Start()
20 {
21 if (!SavedUser.instance.isTutorial)
22 {
23 Destroy(gameObject);
24 yield break;
25 }
26
27 if (instance && instance != this)
28 {
29 Destroy(this);
30 yield break;
31 }
32
33 instance = this;
34 mr = GetComponent<MeshRenderer>();
35 mat = mr.material;
36
37 //DontDestroyOnLoad(gameObject);
38
39 //mr.enabled = false;
40 //foreach (var o in hide)
41 //{
42 // o.SetActive(false);
43 //}
44 while (LoadingManager.instance.isLoading)
45 {
46 yield return new WaitForEndOfFrame();
47 }
48 }
49
50 public void OnLevelEnded()
51 {
52 StartCoroutine(LevelEnded());
53 }
54
55 IEnumerator LevelEnded()
56 {
57 yield return new WaitForSeconds(10);
58
59 var go = new GameObject("TutorialInjector");
60 var ti = go.AddComponent<TutorialInjector>();
61 ti.loadScene = 2;
62 DontDestroyOnLoad(go);
63
66 {
67 yield return new WaitForEndOfFrame();
68 }
69
70 FindObjectOfType<FollowScript>().gameObject.SetActive(false);
71
72 var canvases = FindObjectsOfType<Canvas>();
73 var srs = FindObjectsOfType<SpriteRenderer>();
74 foreach (var canvas in canvases)
75 {
76 canvas.enabled = false;
77 }
78 foreach (var sr in srs)
79 {
80 sr.enabled = false;
81 }
82
83 yield return new WaitForSeconds(0.5f);
84
85 HashingManager.instance.ClearHashTable();
86 pb_Scene.instance.Clear();
88
89 StartCoroutine(FindObjectOfType<LevelEditorOnLoaded>().Replay());
90
91 Destroy(gameObject);
92 yield break;
93
94 while (SceneManager.GetActiveScene().buildIndex != 2)
95 {
96 yield return null;
97 }
98
99 yield return new WaitForSeconds(0.5f);
100
101 while (LoadingManager.instance.isLoading)
102 {
103 yield return new WaitForEndOfFrame();
104 }
105 mr.enabled = true;
106
107 foreach (var o in hide)
108 {
109 o.SetActive(true);
110 }
111 //TutorialManager.instance.StopLoading();
112 //TablePositionSetter.instance.gameObject.SetActive(false);
113 yield return new WaitForSeconds(5.5f);
114 }
115
116
117 private void Update()
118 {
119 if (!GazePickupHelper.instance || done) return;
120
121 if (GazePickupHelper.instance.target != gameObject)
122 {
123 percent -= 0.01f;
124 if (percent <= 0.05f)
125 {
126 percent = 0.05f;
127 }
128 }
129 else
130 {
131 percent += 0.01f;
132 if (percent >= 1.0f)
133 {
134 percent = 1.0f;
135 done = true;
136 //TutorialManager.instance.RestartTut();
137 OnStart?.Invoke();
138 mr.enabled = false;
139 foreach (var o in hide)
140 {
141 o.SetActive(false);
142 }
143 mat.SetFloat("_Cutoff", 0.95f);
144 return;
145 }
146 }
147
148 mat.SetFloat("_Cutoff", 1f - percent);
149 }
150}
void ClearAll()
Definition: Controller.cs:719
static Controller Instance
Definition: Controller.cs:16
static FadeOut instance
Definition: FadeOut.cs:9
bool allBlack
Definition: FadeOut.cs:11
void FadeOutNow()
Definition: FadeOut.cs:24
static GazePickupHelper instance
GameObject[] hide
void OnLevelEnded()
static GazeRestarter instance
UnityEvent OnStart