少年修仙传客户端代码仓库
client_Wu Xijin
2019-01-31 d905e6523a7ef223e581cf7ca652345b654efec9
3335 场景切换重构
6个文件已修改
316 ■■■■■ 已修改文件
Core/GameEngine/DataToCtl/RoleLoginState.cs 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
Fight/PreFightMission.cs 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
Fight/Stage/StageLoad.cs 130 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Fight/Stage/StageLoadProcessor.cs 127 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
System/AssetVersion/AssetVersionUtility.cs 7 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Utility/StageLoadTimeOutCatcher.cs 48 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Core/GameEngine/DataToCtl/RoleLoginState.cs
@@ -32,7 +32,7 @@
            WindowCenter.Instance.Open<DisconnectHintWin>();
        }
        if (StageLoad.Instance.IsWaitFor0109(ServerType.Main))
        if (!StageLoad.Instance.IsServerPrepareOk(ServerType.Main))
        {
            return;
        }
Fight/PreFightMission.cs
@@ -156,7 +156,7 @@
                if (h0827.MissionState == 1)
                {
                    if (!StageLoad.Instance.IsWaitFor0109(ServerType.Main))
                    if (StageLoad.Instance.IsServerPrepareOk(ServerType.Main))
                    {
                        HandlerMission(h0827.MissionID);
                    }
Fight/Stage/StageLoad.cs
@@ -43,6 +43,7 @@
    ServerFlag serverFlag_0109;
    ServerFlag serverFlag_0403;
    float loadStartTime = 0f;
    public bool isLoading { get; private set; }
    public int mapIdRecord { get; private set; }
@@ -57,56 +58,70 @@
    {
        var tasks = new Queue<StageLoadProcessor.StageLoadTask>();
        var needChangeScene = false;
        switch (command.toMapId)
        {
            case 1:
            case 2:
            case 3:
                needChangeScene = true;
                break;
            default:
                if (command.fromMapId != command.toMapId)
                {
                    needChangeScene = true;
                }
                else
                {
                    var config1 = MapResourcesConfig.GetConfig(MapUtility.GetDataMapId(command.fromMapId), command.fromLineId);
                    var config2 = MapResourcesConfig.GetConfig(MapUtility.GetDataMapId(command.toMapId), command.toLineId);
                    needChangeScene = config1.MapResources != config2.MapResources;
                }
                break;
        }
        if (needChangeScene)
        {
            tasks.Enqueue(new StageLoadProcessor.PreProcessTask(command));
            tasks.Enqueue(new StageLoadProcessor.UnLoadAndGCTask(command));
        }
        if (needChangeScene && command.needEmpty)
        {
            tasks.Enqueue(new StageLoadProcessor.LoadEmptyTask(command));
        }
        if (needChangeScene)
        {
            tasks.Enqueue(new StageLoadProcessor.LoadNewSceneTask(command));
        }
        if (!command.isClientLoadMap)
        var assetValid = AssetVersionUtility.IsSceneAssetValid(command.toMapId, command.toLineId);
        if (!assetValid)
        {
            tasks.Enqueue(new StageLoadProcessor.Wait0109Task(command));
            if (command.serverType == ServerType.Main)
            {
                tasks.Enqueue(new StageLoadProcessor.WaitLoginCompleteTask(command));
            }
            tasks.Enqueue(new StageLoadProcessor.WaitSecondsTask(command, 1));
            tasks.Enqueue(new StageLoadProcessor.ReturnToNoviceVillageTask(command));
        }
        if (needChangeScene)
        else
        {
            tasks.Enqueue(new StageLoadProcessor.PostProcessTask(command));
            var needChangeScene = false;
            switch (command.toMapId)
            {
                case 1:
                case 2:
                case 3:
                    needChangeScene = true;
                    break;
                default:
                    if (command.fromMapId != command.toMapId)
                    {
                        needChangeScene = true;
                    }
                    else
                    {
                        var config1 = MapResourcesConfig.GetConfig(MapUtility.GetDataMapId(command.fromMapId), command.fromLineId);
                        var config2 = MapResourcesConfig.GetConfig(MapUtility.GetDataMapId(command.toMapId), command.toLineId);
                        needChangeScene = config1.MapResources != config2.MapResources;
                    }
                    break;
            }
            if (needChangeScene)
            {
                tasks.Enqueue(new StageLoadProcessor.PreProcessTask(command));
                tasks.Enqueue(new StageLoadProcessor.UnLoadAndGCTask(command));
            }
            if (needChangeScene && command.needEmpty)
            {
                tasks.Enqueue(new StageLoadProcessor.LoadEmptyTask(command));
            }
            if (needChangeScene)
            {
                tasks.Enqueue(new StageLoadProcessor.LoadNewSceneTask(command));
            }
            if (!command.isClientLoadMap)
            {
                tasks.Enqueue(new StageLoadProcessor.Wait0109Task(command));
                if (command.serverType == ServerType.Main)
                {
                    tasks.Enqueue(new StageLoadProcessor.WaitLoginCompleteTask(command));
                }
            }
            if (needChangeScene)
            {
                tasks.Enqueue(new StageLoadProcessor.PostProcessTask(command));
            }
        }
        serverFlag_0109 = default(ServerFlag);
@@ -116,6 +131,9 @@
        DontDestroyOnLoad(gameObject);
        stageLoadProcessor = gameObject.AddComponent<StageLoadProcessor>();
        stageLoadProcessor.Begin(tasks);
        StageLoadTimeOutCatcher.Begin(command.toMapId);
        loadStartTime = Time.time;
        isLoading = true;
    }
@@ -126,6 +144,7 @@
        isLoading = false;
        if (stageLoadProcessor != null)
        {
            StageLoadTimeOutCatcher.Stop();
            DestroyImmediate(stageLoadProcessor.gameObject);
            stageLoadProcessor = null;
        }
@@ -178,6 +197,23 @@
        {
            ExcuteCommand(commands.Dequeue());
        }
        if (isLoading)
        {
            if (Time.time - loadStartTime > 30f)
            {
                if (stageLoadProcessor != null)
                {
                    DestroyImmediate(stageLoadProcessor.gameObject);
                    stageLoadProcessor = null;
                }
                isLoading = false;
                commands.Clear();
                StageLoadTimeOutCatcher.ReportLoadingOverTime();
                GameNetSystem.Instance.Reconnect();
            }
        }
    }
    public struct StageLoadCommand
@@ -206,28 +242,28 @@
        public bool flag;
    }
    public bool IsWaitFor0109(ServerType socketType)
    public bool IsServerPrepareOk(ServerType socketType)
    {
        switch (socketType)
        {
            case ServerType.Main:
                return serverFlag_0109.flagType == ServerFlagType.Flag_0109
                    && serverFlag_0109.serverType == ServerType.Main
                    && !serverFlag_0109.flag;
                    && serverFlag_0109.flag;
            case ServerType.CrossSever:
                return serverFlag_0109.flagType == ServerFlagType.Flag_0109
                    && serverFlag_0109.serverType == ServerType.CrossSever
                    && !serverFlag_0109.flag;
                    && serverFlag_0109.flag;
            default:
                return false;
        }
    }
    public bool IsWaitFor0403()
    public bool IsLoginOk()
    {
        if (serverFlag_0403.flagType == ServerFlagType.Flag_0403
            && serverFlag_0403.serverType == ServerType.Main
            && !serverFlag_0403.flag)
            && serverFlag_0403.flag)
        {
            return true;
        }
Fight/Stage/StageLoadProcessor.cs
@@ -9,10 +9,9 @@
public class StageLoadProcessor : MonoBehaviour
{
    float progressBuf = 0f;
    float progressBuf = 0.1f;
    public float progress { get; private set; }
    public StageLoadStep step { get; private set; }
    StageLoadTask currentTask = null;
    Queue<StageLoadTask> tasks = new Queue<StageLoadTask>();
@@ -31,11 +30,6 @@
        }
    }
    public void Interrupt()
    {
    }
    public void Complete(int mapId, int lineId)
    {
        StageLoad.Instance.ReportComplete(mapId, lineId);
@@ -49,35 +43,6 @@
            {
                currentTask = tasks.Dequeue();
                currentTask.Begin();
                if (currentTask is PreProcessTask)
                {
                    step = StageLoadStep.PreProcess;
                }
                else if (currentTask is LoadEmptyTask)
                {
                    step = StageLoadStep.LoadEmpty;
                }
                else if (currentTask is UnLoadAndGCTask)
                {
                    step = StageLoadStep.UnLoadAndGC;
                }
                else if (currentTask is LoadNewSceneTask)
                {
                    step = StageLoadStep.LoadNewScene;
                }
                else if (currentTask is Wait0109Task)
                {
                    step = StageLoadStep.Wait0107;
                }
                else if (currentTask is WaitLoginCompleteTask)
                {
                    step = StageLoadStep.Wait0403;
                }
                else if (currentTask is PostProcessTask)
                {
                    step = StageLoadStep.PostProcess;
                }
            }
        }
@@ -426,7 +391,7 @@
        public override void Update()
        {
            timer += Time.deltaTime;
            if (StageLoad.Instance.IsWaitFor0109(command.serverType))
            if (!StageLoad.Instance.IsServerPrepareOk(command.serverType))
            {
                done = false;
                progress = timer / duration;
@@ -459,7 +424,7 @@
        public override void Update()
        {
            timer += Time.deltaTime;
            if (StageLoad.Instance.IsWaitFor0403())
            if (!StageLoad.Instance.IsLoginOk())
            {
                done = false;
                progress = timer / duration;
@@ -506,6 +471,78 @@
    }
    public class WaitSecondsTask : StageLoadTask
    {
        public WaitSecondsTask(StageLoad.StageLoadCommand command, float seconds) : base(command)
        {
            duration = seconds;
        }
        public override void Begin()
        {
        }
        public override void End()
        {
        }
        public override void Update()
        {
            timer += Time.deltaTime;
            if (timer > duration)
            {
                done = true;
            }
            else
            {
                done = false;
                progress = timer / duration;
            }
        }
    }
    public class ReturnToNoviceVillageTask : StageLoadTask
    {
        public ReturnToNoviceVillageTask(StageLoad.StageLoadCommand command) : base(command)
        {
        }
        public override void Begin()
        {
            if (CrossServerUtility.IsCrossServer())
            {
                var sendInfo = new CC003_tagCGForceQuitCrossState();
                GameNetSystem.Instance.SendInfo(sendInfo);
            }
            else
            {
                var mapConfig = Config.Instance.Get<MapConfig>(PlayerDatas.Instance.baseData.MapID);
                if (mapConfig.MapFBType == (int)MapType.OpenCountry)
                {
                    var sjzMapConfig = Config.Instance.Get<MapConfig>(10010);
                    var position = new Vector3(sjzMapConfig.BornPoints[0].x, 0, sjzMapConfig.BornPoints[0].y);
                    MapTransferUtility.Send_WorldTransfer(10010, position, MapTransferType.WorldTransport, 255, 0);
                }
                else
                {
                    ModelCenter.Instance.GetModel<DungeonModel>().ExitCurrentDungeon();
                }
            }
            done = true;
        }
        public override void End()
        {
        }
        public override void Update()
        {
        }
    }
    private static string GetAssetBundleNameByMapId(int mapId, int lineId)
    {
        switch (mapId)
@@ -529,20 +566,6 @@
                    return string.Empty;
                }
        }
    }
    public enum StageLoadStep
    {
        None,
        WaitStart,
        PreProcess,
        LoadEmpty,
        UnLoadAndGC,
        LoadNewScene,
        Wait0107,
        Wait0403,
        PostProcess,
    }
}
System/AssetVersion/AssetVersionUtility.cs
@@ -183,10 +183,15 @@
    public static bool IsSceneAssetValid(int mapId, int lineId)
    {
        if (AssetSource.sceneFromEditor || mapId < 100)
        {
            return true;
        }
        var dataMapId = MapUtility.GetDataMapId(mapId);
        lineId = MapUtility.GetLineId(mapId, lineId);
        var mapResConfig = MapResourcesConfig.GetConfig(dataMapId, lineId);
        if (mapResConfig==null)
        if (mapResConfig == null)
        {
            return false;
        }
Utility/StageLoadTimeOutCatcher.cs
@@ -5,9 +5,6 @@
public class StageLoadTimeOutCatcher : MonoBehaviour
{
    const int timeOut = 20;//秒
    public static ProtocolRecorder got0102Time;
    public static ProtocolRecorder gotA126Time;
    public static ProtocolRecorder gotA127Time;
@@ -15,39 +12,47 @@
    public static ProtocolRecorder got0403Time;
    public static ProtocolRecorder send0107Time;
    public static StageLoadTimeOutCatcher Begin(int stageId)
    {
        var go = new GameObject("StageLoadTimeOutCatcher");
        var catcher = go.AddMissingComponent<StageLoadTimeOutCatcher>();
        catcher.stageId = stageId;
        DontDestroyOnLoad(go);
        return catcher;
    }
    static StageLoadTimeOutCatcher timeOutCatcher;
    public int stageId = 0;
    DateTime startTime;
    public DateTime startTime;
    private void Awake()
    {
        startTime = DateTime.Now;
    }
    public void Stop()
    public static void Begin(int stageId)
    {
        if (this.gameObject != null)
        if (timeOutCatcher != null)
        {
            Destroy(this.gameObject);
            DestroyImmediate(timeOutCatcher.gameObject);
            timeOutCatcher = null;
        }
        var go = new GameObject("StageLoadTimeOutCatcher");
        var catcher = go.AddMissingComponent<StageLoadTimeOutCatcher>();
        catcher.stageId = stageId;
        timeOutCatcher = catcher;
        DontDestroyOnLoad(go);
    }
    public static void Stop()
    {
        if (timeOutCatcher != null)
        {
            DestroyImmediate(timeOutCatcher.gameObject);
            timeOutCatcher = null;
        }
    }
    void Update()
    public static void ReportLoadingOverTime()
    {
        if (DateTime.Now > startTime + new TimeSpan(timeOut * TimeSpan.TicksPerSecond))
        if (timeOutCatcher != null)
        {
            var title = StringUtility.Contact(stageId, "地图加载超时");
            var title = StringUtility.Contact(timeOutCatcher.stageId, "地图加载超时");
            var description = StringUtility.Contact(
                                        "开始时间:", startTime.ToString("HH:mm:ss"), "$$",
                                        "开始时间:", timeOutCatcher.startTime.ToString("HH:mm:ss"), "$$",
                                        "超时时间:", DateTime.Now.ToString("HH:mm:ss"), "$$",
                                        got0102Time.ToString(), "$$",
                                        gotA126Time.ToString(), "$$",
@@ -57,7 +62,8 @@
                                        got0403Time.ToString());
            ExceptionCatcher.ReportException(title, description);
            Stop();
            DestroyImmediate(timeOutCatcher.gameObject);
            timeOutCatcher = null;
        }
    }