142 lines
5.1 KiB
C#
142 lines
5.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEditor;
|
|
using System.IO;
|
|
using taurus.client;
|
|
using taurus.unity;
|
|
|
|
class ReadAssetBase : Editor
|
|
{
|
|
#if UNITY_IPHONE
|
|
static string PACK_PATH = Path.Combine(Path.GetFullPath(Path.Combine(Application.dataPath, "..")), "Pack", "iOS");
|
|
#else
|
|
static string PACK_PATH = Path.Combine(Path.GetFullPath(Path.Combine(Application.dataPath, "..")), "Pack", "Android32");
|
|
#endif
|
|
static string READ_PATH = Path.Combine(Application.streamingAssetsPath, "Pack");
|
|
static string READ_ZIP = Path.Combine(Application.streamingAssetsPath, "Pack.byte");
|
|
static string READ_VERSION = Path.Combine(Application.streamingAssetsPath, "version.txt");
|
|
|
|
[MenuItem("BuildTools/Read Pack In Local")]
|
|
static public void ReadAssetBaseRun()
|
|
{
|
|
if (!Directory.Exists(PACK_PATH))
|
|
{
|
|
Debug.LogError("请打包后再运行解压操作");
|
|
return;
|
|
}
|
|
try
|
|
{
|
|
EditorApplication.LockReloadAssemblies();
|
|
EditorUtility.DisplayProgressBar("正在解压资源包中", "请稍候,正在处理资源...", 0f);
|
|
if (Directory.Exists(READ_PATH))
|
|
{
|
|
Directory.Delete(READ_PATH, true);
|
|
}
|
|
Directory.CreateDirectory(READ_PATH);
|
|
|
|
if (File.Exists(READ_ZIP))
|
|
{
|
|
File.Delete(READ_ZIP);
|
|
}
|
|
|
|
if (File.Exists(READ_VERSION))
|
|
{
|
|
File.Delete(READ_VERSION);
|
|
}
|
|
|
|
string baseString = Path.Combine(Application.streamingAssetsPath , "init2_1.json");
|
|
string baseBytes = File.ReadAllText(baseString);
|
|
|
|
ArrayList baseList = (ArrayList)MiniJSON.Json.Deserialize(baseBytes);
|
|
string baseVersion = ((Hashtable)baseList[1])["version"] as string;
|
|
for (int i = 0; i < baseList.Count; i++)
|
|
{
|
|
var tem = (Hashtable)baseList[i];
|
|
string _base_path = Path.Combine("base", tem["name"] as string);
|
|
string version = tem["version"] as string;
|
|
__UnPack(version, _base_path);
|
|
}
|
|
|
|
string extendString = Path.Combine(Application.streamingAssetsPath, "init1_1.json");
|
|
string extendBytes = File.ReadAllText(extendString);
|
|
|
|
ArrayList extendList = (ArrayList)MiniJSON.Json.Deserialize(extendBytes);
|
|
for (int i = 0; i < extendList.Count; i++)
|
|
{
|
|
var tem = (Hashtable)extendList[i];
|
|
string extendBundle = tem["bundle"] as string;
|
|
string[] extendNameTem = extendBundle.Split('/');
|
|
string _extend_path = Path.Combine(extendNameTem);
|
|
string version = tem["version"] as string;
|
|
__UnPack(version, _extend_path);
|
|
}
|
|
|
|
string arv = Path.Combine(READ_PATH, string.Format("asset_config{0}.json", baseVersion));
|
|
File.WriteAllText(arv, baseBytes);
|
|
string rv = Path.Combine(READ_PATH , "version.txt");
|
|
File.WriteAllText(rv, baseVersion);
|
|
File.WriteAllText(READ_VERSION, baseVersion);
|
|
|
|
IFilePack zf = null;
|
|
zf = new FilePack20(READ_ZIP, PackMode.Write);
|
|
zf.PackFile(READ_PATH, ".meta|.manifest");
|
|
zf = null;
|
|
|
|
Directory.Delete(READ_PATH, true);
|
|
|
|
EditorUtility.DisplayDialog("完成", "处理完毕!", "确定");
|
|
}
|
|
finally
|
|
{
|
|
EditorUtility.ClearProgressBar();
|
|
EditorApplication.UnlockReloadAssemblies();
|
|
}
|
|
|
|
}
|
|
|
|
static void __UnPack(string version, string _base_path)
|
|
{
|
|
try
|
|
{
|
|
string dir = PACK_PATH;
|
|
var zip_path = Path.Combine(dir, _base_path, $"asset_pack{version}.bytes");
|
|
if (!File.Exists(zip_path))
|
|
{
|
|
Debug.LogError("打包文件不完全,请将打包所有资源包");
|
|
throw new System.Exception();
|
|
}
|
|
IFilePack zip = null;
|
|
zip = new FilePack20(zip_path, PackMode.Read);
|
|
zip.UnPackFile(READ_PATH);
|
|
|
|
var lua_pack_path = Path.Combine(READ_PATH, "lua_pack");
|
|
if (File.Exists(lua_pack_path))
|
|
{
|
|
var lua_dir = Path.Combine(READ_PATH, "lua/");
|
|
if (!Directory.Exists(READ_PATH))
|
|
Directory.CreateDirectory(READ_PATH);
|
|
zip = new FilePack20(lua_pack_path, PackMode.Read);
|
|
zip.UnPackFile(lua_dir);
|
|
File.Delete(lua_pack_path);
|
|
}
|
|
|
|
string rv = Path.Combine(READ_PATH, _base_path, "version.txt");
|
|
string directory = Path.GetDirectoryName(rv);
|
|
|
|
if (!Directory.Exists(directory))
|
|
{
|
|
Directory.CreateDirectory(directory); // 递归创建所有不存在的文件夹
|
|
}
|
|
File.WriteAllText(rv, version, System.Text.Encoding.ASCII);
|
|
}
|
|
catch
|
|
{
|
|
Directory.Delete(READ_PATH, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|