using System; using System.IO; using System.Net.NetworkInformation; using System.Threading.Tasks; using AOT.PostProcess.ColorFade; //using CriWare; //using CriWare; using Cysharp.Threading.Tasks; using Framework; using Gameplay.Net; using Gameplay.Performance; using Gameplay.PostProcess.ColorFade; using Gameplay.SubSystems; using PhxhSDK; using UnityEditor; using UnityEngine; using UnityEngine.Networking; using YooAsset; #if !UNITY_EDITOR using UnityEngine; #endif using Constants = Framework.Constants; namespace Gameplay { public class GameStartLoading : LoadingExecutor { public static bool newMethodLogin = true; public GameStartLoading() : base(E_LoadingType.CommonLoading) { } protected override async UniTask OnExecute() { E_LoadingResult result; Progress = 0.1f; BIManager.Instance.TrackEvent("open_loading_start", null); BIManager.Instance.TrackEventOnce("fte_open_loading_start", null); await Resources.UnloadUnusedAssets(); result = await FirstRunAppCheck(); if (result != E_LoadingResult.Success) return result; BIManager.Instance.TrackEvent("app_open_loading_process", new System.Collections.Generic.Dictionary { {"process",25 } }); Progress = 0.25f; result = await AppVersionCheck(); if (result != E_LoadingResult.Success) { DebugUtil.LogError("AppVersionCheck错误"); return result; } BIManager.Instance.TrackEvent("app_open_loading_process", new System.Collections.Generic.Dictionary { {"process",40 } }); Progress = 0.4f; // result = await CheckCriAtom(); // if (result != E_LoadingResult.Success) // { // DebugUtil.LogError("CheckCriAtom错误"); // return result; // } BIManager.Instance.TrackEvent("app_open_loading_process", new System.Collections.Generic.Dictionary { {"process",55 } }); Progress = 0.55f; result = await LoadLoginUI(); if (result != E_LoadingResult.Success) { DebugUtil.LogError("LoadLoginUI错误"); return result; } BIManager.Instance.TrackEvent("app_open_loading_process", new System.Collections.Generic.Dictionary { {"process",70 } }); Progress = 0.7f; result = await PreloadOthers(); if (result != E_LoadingResult.Success) { DebugUtil.LogError("_PreloadOthers错误"); return result; } BIManager.Instance.TrackEvent("app_open_loading_process", new System.Collections.Generic.Dictionary { {"process",85 } }); Progress = 0.85f; result = await LoadPerformance(); if (result != E_LoadingResult.Success) { DebugUtil.LogError("_LoadPerformance错误"); return result; } BIManager.Instance.TrackEvent("app_open_loading_process", new System.Collections.Generic.Dictionary { {"process",90 } }); Progress = 0.9f; result = InitGameSetting(); if (result != E_LoadingResult.Success) { DebugUtil.LogError("InitGameSetting错误"); return result; } BIManager.Instance.TrackEvent("app_open_loading_process", new System.Collections.Generic.Dictionary { {"process",95 } }); Progress = 0.95f; if (!newMethodLogin)//使用原先登录逻辑 UIManager.Instance.OpenLoadedNormalUI(UINameConst.UI_LogIn); else//新版登陆界面 UIManager.Instance.OpenLoadedNormalUI(UINameConst.UI_StartGameInterface); DebugUtil.Log("GameStart加载完成"); BIManager.Instance.TrackEvent("open_loading_end", null); BIManager.Instance.TrackEventOnce("fte_open_loading_end", null); return E_LoadingResult.Success; } private async UniTask PreloadOthers() { // 渐变shader需要提前加载 AssetManager.Instance.PostPreload(Constants.SHADER_FADEOUT_PATH); AssetManager.Instance.PostPreload(CommonUtils.BLUR_MAT_PATH); await AssetManager.Instance.WaitAllPreloads(); var globalFadeManagerInst = new ColorFadeManagerImpl(); GlobalFadeManager.CreateInstance(globalFadeManagerInst); await globalFadeManagerInst.Init(); return E_LoadingResult.Success; } private async UniTask LoadLoginUI() { if (!newMethodLogin) await UIManager.Instance.LoadWindow(UINameConst.UI_LogIn); else await UIManager.Instance.LoadWindow(UINameConst.UI_StartGameInterface); return E_LoadingResult.Success; } /// /// 是否是安装后第一次运行 /// /// private async UniTask FirstRunAppCheck() { var result = await Net.AppConfig.Instance.UnityRequest(); if (!result) { DebugUtil.LogError("网络错误或服务器列表没有添加对应渠道"); return E_LoadingResult.DeviceNetError; } return E_LoadingResult.Success; } /// /// 强更检查 /// /// private async UniTask AppVersionCheck() { var needUpdate = AppConfig.Instance.UpdateInfo.NeedUpdate; if (needUpdate) { string platform = GetPlatform(); if (null != platform && AppConfig.Instance.UpdateInfo.AppUrl.TryGetValue(platform, out string url)) await UIManager.Instance.CreateAndOpenWindow(UINameConst.UI_Update, url); return E_LoadingResult.ErrorTest; } return E_LoadingResult.Success; } private string GetPlatform() { #if UNITY_EDITOR return EditorUserBuildSettings.activeBuildTarget switch { BuildTarget.Android => "android", BuildTarget.iOS => "ios", _ => null, }; #else return Application.platform switch { RuntimePlatform.Android => "android", RuntimePlatform.IPhonePlayer => "ios", _ => null, }; #endif } private async UniTask LoadPerformance() { if (PerformanceManager.instance != null) { return E_LoadingResult.Success; } PerformanceManager.CreateInstance(); if (PerformanceManager.instance == null) { DebugUtil.LogError("PerformanceManager 创建失败"); return E_LoadingResult.ErrorTest; } await PerformanceManager.instance.LoadRes(); return E_LoadingResult.Success; } private E_LoadingResult InitGameSetting() { StorageMgr.Instance.InitServerData(); return E_LoadingResult.Success; } // private async UniTask CheckCriAtom() // { // const string AUDIO_PATH = "Assets/AudioCPK/"; // // RawFileHandle rawFileHandle = AssetManager.Instance.LoadRawFileAsync($"{AUDIO_PATH}{CriAtom.instance.acfFile}"); // await rawFileHandle; // string realPath = rawFileHandle.GetRawFilePath(); // if (realPath.EndsWith(".acf")) // CriAtom.instance.acfRealPath = realPath; // else // CriAtom.instance.acfRealPath = $"{realPath}.acf"; // // if (!File.Exists(CriAtom.instance.acfRealPath)) // File.Copy(realPath, CriAtom.instance.acfRealPath); // // foreach (CriAtomCueSheet sheet in CriAtom.instance.cueSheets) // { // #region acb // rawFileHandle = AssetManager.Instance.LoadRawFileAsync($"{AUDIO_PATH}{sheet.acbFile}"); // await rawFileHandle; // realPath = rawFileHandle.GetRawFilePath(); // if (realPath.EndsWith(".acb")) // sheet.acbRealPath = realPath; // else // sheet.acbRealPath = $"{realPath}.acb"; // // if (!File.Exists(sheet.acbRealPath)) // File.Copy(realPath, sheet.acbRealPath); // #endregion // // #region awb // rawFileHandle = AssetManager.Instance.LoadRawFileAsync($"{AUDIO_PATH}{sheet.awbFile}"); // await rawFileHandle; // realPath = rawFileHandle.GetRawFilePath(); // if (realPath.EndsWith(".awb")) // sheet.awbRealPath = realPath; // else // sheet.awbRealPath = $"{realPath}.awb"; // // if (!File.Exists(sheet.awbRealPath)) // File.Copy(realPath, sheet.awbRealPath); // #endregion // } // // CriAtom.instance.Load(); // // return E_LoadingResult.Success; // } } }