From 2dcb0c1c3a5048fe3ca8377152c214cde3dcee80 Mon Sep 17 00:00:00 2001 From: changyunjia <905640960@qq.com> Date: Fri, 12 Jun 2026 16:16:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Resources/GameConfig.asset | 2 +- .../Scripts/ConfigLoader/ConfigFileManager.cs | 26 ++-- .../ConfigLoader/FileNetworkManager.cs | 114 ++++++++++++------ ProjectSettings/ProjectSettings.asset | 2 +- 4 files changed, 86 insertions(+), 58 deletions(-) diff --git a/Assets/Resources/GameConfig.asset b/Assets/Resources/GameConfig.asset index 5437143..e2a24cd 100644 --- a/Assets/Resources/GameConfig.asset +++ b/Assets/Resources/GameConfig.asset @@ -12,5 +12,5 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: c836612725633cc4093d7ac06e7d9ef1, type: 3} m_Name: GameConfig m_EditorClassIdentifier: - packageName: com.crazyballcatgame.frozenarena + packageName: com.tronwingame.redhotroast hardwareAcceleration: 1 diff --git a/Assets/SGModule/ConfigLoader/SGModule/Scripts/ConfigLoader/ConfigFileManager.cs b/Assets/SGModule/ConfigLoader/SGModule/Scripts/ConfigLoader/ConfigFileManager.cs index 7225f41..5b462df 100644 --- a/Assets/SGModule/ConfigLoader/SGModule/Scripts/ConfigLoader/ConfigFileManager.cs +++ b/Assets/SGModule/ConfigLoader/SGModule/Scripts/ConfigLoader/ConfigFileManager.cs @@ -46,18 +46,18 @@ namespace SGModule.ConfigLoader private void FirstLaunchCopyConfig(Action callback) { SetFirstLaunch(); -Debug.Log("000000000000000000000000000000"); + Debug.Log("000000000000000000000000000000"); FileNetworkManager.Instance.CopyStreamingAssetsToPersistentDataPath(result => { - Debug.Log("0000000000000000000000000000006"); + Debug.Log("0000000000000000000000000000006"); var isSuccess = false; if (result) { - Debug.Log("0000000000000000000000000000007"); + Debug.Log("0000000000000000000000000000007"); var names = FileNetworkManager.Instance.GetFileNamesFromPersistentDataPath(FileNetworkManager.FolderName); if (names.Length > 0) { - Debug.Log("0000000000000000000000000000008"); + Debug.Log("0000000000000000000000000000008"); SetSavedConfigFileName(names[0]); isSuccess = true; } @@ -151,18 +151,12 @@ Debug.Log("000000000000000000000000000000"); FirstLaunchCopyConfig(success => { FileNetworkManager.Instance.ReadData(path, result => - { - if (!string.IsNullOrEmpty(result)) - { - callback?.Invoke(true, result); - } - else - { - Log.ConfigLoader.Error("读取本地数据异常"); - IncrementErrorCount(); - callback?.Invoke(false, null); - } - }); + { + if (!string.IsNullOrEmpty(result)) + { + callback?.Invoke(true, result); + } + }); }); diff --git a/Assets/SGModule/ConfigLoader/SGModule/Scripts/ConfigLoader/FileNetworkManager.cs b/Assets/SGModule/ConfigLoader/SGModule/Scripts/ConfigLoader/FileNetworkManager.cs index 85efad0..53e4ad8 100644 --- a/Assets/SGModule/ConfigLoader/SGModule/Scripts/ConfigLoader/FileNetworkManager.cs +++ b/Assets/SGModule/ConfigLoader/SGModule/Scripts/ConfigLoader/FileNetworkManager.cs @@ -7,6 +7,8 @@ using SGModule.Common.Base; using SGModule.Common.Helper; using UnityEngine; using UnityEngine.Networking; +using System.Threading.Tasks; + #if UNITY_EDITOR using UnityEditor; #endif @@ -51,7 +53,8 @@ namespace SGModule.ConfigLoader Directory.CreateDirectory(_configFolderPath); } Debug.Log("0000000000000000000000000000002"); - CopyFile(onComplete); + // CopyFile(onComplete); + StartCoroutine(CopyFile(onComplete)); } private void HandleInitializationError() @@ -68,56 +71,87 @@ namespace SGModule.ConfigLoader // 提示用户或执行其他逻辑 // 比如:显示弹窗或退出程序 } + private IEnumerator CopyFile(Action onComplete = null) +{ + Debug.Log("开始加载 Configs 文件夹"); - private void CopyFile(Action onComplete = null) - { + TextAsset[] files = Resources.LoadAll("Configs"); + + if (files.Length > 0) + { + TextAsset jsonFile = files[0]; + string jsonFileName = jsonFile.name; + + Log.ConfigLoader.Info($"Loaded JSON Name:{jsonFileName} content: " + jsonFile.text); + + if (!Directory.Exists(_configFolderPath)) + Directory.CreateDirectory(_configFolderPath); + + var destFilePath = Path.Combine(_configFolderPath, jsonFileName + ".json"); + + // 同步写入文件 + File.WriteAllBytes(destFilePath, jsonFile.bytes); + + // 等待一帧再执行回调,保持协程风格 + yield return null; + onComplete?.Invoke(true); + } + else + { + Log.ConfigLoader.Error("Resources/Configs 下没有找到任何 TextAsset 文件"); + yield return null; + onComplete?.Invoke(false); + } +} + // private IEnumerable CopyFile(Action onComplete = null) + // { - // if (handle.Status == AsyncOperationStatus.Succeeded) { - // 查找以 ".json" 结尾的文件 - // var jsonLocation = handle.Result.FirstOrDefault(loc => loc.PrimaryKey.EndsWith(".json")); + // // if (handle.Status == AsyncOperationStatus.Succeeded) { + // // 查找以 ".json" 结尾的文件 + // // var jsonLocation = handle.Result.FirstOrDefault(loc => loc.PrimaryKey.EndsWith(".json")); - // if (jsonLocation != null) { - // var jsonFileName = Path.GetFileName(jsonLocation.PrimaryKey); - // 加载 JSON 文件 - // var textAssetAsync = Addressables.LoadAssetAsync(jsonLocation); - Debug.Log("0000000000000000000000000000003"); - TextAsset[] files = Resources.LoadAll("Configs"); - // yield return textAssetAsync; + // // if (jsonLocation != null) { + // // var jsonFileName = Path.GetFileName(jsonLocation.PrimaryKey); + // // 加载 JSON 文件 + // // var textAssetAsync = Addressables.LoadAssetAsync(jsonLocation); + // Debug.Log("0000000000000000000000000000003"); + // TextAsset[] files = Resources.LoadAll("Configs"); + // // yield return textAssetAsync; - // if (textAssetAsync.Status == AsyncOperationStatus.Succeeded) - // { - TextAsset jsonFile = files[0]; - string jsonFileName = jsonFile.name; - Log.ConfigLoader.Info($"Loaded JSON Name:{jsonFileName} content: " + jsonFile.text); + // // if (textAssetAsync.Status == AsyncOperationStatus.Succeeded) + // // { + // TextAsset jsonFile = files[0]; + // string jsonFileName = jsonFile.name; + // Log.ConfigLoader.Info($"Loaded JSON Name:{jsonFileName} content: " + jsonFile.text); - Debug.Log("0000000000000000000000000000004"); - var destFilePath = Path.Combine(_configFolderPath, jsonFileName); - File.WriteAllBytes(destFilePath, jsonFile.bytes); - Debug.Log("0000000000000000000000000000005"); - onComplete?.Invoke(true); + // Debug.Log("0000000000000000000000000000004"); + // var destFilePath = Path.Combine(_configFolderPath, jsonFileName); + // File.WriteAllBytes(destFilePath, jsonFile.bytes); + // Debug.Log("0000000000000000000000000000005"); + // onComplete?.Invoke(true); - // } - // else { - // Log.ConfigLoader.Error("Failed to load JSON file"); + // // } + // // else { + // // Log.ConfigLoader.Error("Failed to load JSON file"); - // onComplete?.Invoke(false); - // } - // } - // else { - // Log.ConfigLoader.Error("No JSON file found in folder"); + // // onComplete?.Invoke(false); + // // } + // // } + // // else { + // // Log.ConfigLoader.Error("No JSON file found in folder"); - // onComplete?.Invoke(false); - // } - // } - // else - // { - // Log.ConfigLoader.Error("Failed to load folder resources"); + // // onComplete?.Invoke(false); + // // } + // // } + // // else + // // { + // // Log.ConfigLoader.Error("Failed to load folder resources"); - // onComplete?.Invoke(false); - // } + // // onComplete?.Invoke(false); + // // } - } + // } private IEnumerator CopyFile(string sourceFile, string destFile, Action onComplete = null) { diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index 75e30d3..07ed250 100644 --- a/ProjectSettings/ProjectSettings.asset +++ b/ProjectSettings/ProjectSettings.asset @@ -898,7 +898,7 @@ PlayerSettings: WebGL: UNITY_VISUAL_SCRIPTING;ES3_TMPRO;ES3_UGUI Windows Store Apps: UNITY_VISUAL_SCRIPTING;ES3_TMPRO;ES3_UGUI XboxOne: UNITY_VISUAL_SCRIPTING;ES3_TMPRO;ES3_UGUI - iPhone: MAX;GAME_RELEASE1;UNITY_VISUAL_SCRIPTING;ES3_TMPRO;ES3_UGUI;USE_ADDRESSABLES;UNITY_IAP;UNITY_PURCHASING + iPhone: MAX;GAME_RELEASE1;UNITY_VISUAL_SCRIPTING;ES3_TMPRO;ES3_UGUI;UNITY_IAP;UNITY_PURCHASING tvOS: UNITY_VISUAL_SCRIPTING;ES3_TMPRO;ES3_UGUI additionalCompilerArguments: {} platformArchitecture: {}