Exemplo n.º 1
0
        /// <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);
        }