xLua:生成资源列表
一个生成资源版本列表的工具。遍历streamingAssets目录,记录所有文件的相对路径和md5值,并生成一张资源列表。客户端更新的时候则先读取这张资源列表,比对服务器资源和本地资源的md5值,有变化的再去下载。
每次需要更新资源的时候只需要修改streamingAsset下的资源,然后重新生成一下资源列表文件,再把streamingAsset目录整个丢到资源服务器就可以了,这样的更新是基于streamingAssets目录的。
using UnityEngine;
using UnityEditor;
using System.Collections.Generic;
using System.IO;
using System.Text;
public class MenuAssetMgr : MonoBehaviour {
[MenuItem("AssertMgr/Generate AssetList")]
static void GenerateAssetList()
{
string streamPath = Application.streamingAssetsPath;
string assetList = streamPath + "/assetlist.txt";
if (File.Exists(assetList))
{
File.Delete(assetList);
}
DirectoryInfo dir = new DirectoryInfo(streamPath);
List filePaths = new List();
RecursionFilePath(dir, filePaths);
Stream stream = File.Create(assetList);
using (StreamWriter writer = new StreamWriter(stream, Encoding.Default))
{
string content = string.Empty;
for (int i = 0, Imax = filePaths.Count; i < Imax; i++)
{
string path = filePaths[i];
string md5 = md5Mgr.getMD5Buffer(path);
path = path.Substring(streamPath.Length).Replace('\\', '/');
if (i > 0)
{
content += "\n";
}
content += path + "|" + md5;
}
writer.Write(content);
writer.Flush();
writer.Close();
writer.Dispose();
}
AssetDatabase.Refresh();
Debug.Log("Generate AssetList Finished");
}
static void RecursionFilePath(DirectoryInfo directoryInfo, List paths)
{
foreach (FileSystemInfo fs in directoryInfo.GetFileSystemInfos())
{
FileInfo fi = fs as FileInfo;
if (fi == null)
{
DirectoryInfo di = fs as DirectoryInfo;
RecursionFilePath(di, paths);
}
else
{
string path = fi.FullName;
if (path.IndexOf(".meta") >= 0) continue;
if (paths == null)
{
paths = new List();
}
paths.Add(path);
}
}
}
}
- 上一篇: xLua:一个LuaBehaiour
- 下一篇: 关于protobuf-net非泛型的正反序列化