| | |
| | | using LitJson; |
| | | using System.Collections; |
| | | using System.IO; |
| | | using Cysharp.Threading.Tasks; |
| | | using UnityEngine.Networking; |
| | | |
| | | public class PackManager : GameSystemManager<PackManager> |
| | | { |
| | |
| | | |
| | | 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 |
| | | // { |
| | | // //从服务端拷贝是ini,打包用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 |
| | | { |
| | | //从服务端拷贝是ini,打包用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)) |