From e3e4ed259b23b433a3d6f0dc8c1a50282ad80e2a Mon Sep 17 00:00:00 2001
From: hch <305670599@qq.com>
Date: 星期五, 10 四月 2026 15:20:12 +0800
Subject: [PATCH] 0312 调整异步读表
---
Main/System/KnapSack/PackManager.cs | 87 ++++++++++++++++++++++++++++++-------------
1 files changed, 61 insertions(+), 26 deletions(-)
diff --git a/Main/System/KnapSack/PackManager.cs b/Main/System/KnapSack/PackManager.cs
index 7861f75..9ab0a5f 100644
--- a/Main/System/KnapSack/PackManager.cs
+++ b/Main/System/KnapSack/PackManager.cs
@@ -5,6 +5,8 @@
using LitJson;
using System.Collections;
using System.IO;
+using Cysharp.Threading.Tasks;
+using UnityEngine.Networking;
public class PackManager : GameSystemManager<PackManager>
{
@@ -522,53 +524,86 @@
void ParsePackConfigIni()
{
- string[] lines = LoadConfigIni("MapServerConfig");
- foreach (string line in lines)
+ LoadConfigIni("MapServerConfig").ContinueWith(lines =>
{
- if (line.StartsWith("PackCnt") && line.Contains("="))
+ foreach (string line in lines)
{
- string[] parts = line.Split('=');
- if (parts.Length == 2 && int.TryParse(parts[1], out int count))
+ if (line.StartsWith("PackCnt") && line.Contains("="))
{
- string packTypeStr = parts[0].Replace("PackCnt", "");
- if (int.TryParse(packTypeStr, out int packTypeIndex))
+ string[] parts = line.Split('=');
+ if (parts.Length == 2 && int.TryParse(parts[1], out int count))
{
- PackMaxCountDict[packTypeIndex] = count;
+ string packTypeStr = parts[0].Replace("PackCnt", "");
+ if (int.TryParse(packTypeStr, out int packTypeIndex))
+ {
+ PackMaxCountDict[packTypeIndex] = count;
+ }
}
}
}
- }
+ });
+
+
+
}
- public string[] LoadConfigIni(string name)
+// public string[] LoadConfigIni(string name)
+// {
+// string path = string.Empty;
+// #if UNITY_EDITOR
+// if (!AssetSource.isUseAssetBundle)
+// {
+// path = ResourcesPath.CONFIG_FODLER + "/" + name + ".ini";
+// }
+// else
+// #endif
+// {
+// //浠庢湇鍔$鎷疯礉鏄痠ni锛屾墦鍖呯敤txt缁熶竴澶勭悊
+// path = AssetVersionUtility.GetAssetFilePath($"Config/{name}.txt");
+// }
+
+// // #if UNITY_ANDROID && !UNITY_EDITOR
+// using var req = UnityEngine.Networking.UnityWebRequest.Get(path);
+// req.SendWebRequest();
+// while (!req.isDone) { }
+
+// if (req.result != UnityEngine.Networking.UnityWebRequest.Result.Success)
+// throw new Exception(req.error);
+
+// return req.downloadHandler.text
+// .Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
+// // #endif
+// // return File.ReadAllLines(path);
+// }
+
+ public UniTask<string[]> LoadConfigIni(string name)
{
- string path = string.Empty;
-#if UNITY_EDITOR
+ return LoadConfigIniInternal(name);
+ }
+
+ private async UniTask<string[]> LoadConfigIniInternal(string name)
+ {
+ string path;
+
+ #if UNITY_EDITOR
if (!AssetSource.isUseAssetBundle)
{
- path = ResourcesPath.CONFIG_FODLER + "/" + name + ".ini";
+ path = $"{ResourcesPath.CONFIG_FODLER}/{name}.ini";
+ return File.ReadAllLines(path);
}
- else
-#endif
- {
- //浠庢湇鍔$鎷疯礉鏄痠ni锛屾墦鍖呯敤txt缁熶竴澶勭悊
- path = AssetVersionUtility.GetAssetFilePath($"Config/{name}.txt");
- }
+ #endif
- // #if UNITY_ANDROID && !UNITY_EDITOR
+ path = AssetVersionUtility.GetAssetFilePath($"Config/{name}.txt");
+
using var req = UnityEngine.Networking.UnityWebRequest.Get(path);
- req.SendWebRequest();
- while (!req.isDone) { }
+ await req.SendWebRequest();
if (req.result != UnityEngine.Networking.UnityWebRequest.Result.Success)
- throw new Exception(req.error);
+ throw new Exception($"LoadConfigIni failed: {req.error}");
return req.downloadHandler.text
.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
- // #endif
- // return File.ReadAllLines(path);
}
-
public int GetCanBuyPackGirdCount(PackType type)
{
if (!PackMaxCountDict.ContainsKey((int)type))
--
Gitblit v1.8.0