From 6eb915c129fc90c6f4c82ae097dd6ffad5239efc Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Jan 2021 14:28:30 +0800 Subject: +scripts --- Client/Assets/Scripts/XMainClient/XGame.cs | 615 +++++++++++++++++++++++++++++ 1 file changed, 615 insertions(+) create mode 100644 Client/Assets/Scripts/XMainClient/XGame.cs (limited to 'Client/Assets/Scripts/XMainClient/XGame.cs') diff --git a/Client/Assets/Scripts/XMainClient/XGame.cs b/Client/Assets/Scripts/XMainClient/XGame.cs new file mode 100644 index 00000000..cd375fcf --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/XGame.cs @@ -0,0 +1,615 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Threading; +using KKSG; +using ProtoBuf; +using UnityEngine; +using XMainClient.UI; +using XMainClient.UI.UICommon; +using XUpdater; +using XUtliPoolLib; + +namespace XMainClient +{ + public class XGame : XSingleton + { + public bool IsGMAccount + { + get + { + return this._isgmaccount; + } + set + { + this._isgmaccount = value; + } + } + + public bool ShowBuildLog + { + get + { + return this._show_build_log; + } + set + { + this._show_build_log = value; + } + } + + public ulong PlayerID + { + get + { + return this._player_id; + } + set + { + this._player_id = value; + } + } + + public bool CalcFps + { + get + { + return this._calc_fps; + } + } + + public float Fps + { + get + { + return this._fps; + } + } + + public float FpsAvg + { + get + { + return this._fpsAvg; + } + } + + public XStage CurrentStage + { + get + { + return this._stage; + } + } + + public bool StageReady + { + get + { + return this._stage != null && this._stage.IsEntered; + } + } + + internal XDocuments Doc + { + get + { + return this._doc; + } + } + + public int SyncModeValue + { + get + { + return this._nSyncMode; + } + set + { + this._nSyncMode = value; + Physics.IgnoreLayerCollision(10, 10, this.SyncMode); + Physics.IgnoreLayerCollision(21, 13, this.SyncMode); + } + } + + public bool SyncMode + { + get + { + return this._nSyncMode == 1; + } + } + + public static int RoleCount; + + private XStage _stage = null; + + private XStage _old_stage = null; + + private List _singletons = null; + + private XDocuments _doc = null; + + private int _nSyncMode = 0; + + private bool _show_build_log = true; + + private int _fps_count = 0; + + private float _fps = (float)XShell.TargetFrame; + + private float _fpsAvg = (float)XShell.TargetFrame; + + private float _fps_interval = 0.16667f; + + private bool _calc_fps = true; + + private float _fps_real_time = 0f; + + private int _fpsCalcCount = 0; + + private float _fpsAcc = 0f; + + private bool _isgmaccount = false; + + private ulong _player_id = 0UL; + + private int _millisecondsToWait = 0; + + private float _lastExitClickTime = 0f; + + private XTimerMgr.ElapsedEventHandler _fpsHandler = null; + + private XTimerMgr.ElapsedEventHandler _innerSwitchCb = null; + + public bool notLoadScene = true; + + public bool networkRun = true; + + public bool switchScene = false; + + public static bool EditorMode = false; + + public XGame() + { + this._singletons = new List(); + this._singletons.Add(XSingleton.singleton); + this._singletons.Add(XSingleton.singleton); + XSingleton.singleton.Uninit(); + this._singletons.Add(XSingleton.singleton); + this._singletons.Add(XSingleton.singleton); + this._singletons.Add(XSingleton.singleton); + this._singletons.Add(XSingleton.singleton); + this._singletons.Add(XSingleton.singleton); + this._singletons.Add(XSingleton.singleton); + this._singletons.Add(XSingleton.singleton); + this._singletons.Add(XSingleton.singleton); + this._singletons.Add(XSingleton.singleton); + this._singletons.Add(XSingleton.singleton); + this._singletons.Add(XSingleton.singleton); + this._singletons.Add(XSingleton.singleton); + this._singletons.Add(XSingleton.singleton); + this._singletons.Add(XSingleton.singleton); + this._singletons.Add(XSingleton.singleton); + this._singletons.Add(XSingleton.singleton); + this._singletons.Add(XSingleton.singleton); + this._singletons.Add(XSingleton.singleton); + this._singletons.Add(XSingleton.singleton); + this._singletons.Add(XSingleton.singleton); + this._singletons.Add(XSingleton.singleton); + this._singletons.Add(XSingleton.singleton); + this._singletons.Add(XSingleton.singleton); + this._singletons.Add(XSingleton.singleton); + this._singletons.Add(XSingleton.singleton); + this._singletons.Add(XSingleton.singleton); + this._singletons.Add(XSingleton.singleton); + this._singletons.Add(XSingleton.singleton); + this._fpsHandler = new XTimerMgr.ElapsedEventHandler(this.CalculateFPS); + this._innerSwitchCb = new XTimerMgr.ElapsedEventHandler(this.InnerSwitch); + this._doc = new XDocuments(); + } + + public IEnumerator Awake() + { + XLinkTimeStamp.FetchBuildDateTime(); + this.TriggerFps(); + PtcRegister.RegistProtocol(); + XSingleton.singleton.LoadServerCurve("Table/Curve"); + XSingleton.singleton.Initialize(); + CVSReader.Init(); + int i = 0; + int num; + for (i = 0; i < this._singletons.Count; i = num + 1) + { + int tryCount = 0; + while (!this._singletons[i].Init()) + { + num = tryCount; + tryCount = num + 1; + bool flag = tryCount % 1000 == 0; + if (flag) + { + Thread.Sleep(1); + } + } + num = i; + } + GC.Collect(); + i = 0; + XBagDocument.Execute(new OnLoadedCallback(XBagDocument.OnTableLoaded)); + while (!XBagDocument.AsyncLoader.IsDone) + { + num = i + 1; + i = num; + bool flag2 = num % 1000 == 0; + if (flag2) + { + Thread.Sleep(1); + } + } + this._doc.CtorLoad(); + this._doc.Initilize(0); + Serializer.SetMultiThread(XSingleton.singleton.GetSettingEnum(ESettingConfig.EMultiThreadProtoBuf)); + Serializer.SetSkipProtoIgnore(XSingleton.singleton.GetSettingEnum(ESettingConfig.ESkipProtoIgnore)); + XAutoFade.MakeBlack(true); + XOptionsDocument optDoc = XDocuments.GetSpecificDocument(XOptionsDocument.uuID); + bool flag3 = optDoc != null; + if (flag3) + { + int value = optDoc.GetValue(XOptionsDefine.OD_SMOOTH); + XSingleton.singleton.SetUIOptOption(false, value == 1, false, false); + } + bool settingEnum = XSingleton.singleton.GetSettingEnum(ESettingConfig.EApm); + if (settingEnum) + { + XSingleton.singleton.XPlatform.InitApm(); + } + XResourceLoaderMgr.UseCurveTable = XSingleton.singleton.GetSettingEnum(ESettingConfig.ELoadCurveTable); + XSingleton.singleton.DelayLoad = XSingleton.singleton.GetSettingEnum(ESettingConfig.EDelayLoad); + XFxMgr.FilterFarFx = XSingleton.singleton.GetSettingEnum(ESettingConfig.EFilterFarFx); + yield return null; + yield break; + } + + public override bool Init() + { + XQualitySetting.InitResolution(); + bool flag = (int)Application.platform == 7 || (int)Application.platform == 0|| (int)Application.platform == 2; + if (flag) + { + Application.targetFrameRate = 60; + } + else + { + Application.targetFrameRate = XShell.TargetFrame; + } + XAutoFade.FadeIn(0f, true); + this.SwitchTo(EXStage.Login, 3u); + return true; + } + + public override void Uninit() + { + this.SwitchTo(EXStage.Null, 0u); + this._doc.Uninitilize(); + for (int i = this._singletons.Count - 1; i >= 0; i--) + { + this._singletons[i].Uninit(); + } + XSingleton.singleton.Close(NetErrCode.Net_NoError); + XSingleton.singleton.Uninit(); + INativePlugin nativePlugin = XSingleton.singleton.XPlatform.GetNativePlugin(); + bool flag = nativePlugin != null; + if (flag) + { + nativePlugin.CloseHooks(); + } + } + + public void UpdateNetwork() + { + bool flag = this.networkRun; + if (flag) + { + XSingleton.singleton.Update(); + } + } + + public void PreUpdate(float fDeltaT) + { + bool flag = this.StageReady && this.notLoadScene; + if (flag) + { + XSingleton.singleton.Update(); + this._stage.PreUpdate(fDeltaT); + } + } + + public void Update(float fDeltaT) + { + bool flag = this.StageReady && this.notLoadScene; + if (flag) + { + this._stage.Update(fDeltaT); + this._doc.Update(fDeltaT); + XSingleton.singleton.Update(fDeltaT); + } + bool calc_fps = this._calc_fps; + if (calc_fps) + { + this._fps_count++; + } + bool key = Input.GetKey((KeyCode)284); + if (key) + { + XSingleton.singleton.OnProcess3DTouch(""); + } + } + + private void CheckExit() + { + bool keyDown = Input.GetKeyDown((KeyCode)27); + if (keyDown) + { + bool flag = Time.time - this._lastExitClickTime < float.Parse(XSingleton.singleton.GetValue("DoubleClickExitTime")); + if (flag) + { + Application.Quit(); + } + XSingleton.singleton.ShowSystemTip(XSingleton.singleton.GetString("EXIT_GAME_TIP"), "fece00"); + this._lastExitClickTime = Time.time; + } + } + + public void PostUpdate(float fDeltaT) + { + bool flag = this.StageReady && this.notLoadScene; + if (flag) + { + this._stage.PostUpdate(fDeltaT); + this._doc.PostUpdate(fDeltaT); + XSingleton.singleton.PostUpdate(fDeltaT); + } + } + + public void SwitchTo(EXStage eStage, uint sceneID) + { + bool flag = sceneID == XSingleton.singleton.SceneID && this.CurrentStage.Stage == eStage && sceneID != 3u && XSingleton.singleton.SceneType != SceneType.SCENE_TOWER; + if (flag) + { + XSingleton.singleton.AddLog("switch to the same scene id ", sceneID.ToString(), " with same stage.", null, null, null, XDebugColor.XDebug_None); + } + bool flag2 = eStage == EXStage.Null || sceneID == 0u; + if (flag2) + { + this._old_stage = this._stage; + this._old_stage.OnLeaveStage(EXStage.Null); + this._old_stage.OnLeaveScene(false); + XSingleton.singleton.OnLeaveScene(false); + this._old_stage = null; + } + else + { + int num = XFastEnumIntEqualityComparer.ToInt(eStage); + uint num2 = (uint)(num << 24 | (int)sceneID); + bool flag3 = this._stage == null || sceneID != XSingleton.singleton.SceneID || XSingleton.singleton.GetSceneSwitchToSelf(sceneID); + if (flag3) + { + XSingleton.singleton.UntriggerScene(); + } + bool flag4 = (eStage == EXStage.World || eStage == EXStage.Hall) && XSingleton.singleton.TurnToTransfer(sceneID); + if (flag4) + { + XAutoFade.FadeOut(0.5f); + XSingleton.singleton.SetTimer(1f, this._innerSwitchCb, num2 | 2147483648u); + } + else + { + float sceneDelayTransfer = XSingleton.singleton.GetSceneDelayTransfer(sceneID); + bool flag5 = sceneDelayTransfer > 0f; + if (flag5) + { + XAutoFade.FadeOut(sceneDelayTransfer); + XSingleton.singleton.SetTimer(sceneDelayTransfer + 0.03f, this._innerSwitchCb, num2); + } + else + { + this.InnerSwitch(num2); + } + } + } + } + + public XStage CreateSpecifiecStage(EXStage eStage) + { + XStage result; + switch (eStage) + { + case EXStage.Login: + result = XStage.CreateSpecificStage(); + break; + case EXStage.SelectChar: + result = XStage.CreateSpecificStage(); + break; + case EXStage.World: + result = XStage.CreateSpecificStage(); + break; + case EXStage.Hall: + result = XStage.CreateSpecificStage(); + break; + default: + result = null; + break; + } + return result; + } + + public void TriggerFps() + { + bool calc_fps = this._calc_fps; + if (calc_fps) + { + XSingleton.singleton.SetGlobalTimer(this._fps_interval, this._fpsHandler, null); + } + } + + private void InnerSwitch(object o) + { + this.switchScene = true; + uint num = (uint)o; + bool flag = num >> 31 > 0u; + uint num2 = num & 16777215u; + EXStage exstage = (EXStage)(num >> 24 & 127u); + bool flag2 = flag; + if (flag2) + { + XAutoFade.MakeBlack(false); + } + bool flag3 = XSingleton.singleton.SceneID == 100u; + if (flag3) + { + XAutoFade.FadeIn(0.2f, false); + } + this._old_stage = this._stage; + this._stage = ((this._old_stage != null && exstage == this._old_stage.Stage) ? this._old_stage : this.CreateSpecifiecStage(exstage)); + bool flag4 = this._old_stage != null; + if (flag4) + { + this._old_stage.OnLeaveStage(this._stage.Stage); + bool flag5 = num2 != XSingleton.singleton.SceneID || XSingleton.singleton.GetSceneSwitchToSelf(num2); + if (flag5) + { + XSingleton.singleton.m_uiTool.EnableUILoadingUpdate(false); + this._old_stage.OnLeaveScene(flag); + bool flag6 = XSingleton.singleton.SceneID > 0u; + if (flag6) + { + XSingleton.singleton.OnLeaveScene(flag); + } + XSingleton.singleton.LoadSceneAsync(num2, exstage, !flag, flag); + } + else + { + this.OnEnterStage(); + this.switchScene = false; + } + } + else + { + XSingleton.singleton.LoadSceneAsync(num2, exstage, true, false); + } + } + + private void LockFps(int goal) + { + float num = 1f / (float)goal - Time.smoothDeltaTime; + bool flag = num > 0f; + if (flag) + { + this._millisecondsToWait++; + } + else + { + this._millisecondsToWait--; + } + Thread.Sleep((int)Mathf.Clamp((float)this._millisecondsToWait, 0f, 1f / (float)goal * 1000f)); + } + + private void CalculateFPS(object o) + { + float realtimeSinceStartup = Time.realtimeSinceStartup; + this._fps = (float)this._fps_count / (realtimeSinceStartup - this._fps_real_time); + this._fpsCalcCount++; + this._fpsAcc += this._fps; + bool flag = this._fpsCalcCount >= 20; + if (flag) + { + this._fpsAvg = this._fpsAcc / (float)this._fpsCalcCount; + this._fpsCalcCount = 0; + this._fpsAcc = 0f; + } + bool flag2 = DlgBase.singleton.MainDoc != null; + if (flag2) + { + bool flag3 = DlgBase.singleton.MainDoc.GetFpsState == XMainInterfaceDocument.GetFps.start; + if (flag3) + { + DlgBase.singleton.MainDoc.FpsStartTime = realtimeSinceStartup; + DlgBase.singleton.MainDoc.PeakFps = this._fps; + DlgBase.singleton.MainDoc.FpsCount = this._fps_count; + DlgBase.singleton.MainDoc.GetFpsState = XMainInterfaceDocument.GetFps.running; + } + else + { + bool flag4 = DlgBase.singleton.MainDoc.GetFpsState == XMainInterfaceDocument.GetFps.running; + if (flag4) + { + DlgBase.singleton.MainDoc.PeakFps = Math.Max(this._fps, DlgBase.singleton.MainDoc.PeakFps); + DlgBase.singleton.MainDoc.FpsCount += this._fps_count; + } + } + } + this._fps_real_time = realtimeSinceStartup; + this._fps_count = 0; + XSingleton.singleton.SetGlobalTimer(this._fps_interval, this._fpsHandler, null); + } + + private void OnEnterStage() + { + this._stage.OnEnterStage((this._old_stage != null) ? this._old_stage.Stage : EXStage.Null); + } + + public void OnEnterScene(uint sceneid, bool bTransfer = false) + { + bool bHall = XSingleton.singleton.GetSceneType(sceneid) == SceneType.SCENE_HALL || XSingleton.singleton.GetSceneType(sceneid) == SceneType.SCENE_GUILD_HALL || XSingleton.singleton.GetSceneType(sceneid) == SceneType.SCENE_LEISURE; + XSingleton.singleton.GameCamera.PreInstall(GameObject.Find("Main Camera"), bHall); + XSingleton.singleton.OnEnterScene(sceneid, bTransfer); + this._stage.OnEnterScene(sceneid, bTransfer); + XSingleton.singleton.GameCamera.Installed(); + XSingleton.singleton.AssociatedCamera = XSingleton.singleton.GameCamera.UnityCamera; + XSingleton.singleton.InitAIMgr(); + this.OnEnterStage(); + } + + public string GetSyncModeString() + { + bool flag = this._nSyncMode == 0; + string result; + if (flag) + { + result = " Solo Mode "; + } + else + { + bool flag2 = this._nSyncMode == 1; + if (flag2) + { + result = " OnLine Mode "; + } + else + { + bool flag3 = this._nSyncMode == 2; + if (flag3) + { + result = " Mixed Mode "; + } + else + { + result = "Unknown"; + } + } + } + return result; + } + + public static void SetVisible(GameObject go, int layer) + { + go.layer = layer; + for (int i = 0; i < go.transform.childCount; i++) + { + Transform child = go.transform.GetChild(i); + XGame.SetVisible(child.gameObject, layer); + } + } + } +} -- cgit v1.1-26-g67d0