private void CloseImpl(Action <IWindowController> callback = null)
 {
     gameObject.SetActive(false);
     OnClose();
     Manager.Close(this);
     callback?.Invoke(this);
 }
示例#2
0
 public void Close(Action <IWindowController> callback = null)
 {
     gameObject.SetActive(false);
     Manager.Close(this);
     OnClose();
 }
示例#3
0
        /// <summary>
        /// 加载场景,这里使用的async加载方式
        /// </summary>
        /// <param name="sceneID"></param>
        /// <param name="callBackBeforeChanging"></param>
        /// <param name="callBackAfterChanging"></param>
        /// <param name="loadingUIPath"></param>
        /// <param name="needFading"></param>
        /// <param name="fadingTime"></param>
        /// <param name="isAdditive"></param>
        public void ChangeScene(int sceneID, Action callBackBeforeChanging = null, Action callBackAfterChanging = null, string loadingUIPath = null, bool needFading = true, float fadingTime = 0.5f, bool isAdditive = false)
        {
            if (FrameworkConfig.Instance.UseHotFixMode)
            {
                _iUIManger = HotFix.UIManager.Instance;
            }
            else
            {
                _iUIManger = Mono.UIManager.Instance;
            }

            //No UIloading && No Fading
            if (string.IsNullOrEmpty(loadingUIPath) && !needFading)
            {
                callBackBeforeChanging?.Invoke();

                _asyncOperation = SceneLoadManager.Instance.LoadSceneAsync(sceneID, isAdditive);
                _asyncOperation.allowSceneActivation = false;
                while (_asyncOperation.progress < 0.9f)
                {
                }
                _asyncOperation.allowSceneActivation = true;

                LitTool.LitTool.WaitUntilFunction(() => { return(_asyncOperation.isDone); }, () => { callBackAfterChanging?.Invoke(); });
            }

            //No UIloading && Fading
            else if (string.IsNullOrEmpty(loadingUIPath) && needFading)
            {
                _iUIManger.ShowFade(() =>
                {
                    callBackBeforeChanging?.Invoke();

                    _asyncOperation = SceneLoadManager.Instance.LoadSceneAsync(sceneID, isAdditive);
                    _asyncOperation.allowSceneActivation = false;
                    while (_asyncOperation.progress < 0.9f)
                    {
                    }
                    _asyncOperation.allowSceneActivation = true;

                    LitTool.LitTool.WaitUntilFunction(() => { return(_asyncOperation.isDone); }, () => { callBackAfterChanging?.Invoke(); });

                    _iUIManger.HideFade(time: fadingTime);
                }, fadingTime);
            }

            //UIloading && No Fading
            else if (!string.IsNullOrEmpty(loadingUIPath) && !needFading)
            {
                // 默认占用0帧
                LoadingTaskModel.Instance.AddTask(0, () =>
                {
                    callBackBeforeChanging?.Invoke();

                    _asyncOperation = SceneLoadManager.Instance.LoadSceneAsync(sceneID, isAdditive);
                    _asyncOperation.allowSceneActivation = false;
                    return(true);
                }, true);

                // 默认占用1帧 牺牲了场景加载的进度性
                LoadingTaskModel.Instance.AddTask(1, () =>
                {
                    bool over = _asyncOperation.progress >= 0.9f;
                    return(over);
                }, true);
                //场景加载完成后的回调
                LoadingTaskModel.Instance.AddTask(90, () =>
                {
                    _iUIManger.ShowFade(() =>
                    {
                        _asyncOperation.allowSceneActivation = true;
                    }, fadingTime);
                    return(true);
                }, true);
                //场景加载完成后的回调
                LoadingTaskModel.Instance.AddTask(100, () =>
                {
                    LoadingTaskModel.Instance.ClearTask();
                    callBackAfterChanging?.Invoke();

                    _iUIManger.Close(loadingUIPath);
                    return(true);
                }, true);

                _iUIManger.Show(loadingUIPath);
            }

            //UIloading && Fading
            else
            {
                _iUIManger.ShowFade(() =>
                {
                    //显示UILoading
                    _iUIManger.HideFade(() =>
                    {
                        _iUIManger.Show(loadingUIPath);
                    }, fadingTime);

                    // 默认占用0帧
                    LoadingTaskModel.Instance.AddTask(0, () =>
                    {
                        callBackBeforeChanging?.Invoke();

                        _asyncOperation = SceneLoadManager.Instance.LoadSceneAsync(sceneID, isAdditive);
                        _asyncOperation.allowSceneActivation = false;
                        return(true);
                    }, true);

                    // 默认占用1帧 牺牲了场景加载的进度性
                    LoadingTaskModel.Instance.AddTask(1, () =>
                    {
                        bool over = _asyncOperation.progress >= 0.9f;
                        return(over);
                    }, true);

                    //场景加载完成后的回调
                    LoadingTaskModel.Instance.AddTask(90, () =>
                    {
                        _iUIManger.ShowFade(() =>
                        {
                            _asyncOperation.allowSceneActivation = true;
                        }, fadingTime);
                        return(true);
                    }, true);

                    //场景加载完成后的回调
                    LoadingTaskModel.Instance.AddTask(100, () =>
                    {
                        _iUIManger.ShowFade(() =>
                        {
                            callBackAfterChanging?.Invoke();

                            _iUIManger.Close(loadingUIPath);
                            _iUIManger.HideFade(() => { LoadingTaskModel.Instance.ClearTask(); }, fadingTime);
                        }, fadingTime);
                        return(true);
                    }, true);
                }, fadingTime);
            }
        }