/// <summary> /// Clears the scene. /// </summary> /// <param name="sceneName">Scene name.</param> protected virtual void ClearScene(string sceneName = "") { List <string> keys = new List <string> (); foreach (var pair in scenes) { if (pair.Key == sceneName) { continue; } SSceneController ctrl = pair.Value.GetComponent <SSceneController> (); if (ctrl.IsCache) { OnDeativeScreen(pair.Value); } else { keys.Add(pair.Key); } } foreach (string key in keys) { DestroyScene(key); } popups.Clear(); ClearShield(); }
/// <summary> /// Callbacks the request. /// </summary> /// <param name="data">Data.</param> /// <param name="www">Www.</param> protected virtual void CallbackRequest() { Log(); Action innerCallback = () => { popUp = null; if (response != null) { if (!response(www)) { return; } } if (data.finishedDelegate != null) { data.finishedDelegate(www); } }; if (popUp != null) { SceneManager.Instance.Close(delegate { innerCallback(); }); } else { innerCallback(); } }
protected virtual void Update() { if (Input.GetKeyDown(KeyCode.Escape)) { SSceneController ctrl = null; if (popups.Count > 0) { ctrl = scenes [popups.Peek()].GetComponent <SSceneController> (); } else { foreach (var pair in scenes) { if (pair.Value.activeSelf) { ctrl = pair.Value.GetComponent <SSceneController> (); break; } } } if (ctrl == null) { Close(); } else { ctrl.OnKeyBack(); } } }
protected virtual void Awake() { if (instance == null) { instance = this; #if !UNITY_5_3_OR_NEWER DontDestroyOnLoad(gameObject); #endif } popUp = null; }
/// <summary> /// Destories the main menu. /// </summary> public virtual void DestoryMainMenu() { if (menuSceneName == "") { return; } if (mainMenu != null) { DestroyScenesFrom(menuSceneName); mainMenu = null; } }
/// <summary> /// Loads the main menu. /// </summary> /// <param name="active">Active.</param> /// <param name="deactive">Deactive.</param> public virtual void LoadMainMenu(SceneCallbackDelegate active = null, SceneCallbackDelegate deactive = null) { if (menuSceneName == "") { // HDebug.LogWarning ("The default menu scene is not set"); return; } LoadMenu(menuSceneName, null, delegate(SSceneController ctrl) { mainMenu = ctrl; if (active != null) { active(ctrl); } }, deactive); }
/// <summary> /// Close this pop up only. /// </summary> public virtual void Close(CallbackDelegate callback = null) { if (popups.Count <= 0) { return; } string sceneName = popups.Peek(); if (scenes.ContainsKey(sceneName)) { GameObject root = scenes [sceneName]; SSceneController ctrl = root.GetComponent <SSceneController> (); ctrl.callback = callback; if (ctrl.IsCache) { OnDeativeScreen(root); } else { DestroyScene(sceneName); } popups.Pop(); GameObject shield = LastShield(true); if (shield != null) { shields.Remove(shield); Destroy(shield); } } else { if (callback != null) { callback(); } } }
/// <summary> /// Clears the menu. /// </summary> protected virtual void ClearMenu() { List <string> keys = new List <string> (); foreach (var pair in menus) { SSceneController ctrl = pair.Value.GetComponent <SSceneController> (); if (ctrl.IsCache) { OnDeativeScreen(pair.Value); } else { keys.Add(pair.Key); } } foreach (string key in keys) { DestroyScene(key); } }
/// <summary> /// Request the specified data and post. /// </summary> /// <param name="data">HttpData.</param> /// <param name="post">If set to <c>true</c> post.</param> public void Request(HttpData data, Http.FinishedDelegate finish = null) { time = Time.time; Action innerRequest = () => { if (preReuqest != null) { data = preReuqest(data); } this.data = data; Http http; #if UNITY_5_4_OR_NEWER if (data.method == UnityWebRequest.kHttpVerbPOST) { #else if (data.post) { #endif http = new Http(this, data.url); http.AddRangeData(data.datas); } else { http = new Http(this, data.url, data.datas); } #if UNITY_5_4_OR_NEWER http.method = data.method; http.audioType = data.audioType; http.OnFail = (UnityWebRequest www) => { this.www = www; OnFail(); }; http.OnDisposed = (UnityWebRequest www) => { this.www = www; OnDisposed(); }; http.OnDone = (UnityWebRequest www) => { this.www = www; OnDone(); }; #else http.OnFail = (WWW www) => { this.www = www; OnFail(); }; http.OnDisposed = (WWW www) => { this.www = www; OnDisposed(); }; http.OnDone = (WWW www) => { this.www = www; OnDone(); }; #endif // set headers http.Headers = data.headers; // set timeout time http.Timeout = data.timeout; http.Request(); }; if (finish != null) { data.finishedDelegate = finish; } if (data.popUp) { if (SceneManager.Instance.DefaultLoadingJobSceneName != "") { if (SceneManager.Instance.IsLoadingJob) { HDebug.LogWarning("Now loading scene active"); } SceneManager.Instance.PopUp(SceneManager.Instance.DefaultLoadingJobSceneName, null, delegate(SSceneController ctrl) { popUp = ctrl; innerRequest(); }); } else { HDebug.LogWarning("The default loading scene is not set"); } } else { innerRequest(); } }
/// <summary> /// Loads the main menu. /// </summary> /// <param name="active">Active.</param> /// <param name="deactive">Deactive.</param> public virtual void LoadMainMenu(SceneCallbackDelegate active = null, SceneCallbackDelegate deactive = null) { if (menuSceneName == "") { // HDebug.LogWarning ("The default menu scene is not set"); return; } LoadMenu (menuSceneName, null, delegate(SSceneController ctrl) { mainMenu = ctrl; if (active != null) { active (ctrl); } }, deactive); }
/// <summary> /// Destories the main menu. /// </summary> public virtual void DestoryMainMenu() { if (menuSceneName == "") { return; } if (mainMenu != null) { DestroyScenesFrom (menuSceneName); mainMenu = null; } }
/// <summary> /// Loads the level. /// </summary> /// <param name="loadLevelData">Load level data.</param> protected virtual void LoadLevel(LoadLevelData loadLevelData) { switch (loadLevelData.type) { case SceneType.Popup: case SceneType.Screen: case SceneType.AddScreen: if (scenes.ContainsKey(loadLevelData.sceneName)) { GameObject root = scenes [loadLevelData.sceneName]; if (!root.activeSelf) { if (loadLevelData.type == SceneType.Popup) { DistancePopUp(root); popups.Push(loadLevelData.sceneName); } if (loadLevelData.type != SceneType.Popup) { ClearScene(loadLevelData.sceneName); } if (loadLevelData.type == SceneType.AddScreen) { screens.Push(loadLevelData.sceneName); } } OnActiveScreen(root); SSceneController ctrl = root.GetComponent <SSceneController> (); ctrl.OnReset(loadLevelData.data); return; } // ugui if (uIType == UIType.UGUI) { if (loadLevelData.type != SceneType.Popup) { ClearEventSystem(loadLevelData.sceneName); } } break; case SceneType.Menu: if (menus.ContainsKey(loadLevelData.sceneName)) { GameObject root = menus [loadLevelData.sceneName]; OnActiveScreen(root); return; } break; } bool isAddtive = false; if (loadLevelData.type == SceneType.Menu || loadLevelData.type == SceneType.Popup) { isAddtive = true; } SSceneApplication.LoadLevel(loadLevelData.sceneName, delegate(GameObject root) { root.transform.parent = scene.transform; root.transform.localPosition = Vector3.zero; SSceneRoot sRoot = root.GetComponent <SSceneRoot> (); foreach (Camera cam in sRoot.Cameras) { AudioListener audio = cam.GetComponent <AudioListener> (); if (audio != null) { audio.enabled = false; } // ngui if (uIType == UIType.NGUI) { if (nGUICamera == null) { if (cam.GetComponent("UICamera") != null) { cam.clearFlags = CameraClearFlags.Depth; nGUICamera = Instantiate(cam.gameObject) as GameObject; nGUICamera.name = "UICamera"; nGUICamera.transform.parent = gCamera.transform; nGUICamera.transform.localPosition = Vector3.zero; nGUICamera.SetActive(true); cam.gameObject.SetActive(false); } } else { if (loadLevelData.type != SceneType.Popup && cam.GetComponent("UICamera") != null) { cam.gameObject.SetActive(false); } } } } if (sRoot.EventSystem != null) { eventSystem = sRoot.EventSystem.gameObject; } SSceneController ctrl = root.GetComponent <SSceneController> (); if (ctrl == null) { HDebug.LogError("No SceneController."); return; } ctrl.active = loadLevelData.active; ctrl.deactive = loadLevelData.deactive; switch (loadLevelData.type) { case SceneType.Screen: case SceneType.AddScreen: ctrl.OnSet(loadLevelData.data); scenes.Add(loadLevelData.sceneName, root); ClearScene(loadLevelData.sceneName); if (screenStartChange != null) { screenStartChange(loadLevelData.sceneName); } if (loadLevelData.type == SceneType.AddScreen) { screens.Push(loadLevelData.sceneName); } break; case SceneType.Popup: scenes.Add(loadLevelData.sceneName, root); DistancePopUp(root); popups.Push(loadLevelData.sceneName); ctrl.OnSet(loadLevelData.data); if (popUpStart != null) { popUpStart(loadLevelData.sceneName); } break; case SceneType.Menu: ctrl.OnSet(loadLevelData.data); menus.Add(loadLevelData.sceneName, root); if (menuStart != null) { menuStart(loadLevelData.sceneName); } break; } if (uIType == UIType.NGUI) // ngui { if (nGUICamera != null) { MonoBehaviour uicam = nGUICamera.GetComponent <MonoBehaviour> (); uicam.enabled = false; uicam.enabled = true; } } }, isAddtive); }
/// <summary> /// Callbacks the request. /// </summary> /// <param name="data">Data.</param> /// <param name="www">Www.</param> protected virtual void CallbackRequest (HttpData data, WWW www) { Action innerCallback = () => { popUp = null; if (response != null) { if (!response (www)) { return; } } if (data.finishedDelegate != null) { data.finishedDelegate (www); } }; if (popUp != null) { SceneManager.Instance.Close (delegate { innerCallback (); }); } else { innerCallback (); } }
protected virtual void Awake () { if (instance == null) { instance = this; #if !UNITY_5_3 && !UNITY_5_4 DontDestroyOnLoad (gameObject); #endif } popUp = null; }
public virtual void Awake() { isCache = false; ctrl = this; }
/// <summary> /// Request the specified data and post. /// </summary> /// <param name="data">HttpData.</param> /// <param name="post">If set to <c>true</c> post.</param> public void Request (HttpData data, bool post) { time = Time.time; Action innerRequest = () => { if (preReuqest != null) { data = preReuqest (data); } Http http; if (post) { // post reuqest http = new Http (this, data.url); http.Headers = data.headers; foreach (KeyValuePair<string, string> kVP in data.datas) { http.AddData (kVP.Key, kVP.Value); } } else { // get request http = new Http (this, data.url, data.datas); } // Set timeout time. http.Timeout = data.timeout; http.OnFail = (WWW www) => { OnFail (data, www); }; http.OnDisposed = (WWW www) => { OnDisposed (data, www); }; http.OnDone = (WWW www) => { OnDone (data, www); }; http.Request (); }; if (data.popUp) { if (SceneManager.Instance.DefaultLoadingJobSceneName != "") { if (SceneManager.Instance.IsLoadingJob) { HDebug.LogWarning ("Now loading scene active"); } SceneManager.Instance.PopUp (SceneManager.Instance.DefaultLoadingJobSceneName, null, delegate(SSceneController ctrl) { popUp = ctrl; innerRequest (); }); } else { HDebug.LogWarning ("The default loading scene is not set"); } } else { innerRequest (); } }