Tanoda
LevelEditorOnLoaded.cs
Go to the documentation of this file.
1using System.Collections;
2using System.Collections.Generic;
3using GILES;
4using UnityEngine;
5using UnityEngine.SceneManagement;
6#if !UNITY_WEBGL
7using Valve.VR.InteractionSystem;
8#endif
9
10public class LevelEditorOnLoaded : MonoBehaviour
11{
13 public bool AutoStartStages = false;
14 public GameObject[] hideFromUser;
15 internal string lastLoadedJson = "";
16 internal string lastLoadedName = "";
17
18 public IEnumerator Replay()
19 {
20 //Destroy(GameObject.Find("Player"));
21 yield return new WaitForEndOfFrame();
22 //pb_Scene.LoadLevel(lastLoadedJson, true);
23 var go = new GameObject("ssol");
24 var ssol = go.AddComponent<StartStageOnLoad>();
25 ssol.lastLevelName = lastLoadedName;
26 ssol.stageJson = lastLoadedJson;
27 yield return new WaitForEndOfFrame();
28 SceneManager.LoadScene(1);
29 }
30
31 public IEnumerator Start()
32 {
33 instance = this;
34 yield return new WaitForEndOfFrame();
35#if UNITY_WEBGL || USENETWORK
36 LoadingManager.instance.SetSyncing();
37 LoadingManager.instance.ShowWindow();
38 LoadingManager.instance.timeout += 10;
39 LoadingManager.instance.MainLoading = true;
40 yield return NetworkManager.instance.LoadAllFilesForThisCourse(() => Debug.Log("Downloaded all files for this course!"),
41 error =>
42 {
43 LoadingManager.instance.HideWindow();
44 PopupManager.instance.ShowPopup("Network Failure", "Failed to download course assets!\n" + error);
45 });
46 yield return NetworkManager.instance.LoadAllGlobalFiles(() => Debug.Log("Downloaded all global files!"),
47 error =>
48 {
49 LoadingManager.instance.HideWindow();
50 PopupManager.instance.ShowPopup("Network Failure", "Failed to download global assets!\n" + error);
51 });
52 LoadingManager.instance.MainLoading = false;
53#endif
54 var ssol = FindObjectOfType<StartStageOnLoad>();
55 bool wasssol = false;
56 if (ssol)
57 {
58 wasssol = true;
59 while (LoadingManager.instance.isLoading)
60 {
61 yield return new WaitForEndOfFrame();
62 }
63
64 pb_Scene.instance.currentLevelName = ssol.lastLevelName;
65 pb_Scene.LoadLevel(ssol.stageJson, true);
66 lastLoadedName = ssol.lastLevelName;
67 lastLoadedJson = ssol.stageJson;
68 Destroy(ssol.gameObject);
69 }
70 if (SavedUser.instance.currentUser.HasValue && SavedUser.instance.currentUser.Value.Access == UserManager.UserType.User)
71 {
72 foreach (var o in hideFromUser)
73 {
74 o.SetActive(false);
75 }
76 }
77
78 yield return new WaitForEndOfFrame(); // Controller loading starts
79
81 {
82 yield return new WaitForEndOfFrame();
83 }
84
85 yield return new WaitForEndOfFrame(); // Wait 1 extra frame
86
88 {
89 var startAction = FindObjectOfType<StartAction>();
90 if (startAction)
91 {
92 startAction.Play();
93 }
94 }
95
96 if (wasssol)
97 {
98#if !UNITY_WEBGL
99 var hoverObjects = FindObjectsOfType<InteractableHoverEvents>();
100 foreach (var e in hoverObjects)
101 {
102 e.onHandHoverEnd.Invoke();
103 }
104#endif
105 }
106 }
107
108 public void StartStages()
109 {
110 if (SavedUser.instance.isEditor)
111 {
112 return;
113 }
114 var startAction = FindObjectOfType<StartAction>();
115 if (startAction)
116 {
117 startAction.Play();
118 ReplayLogic.instance.StageStarted = true;
119 }
120
121 ConveyorBeltManager.instance.InitItems();
122 ConveyorBeltManager.instance.started = true;
123 }
124
126 {
127 if (SavedUser.instance.isEditor)
128 {
129 return;
130 }
131 var startActions = FindObjectsOfType<StartAction>();
132 foreach (var startAction in startActions)
133 {
134 if (startAction.inPuts == null || startAction.outPuts == null)
135 {
136 Destroy(startAction.gameObject);
137 continue;
138 }
139 if (startAction.transform.parent == null)
140 {
141 Destroy(startAction.gameObject);
142 continue;
143 }
144 startAction.Play();
145 ReplayLogic.instance.StageStarted = true;
146 }
147
148
149 ConveyorBeltManager.instance.InitItems();
150 ConveyorBeltManager.instance.started = true;
151 }
152}
UnityEngine.Debug Debug
Definition: TanodaServer.cs:19
bool isLoading
Definition: Controller.cs:28
static Controller Instance
Definition: Controller.cs:16
static void LoadLevel(string levelJson, bool ssol=false)
Definition: pb_Scene.cs:238
static LevelEditorOnLoaded instance