From 6eb915c129fc90c6f4c82ae097dd6ffad5239efc Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Jan 2021 14:28:30 +0800 Subject: +scripts --- .../Assets/Scripts/XMainClient/XSceneTransfer.cs | 183 +++++++++++++++++++++ 1 file changed, 183 insertions(+) create mode 100644 Client/Assets/Scripts/XMainClient/XSceneTransfer.cs (limited to 'Client/Assets/Scripts/XMainClient/XSceneTransfer.cs') diff --git a/Client/Assets/Scripts/XMainClient/XSceneTransfer.cs b/Client/Assets/Scripts/XMainClient/XSceneTransfer.cs new file mode 100644 index 00000000..de018dc6 --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/XSceneTransfer.cs @@ -0,0 +1,183 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using KKSG; +using UnityEngine; +using XMainClient.UI; +using XMainClient.UI.UICommon; +using XUtliPoolLib; + +namespace XMainClient +{ + public sealed class XSceneTransfer : MonoBehaviour + { + private uint _loading_scene_id = 0u; + + public void TransferScene(uint sceneid) + { + this._loading_scene_id = sceneid; + base.StartCoroutine(this.TransferLevelInMainCity()); + } + + private IEnumerator TransferLevelInMainCity() + { + XSingleton.singleton.OnSceneBeginLoad(this._loading_scene_id); + XSingleton.singleton.OnSceneLoaded(this._loading_scene_id); + XSingleton.singleton.m_uiTool.EnableUILoadingUpdate(true); + XSingleton.singleton.RefreshScenMustTransform(); + this.CreatePlayer(this._loading_scene_id); + while (XSingleton.singleton.Player.Equipment != null && XSingleton.singleton.Player.Equipment.IsLoadingPart()) + { + yield return null; + } + this.DocPreload(this._loading_scene_id); + yield return null; + this.PreLoadSceneMonster(this._loading_scene_id); + yield return null; + this.PlaceSceneNpc(this._loading_scene_id); + yield return null; + this.ResetLevelAirWall(); + yield return null; + XSingleton.singleton.OnEnterScene(this._loading_scene_id, true); + SceneType sceneType = XSingleton.singleton.GetSceneType(this._loading_scene_id); + AsyncSceneAnimationRequest asar = XSingleton.singleton.ShowSceneLoadAnim(sceneType); + while (asar != null && !asar.IsDone) + { + XSingleton.singleton.UpdateSceneLoadAnim(asar, sceneType); + yield return null; + } + RpcC2G_DoEnterScene DoEnterSceneRpc = new RpcC2G_DoEnterScene(); + DoEnterSceneRpc.oArg.sceneid = XSingleton.singleton.SceneID; + XSingleton.singleton.Send(DoEnterSceneRpc); + XSingleton.singleton.bSceneLoadedRpcSend = true; + while (!XSingleton.singleton.bSceneServerReady) + { + bool flag = XSingleton.singleton.Error > ErrorCode.ERR_SUCCESS; + if (flag) + { + XSingleton.singleton.OnFatalErrorClosed(XSingleton.singleton.Error); + XSingleton.singleton.Error = ErrorCode.ERR_SUCCESS; + XSingleton.singleton.CloseOnServerErrorNtf = false; + break; + } + bool flag2 = XSingleton.singleton.SceneEntranceConfig != null; + if (flag2) + { + DlgBase.singleton.HidePkLoading(); + DlgBase.singleton.HidePkLoading(); + DlgBase.singleton.HidePkLoading(); + XSingleton.singleton.TriggerScene(); + break; + } + yield return null; + } + bool bSceneServerReady = XSingleton.singleton.bSceneServerReady; + if (bSceneServerReady) + { + this.PlayBGM(this._loading_scene_id); + DlgBase.singleton.HidePkLoading(); + DlgBase.singleton.HidePkLoading(); + DlgBase.singleton.HidePkLoading(); + XAutoFade.FadeIn(1f, true); + XSingleton.singleton.TriggerScene(); + } + bool flag3 = XSingleton.singleton.SceneEntranceConfig != null; + if (flag3) + { + XSingleton.singleton.SceneEnterTo(true); + } + XSingleton.singleton.switchScene = false; + yield break; + } + + private void CreatePlayer(uint sceneID) + { + 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)); + } + + private void PreLoadSceneMonster(uint sceneID) + { + List list = new List(); + XLevelSpawnInfo spawnerBySceneID = XSingleton.singleton.GetSpawnerBySceneID(sceneID); + bool flag = spawnerBySceneID != null; + if (flag) + { + Dictionary dictionary = new Dictionary(); + foreach (KeyValuePair keyValuePair in spawnerBySceneID._preloadInfo) + { + bool flag2 = keyValuePair.Key == 0; + if (!flag2) + { + dictionary.Add(keyValuePair.Key, keyValuePair.Value); + } + } + for (int i = 0; i < XSingleton.singleton.MonsterIDs.Count; i++) + { + bool flag3 = XSingleton.singleton.MonsterIDs[i] == 0u; + if (!flag3) + { + bool flag4 = !dictionary.ContainsKey((int)XSingleton.singleton.MonsterIDs[i]); + if (flag4) + { + dictionary.Add((int)XSingleton.singleton.MonsterIDs[i], 1); + } + } + } + foreach (KeyValuePair keyValuePair2 in dictionary) + { + uint key = (uint)keyValuePair2.Key; + XEntityStatistics.RowData byID = XSingleton.singleton.EntityStatistics.GetByID(key); + bool flag5 = byID == null; + if (!flag5) + { + string prefab = XSingleton.singleton.EntityInfo.GetByPresentID(byID.PresentID).Prefab; + bool flag6 = !list.Contains(byID.PresentID); + if (flag6) + { + XSingleton.singleton.PreloadTemp(byID.PresentID, key, (EntitySpecies)byID.Type); + list.Add(byID.PresentID); + } + } + } + } + } + + private void PlaceSceneNpc(uint sceneID) + { + List npcs = XSingleton.singleton.GetNpcs(sceneID); + bool flag = npcs != null; + if (flag) + { + XTaskDocument specificDocument = XDocuments.GetSpecificDocument(XTaskDocument.uuID); + for (int i = 0; i < npcs.Count; i++) + { + bool flag2 = !specificDocument.ShouldNpcExist(npcs[i]); + if (!flag2) + { + XSingleton.singleton.CreateNpc(npcs[i], true); + } + } + } + } + + private void ResetLevelAirWall() + { + XSingleton.singleton.ResetAirWallState(); + } + + private void DocPreload(uint sceneid) + { + for (int i = 0; i < XSingleton.singleton.Doc.Components.Count; i++) + { + XSingleton.singleton.Doc.Components[i].OnEnterScene(); + } + } + + private void PlayBGM(uint sceneid) + { + string sceneBGM = XSingleton.singleton.GetSceneBGM(sceneid); + XSingleton.singleton.PlayBGM(sceneBGM); + } + } +} -- cgit v1.1-26-g67d0