using System; using System.Collections; using System.Collections.Generic; using KKSG; using UnityEngine; using UnityEngine.SceneManagement; using XMainClient.UI; using XMainClient.UI.UICommon; using XUpdater; using XUtliPoolLib; namespace XMainClient { public sealed class XSceneLoader : MonoBehaviour { private AsyncOperation _op = null; private XSceneLoader.AsyncSceneBuildRequest _asbr = null; private uint _loading_scene_id = 0u; private EXStage _loading_scene_stage = EXStage.Null; private bool _enabled = false; private bool _prograss = true; private float _sub_progress = 0f; private float _current_progress = 0f; private float _target_progress = 0f; private bool _DelayLoadCache = true; private bool _LoadingSpectateScene = false; private enum LoadingPhase { Scene_Downlaod, Scene_Load, Scene_Build, Scene_Doc } private class AsyncSceneBuildRequest { public float Progress = 1f; public IEnumerator Pedometer = null; } public void LoadScene(string scene, EXStage eStage, bool prograss, uint nextsceneid, uint currentsceneid) { XSingleton.singleton.notLoadScene = false; XSingleton.singleton.networkRun = false; XSingleton.singleton.update = false; this._loading_scene_id = nextsceneid; this._loading_scene_stage = eStage; this._prograss = prograss; XSingleton.singleton.Clear(); ObjectPoolCache.Clear(); XSingleton.singleton.XPlatform.ClearClass(); bool settingEnum = XSingleton.singleton.GetSettingEnum(ESettingConfig.EClearBundle); if (settingEnum) { XSingleton.singleton.Clear(); } XSingleton.singleton.BeginRecord(); XSingleton.singleton.XPlatform.MarkLevelEnd(); XSingleton.singleton.XPlatform.MarkLoadlevel(scene); XQualitySetting.SwitchScene(); XSingleton.singleton.m_uiTool.PreLoad(false); XSingleton.singleton.m_uiTool.ReleaseAllDrawCall(); XSingleton.singleton.CallUnloadCallback(); XSingleton.singleton.ReleasePool(); this._DelayLoadCache = XSingleton.singleton.DelayLoad; XSingleton.singleton.DelayLoad = false; XSpectateDocument specificDocument = XDocuments.GetSpecificDocument(XSpectateDocument.uuID); this._LoadingSpectateScene = specificDocument.IsLoadingSpectateScene; bool flag = SceneType.SCENE_PK != XSingleton.singleton.GetSceneType(nextsceneid) && SceneType.SCENE_INVFIGHT != XSingleton.singleton.GetSceneType(nextsceneid) && SceneType.SCENE_LEAGUE_BATTLE != XSingleton.singleton.GetSceneType(nextsceneid); if (flag) { DlgBase.singleton.Load(); bool isLoadingSpectateScene = specificDocument.IsLoadingSpectateScene; if (isLoadingSpectateScene) { specificDocument.IsLoadingSpectateScene = false; string[] array = XSingleton.singleton.GetValue("Spectate_Tips").Split(XGlobalConfig.ListSeparator); int num = UnityEngine.Random.Range(0, array.Length); DlgBase.singleton.SetLoadingTip(array[num]); } else { string loadingTip = (currentsceneid == 1u) ? XSingleton.singleton.GetSceneLoadingTips(true, nextsceneid) : ((nextsceneid == 1u) ? XSingleton.singleton.GetSceneLoadingTips(false, currentsceneid) : ((nextsceneid == 100u) ? XSingleton.singleton.GetSceneLoadingTips(true, nextsceneid) : ((nextsceneid == 3u) ? XSingleton.singleton.GetSceneLoadingTips(false, 2u) : XSingleton.singleton.GetSceneLoadingTips(true, nextsceneid)))); DlgBase.singleton.SetLoadingTip(loadingTip); } bool flag2 = nextsceneid == 100u || nextsceneid == 21u || nextsceneid == 22u; string text; if (flag2) { text = this.GetMyProfessionLoadingPic(); } else { text = XSingleton.singleton.GetSceneLoadingPic(nextsceneid); } bool flag3 = string.IsNullOrEmpty(text); if (flag3) { prograss = false; } else { DlgBase.singleton.SetLoadingPic(text); } DlgBase.singleton.SetVisible(prograss, true); DlgBase.singleton.SetLoadingProgress(0f); } Application.backgroundLoadingPriority = (ThreadPriority)4; base.StartCoroutine(this.LoadLevelWithProgress(scene)); XSingleton.singleton.OnSceneBeginLoad(this._loading_scene_id); } private IEnumerator LoadLevelWithProgress(string scene) { base.enabled = true; this._enabled = true; this._current_progress = 0f; this._target_progress = 0f; this.DisplayPrograss(XSceneLoader.LoadingPhase.Scene_Downlaod, 1f); yield return null; bool flag = SceneType.SCENE_PK == XSingleton.singleton.SceneType || SceneType.SCENE_INVFIGHT == XSingleton.singleton.SceneType; if (flag) { DlgBase.singleton.ShowPkLoading(XSingleton.singleton.SceneType); } else { bool flag2 = SceneType.SCENE_LEAGUE_BATTLE == XSingleton.singleton.SceneType; if (flag2) { DlgBase.singleton.ShowPkLoading(); } else { bool flag3 = SceneType.SCENE_PKTWO == XSingleton.singleton.SceneType; if (flag3) { DlgBase.singleton.ShowPkLoading(); } } } XSingleton.singleton.m_uiTool.EnableUILoadingUpdate(true); yield return null; this.DisplayPrograss(XSceneLoader.LoadingPhase.Scene_Load, 0f); bool flag4 = XSingleton.singleton.ABManager != null; if (flag4) { XSingleton.singleton.ABManager.UnloadUnusedBundle(true); } this._op = SceneManager.LoadSceneAsync("empty"); while (!this._op.isDone) { yield return null; } this._op = Resources.UnloadUnusedAssets(); while (!this._op.isDone) { yield return null; } XSingleton.singleton.LoadABScene(XSingleton.singleton.GetScenePath(this._loading_scene_id)); this._op = SceneManager.LoadSceneAsync(scene); while (!this._op.isDone) { yield return null; } XSingleton.singleton.DelayLoad = this._DelayLoadCache; XQualitySetting.PostSceneLoad(); this.DisplayPrograss(XSceneLoader.LoadingPhase.Scene_Load, 1f); XSingleton.singleton.AddLog("-------------scene ready & begin load other res-------------", null, null, null, null, null, XDebugColor.XDebug_None); yield return null; this._asbr = this.SceneBuildAsync(this._loading_scene_id); yield return null; while (this._asbr.Pedometer.MoveNext()) { this.DisplayPrograss(XSceneLoader.LoadingPhase.Scene_Build, this._asbr.Progress); yield return null; } this._asbr = null; bool prograss = this._prograss; if (prograss) { bool flag5 = XStage.IsConcreteStage(this._loading_scene_stage); if (flag5) { XSingleton.singleton.RefreshScenMustTransform(); this.CreatePlayer(); this.DisplayPrograss(XSceneLoader.LoadingPhase.Scene_Doc, 0.3f); yield return null; IEnumerator iter = this.DocPreload(this._loading_scene_id); while (iter.MoveNext()) { this.DisplayPrograss(XSceneLoader.LoadingPhase.Scene_Doc, 0.3f + 0.4f * this._sub_progress); yield return null; } iter = null; } XSingleton.singleton.OnEnterScene(this._loading_scene_id, false); this.DisplayPrograss(XSceneLoader.LoadingPhase.Scene_Doc, 0.9f); bool flag6 = this._loading_scene_id == 100u; if (flag6) { uint idx = XSingleton.singleton.Player.BasicTypeID - 1u; uint id = XSingleton.singleton.NewbieLevelRoleID[(int)idx]; XEntityStatistics.RowData raw = XSingleton.singleton.EntityStatistics.GetByID(id); XSingleton.singleton.Player.OnTransform(raw.ID); yield return null; raw = null; } this.DisplayPrograss(XSceneLoader.LoadingPhase.Scene_Doc, 1f); yield return null; this._target_progress = 0.9f; bool flag7 = this._prograss && this._current_progress < 0.89f; if (flag7) { yield return null; } this._enabled = false; DlgBase.singleton.SetLoadingProgress(1f); yield return null; bool flag8 = XStage.IsConcreteStage(this._loading_scene_stage); if (flag8) { RpcC2G_DoEnterScene DoEnterSceneRpc = new RpcC2G_DoEnterScene(); DoEnterSceneRpc.oArg.sceneid = XSingleton.singleton.SceneID; XSingleton.singleton.Send(DoEnterSceneRpc); XSingleton.singleton.bSceneLoadedRpcSend = true; DoEnterSceneRpc = null; } } else { XSingleton.singleton.OnEnterScene(this._loading_scene_id, false); } bool flag9 = XStage.IsConcreteStage(this._loading_scene_stage); if (flag9) { yield return null; } else { XSingleton.singleton.bSceneServerReady = (XSingleton.singleton.Error == ErrorCode.ERR_SUCCESS); yield return null; } int waitTime = 1; XSingleton.singleton.networkRun = true; while (!XSingleton.singleton.bSceneServerReady) { int num = waitTime; waitTime = num + 1; bool flag10 = XSingleton.singleton.Error > ErrorCode.ERR_SUCCESS; if (flag10) { bool flag11 = string.IsNullOrEmpty(XSingleton.singleton.ErrorAddtional); if (flag11) { XSingleton.singleton.OnFatalErrorClosed(XSingleton.singleton.Error); } else { XSingleton.singleton.OnFatalErrorClosed(string.Format(XStringDefineProxy.GetString(XSingleton.singleton.Error), XSingleton.singleton.ErrorAddtional)); } XSingleton.singleton.Error = ErrorCode.ERR_SUCCESS; XSingleton.singleton.ErrorAddtional = null; XSingleton.singleton.CloseOnServerErrorNtf = false; break; } bool flag12 = XSingleton.singleton.SceneEntranceConfig != null; if (flag12) { this._prograss = false; XSingleton.singleton.TriggerScene(); break; } yield return null; } bool bSceneServerReady = XSingleton.singleton.bSceneServerReady; if (bSceneServerReady) { this.PlayBGM(this._loading_scene_id); XAutoFade.MakeBlack(true); this._prograss = false; yield return null; DlgBase.singleton.HideSelf(false); XSingleton.singleton.TriggerScene(); yield return null; XAutoFade.FadeIn(1f, true); } this._op = null; bool flag13 = XSingleton.singleton.SceneEntranceConfig != null; if (flag13) { XSingleton.singleton.SceneEnterTo(true); } XSingleton.singleton.notLoadScene = true; XSingleton.singleton.switchScene = false; XSingleton.singleton.update = true; Application.backgroundLoadingPriority = (ThreadPriority)2; bool settingEnum = XSingleton.singleton.GetSettingEnum(ESettingConfig.ESceneUnloadResource); if (settingEnum) { Resources.UnloadUnusedAssets(); } bool flag14 = this._loading_scene_id == 1u; if (flag14) { GC.Collect(); } XSingleton.singleton.XPlatform.MarkLoadlevelCompleted(); yield break; } private void Update() { bool flag = this._enabled && this._prograss; if (flag) { this._current_progress += Mathf.Abs(this._target_progress - this._current_progress) * 0.5f; DlgBase.singleton.SetLoadingProgress(this._current_progress); } } private void DisplayPrograss(XSceneLoader.LoadingPhase phase, float progress) { bool flag = !this._prograss; if (!flag) { switch (phase) { case XSceneLoader.LoadingPhase.Scene_Downlaod: this._target_progress = progress * 0.1f; break; case XSceneLoader.LoadingPhase.Scene_Load: this._target_progress = progress * 0.2f + 0.1f; break; case XSceneLoader.LoadingPhase.Scene_Build: this._target_progress = progress * 0.4f + 0.3f; break; case XSceneLoader.LoadingPhase.Scene_Doc: this._target_progress = progress * 0.2f + 0.7f; break; } } } private XSceneLoader.AsyncSceneBuildRequest SceneBuildAsync(uint sceneID) { return new XSceneLoader.AsyncSceneBuildRequest { Pedometer = this.Preloader(sceneID) }; } private IEnumerator Preloader(uint sceneID) { IEnumerator ietr = null; this._asbr.Progress = 0f; yield return null; XSingleton.singleton.OnSceneLoaded(sceneID); this._asbr.Progress = 0.05f; yield return null; ietr = this.PreLoadSceneMonster(sceneID); while (ietr.MoveNext()) { this._asbr.Progress = 0.05f + this._sub_progress * 0.75f; yield return null; } ietr = this.PreLoadSceneRes(sceneID); while (ietr.MoveNext()) { this._asbr.Progress = 0.8f + this._sub_progress * 0.1f; yield return null; } ietr = this.PlaceSceneNpc(sceneID); while (ietr.MoveNext()) { this._asbr.Progress = 0.9f + this._sub_progress * 0.1f; yield return null; } this._asbr.Progress = 1f; yield break; } private void CreatePlayer() { this._sub_progress = 0f; XSingleton.singleton.AddLog("Preload Player", null, null, null, null, null, XDebugColor.XDebug_None); XSingleton.singleton.Add(XSingleton.singleton.CreatePlayer(Vector3.zero, Quaternion.identity, false, XSingleton.singleton.IsMustTransform || this._LoadingSpectateScene)); this._LoadingSpectateScene = false; } private IEnumerator PlaceSceneNpc(uint sceneID) { this._sub_progress = 0f; List npcList = XSingleton.singleton.GetNpcs(sceneID); bool flag = npcList != null && npcList.Count > 0; if (flag) { int step = 0; XTaskDocument taskDoc = XDocuments.GetSpecificDocument(XTaskDocument.uuID); int num; for (int i = 0; i < npcList.Count; i = num + 1) { num = step; step = num + 1; bool flag2 = !taskDoc.ShouldNpcExist(npcList[i]); if (!flag2) { XSingleton.singleton.CreateNpc(npcList[i], true); this._sub_progress = (float)step / (float)npcList.Count; } num = i; } taskDoc = null; } this._sub_progress = 1f; yield return null; yield break; } private IEnumerator PreLoadSceneMonster(uint sceneID) { this._sub_progress = 0f; List prefabs = new List(); XLevelSpawnInfo spawner = XSingleton.singleton.GetSpawnerBySceneID(sceneID); bool flag = spawner != null; if (flag) { Dictionary preloadInfo = new Dictionary(); foreach (KeyValuePair keyValuePair in spawner._preloadInfo) { bool flag2 = keyValuePair.Key == 0; if (!flag2) { preloadInfo.Add(keyValuePair.Key, keyValuePair.Value); //! // keyValuePair = default(KeyValuePair); } } Dictionary.Enumerator enumerator = default(Dictionary.Enumerator); bool flag3 = !XSingleton.singleton.ForcePreloadOneWave; if (flag3) { int i = 0; while (i < XSingleton.singleton.MonsterIDs.Count && preloadInfo.Count < XSingleton.singleton.MaxPreloadCount) { bool flag4 = XSingleton.singleton.MonsterIDs[i] == 0u; if (!flag4) { bool flag5 = !preloadInfo.ContainsKey((int)XSingleton.singleton.MonsterIDs[i]); if (flag5) { preloadInfo.Add((int)XSingleton.singleton.MonsterIDs[i], 1); } } int num = i + 1; i = num; } } int step = 0; float progress = 0f; foreach (KeyValuePair keyValuePair2 in preloadInfo) { int num = step; step = num + 1; progress = (float)step / (float)preloadInfo.Count * 0.9f; uint enemyID = (uint)keyValuePair2.Key; XEntityStatistics.RowData data = XSingleton.singleton.EntityStatistics.GetByID(enemyID); bool flag6 = data == null; if (flag6) { XSingleton.singleton.AddErrorLog("Cant find statistic id: ", enemyID.ToString(), null, null, null, null); } else { XEntityPresentation.RowData presentData = XSingleton.singleton.EntityInfo.GetByPresentID(data.PresentID); bool flag7 = presentData == null; if (flag7) { XSingleton.singleton.AddErrorLog("Cant find present id ", data.PresentID.ToString(), " while statistic id = ", data.ID.ToString(), null, null); } else { string prefab = presentData.Prefab; bool flag8 = !prefabs.Contains(data.PresentID); if (flag8) { string location = "Prefabs/" + prefab; float diff = progress - this._sub_progress; XSingleton.singleton.CreateInAdvance(location, 1, ECreateHideType.DisableAnim); this._sub_progress += diff * 0.2f; XSingleton.singleton.AddLog("Preload ", prefab, " with pid ", data.PresentID.ToString(), null, null, XDebugColor.XDebug_None); XSingleton.singleton.PreloadTemp(data.PresentID, enemyID, (EntitySpecies)data.Type); this._sub_progress += diff * 0.7f; prefabs.Add(data.PresentID); location = null; } this._sub_progress = progress; bool flag9 =(int) Application.platform == 7 || Application.platform == 0; if (flag9) { yield return null; } data = null; presentData = null; prefab = null; //! //keyValuePair2 = default(KeyValuePair); } } } Dictionary.Enumerator enumerator2 = default(Dictionary.Enumerator); this._sub_progress = 0.9f; XSingleton.singleton.CreateInAdvance(XCombatHUDMgr.HUD_NORMAL, 10, ECreateHideType.NotHide); XSingleton.singleton.CreateInAdvance(XCombatHUDMgr.HUD_CRITICAL, 5, ECreateHideType.NotHide); XSingleton.singleton.CreateInAdvance(XCombatHUDMgr.HUD_PLAYER, 5, ECreateHideType.NotHide); this._sub_progress = 1f; preloadInfo = null; } bool flag10 = XSingleton.singleton.SceneType == SceneType.SCENE_HALL; if (flag10) { XBillBoardDocument.PreLoad(16); XSingleton.singleton.m_uiTool.PreLoad(true); } else { bool flag11 = XSingleton.singleton.SceneType == SceneType.SCENE_LOGIN; if (!flag11) { XSingleton.singleton.m_uiTool.PreLoad(true); } } yield return null; this._sub_progress = 1f; yield break; yield break; } private IEnumerator PreLoadSceneRes(uint sceneID) { this._sub_progress = 0f; bool flag = sceneID > 3u; if (flag) { PreloadAnimationList.RowData[] Anims = XSingleton.singleton.AnimReader.Table; int step = 0; int i = 0; int imax = Anims.Length; while (i < imax) { this._sub_progress = 0.5f + (float)step / ((float)Anims.Length * 2f); PreloadAnimationList.RowData rowData = Anims[i]; bool flag2 = rowData.SceneID == 0 || (long)rowData.SceneID == (long)((ulong)sceneID); int num; if (flag2) { num = step; step = num + 1; XSingleton.singleton.GetXAnimation(rowData.AnimName, true, true); yield return null; } rowData = null; num = i + 1; i = num; } Anims = null; } this._sub_progress = 1f; yield break; } private void PlayBGM(uint sceneid) { string sceneBGM = XSingleton.singleton.GetSceneBGM(sceneid); XSingleton.singleton.PlayBGM(sceneBGM); } private IEnumerator DocPreload(uint sceneid) { this._sub_progress = 0f; int num; for (int i = 0; i < XSingleton.singleton.Doc.Components.Count; i = num + 1) { XSingleton.singleton.Doc.Components[i].OnEnterScene(); this._sub_progress = (float)i / (float)XSingleton.singleton.Doc.Components.Count; num = i; } yield return null; this._sub_progress = 1f; yield break; } private string GetMyProfessionLoadingPic() { uint num = XSingleton.singleton.XPlayerData.TypeID % 10u; string[] array = XSingleton.singleton.GetValue("ProfessionLoadingPic").Split(XGlobalConfig.AllSeparators); bool flag = array.Length % 2 != 0; string result; if (flag) { result = ""; } else { for (int i = 0; i < array.Length; i += 2) { bool flag2 = uint.Parse(array[i]) == num; if (flag2) { return array[i + 1]; } } result = ""; } return result; } } }