提交
This commit is contained in:
@@ -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,18 +46,18 @@ namespace SGModule.ConfigLoader
|
||||
private void FirstLaunchCopyConfig(Action<bool> 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);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
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) {
|
||||
// 查找以 ".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<TextAsset>(jsonLocation);
|
||||
Debug.Log("0000000000000000000000000000003");
|
||||
TextAsset[] files = Resources.LoadAll<TextAsset>("Configs");
|
||||
// yield return textAssetAsync;
|
||||
// // 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);
|
||||
// // 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<bool> onComplete = null)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user