-
Notifications
You must be signed in to change notification settings - Fork 0
/
SceneAndUiManager.cs
107 lines (95 loc) · 3.11 KB
/
SceneAndUiManager.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
#if UNITY_5_3_OR_NEWER
using UnityEngine.SceneManagement;
#endif
using FairyGUI;
public class SceneAndUiManager : MonoBehaviour
{
public SceneAndUiManager()
{
}
static SceneAndUiManager _instance;
public static SceneAndUiManager inst
{
get
{
if (_instance == null)
{
GameObject go = new GameObject("SceneAndUiManager");
DontDestroyOnLoad(go);
_instance = go.AddComponent<SceneAndUiManager>();
}
return _instance;
}
}
Dictionary <string, string> levelScenesInterfacesIndex;
Dictionary <string, int> _levelDictionary;
Dictionary <string, int> _uiDictionary;
List<GComponent> _sceneLevels;
GComponent _sceneLoaderView;
public void Init()
{
_sceneLoaderView = UIPackage.CreateObject("CutScene", "CutScene").asCom;
_sceneLoaderView.SetSize(GRoot.inst.width, GRoot.inst.height);
_sceneLoaderView.AddRelation(GRoot.inst, RelationType.Size);
_sceneLevels = new List<GComponent>();
_levelDictionary = new Dictionary<string,int>();
_uiDictionary = new Dictionary<string,int>();
}
public void SetlevelScenesInterfacesIndex(Dictionary <string, string> _levelScenesInterfacesIndex)
{
levelScenesInterfacesIndex = _levelScenesInterfacesIndex;
foreach(KeyValuePair<string, string> entry in levelScenesInterfacesIndex)
{
SetSceneForUse(entry.Key, entry.Value);
}
}
void SetSceneForUse(string sceneName, string interfaceName)
{
if (!_uiDictionary.ContainsKey(interfaceName)) {
int c = _uiDictionary.Count;
_uiDictionary[interfaceName] = c;
_sceneLevels.Add(UIPackage.CreateObject("CutScene", interfaceName).asCom);
_sceneLevels[c].SetSize(GRoot.inst.width, GRoot.inst.height);
_sceneLevels[c].AddRelation(GRoot.inst, RelationType.Size);
} else {
_levelDictionary[sceneName] = _uiDictionary[interfaceName];
}
Debug.Log(_uiDictionary);
Debug.Log(_levelDictionary);
Debug.Log(_sceneLevels);
_sceneLevels[_uiDictionary[interfaceName]].GetChild(sceneName).onClick.Add(() =>
{
LoadLevel(sceneName);
});
}
public void LoadLevel(string levelName)
{
StartCoroutine(DoLoad(levelName));
GRoot.inst.AddChild(_sceneLoaderView);
}
IEnumerator DoLoad(string sceneName)
{
GRoot.inst.AddChild(_sceneLoaderView);
GProgressBar pb = _sceneLoaderView.GetChild("pb").asProgress;
pb.value = 0;
#if UNITY_5_3_OR_NEWER
AsyncOperation op = SceneManager.LoadSceneAsync(sceneName);
#else
AsyncOperation op = Application.LoadLevelAsync(sceneName);
#endif
float startTime = Time.time;
while (!op.isDone || pb.value != 100)
{
int value = (int)((Time.time - startTime) * 100f / 3f);
if (value > 100)
value = 100;
pb.value = value;
yield return null;
}
GRoot.inst.RemoveChild(_sceneLoaderView);
GRoot.inst.AddChild(_sceneLevels[_uiDictionary[levelScenesInterfacesIndex[sceneName]]]);
}
}