在生成新的AB包后,辅助生成version.txt工具,代码很简单 找出最新的AB包版本的BuildReport文件读取最新的length,hashcode,zip_length, zip hash code设置到桌面上的version.txt。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using StarForce;
using UnityGameFramework.Editor.ResourceTools;
using System.IO;
//------------------------------------------------------------
// Game Framework
// Copyright © 2013-2020 Jiang Yin. All rights reserved.
// Homepage: https://gameframework.cn/
// Feedback: mailto:ellan@gameframework.cn
//------------------------------------------------------------
[System.Serializable]
public class GameVersionInfo
{
// 是否需要强制更新游戏应用
public bool ForceUpdateGame;
// 最新的游戏版本号
public string LatestGameVersion;
// 最新的游戏内部版本号
public int InternalGameVersion;
// 最新的资源内部版本号
public int InternalResourceVersion;
// 资源更新下载地址
public string UpdatePrefixUri;
// 资源版本列表长度
public int VersionListLength;
// 资源版本列表哈希值
public int VersionListHashCode;
// 资源版本列表压缩后长度
public int VersionListZipLength;
// 资源版本列表压缩后哈希值
public int VersionListZipHashCode;
}
public static class HotfixHelperEditor
{
static string BuildReportPath = @"E:\UnityIndieGame\GameDemo\AssetBundle\BuildReport\";
[MenuItem("Tools/UpdateVersionConfig")]
static void UpdateVersionConfig()
{
string[] allDirectories = Directory.GetDirectories(BuildReportPath);
int maxNum = -1;
string maxPath = "";
foreach (var v in allDirectories)
{
string[] arr = v.Split('_');
int num = int.Parse(arr[arr.Length - 1]);
if (num > maxNum)
{
maxNum = num;
maxPath = v;
}
}
if (!string.IsNullOrEmpty(maxPath))
{
//Debug.LogError("maxPath:" + maxPath);
string path = @"C:\Users\lenovo\Desktop\version.txt";
//Debug.LogError(path);
string versionStr = File.ReadAllText(path);
//Debug.Log(versionStr);
string[] buildLogLines = File.ReadAllLines(maxPath + "/BuildLog.txt");
int length, zip_length, hash_code, zip_hash_code;
length = 0;
zip_length = 0;
hash_code = 0;
zip_hash_code = 0;
foreach (var v in buildLogLines)
{
if (v.IndexOf("length is '") != -1)
{
string temp1 = v.Substring(v.IndexOf("length is '"));
length = int.Parse(temp1.Split('\'')[1]);
}
if (v.IndexOf("zip length is '") != -1)
{
string temp1 = v.Substring(v.IndexOf("zip length is '"));
zip_length = int.Parse(temp1.Split('\'')[1]);
}
if (v.IndexOf("hash code is '") != -1)
{
string temp1 = v.Substring(v.IndexOf("hash code is '"));
temp1 = temp1.Split('\'')[1];
hash_code = int.Parse(temp1.Split('[')[0]);
}
if (v.IndexOf("zip hash code is '") != -1)
{
string temp1 = v.Substring(v.IndexOf("zip hash code is '"));
temp1 = temp1.Split('\'')[1];
zip_hash_code = int.Parse(temp1.Split('[')[0]);
}
}
//Debug.LogError("maxNum:" + maxNum);
//Debug.LogError("length:" + length);
//Debug.LogError("hash_code:" + hash_code);
//Debug.LogError("zip_length:" + zip_length);
//Debug.LogError("zip_hash_code:" + zip_hash_code);
GameVersionInfo versionConfig = JsonUtility.FromJson<GameVersionInfo>(versionStr);
versionConfig.InternalResourceVersion = maxNum;
versionConfig.VersionListLength = length;
versionConfig.VersionListHashCode = hash_code;
versionConfig.VersionListZipLength = zip_length;
versionConfig.VersionListZipHashCode = zip_hash_code;
File.WriteAllText(path, JsonUtility.ToJson(versionConfig, true));
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
}
else
{
Debug.LogError("完全没有任何文件");
}
}
}