【热更大小】对比大小
parent
8ea6f2fcf8
commit
4549be3c7e
|
@ -9,6 +9,8 @@ using GameEditor.GameEditor.PlayerBuilder;
|
|||
using GameLogic;
|
||||
using System.Diagnostics;
|
||||
using ResUpdate;
|
||||
using GameCore;
|
||||
using System.Net;
|
||||
|
||||
namespace GameEditor.FrameTool {
|
||||
public class BuildWindow : EditorWindow
|
||||
|
@ -381,4 +383,129 @@ namespace GameEditor.FrameTool {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
//看热更大小
|
||||
public class HotfixWindow : EditorWindow
|
||||
{
|
||||
static VersionTxt m_VersionTxt; // 热更版本
|
||||
static string fixVersion;
|
||||
static string fPath;
|
||||
static List<ResourceFile> exDataList;
|
||||
static List<ResourceFile> inDataList;
|
||||
static DirectoryInfo pathInfo;
|
||||
static decimal Size = 0;
|
||||
static Dictionary<string, ResourceFile> inDataDic = new Dictionary<string, ResourceFile>();
|
||||
|
||||
[MenuItem("Build/HotfixSize")]
|
||||
static void Init()
|
||||
{
|
||||
fixVersion = Application.dataPath + "/../AssetBundles/version.txt";
|
||||
pathInfo = new DirectoryInfo(Application.dataPath);
|
||||
GetExternalFile(fixVersion);
|
||||
GetInternalData();
|
||||
|
||||
// Get existing open window or if none, make a new one:
|
||||
HotfixWindow window = (HotfixWindow)EditorWindow.GetWindow(typeof(HotfixWindow));
|
||||
window.titleContent = new GUIContent("热更大小");
|
||||
window.Show();
|
||||
}
|
||||
//下载外部.unity3d文件
|
||||
private static void GetExternalFile(string path)
|
||||
{
|
||||
//获取下载文件链接
|
||||
string json = File.ReadAllText(path);
|
||||
m_VersionTxt = JsonUtility.FromJson<VersionTxt>(json);
|
||||
string url = m_VersionTxt.resUrl + "Android/files.unity3d";
|
||||
//获取文件存放路径
|
||||
fPath = pathInfo.Parent.FullName + @"\Temp";
|
||||
if (File.Exists(fPath + @"\files.unity3d"))
|
||||
{
|
||||
File.Delete(fPath + @"\files.unity3d");
|
||||
}
|
||||
// 设置参数
|
||||
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
|
||||
//发送请求并获取相应回应数据
|
||||
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
|
||||
//直到request.GetResponse()程序才开始向目标网页发送Post请求
|
||||
Stream responseStream = response.GetResponseStream();
|
||||
//创建本地文件写入流
|
||||
Stream stream = new FileStream(fPath + @"\files.unity3d", FileMode.Create, FileAccess.Write);
|
||||
byte[] bArr = new byte[1024];
|
||||
int size = responseStream.Read(bArr, 0, (int)bArr.Length);
|
||||
while (size > 0)
|
||||
{
|
||||
stream.Write(bArr, 0, size);
|
||||
size = responseStream.Read(bArr, 0, (int)bArr.Length);
|
||||
}
|
||||
stream.Close();
|
||||
responseStream.Close();
|
||||
}
|
||||
|
||||
//遍历外部unity3d数据
|
||||
private static void GetExternalData()
|
||||
{
|
||||
UnityEngine.Debug.Log(fPath + "\\" + UpdateConfigs.FILES);
|
||||
UnityEngine.AssetBundle bundle = UnityEngine.AssetBundle.LoadFromFile(fPath + "\\" + UpdateConfigs.FILES);
|
||||
ResourceFiles files = bundle.LoadAsset<ResourceFiles>("game");
|
||||
exDataList = files.files;
|
||||
bundle.Unload(true);
|
||||
}
|
||||
|
||||
//遍历内部unity3d数据
|
||||
private static void GetInternalData()
|
||||
{
|
||||
UnityEngine.AssetBundle bundle = UnityEngine.AssetBundle.LoadFromFile(pathInfo.Parent.FullName + @"\AssetBundles\" + UpdateConfigs.FILES);
|
||||
ResourceFiles files = bundle.LoadAsset<ResourceFiles>("game");
|
||||
inDataList = files.files;
|
||||
bundle.Unload(true);
|
||||
inDataList.Sort(delegate (ResourceFile a, ResourceFile b) { return a.crc.CompareTo(b.crc); });
|
||||
for (int i = 0; i < inDataList.Count; i++)
|
||||
{
|
||||
if (!inDataDic.ContainsKey(inDataList[i].fileName))
|
||||
{
|
||||
inDataDic.Add(inDataList[i].fileName, inDataList[i]);
|
||||
}else
|
||||
{
|
||||
inDataDic[inDataList[i].fileName] = inDataList[i];
|
||||
}
|
||||
|
||||
//inDataDic.Add(inDataList[i].fileName, inDataList[i]);
|
||||
//UnityEngine.Debug.Log("fileName:" + inDataList[i].fileName + " CRC:" + inDataList[i].crc + " Size:" + inDataList[i].size);
|
||||
}
|
||||
}
|
||||
|
||||
//对比数据
|
||||
private static void CompareData()
|
||||
{
|
||||
for (int i = 0; i < exDataList.Count; i++)
|
||||
{
|
||||
if (!inDataDic.ContainsKey (exDataList[i].fileName))
|
||||
{
|
||||
Size = exDataList[i].size + Size;
|
||||
}
|
||||
}
|
||||
UnityEngine.Debug.Log("Size:" + Size);
|
||||
Size = Size / 1048576;
|
||||
UnityEngine.Debug.Log("Size:" + Size);
|
||||
}
|
||||
|
||||
void OnGUI()
|
||||
{
|
||||
EditorGUILayout.BeginVertical();
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.LabelField("线上:");
|
||||
//m_VersionTxt.resUrl = EditorGUILayout.TextField(m_VersionTxt.resUrl);
|
||||
EditorGUILayout.EndVertical();
|
||||
|
||||
if (GUILayout.Button("对比大小", GUILayout.Height(40f)))
|
||||
{
|
||||
Size = 0;
|
||||
UnityEngine.Debug.Log("对比成功");
|
||||
GetExternalData();
|
||||
CompareData();
|
||||
}
|
||||
string resUrl = Size.ToString("0.00") + "M";
|
||||
resUrl = EditorGUILayout.TextField(resUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue