using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using UnityEngine; using UnityEngine.Gonbest.MagicCube; namespace Thousandto.Code.Logic { /// /// ProtoBuff的处理 /// public class LuaProtoBuff { private static List _pbBufs = new List(); private static List _pbFiles = new List(); private static bool _isLoaded = false; public static bool IsLoaded() { return _isLoaded && _pbFiles.Count > 0 && _pbBufs.Count == _pbFiles.Count; } public static void Init() { _isLoaded = false; Debug.LogError("::::" + AppManager.Instance.AssetData.Count); #if UNITY_WEBGL var e = AppManager.Instance.AssetData.GetEnumerator(); while (e.MoveNext()) { if (e.Current.Key.EndsWith(".pb")) { _pbFiles.Add(e.Current.Value.Path); AppManager.Instance.ReadBytesAsync(e.Current.Value.Path, x => { if (x != null) { _pbBufs.Add(x); } else { Debug.LogError("读取Bytes失败:"+ e.Current.Value.Path); } }); } } #else DirectoryInfo root = new DirectoryInfo(PathUtils.GetConfigFilePath("proto")); FileInfo[] fileInfos = root.GetFiles("*.pb"); Debug.Log("Pb文件数量:" + fileInfos.Length); for (int i = 0; i < fileInfos.Length; i++) { _pbFiles.Add(fileInfos[i].FullName); _pbBufs.Add(File.ReadAllBytes(fileInfos[i].FullName)); } #endif _isLoaded = true; } public static List GetAllProtoPath() { Debug.LogError("获取PB:" + _pbFiles.Count); return _pbBufs; } } }