Update editor code

pull/51/head
hevinci 2022-11-02 21:57:08 +08:00
parent e8e69a2e86
commit a805e0639e
8 changed files with 65 additions and 101 deletions

View File

@ -58,11 +58,16 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
public readonly BuildPatchInfo PatchInfo = new BuildPatchInfo(); public readonly BuildPatchInfo PatchInfo = new BuildPatchInfo();
/// <summary>
/// Bundle文件的加载方法
/// </summary>
public EBundleLoadMethod LoadMethod { set; get; }
/// <summary> /// <summary>
/// 加密生成文件的路径 /// 加密生成文件的路径
/// 注意:如果未加密该路径为空 /// 注意:如果未加密该路径为空
/// </summary> /// </summary>
public string EncryptedFilePath { set; get; } = string.Empty; public string EncryptedFilePath { set; get; }
/// <summary> /// <summary>
/// 是否为原生文件 /// 是否为原生文件
@ -177,9 +182,13 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
internal PatchBundle CreatePatchBundle() internal PatchBundle CreatePatchBundle()
{ {
string fileHash = PatchInfo.PatchFileHash;
string fileCRC = PatchInfo.PatchFileCRC;
long fileSize = PatchInfo.PatchFileSize;
bool isRawFile = IsRawFile;
byte loadMethod = (byte)LoadMethod;
string[] tags = GetBundleTags(); string[] tags = GetBundleTags();
PatchBundle patchBundle = new PatchBundle(BundleName, PatchInfo.PatchFileHash, PatchInfo.PatchFileCRC, PatchInfo.PatchFileSize, tags); PatchBundle patchBundle = new PatchBundle(BundleName, fileHash, fileCRC, fileSize, isRawFile, loadMethod, tags);
patchBundle.SetFlagsValue(IsRawFile, IsEncryptedFile);
return patchBundle; return patchBundle;
} }
} }

View File

@ -8,21 +8,6 @@ namespace YooAsset.Editor
[Serializable] [Serializable]
public class ReportBundleInfo public class ReportBundleInfo
{ {
public class FlagsData
{
public bool IsEncrypted { private set; get; }
public bool IsBuildin { private set; get; }
public bool IsRawFile { private set; get; }
public FlagsData(bool isEncrypted, bool isBuildin, bool isRawFile)
{
IsEncrypted = isEncrypted;
IsBuildin = isBuildin;
IsRawFile = isRawFile;
}
}
private FlagsData _flagData;
/// <summary> /// <summary>
/// 资源包名称 /// 资源包名称
/// </summary> /// </summary>
@ -48,33 +33,21 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
public long FileSize; public long FileSize;
/// <summary>
/// 是否为原生文件
/// </summary>
public bool IsRawFile;
/// <summary>
/// 加载方法
/// </summary>
public EBundleLoadMethod LoadMethod;
/// <summary> /// <summary>
/// Tags /// Tags
/// </summary> /// </summary>
public string[] Tags; public string[] Tags;
/// <summary>
/// Flags
/// </summary>
public int Flags;
/// <summary>
/// 获取标志位的解析数据
/// </summary>
public FlagsData GetFlagData()
{
if (_flagData == null)
{
BitMask32 value = Flags;
bool isEncrypted = value.Test(0);
bool isBuildin = value.Test(1);
bool isRawFile = value.Test(2);
_flagData = new FlagsData(isEncrypted, isBuildin, isRawFile);
}
return _flagData;
}
/// <summary> /// <summary>
/// 获取资源分类标签的字符串 /// 获取资源分类标签的字符串
/// </summary> /// </summary>
@ -85,16 +58,5 @@ namespace YooAsset.Editor
else else
return string.Empty; return string.Empty;
} }
/// <summary>
/// 是否为原生文件
/// </summary>
public bool IsRawFile()
{
if (System.IO.Path.GetExtension(BundleName) == $".{YooAssetSettingsData.Setting.RawFileVariant}")
return true;
else
return false;
}
} }
} }

View File

@ -98,7 +98,8 @@ namespace YooAsset.Editor
reportBundleInfo.FileCRC = patchBundle.FileCRC; reportBundleInfo.FileCRC = patchBundle.FileCRC;
reportBundleInfo.FileSize = patchBundle.FileSize; reportBundleInfo.FileSize = patchBundle.FileSize;
reportBundleInfo.Tags = patchBundle.Tags; reportBundleInfo.Tags = patchBundle.Tags;
reportBundleInfo.Flags = patchBundle.Flags; reportBundleInfo.IsRawFile = patchBundle.IsRawFile;
reportBundleInfo.LoadMethod = (EBundleLoadMethod)patchBundle.LoadMethod;
buildReport.BundleInfos.Add(reportBundleInfo); buildReport.BundleInfos.Add(reportBundleInfo);
} }
@ -178,7 +179,7 @@ namespace YooAsset.Editor
int fileCount = 0; int fileCount = 0;
foreach (var patchBundle in patchManifest.BundleList) foreach (var patchBundle in patchManifest.BundleList)
{ {
if (patchBundle.IsEncrypted) if (patchBundle.LoadMethod != (byte)EBundleLoadMethod.Normal)
fileCount++; fileCount++;
} }
return fileCount; return fileCount;
@ -188,7 +189,7 @@ namespace YooAsset.Editor
long fileBytes = 0; long fileBytes = 0;
foreach (var patchBundle in patchManifest.BundleList) foreach (var patchBundle in patchManifest.BundleList)
{ {
if (patchBundle.IsEncrypted) if (patchBundle.LoadMethod != (byte)EBundleLoadMethod.Normal)
fileBytes += patchBundle.FileSize; fileBytes += patchBundle.FileSize;
} }
return fileBytes; return fileBytes;

View File

@ -36,21 +36,27 @@ namespace YooAsset.Editor
string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory(); string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory();
foreach (var bundleInfo in buildMapContext.BundleInfos) foreach (var bundleInfo in buildMapContext.BundleInfos)
{ {
if (encryptionServices.Check(bundleInfo.BundleName)) bundleInfo.LoadMethod = EBundleLoadMethod.Normal;
EncryptFileInfo fileInfo = new EncryptFileInfo();
fileInfo.BundleName = bundleInfo.BundleName;
fileInfo.FilePath = $"{pipelineOutputDirectory}/{bundleInfo.BundleName}";
var encryptResult = encryptionServices.Encrypt(fileInfo);
if (encryptResult.LoadMethod != EBundleLoadMethod.Normal)
{ {
// 注意:原生文件不支持加密
if (bundleInfo.IsRawFile) if (bundleInfo.IsRawFile)
{ {
UnityEngine.Debug.LogWarning($"Encryption not support raw file : {bundleInfo.BundleName}"); UnityEngine.Debug.LogWarning($"Encryption not support raw file : {bundleInfo.BundleName}");
continue; continue;
} }
string filePath = $"{pipelineOutputDirectory}/{bundleInfo.BundleName}"; string filePath = $"{pipelineOutputDirectory}/{bundleInfo.BundleName}.encrypt";
string savePath = $"{pipelineOutputDirectory}/{bundleInfo.BundleName}.encrypt"; FileUtility.CreateFile(filePath, encryptResult.EncryptedData);
byte[] fileData = File.ReadAllBytes(filePath); bundleInfo.EncryptedFilePath = filePath;
byte[] encryptData = encryptionServices.Encrypt(fileData); bundleInfo.LoadMethod = encryptResult.LoadMethod;
FileUtility.CreateFile(savePath, encryptData); BuildRunner.Log($"Bundle文件加密完成{filePath}");
bundleInfo.EncryptedFilePath = savePath;
BuildRunner.Log($"Bundle文件加密完成{savePath}");
} }
// 进度条 // 进度条

View File

@ -1,18 +0,0 @@

namespace YooAsset.Editor
{
public interface IEncryptionServices
{
/// <summary>
/// 检测是否需要加密
/// </summary>
bool Check(string bundleName);
/// <summary>
/// 加密方法
/// </summary>
/// <param name="fileData">要加密的文件数据</param>
/// <returns>返回加密后的字节数据</returns>
byte[] Encrypt(byte[] fileData);
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 04491137351983348959c00ec4ee226a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -25,7 +25,7 @@ namespace YooAsset.Editor
private ToolbarButton _topBar1; private ToolbarButton _topBar1;
private ToolbarButton _topBar2; private ToolbarButton _topBar2;
private ToolbarButton _topBar3; private ToolbarButton _topBar3;
private ToolbarButton _topBar4; private ToolbarButton _topBar5;
private ToolbarButton _bottomBar1; private ToolbarButton _bottomBar1;
private ListView _bundleListView; private ListView _bundleListView;
private ListView _includeListView; private ListView _includeListView;
@ -53,11 +53,11 @@ namespace YooAsset.Editor
_topBar1 = _root.Q<ToolbarButton>("TopBar1"); _topBar1 = _root.Q<ToolbarButton>("TopBar1");
_topBar2 = _root.Q<ToolbarButton>("TopBar2"); _topBar2 = _root.Q<ToolbarButton>("TopBar2");
_topBar3 = _root.Q<ToolbarButton>("TopBar3"); _topBar3 = _root.Q<ToolbarButton>("TopBar3");
_topBar4 = _root.Q<ToolbarButton>("TopBar4"); _topBar5 = _root.Q<ToolbarButton>("TopBar5");
_topBar1.clicked += TopBar1_clicked; _topBar1.clicked += TopBar1_clicked;
_topBar2.clicked += TopBar2_clicked; _topBar2.clicked += TopBar2_clicked;
_topBar3.clicked += TopBar3_clicked; _topBar3.clicked += TopBar3_clicked;
_topBar4.clicked += TopBar4_clicked; _topBar5.clicked += TopBar4_clicked;
// 底部按钮栏 // 底部按钮栏
_bottomBar1 = _root.Q<ToolbarButton>("BottomBar1"); _bottomBar1 = _root.Q<ToolbarButton>("BottomBar1");
@ -144,7 +144,7 @@ namespace YooAsset.Editor
_topBar1.text = $"Bundle Name ({_bundleListView.itemsSource.Count})"; _topBar1.text = $"Bundle Name ({_bundleListView.itemsSource.Count})";
_topBar2.text = "Size"; _topBar2.text = "Size";
_topBar3.text = "Hash"; _topBar3.text = "Hash";
_topBar4.text = "Tags"; _topBar5.text = "Tags";
if (_sortMode == ESortMode.BundleName) if (_sortMode == ESortMode.BundleName)
{ {
@ -163,9 +163,9 @@ namespace YooAsset.Editor
else if (_sortMode == ESortMode.BundleTags) else if (_sortMode == ESortMode.BundleTags)
{ {
if (_descendingSort) if (_descendingSort)
_topBar4.text = "Tags ↓"; _topBar5.text = "Tags ↓";
else else
_topBar4.text = "Tags ↑"; _topBar5.text = "Tags ↑";
} }
else else
{ {
@ -231,6 +231,16 @@ namespace YooAsset.Editor
label.name = "Label5"; label.name = "Label5";
label.style.unityTextAlign = TextAnchor.MiddleLeft; label.style.unityTextAlign = TextAnchor.MiddleLeft;
label.style.marginLeft = 3f; label.style.marginLeft = 3f;
//label.style.flexGrow = 1f;
label.style.width = 150;
element.Add(label);
}
{
var label = new Label();
label.name = "Label6";
label.style.unityTextAlign = TextAnchor.MiddleLeft;
label.style.marginLeft = 3f;
label.style.flexGrow = 1f; label.style.flexGrow = 1f;
label.style.width = 80; label.style.width = 80;
element.Add(label); element.Add(label);
@ -255,9 +265,13 @@ namespace YooAsset.Editor
var label3 = element.Q<Label>("Label3"); var label3 = element.Q<Label>("Label3");
label3.text = bundleInfo.FileHash; label3.text = bundleInfo.FileHash;
// Tags // LoadMethod
var label5 = element.Q<Label>("Label5"); var label5 = element.Q<Label>("Label5");
label5.text = bundleInfo.GetTagsString(); label5.text = bundleInfo.LoadMethod.ToString();
// Tags
var label6 = element.Q<Label>("Label6");
label6.text = bundleInfo.GetTagsString();
} }
private void BundleListView_onSelectionChange(IEnumerable<object> objs) private void BundleListView_onSelectionChange(IEnumerable<object> objs)
{ {
@ -271,7 +285,7 @@ namespace YooAsset.Editor
} }
private void ShowAssetBundleInspector(ReportBundleInfo bundleInfo) private void ShowAssetBundleInspector(ReportBundleInfo bundleInfo)
{ {
if (bundleInfo.IsRawFile()) if (bundleInfo.IsRawFile)
return; return;
string rootDirectory = Path.GetDirectoryName(_reportFilePath); string rootDirectory = Path.GetDirectoryName(_reportFilePath);

View File

@ -5,7 +5,8 @@
<uie:ToolbarButton text="Bundle Name" display-tooltip-when-elided="true" name="TopBar1" style="width: 280px; -unity-text-align: middle-left; flex-grow: 1;" /> <uie:ToolbarButton text="Bundle Name" display-tooltip-when-elided="true" name="TopBar1" style="width: 280px; -unity-text-align: middle-left; flex-grow: 1;" />
<uie:ToolbarButton text="Size" display-tooltip-when-elided="true" name="TopBar2" style="width: 100px; -unity-text-align: middle-left; flex-grow: 0;" /> <uie:ToolbarButton text="Size" display-tooltip-when-elided="true" name="TopBar2" style="width: 100px; -unity-text-align: middle-left; flex-grow: 0;" />
<uie:ToolbarButton text="Hash" display-tooltip-when-elided="true" name="TopBar3" style="width: 280px; -unity-text-align: middle-left;" /> <uie:ToolbarButton text="Hash" display-tooltip-when-elided="true" name="TopBar3" style="width: 280px; -unity-text-align: middle-left;" />
<uie:ToolbarButton text="Tags" display-tooltip-when-elided="true" name="TopBar4" style="width: 80px; -unity-text-align: middle-left; flex-grow: 1;" /> <uie:ToolbarButton text="LoadMethod" display-tooltip-when-elided="true" name="TopBar4" style="width: 150px; -unity-text-align: middle-left; flex-grow: 0;" />
<uie:ToolbarButton text="Tags" display-tooltip-when-elided="true" name="TopBar5" style="width: 80px; -unity-text-align: middle-left; flex-grow: 1;" />
</uie:Toolbar> </uie:Toolbar>
<ui:ListView focusable="true" name="TopListView" item-height="18" virtualization-method="DynamicHeight" style="flex-grow: 1;" /> <ui:ListView focusable="true" name="TopListView" item-height="18" virtualization-method="DynamicHeight" style="flex-grow: 1;" />
</ui:VisualElement> </ui:VisualElement>