少年修仙传客户端代码仓库
client_Zxw
2018-08-30 861522f900702bf928f4ee4857bfef90e1939711
Fight/Stage/StageManager.cs
@@ -76,6 +76,8 @@
    public bool isLoading { get; private set; }
    StageLoadTimeOutCatcher loadTimeOutCatcher;
    public StageManager()
    {
        DebugEx.LogFormat("初始化StageManager");
@@ -83,6 +85,9 @@
    public void Load<T>(int stageId) where T : Stage
    {
        loadTimeOutCatcher = StageLoadTimeOutCatcher.Begin(stageId);
        // 读取配置的方式创建场景
        var mapResConfig = DTCA127_tagMCStartChangeMap.GetMapResourcesConfig();
@@ -129,10 +134,10 @@
    {
        if (currentMapResId != 0 && currentMapResId == mapResConfigID)
        {
            //OperationLogCollect.Instance.BugReport("Warning", "StageManager Load Same MapID:" + mapResConfigID);
#if UNITY_EDITOR
            Debug.LogFormat("StageManager出现加载相同地图行为:" + mapResConfigID);
#endif
            ExceptionCatcher.ReportException("场景加载 Step1", StringUtility.Contact("StageManager出现加载相同地图行为:", mapResConfigID));
            yield break;
        }
@@ -148,6 +153,7 @@
        catch (Exception ex)
        {
            Debug.LogError("场景加载开始事件发生异常:" + ex);
            ExceptionCatcher.ReportException("场景加载 Step2", ex);
        }
        var progressBuf = loadingProgress = 0f;
@@ -162,42 +168,49 @@
        SystemSetting.Instance.LetFPSUnLimit();
        WindowCenter.Instance.asyncLoad.StopAllTasks();
        //为什么在这个地方要调用两次关闭其他窗口的接口呢,这个水就深了。
        //因为有些界面被关闭的时候,会去打开主界面,所以,还得再关闭一次关闭其他窗口的界面,防止主界面被意外开启。
        switch (_stageId)
        try
        {
            case 2:
                WindowCenter.Instance.DestoryWinsByStage(WindowCenter.WindowStage.Login);
                WindowCenter.Instance.CloseOthers<LaunchBackGroundWin>();
                if (!WindowCenter.Instance.CheckOpen<LaunchBackGroundWin>())
                {
                    WindowCenter.Instance.Open<LaunchBackGroundWin>(true);
                }
            WindowCenter.Instance.asyncLoad.StopAllTasks();
            //为什么在这个地方要调用两次关闭其他窗口的接口呢,这个水就深了。
            //因为有些界面被关闭的时候,会去打开主界面,所以,还得再关闭一次关闭其他窗口的界面,防止主界面被意外开启。
            switch (_stageId)
            {
                case 2:
                    WindowCenter.Instance.DestoryWinsByStage(WindowCenter.WindowStage.Login);
                    WindowCenter.Instance.CloseOthers<LaunchBackGroundWin>();
                    if (!WindowCenter.Instance.CheckOpen<LaunchBackGroundWin>())
                    {
                        WindowCenter.Instance.Open<LaunchBackGroundWin>(true);
                    }
                WindowCenter.Instance.CloseOthers<LaunchBackGroundWin>();
                break;
            case 1:
                WindowCenter.Instance.DestoryWinsByStage(WindowCenter.WindowStage.Launch);
                WindowCenter.Instance.CloseOthers<LaunchBackGroundWin>();
                if (!WindowCenter.Instance.CheckOpen<LaunchBackGroundWin>())
                {
                    WindowCenter.Instance.Open<LaunchBackGroundWin>(true);
                }
                    WindowCenter.Instance.CloseOthers<LaunchBackGroundWin>();
                    break;
                case 1:
                    WindowCenter.Instance.DestoryWinsByStage(WindowCenter.WindowStage.Launch);
                    WindowCenter.Instance.CloseOthers<LaunchBackGroundWin>();
                    if (!WindowCenter.Instance.CheckOpen<LaunchBackGroundWin>())
                    {
                        WindowCenter.Instance.Open<LaunchBackGroundWin>(true);
                    }
                WindowCenter.Instance.CloseOthers<LaunchBackGroundWin>();
                break;
            default:
                WindowCenter.Instance.DestoryWinsByStage(WindowCenter.WindowStage.SelectRole);
                WindowCenter.Instance.CloseOthers<LoadingWin>();
                if (!WindowCenter.Instance.CheckOpen<LoadingWin>())
                {
                    LoadingWin.targetMapResId = currentMapResId;
                    WindowCenter.Instance.Open<LoadingWin>(true);
                }
                    WindowCenter.Instance.CloseOthers<LaunchBackGroundWin>();
                    break;
                default:
                    WindowCenter.Instance.DestoryWinsByStage(WindowCenter.WindowStage.SelectRole);
                    WindowCenter.Instance.CloseOthers<LoadingWin>();
                    if (!WindowCenter.Instance.CheckOpen<LoadingWin>())
                    {
                        LoadingWin.targetMapResId = currentMapResId;
                        WindowCenter.Instance.Open<LoadingWin>(true);
                    }
                WindowCenter.Instance.CloseOthers<LoadingWin>();
                break;
                    WindowCenter.Instance.CloseOthers<LoadingWin>();
                    break;
            }
        }
        catch (System.Exception ex)
        {
            ExceptionCatcher.ReportException("场景加载 Step3", ex);
        }
        loadingProgress += 0.05f;
@@ -225,15 +238,21 @@
        GC.Collect();
        loadingProgress += 0.1f;
        if (!AssetSource.sceneFromEditor)
        try
        {
            AssetBundleUtility.Instance.UnloadAssetBundle("maps/map000_xsdt", true, false);
            AssetBundleUtility.Instance.UnloadAssetBundle(GetAssetBundleNameByStageId(lastMapId, lastCurrentMapResId), true, false);
            AssetBundleUtility.Instance.Sync_LoadAll(GetAssetBundleNameByStageId(currentMapId, currentMapResId));
            if (!AssetSource.sceneFromEditor)
            {
                AssetBundleUtility.Instance.UnloadAssetBundle("maps/map000_xsdt", true, false);
                AssetBundleUtility.Instance.UnloadAssetBundle(GetAssetBundleNameByStageId(lastMapId, lastCurrentMapResId), true, false);
                AssetBundleUtility.Instance.Sync_LoadAll(GetAssetBundleNameByStageId(currentMapId, currentMapResId));
            }
        }
        catch (System.Exception ex)
        {
            ExceptionCatcher.ReportException("场景加载 Step4", ex);
        }
        var sceneLoadOperation = SceneManager.LoadSceneAsync(_resources);
        progressBuf = loadingProgress;
        timer = 0f;
        duration = 1f;
@@ -251,14 +270,21 @@
                yield return null;
            }
            // 如果用户尚未完成前期战斗部分
            if (!PreFightMission.Instance.IsFinished())
            try
            {
                if (!AssetSource.sceneFromEditor)
                // 如果用户尚未完成前期战斗部分
                if (!PreFightMission.Instance.IsFinished())
                {
                    AssetBundleUtility.Instance.Sync_LoadAll("maps/map000_xsdt");
                    if (!AssetSource.sceneFromEditor)
                    {
                        AssetBundleUtility.Instance.Sync_LoadAll("maps/map000_xsdt");
                    }
                    SceneManager.LoadScene("Map000_Xsdt", LoadSceneMode.Additive);
                }
                SceneManager.LoadScene("Map000_Xsdt", LoadSceneMode.Additive);
            }
            catch (System.Exception ex)
            {
                ExceptionCatcher.ReportException("场景加载 Step5", ex);
            }
        }
@@ -268,13 +294,27 @@
        // 场景加载完就可以确定玩家位置了, 不需要等待具体场景的逻辑初始化
        if (_stageId > 2)
        {
            InitHero();
            try
            {
                InitHero();
            }
            catch (System.Exception ex)
            {
                ExceptionCatcher.ReportException("场景加载 Step6", ex);
            }
        }
        GameObject _gameObject = new GameObject(string.Format("__Stage_{0}_", _resources));
        m_CurrentStage = _gameObject.AddComponent<T>();
        m_StageType = m_CurrentStage is DungeonStage ? Stage.E_StageType.Dungeon : Stage.E_StageType.MainCity;
        m_CurrentStage.mapId = _stageId;
        try
        {
            GameObject _gameObject = new GameObject(string.Format("__Stage_{0}_", _resources));
            m_CurrentStage = _gameObject.AddComponent<T>();
            m_StageType = m_CurrentStage is DungeonStage ? Stage.E_StageType.Dungeon : Stage.E_StageType.MainCity;
            m_CurrentStage.mapId = _stageId;
        }
        catch (System.Exception ex)
        {
            ExceptionCatcher.ReportException("场景加载 Step7", ex);
        }
        yield return null;
@@ -325,13 +365,22 @@
        catch (Exception ex)
        {
            Debug.LogError("场景加载完成事件发生异常:" + ex);
            ExceptionCatcher.ReportException("场景加载 Step8", ex);
        }
        if (loadTimeOutCatcher != null)
        {
            loadTimeOutCatcher.Stop();
        }
        loadTimeOutCatcher = null;
        Application.backgroundLoadingPriority = ThreadPriority.BelowNormal;
        isLoading = false;
        DebugEx.LogFormat("StageManager => Load Scene : {0} Finished.", _resources);
        WindowCenter.Instance.Close<LoadingWin>();
        SystemSetting.Instance.SetFPSLimit(SystemSetting.Instance.GetFPSLimit());
    }
    IEnumerator BackToNoviceVillageWhileMapResourceLacked(int _mapResId)