Tanoda
pb_LoadSceneButton.cs
Go to the documentation of this file.
1using UnityEngine;
2using System.Collections;
3using GILES.Interface;
4using System.IO;
5using System.Collections.Generic;
6using Newtonsoft.Json;
7using UnityEngine.SceneManagement;
8using System;
9
10namespace GILES
11{
16 {
18
19 public override string tooltip { get { return ""; } }
20
24 public void OpenLoadPanel()
25 {
26 pb_FileDialog dlog = GameObject.Instantiate(dialogPrefab);
27 dlog.SetDirectory(System.IO.Directory.GetCurrentDirectory());
28 dlog.isFileBrowser = true;
29 dlog.filePattern = "*.json";
30 dlog.AddOnSaveListener(OnOpen);
31
32 pb_ModalWindow.SetContent(dlog.gameObject);
33 pb_ModalWindow.SetTitle("Open Scene");
35 }
36
37 private void OnOpen(string path)
38 {
39#if DANA
40 //if (SavedUser.instance.isEditor) Open(path);
41 //else
42 //{
43 StartCoroutine(Open2(path));
44 //}
45
46
47#else
48 Open(path);
49#endif
50 }
51
52 public void Open(string path)
53 {
54 string san = pb_FileUtility.SanitizePath(path);
55
56 if(!pb_FileUtility.IsValidPath(san, ".json"))
57 {
58 Debug.LogWarning(san + " not found, or file is not a JSON scene.");
59 return;
60 }
61
62 string level = pb_FileUtility.ReadFile(san);
63
64 HashingManager.instance.ClearHashTable();
65 var filename = System.IO.Path.GetFileName(san);
66 filename = filename.Remove(filename.LastIndexOf('.'));
67 pb_Scene.instance.currentLevelName = filename;
68 pb_Scene.LoadLevel(level);
70 }
71
72 public IEnumerator Open2(string path)
73 {
74 Clear();
77 string san = pb_FileUtility.SanitizePath(path);
78
79 if (!pb_FileUtility.IsValidPath(san, ".json"))
80 {
81 Debug.LogWarning(san + " not found, or file is not a JSON scene.");
82 yield break;
83 }
84 string level = pb_FileUtility.ReadFile(san);
85 var go = new GameObject("loader");
86 var ssol = go.AddComponent<StartStageOnLoad>();
87 var filename = System.IO.Path.GetFileName(san);
88 filename = filename.Remove(filename.LastIndexOf('.'));
89 ssol.lastLevelName = filename;
90 ssol.stageJson = level;
91 ssol.levelName = Path.GetFileName(san);
92
93 ssol.filesToLoad = new List<string>();
94 var json = File.ReadAllText(san);
95 var scenenodeJson = json.Remove(Macro.FindClosingBracketIndex(json) + 1).Remove(0, 1);
96 var sceneNode = JsonConvert.DeserializeObject<GILES.Serialization.pb_SceneNode>(scenenodeJson, GILES.Serialization.pb_Serialization.ConverterSettings);
97 //pb_Scene.LoadLevel(level); miƩrt??
98 Macro.GetAllPossibleFileName(sceneNode, ref ssol.filesToLoad);
99 yield return null;
101 pb_Scene.instance.currentLevelName = filename;
102
103 SavedUser.instance.levelName = Path.GetFileName(san);
104
106
107 while (LoadingManager.instance.isLoading)
108 {
109 yield return null;
110 }
111 pb_Scene.instance.LoadEnvAndTools();
112 yield return null;
113 pb_Scene.LoadLevel(level);
114 yield return null;
115
117 }
118 public void Clear()
119 {
120 try
121 {
122 GameObject.Find("EpilepsyFixer").SetActive(true);
123 }
124 catch (Exception)
125 {
126 // ignored
127 }
128
129#if !UNITY_WEBGL
130 //Destroy(Valve.VR.InteractionSystem.Player.instance);
131 Destroy(FindObjectOfType<PreventDestroy>());
132#if !DANA
133 Destroy(GameObject.Find("CurrentUser"));
134 Destroy(GameObject.Find("SavedUser Singleton"));
135#endif
136 Destroy(GameObject.Find("NetworkManager"));
137 Destroy(GameObject.Find("[ChaperoneInfo]"));
138 Destroy(GameObject.Find("pb_AssetBundles Singleton"));
139#endif
140 //var Players = GameObject.FindGameObjectsWithTag("Player");
141 //foreach (var player in Players)
142 // {
143 // if (!player.GetComponent<DoNotDestroyThis>()) Destroy(player.gameObject);
144 // }
145#if UNITY_5_2
146 Application.LoadLevel(scene);
147#else
148 HashingManager.instance.ClearHashTable();
149 pb_Scene.instance.Clear();
150 pb_Hierarchy.instance.RebuildInspector();
152 PanoramaManager.instance.ClearImage();
153#endif
154
155 }
156
157 }
158}
UnityEngine.Debug Debug
Definition: TanodaServer.cs:19
void ClearAll()
Definition: Controller.cs:719
static Controller Instance
Definition: Controller.cs:16
string filePattern
If isFileBrowser is true, this string my be used to filter file results (see https://msdn....
void AddOnSaveListener(Callback< string > listener)
void SetDirectory(string directory)
static void SetTitle(string title)
static void SetContent(GameObject prefab)
void LoadJsonsFile(StartStageOnLoad ssol)
void Reload(bool global=false)
static pb_PrefabBrowser instance
IEnumerator Open2(string path)
static void LoadLevel(string levelJson, bool ssol=false)
Definition: pb_Scene.cs:238
Definition: Macro.cs:12
static void GetAllPossibleFileName(GILES.Serialization.pb_SceneNode node, ref List< string > list)
Definition: Macro.cs:213
static int FindClosingBracketIndex(string text, char openedBracket='{', char closedBracket='}')
Definition: Macro.cs:249
static ManipulatorArm instance
static ToolPositioner instance