69 lines
2.1 KiB
C#
69 lines
2.1 KiB
C#
|
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
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// ProtoBuff的处理
|
|||
|
/// </summary>
|
|||
|
public class LuaProtoBuff
|
|||
|
{
|
|||
|
private static List<byte[]> _pbBufs = new List<byte[]>();
|
|||
|
private static List<string> _pbFiles = new List<string>();
|
|||
|
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<byte[]> GetAllProtoPath()
|
|||
|
{
|
|||
|
Debug.LogError("获取PB:" + _pbFiles.Count);
|
|||
|
return _pbBufs;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|