Пример #1
0
        /// <summary>
        /// 切换场景
        /// </summary>
        /// <param name="sceneID"></param>
        /// <param name="param"></param>
        /// <param name="onloaded"></param>
        /// <param name="isback"></param>
        /// <param name="addSceneBackStack"></param>
        public void ChangeScene(int sceneID, SceneParam param, Action onloaded, bool sceneUIPush, bool isback, bool addSceneBackStack = false)
        {
            int currSceneID = this.GetSceneID();

            if (currSceneID == sceneID)
            {
                Debug.Log("ChangeScene current scene is the target....sceneID:" + sceneID);

                return;
            }

            if (this.IsLoading())
            {
                Debug.Log("ChangeScene current scene is loading...." + currSceneID + "  " + sceneID);

                return;
            }

            if (currSceneID != -1)
            {
                Debug.Log("StopMusic  " + currSceneID);

                SoundComponent.Instance.Stop("bgSound");
            }

            this.LoadScene(sceneID, param, onloaded, sceneUIPush, isback, addSceneBackStack);
        }
Пример #2
0
 /// <summary>
 /// 返回上个场景
 /// </summary>
 /// <param name="param"></param>
 /// <param name="onloaded"></param>
 public void Back(SceneParam param, Action onloaded)
 {
     if (this.lastSceenID != -1)
     {
         this.ChangeScene(this.lastSceenID, param, onloaded, false, true);
     }
 }
Пример #3
0
        /// <summary>
        ///加载场景
        /// </summary>
        /// <param name="param"></param>
        /// <param name="onComplete"></param>
        /// <param name="isback"></param>
        public void Load(SceneParam param, Action onComplete = null, bool isback = false)
        {
            this.sceneParam = param;

            this.onLoadComplete = onComplete;

            this.SceneLoadState = (int)SceneDefine.LoadState.None;

            this.isBack = isback;

            //调用加载
            SceneManagerComponent.instance.ChangeSceneAsync(this.SceneName, DoSceneLoader);
        }
Пример #4
0
        /// <summary>
        /// 叠加场景
        /// </summary>
        /// <param name="sceneID"></param>
        /// <param name="param"></param>
        public void LoadAdditiveScene(int sceneID, SceneParam param)
        {
            SceneBase newScene = this.CreateScene(sceneID);

            if (newScene == null)
            {
                return;
            }

            newScene.Load(param);

            this.bgScene = newScene;
        }
Пример #5
0
        /// <summary>
        /// 返回上次记录的场景,如果上次记录为空,则返回上个场景
        /// </summary>
        /// <param name="param"></param>
        /// <param name="onloaded"></param>
        public void PopSceneStack(SceneParam param, Action onloaded)
        {
            int count = this.sceneBackStack.Count;

            if (count > 0)
            {
                int sceneId = this.sceneBackStack[count - 1];

                this.sceneBackStack.RemoveAt(count - 1);

                this.ChangeScene(sceneId, param, onloaded, false, true);
            }
            else
            {
                this.Back(param, onloaded);
            }
        }
Пример #6
0
        public SceneBase(SceneConfig sceneConfig)
        {
            this.SceneType = sceneConfig.SceneType;

            this.SceneId = sceneConfig.SceneId;

            this.SceneName = sceneConfig.SceneName;

            this.SceneFolder = sceneConfig.SceneFolder;

            this.SceneLoadState = sceneConfig.SceneLoadState;

            this.SceneMusic = sceneConfig.SceneMusic;

            this.sceneRoot = null;//根节hko

            this.isEnter = false;

            this.sceneParam = null;//切换场景,外部传入的参数
        }
Пример #7
0
        /// <summary>
        /// 场景加载完成,通知业务可以实例化对象了
        /// </summary>
        public void OnLoaded(SceneParam param = null)
        {
            Transform root = GameObject.Find("SceneRoot").transform;

            if (root != null)
            {
                //找到场景节点
                this.sceneRoot = root;

                //初始化UI信息,并保持相关引用
                SceneUIHelper.MainCamera = null;

                SceneUIHelper.SceneUIRoot = null;

                if (SceneUIHelper.SceneUIRoot != null)
                {
                    SceneUIHelper.SceneCanvas = SceneUIHelper.SceneUIRoot.GetComponent <Canvas>();
                }
            }
        }
Пример #8
0
        /// <summary>
        /// 根据场景ID加载新的场景
        /// </summary>
        /// <param name="sceneID"></param>
        /// <param name="param"></param>
        /// <param name="onloaded"></param>
        /// <param name="isback"></param>
        /// <param name="sceneBackStackPush"></param>
        private void LoadScene(int sceneID, SceneParam param, Action onloaded, bool sceneUIPush, bool isback, bool sceneBackStackPush)
        {
            //新建下一个场景
            SceneBase newScene = this.CreateScene(sceneID);

            if (newScene == null)
            {
                return;
            }

            int lastSceneId = this.GetSceneID();

            if (sceneBackStackPush)
            {
                this.sceneBackStack.Add(lastSceneId);
            }

            //缷载旧的场景

            this.lastSceenID = lastSceneId;

            SceneBase lastScene = this.currScene;

            if (lastScene != null)
            {
                string lastSceneName = lastScene.GetSceneName();

                int lastSceneType = lastScene.GetSceneType();

                //退出当前场景并通知UI关闭当前场景UI
                this.ExitCurrent(sceneUIPush);

                //清理当前场景缓存的对象,终止正在加载的队列
                if (lastSceneType != newScene.GetSceneType())
                {
                    SceneUIHelper.UnloadSceneAB(lastSceneName, false);
                }

                SceneUIHelper.MainScene = null;

                SceneUIHelper.MainCamera = null;

                SceneUIHelper.SceneUIRoot = null;

                //除了登陆场景,其他场景切换均有场景过渡

                if (lastSceneType != (int)SceneDefine.SceneType.LOGIN)
                {
                    //如果参数里标记了使用CUTSCENE过渡,那么不要打开这个普通过渡 界面

                    bool useNormalTransition = true;

                    if (param != null)
                    {
                        if (param.UseCutSceneTransition)
                        {
                            useNormalTransition = false;
                        }
                        else if (param.useCivSceneTransition)
                        {
                            useNormalTransition = false;

                            //打开一个加载界面
                        }
                    }

                    if (useNormalTransition)
                    {
                        //打开正常的加载过渡界面
                    }
                }
            }

            this.currScene = newScene;

            //通知开始加载新场景

            SceneUIHelper.MainScene = newScene;

            newScene.Load(param, onloaded, isback);

            //发送场景切换事件
        }