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

View File

@ -8,21 +8,6 @@ namespace YooAsset.Editor
[Serializable]
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>
@ -48,33 +33,21 @@ namespace YooAsset.Editor
/// </summary>
public long FileSize;
/// <summary>
/// 是否为原生文件
/// </summary>
public bool IsRawFile;
/// <summary>
/// 加载方法
/// </summary>
public EBundleLoadMethod LoadMethod;
/// <summary>
/// Tags
/// </summary>
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>
@ -85,16 +58,5 @@ namespace YooAsset.Editor
else
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.FileSize = patchBundle.FileSize;
reportBundleInfo.Tags = patchBundle.Tags;
reportBundleInfo.Flags = patchBundle.Flags;
reportBundleInfo.IsRawFile = patchBundle.IsRawFile;
reportBundleInfo.LoadMethod = (EBundleLoadMethod)patchBundle.LoadMethod;
buildReport.BundleInfos.Add(reportBundleInfo);
}
@ -178,7 +179,7 @@ namespace YooAsset.Editor
int fileCount = 0;
foreach (var patchBundle in patchManifest.BundleList)
{
if (patchBundle.IsEncrypted)
if (patchBundle.LoadMethod != (byte)EBundleLoadMethod.Normal)
fileCount++;
}
return fileCount;
@ -188,7 +189,7 @@ namespace YooAsset.Editor
long fileBytes = 0;
foreach (var patchBundle in patchManifest.BundleList)
{
if (patchBundle.IsEncrypted)
if (patchBundle.LoadMethod != (byte)EBundleLoadMethod.Normal)
fileBytes += patchBundle.FileSize;
}
return fileBytes;

View File

@ -36,21 +36,27 @@ namespace YooAsset.Editor
string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory();
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)
{
UnityEngine.Debug.LogWarning($"Encryption not support raw file : {bundleInfo.BundleName}");
continue;
}
string filePath = $"{pipelineOutputDirectory}/{bundleInfo.BundleName}";
string savePath = $"{pipelineOutputDirectory}/{bundleInfo.BundleName}.encrypt";
byte[] fileData = File.ReadAllBytes(filePath);
byte[] encryptData = encryptionServices.Encrypt(fileData);
FileUtility.CreateFile(savePath, encryptData);
bundleInfo.EncryptedFilePath = savePath;
BuildRunner.Log($"Bundle文件加密完成{savePath}");
string filePath = $"{pipelineOutputDirectory}/{bundleInfo.BundleName}.encrypt";
FileUtility.CreateFile(filePath, encryptResult.EncryptedData);
bundleInfo.EncryptedFilePath = filePath;
bundleInfo.LoadMethod = encryptResult.LoadMethod;
BuildRunner.Log($"Bundle文件加密完成{filePath}");
}
// 进度条

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 _topBar2;
private ToolbarButton _topBar3;
private ToolbarButton _topBar4;
private ToolbarButton _topBar5;
private ToolbarButton _bottomBar1;
private ListView _bundleListView;
private ListView _includeListView;
@ -53,11 +53,11 @@ namespace YooAsset.Editor
_topBar1 = _root.Q<ToolbarButton>("TopBar1");
_topBar2 = _root.Q<ToolbarButton>("TopBar2");
_topBar3 = _root.Q<ToolbarButton>("TopBar3");
_topBar4 = _root.Q<ToolbarButton>("TopBar4");
_topBar5 = _root.Q<ToolbarButton>("TopBar5");
_topBar1.clicked += TopBar1_clicked;
_topBar2.clicked += TopBar2_clicked;
_topBar3.clicked += TopBar3_clicked;
_topBar4.clicked += TopBar4_clicked;
_topBar5.clicked += TopBar4_clicked;
// 底部按钮栏
_bottomBar1 = _root.Q<ToolbarButton>("BottomBar1");
@ -144,7 +144,7 @@ namespace YooAsset.Editor
_topBar1.text = $"Bundle Name ({_bundleListView.itemsSource.Count})";
_topBar2.text = "Size";
_topBar3.text = "Hash";
_topBar4.text = "Tags";
_topBar5.text = "Tags";
if (_sortMode == ESortMode.BundleName)
{
@ -163,9 +163,9 @@ namespace YooAsset.Editor
else if (_sortMode == ESortMode.BundleTags)
{
if (_descendingSort)
_topBar4.text = "Tags ↓";
_topBar5.text = "Tags ↓";
else
_topBar4.text = "Tags ↑";
_topBar5.text = "Tags ↑";
}
else
{
@ -231,6 +231,16 @@ namespace YooAsset.Editor
label.name = "Label5";
label.style.unityTextAlign = TextAnchor.MiddleLeft;
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.width = 80;
element.Add(label);
@ -255,9 +265,13 @@ namespace YooAsset.Editor
var label3 = element.Q<Label>("Label3");
label3.text = bundleInfo.FileHash;
// Tags
// LoadMethod
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)
{
@ -271,7 +285,7 @@ namespace YooAsset.Editor
}
private void ShowAssetBundleInspector(ReportBundleInfo bundleInfo)
{
if (bundleInfo.IsRawFile())
if (bundleInfo.IsRawFile)
return;
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="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="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>
<ui:ListView focusable="true" name="TopListView" item-height="18" virtualization-method="DynamicHeight" style="flex-grow: 1;" />
</ui:VisualElement>