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_Name: GameConfig
m_EditorClassIdentifier:
packageName: com.crazyballcatgame.frozenarena
packageName: com.tronwingame.redhotroast
hardwareAcceleration: 1
@@ -46,7 +46,7 @@ namespace SGModule.ConfigLoader
private void FirstLaunchCopyConfig(Action<bool> callback)
{
SetFirstLaunch();
Debug.Log("000000000000000000000000000000");
Debug.Log("000000000000000000000000000000");
FileNetworkManager.Instance.CopyStreamingAssetsToPersistentDataPath(result =>
{
Debug.Log("0000000000000000000000000000006");
@@ -156,12 +156,6 @@ Debug.Log("000000000000000000000000000000");
{
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 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<bool> onComplete = null)
{
Debug.Log("开始加载 Configs 文件夹");
private void CopyFile(Action<bool> onComplete = null)
{
// 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<TextAsset>(jsonLocation);
Debug.Log("0000000000000000000000000000003");
TextAsset[] files = Resources.LoadAll<TextAsset>("Configs");
// yield return textAssetAsync;
// if (textAssetAsync.Status == AsyncOperationStatus.Succeeded)
// {
if (files.Length > 0)
{
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);
if (!Directory.Exists(_configFolderPath))
Directory.CreateDirectory(_configFolderPath);
var destFilePath = Path.Combine(_configFolderPath, jsonFileName + ".json");
// 同步写入文件
File.WriteAllBytes(destFilePath, jsonFile.bytes);
Debug.Log("0000000000000000000000000000005");
// 等待一帧再执行回调,保持协程风格
yield return null;
onComplete?.Invoke(true);
// }
// 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("Failed to load folder resources");
// onComplete?.Invoke(false);
// }
}
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) {
// // 查找以 ".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<TextAsset>(jsonLocation);
// Debug.Log("0000000000000000000000000000003");
// TextAsset[] files = Resources.LoadAll<TextAsset>("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);
// 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");
// // 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);
// // }
// }
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
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: {}