This commit is contained in:
2026-06-12 16:16:48 +08:00
parent 3bf5bb091b
commit 2dcb0c1c3a
4 changed files with 86 additions and 58 deletions
+1 -1
View File
@@ -12,5 +12,5 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: c836612725633cc4093d7ac06e7d9ef1, type: 3} m_Script: {fileID: 11500000, guid: c836612725633cc4093d7ac06e7d9ef1, type: 3}
m_Name: GameConfig m_Name: GameConfig
m_EditorClassIdentifier: m_EditorClassIdentifier:
packageName: com.crazyballcatgame.frozenarena packageName: com.tronwingame.redhotroast
hardwareAcceleration: 1 hardwareAcceleration: 1
@@ -46,18 +46,18 @@ namespace SGModule.ConfigLoader
private void FirstLaunchCopyConfig(Action<bool> callback) private void FirstLaunchCopyConfig(Action<bool> callback)
{ {
SetFirstLaunch(); SetFirstLaunch();
Debug.Log("000000000000000000000000000000"); Debug.Log("000000000000000000000000000000");
FileNetworkManager.Instance.CopyStreamingAssetsToPersistentDataPath(result => FileNetworkManager.Instance.CopyStreamingAssetsToPersistentDataPath(result =>
{ {
Debug.Log("0000000000000000000000000000006"); Debug.Log("0000000000000000000000000000006");
var isSuccess = false; var isSuccess = false;
if (result) if (result)
{ {
Debug.Log("0000000000000000000000000000007"); Debug.Log("0000000000000000000000000000007");
var names = FileNetworkManager.Instance.GetFileNamesFromPersistentDataPath(FileNetworkManager.FolderName); var names = FileNetworkManager.Instance.GetFileNamesFromPersistentDataPath(FileNetworkManager.FolderName);
if (names.Length > 0) if (names.Length > 0)
{ {
Debug.Log("0000000000000000000000000000008"); Debug.Log("0000000000000000000000000000008");
SetSavedConfigFileName(names[0]); SetSavedConfigFileName(names[0]);
isSuccess = true; isSuccess = true;
} }
@@ -151,18 +151,12 @@ Debug.Log("000000000000000000000000000000");
FirstLaunchCopyConfig(success => FirstLaunchCopyConfig(success =>
{ {
FileNetworkManager.Instance.ReadData(path, result => FileNetworkManager.Instance.ReadData(path, result =>
{ {
if (!string.IsNullOrEmpty(result)) if (!string.IsNullOrEmpty(result))
{ {
callback?.Invoke(true, result); callback?.Invoke(true, result);
} }
else });
{
Log.ConfigLoader.Error("读取本地数据异常");
IncrementErrorCount();
callback?.Invoke(false, null);
}
});
}); });
@@ -7,6 +7,8 @@ using SGModule.Common.Base;
using SGModule.Common.Helper; using SGModule.Common.Helper;
using UnityEngine; using UnityEngine;
using UnityEngine.Networking; using UnityEngine.Networking;
using System.Threading.Tasks;
#if UNITY_EDITOR #if UNITY_EDITOR
using UnityEditor; using UnityEditor;
#endif #endif
@@ -51,7 +53,8 @@ namespace SGModule.ConfigLoader
Directory.CreateDirectory(_configFolderPath); Directory.CreateDirectory(_configFolderPath);
} }
Debug.Log("0000000000000000000000000000002"); Debug.Log("0000000000000000000000000000002");
CopyFile(onComplete); // CopyFile(onComplete);
StartCoroutine(CopyFile(onComplete));
} }
private void HandleInitializationError() private void HandleInitializationError()
@@ -68,56 +71,87 @@ namespace SGModule.ConfigLoader
// 提示用户或执行其他逻辑 // 提示用户或执行其他逻辑
// 比如:显示弹窗或退出程序 // 比如:显示弹窗或退出程序
} }
private IEnumerator CopyFile(Action<bool> onComplete = null)
{
Debug.Log("开始加载 Configs 文件夹");
private void CopyFile(Action<bool> onComplete = null) TextAsset[] files = Resources.LoadAll<TextAsset>("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<bool> onComplete = null)
// {
// if (handle.Status == AsyncOperationStatus.Succeeded) { // // if (handle.Status == AsyncOperationStatus.Succeeded) {
// 查找以 ".json" 结尾的文件 // // 查找以 ".json" 结尾的文件
// var jsonLocation = handle.Result.FirstOrDefault(loc => loc.PrimaryKey.EndsWith(".json")); // // var jsonLocation = handle.Result.FirstOrDefault(loc => loc.PrimaryKey.EndsWith(".json"));
// if (jsonLocation != null) { // // if (jsonLocation != null) {
// var jsonFileName = Path.GetFileName(jsonLocation.PrimaryKey); // // var jsonFileName = Path.GetFileName(jsonLocation.PrimaryKey);
// 加载 JSON 文件 // // 加载 JSON 文件
// var textAssetAsync = Addressables.LoadAssetAsync<TextAsset>(jsonLocation); // // var textAssetAsync = Addressables.LoadAssetAsync<TextAsset>(jsonLocation);
Debug.Log("0000000000000000000000000000003"); // Debug.Log("0000000000000000000000000000003");
TextAsset[] files = Resources.LoadAll<TextAsset>("Configs"); // TextAsset[] files = Resources.LoadAll<TextAsset>("Configs");
// yield return textAssetAsync; // // yield return textAssetAsync;
// if (textAssetAsync.Status == AsyncOperationStatus.Succeeded) // // if (textAssetAsync.Status == AsyncOperationStatus.Succeeded)
// { // // {
TextAsset jsonFile = files[0]; // TextAsset jsonFile = files[0];
string jsonFileName = jsonFile.name; // string jsonFileName = jsonFile.name;
Log.ConfigLoader.Info($"Loaded JSON Name:{jsonFileName} content: " + jsonFile.text); // Log.ConfigLoader.Info($"Loaded JSON Name:{jsonFileName} content: " + jsonFile.text);
Debug.Log("0000000000000000000000000000004"); // Debug.Log("0000000000000000000000000000004");
var destFilePath = Path.Combine(_configFolderPath, jsonFileName); // var destFilePath = Path.Combine(_configFolderPath, jsonFileName);
File.WriteAllBytes(destFilePath, jsonFile.bytes); // File.WriteAllBytes(destFilePath, jsonFile.bytes);
Debug.Log("0000000000000000000000000000005"); // Debug.Log("0000000000000000000000000000005");
onComplete?.Invoke(true); // onComplete?.Invoke(true);
// } // // }
// else { // // else {
// Log.ConfigLoader.Error("Failed to load JSON file"); // // Log.ConfigLoader.Error("Failed to load JSON file");
// onComplete?.Invoke(false); // // onComplete?.Invoke(false);
// } // // }
// } // // }
// else { // // else {
// Log.ConfigLoader.Error("No JSON file found in folder"); // // Log.ConfigLoader.Error("No JSON file found in folder");
// onComplete?.Invoke(false); // // onComplete?.Invoke(false);
// } // // }
// } // // }
// else // // else
// { // // {
// Log.ConfigLoader.Error("Failed to load folder resources"); // // Log.ConfigLoader.Error("Failed to load folder resources");
// onComplete?.Invoke(false); // // onComplete?.Invoke(false);
// } // // }
} // }
private IEnumerator CopyFile(string sourceFile, string destFile, Action<bool> onComplete = null) private IEnumerator CopyFile(string sourceFile, string destFile, Action<bool> onComplete = null)
{ {
+1 -1
View File
@@ -898,7 +898,7 @@ PlayerSettings:
WebGL: UNITY_VISUAL_SCRIPTING;ES3_TMPRO;ES3_UGUI WebGL: UNITY_VISUAL_SCRIPTING;ES3_TMPRO;ES3_UGUI
Windows Store Apps: 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 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 tvOS: UNITY_VISUAL_SCRIPTING;ES3_TMPRO;ES3_UGUI
additionalCompilerArguments: {} additionalCompilerArguments: {}
platformArchitecture: {} platformArchitecture: {}