[+] Update YooAssets v1.4.14

[+] Update YooAssets v1.4.14
This commit is contained in:
ALEXTANG
2023-06-05 12:19:24 +08:00
parent f92bf5c602
commit 699ccb3b09
69 changed files with 688 additions and 162 deletions

View File

@@ -41,7 +41,7 @@ public static class EditorResourceBuilder
}
else
{
Debug.LogError($"构建失败 : {buildResult.FailedInfo}");
Debug.LogError($"构建失败 : {buildResult.ErrorInfo}");
}
}

View File

@@ -94,7 +94,7 @@ namespace YooAsset.Editor
{
BuildLogger.Warning($"{buildParameters.BuildMode} pipeline build failed !");
BuildLogger.Error($"Build task failed : {buildResult.FailedTask}");
BuildLogger.Error($"Build task error : {buildResult.FailedInfo}");
BuildLogger.Error(buildResult.ErrorInfo);
}
return buildResult;

View File

@@ -3,6 +3,7 @@ using UnityEngine;
namespace YooAsset.Editor
{
[CreateAssetMenu(fileName = "AssetBundleBuilderSetting", menuName = "YooAsset/Create AssetBundle Builder Settings")]
public class AssetBundleBuilderSetting : ScriptableObject
{
/// <summary>

View File

@@ -12,7 +12,7 @@ namespace YooAsset.Editor
public class AssetBundleBuilderWindow : EditorWindow
{
[MenuItem("YooAsset/AssetBundle Builder", false, 102)]
public static void ShowExample()
public static void OpenWindow()
{
AssetBundleBuilderWindow window = GetWindow<AssetBundleBuilderWindow>("资源包构建工具", true, WindowsDefine.DockedWindowTypes);
window.minSize = new Vector2(800, 600);
@@ -275,6 +275,7 @@ namespace YooAsset.Editor
buildParameters.PackageName = AssetBundleBuilderSettingData.Setting.BuildPackage;
buildParameters.PackageVersion = _buildVersionField.value;
buildParameters.VerifyBuildingResult = true;
buildParameters.ShareAssetPackRule = new DefaultShareAssetPackRule();
buildParameters.EncryptionServices = CreateEncryptionServicesInstance();
buildParameters.CompressOption = AssetBundleBuilderSettingData.Setting.CompressOption;
buildParameters.OutputNameStyle = AssetBundleBuilderSettingData.Setting.OutputNameStyle;

View File

@@ -157,7 +157,7 @@ namespace YooAsset.Editor
/// <summary>
/// 计算共享资源包的完整包名
/// </summary>
public void CalculateShareBundleName(bool uniqueBundleName, string packageName, string shadersBundleName)
public void CalculateShareBundleName(IShareAssetPackRule packRule, bool uniqueBundleName, string packageName, string shadersBundleName)
{
if (CollectorType != ECollectorType.None)
return;
@@ -173,8 +173,7 @@ namespace YooAsset.Editor
{
if (_referenceBundleNames.Count > 1)
{
IPackRule packRule = PackDirectory.StaticPackRule;
PackRuleResult packRuleResult = packRule.GetPackRuleResult(new PackRuleData(AssetPath));
PackRuleResult packRuleResult = packRule.GetPackRuleResult(AssetPath);
BundleName = packRuleResult.GetShareBundleName(packageName, uniqueBundleName);
}
else

View File

@@ -76,9 +76,14 @@ namespace YooAsset.Editor
/// 验证构建结果
/// </summary>
public bool VerifyBuildingResult = false;
/// <summary>
/// 加密类
/// 共享资源的打包规则
/// </summary>
public IShareAssetPackRule ShareAssetPackRule = null;
/// <summary>
/// 资源的加密接口
/// </summary>
public IEncryptionServices EncryptionServices = null;

View File

@@ -19,7 +19,7 @@ namespace YooAsset.Editor
/// <summary>
/// 构建失败的信息
/// </summary>
public string FailedInfo;
public string ErrorInfo;
/// <summary>
/// 输出的补丁包目录

View File

@@ -52,7 +52,7 @@ namespace YooAsset.Editor
{
EditorTools.ClearProgressBar();
buildResult.FailedTask = task.GetType().Name;
buildResult.FailedInfo = e.ToString();
buildResult.ErrorInfo = e.ToString();
buildResult.Success = false;
break;
}

View File

@@ -205,6 +205,7 @@ namespace YooAsset.Editor
throw new Exception("没有发现着色器资源包!");
// 检测依赖交集并更新依赖ID
HashSet<string> tagTemps = new HashSet<string>();
foreach (var packageAsset in manifest.AssetList)
{
List<string> dependBundles = GetPackageAssetAllDependBundles(manifest, packageAsset);
@@ -215,8 +216,23 @@ namespace YooAsset.Editor
if (newDependIDs.Contains(shaderBundleId) == false)
newDependIDs.Add(shaderBundleId);
packageAsset.DependIDs = newDependIDs.ToArray();
foreach (var tag in packageAsset.AssetTags)
{
if (tagTemps.Contains(tag) == false)
tagTemps.Add(tag);
}
}
}
// 更新资源包标签
var packageBundle = manifest.BundleList[shaderBundleId];
List<string> newTags = new List<string>(packageBundle.Tags);
foreach (var tag in tagTemps)
{
if (newTags.Contains(tag) == false)
newTags.Add(tag);
}
packageBundle.Tags = newTags.ToArray();
}
private List<string> GetPackageAssetAllDependBundles(PackageManifest manifest, PackageAsset packageAsset)
{
@@ -302,7 +318,7 @@ namespace YooAsset.Editor
{
if (packageBundle.IsRawFile)
{
_cachedBundleDepends.Add(packageBundle.BundleName, new string[] { } );
_cachedBundleDepends.Add(packageBundle.BundleName, new string[] { });
continue;
}
@@ -321,7 +337,7 @@ namespace YooAsset.Editor
}
EditorTools.ClearProgressBar();
}
private int[] GetBundleRefrenceIDs(PackageManifest manifest, PackageBundle targetBundle)
{
List<string> referenceList = new List<string>();

View File

@@ -13,7 +13,8 @@ namespace YooAsset.Editor
void IBuildTask.Run(BuildContext context)
{
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
var buildMapContext = CreateBuildMap(buildParametersContext.Parameters.BuildMode, buildParametersContext.Parameters.PackageName);
var buildParameters = buildParametersContext.Parameters;
var buildMapContext = CreateBuildMap(buildParameters.BuildMode, buildParameters.ShareAssetPackRule, buildParameters.PackageName);
context.SetContextObject(buildMapContext);
BuildLogger.Log("构建内容准备完毕!");
@@ -24,7 +25,7 @@ namespace YooAsset.Editor
/// <summary>
/// 资源构建上下文
/// </summary>
public BuildMapContext CreateBuildMap(EBuildMode buildMode, string packageName)
public BuildMapContext CreateBuildMap(EBuildMode buildMode, IShareAssetPackRule packRule, string packageName)
{
Dictionary<string, BuildAssetInfo> allBuildAssetInfoDic = new Dictionary<string, BuildAssetInfo>(1000);
@@ -101,7 +102,7 @@ namespace YooAsset.Editor
var command = collectResult.Command;
foreach (var buildAssetInfo in allBuildAssetInfoDic.Values)
{
buildAssetInfo.CalculateShareBundleName(command.UniqueBundleName, command.PackageName, command.ShadersBundleName);
buildAssetInfo.CalculateShareBundleName(packRule, command.UniqueBundleName, command.PackageName, command.ShadersBundleName);
}
// 9. 移除不参与构建的资源

View File

@@ -24,6 +24,13 @@ namespace YooAsset.Editor
if (buildParameters.BuildMode != EBuildMode.SimulateBuild)
{
#if UNITY_2021_3_OR_NEWER
if (buildParameters.BuildPipeline == EBuildPipeline.BuiltinBuildPipeline)
{
BuildLogger.Warning("推荐使用可编程构建管线SBP");
}
#endif
// 检测当前是否正在构建资源包
if (BuildPipeline.isBuildingPlayer)
throw new Exception("当前正在构建资源包,请结束后再试");
@@ -40,6 +47,20 @@ namespace YooAsset.Editor
throw new Exception("首包资源标签不能为空!");
}
// 检测共享资源打包规则
if (buildParameters.ShareAssetPackRule == null)
throw new Exception("共享资源打包规则不能为空!");
#if UNITY_WEBGL
if (buildParameters.EncryptionServices != null)
{
if (buildParameters.EncryptionServices.GetType() != typeof(EncryptionNone))
{
throw new Exception("WebGL平台不支持加密");
}
}
#endif
// 检测包裹输出目录是否存在
string packageOutputDirectory = buildParametersContext.GetPackageOutputDirectory();
if (Directory.Exists(packageOutputDirectory))

View File

@@ -197,16 +197,17 @@ namespace YooAsset.Editor
// 检测可寻址地址是否重复
if (command.EnableAddressable)
{
HashSet<string> adressTemper = new HashSet<string>();
var addressTemper = new Dictionary<string, string>();
foreach (var collectInfoPair in result)
{
if (collectInfoPair.Value.CollectorType == ECollectorType.MainAssetCollector)
{
string address = collectInfoPair.Value.Address;
if (adressTemper.Contains(address) == false)
adressTemper.Add(address);
string assetPath = collectInfoPair.Value.AssetPath;
if (addressTemper.TryGetValue(address, out var existed) == false)
addressTemper.Add(address, assetPath);
else
throw new Exception($"The address is existed : {address} in collector : {CollectPath}");
throw new Exception($"The address is existed : {address} in collector : {CollectPath} \nAssetPath:\n {existed}\n {assetPath}");
}
}
}
@@ -243,8 +244,8 @@ namespace YooAsset.Editor
return false;
// 忽略编辑器下的类型资源
Type type = AssetDatabase.GetMainAssetTypeAtPath(assetPath);
if (type == typeof(LightingDataAsset))
Type assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath);
if (assetType == typeof(LightingDataAsset))
return false;
// 检测原生文件是否合规
@@ -252,27 +253,29 @@ namespace YooAsset.Editor
{
string extension = StringUtility.RemoveFirstChar(System.IO.Path.GetExtension(assetPath));
if (extension == EAssetFileExtension.unity.ToString() || extension == EAssetFileExtension.prefab.ToString() ||
extension == EAssetFileExtension.mat.ToString() || extension == EAssetFileExtension.controller.ToString() ||
extension == EAssetFileExtension.fbx.ToString() || extension == EAssetFileExtension.anim.ToString() ||
extension == EAssetFileExtension.shader.ToString())
extension == EAssetFileExtension.fbx.ToString() || extension == EAssetFileExtension.mat.ToString() ||
extension == EAssetFileExtension.controller.ToString() || extension == EAssetFileExtension.anim.ToString() ||
extension == EAssetFileExtension.ttf.ToString() || extension == EAssetFileExtension.shader.ToString())
{
UnityEngine.Debug.LogWarning($"Raw file pack rule can not support file estension : {extension}");
return false;
}
// 注意:原生文件只支持无依赖关系的资源
/*
string[] depends = AssetDatabase.GetDependencies(assetPath, true);
if (depends.Length != 1)
{
UnityEngine.Debug.LogWarning($"Raw file pack rule can not support estension : {extension}");
return false;
}
*/
}
else
{
// 忽略Unity无法识别的无效文件
// 注意:只对非原生文件收集器处理
if (type == typeof(UnityEditor.DefaultAsset))
if (assetType == typeof(UnityEditor.DefaultAsset))
{
UnityEngine.Debug.LogWarning($"Cannot pack default asset : {assetPath}");
return false;
@@ -287,10 +290,6 @@ namespace YooAsset.Editor
}
private bool IsCollectAsset(string assetPath)
{
Type assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath);
if (assetType == typeof(UnityEngine.Shader) || assetType == typeof(UnityEngine.ShaderVariantCollection))
return true;
// 根据规则设置过滤资源文件
IFilterRule filterRuleInstance = AssetBundleCollectorSettingData.GetFilterRuleInstance(FilterRuleName);
return filterRuleInstance.IsCollectAsset(new FilterRuleData(assetPath));

View File

@@ -96,16 +96,17 @@ namespace YooAsset.Editor
// 检测可寻址地址是否重复
if (command.EnableAddressable)
{
HashSet<string> adressTemper = new HashSet<string>();
var addressTemper = new Dictionary<string, string>();
foreach (var collectInfoPair in result)
{
if (collectInfoPair.Value.CollectorType == ECollectorType.MainAssetCollector)
{
string address = collectInfoPair.Value.Address;
if (adressTemper.Contains(address) == false)
adressTemper.Add(address);
string assetPath = collectInfoPair.Value.AssetPath;
if (addressTemper.TryGetValue(address, out var existed) == false)
addressTemper.Add(address, assetPath);
else
throw new Exception($"The address is existed : {address} in group : {GroupName}");
throw new Exception($"The address is existed : {address} in group : {GroupName} \nAssetPath:\n {existed}\n {assetPath}");
}
}
}

View File

@@ -76,16 +76,17 @@ namespace YooAsset.Editor
// 检测可寻址地址是否重复
if (command.EnableAddressable)
{
HashSet<string> adressTemper = new HashSet<string>();
var addressTemper = new Dictionary<string, string>();
foreach (var collectInfoPair in result)
{
if (collectInfoPair.Value.CollectorType == ECollectorType.MainAssetCollector)
{
string address = collectInfoPair.Value.Address;
if (adressTemper.Contains(address) == false)
adressTemper.Add(address);
string assetPath = collectInfoPair.Value.AssetPath;
if (addressTemper.TryGetValue(address, out var existed) == false)
addressTemper.Add(address, assetPath);
else
throw new Exception($"The address is existed : {address}");
throw new Exception($"The address is existed : {address} \nAssetPath:\n {existed}\n {assetPath}");
}
}
}

View File

@@ -6,6 +6,7 @@ using UnityEngine;
namespace YooAsset.Editor
{
[CreateAssetMenu(fileName = "AssetBundleCollectorSetting", menuName = "YooAsset/Create AssetBundle Collector Settings")]
public class AssetBundleCollectorSetting : ScriptableObject
{
/// <summary>

View File

@@ -27,24 +27,8 @@ namespace YooAsset.Editor
public static bool IsDirty { private set; get; } = false;
private static AssetBundleCollectorSetting _setting = null;
public static AssetBundleCollectorSetting Setting
static AssetBundleCollectorSettingData()
{
get
{
if (_setting == null)
LoadSettingData();
return _setting;
}
}
/// <summary>
/// 加载配置文件
/// </summary>
private static void LoadSettingData()
{
_setting = SettingLoader.LoadSettingData<AssetBundleCollectorSetting>();
// IPackRule
{
// 清空缓存集合
@@ -147,6 +131,17 @@ namespace YooAsset.Editor
}
}
private static AssetBundleCollectorSetting _setting = null;
public static AssetBundleCollectorSetting Setting
{
get
{
if (_setting == null)
_setting = SettingLoader.LoadSettingData<AssetBundleCollectorSetting>();
return _setting;
}
}
/// <summary>
/// 存储配置文件
/// </summary>
@@ -184,9 +179,6 @@ namespace YooAsset.Editor
public static List<RuleDisplayName> GetActiveRuleNames()
{
if (_setting == null)
LoadSettingData();
List<RuleDisplayName> names = new List<RuleDisplayName>();
foreach (var pair in _cacheActiveRuleTypes)
{
@@ -199,9 +191,6 @@ namespace YooAsset.Editor
}
public static List<RuleDisplayName> GetAddressRuleNames()
{
if (_setting == null)
LoadSettingData();
List<RuleDisplayName> names = new List<RuleDisplayName>();
foreach (var pair in _cacheAddressRuleTypes)
{
@@ -214,9 +203,6 @@ namespace YooAsset.Editor
}
public static List<RuleDisplayName> GetPackRuleNames()
{
if (_setting == null)
LoadSettingData();
List<RuleDisplayName> names = new List<RuleDisplayName>();
foreach (var pair in _cachePackRuleTypes)
{
@@ -229,9 +215,6 @@ namespace YooAsset.Editor
}
public static List<RuleDisplayName> GetFilterRuleNames()
{
if (_setting == null)
LoadSettingData();
List<RuleDisplayName> names = new List<RuleDisplayName>();
foreach (var pair in _cacheFilterRuleTypes)
{

View File

@@ -12,7 +12,7 @@ namespace YooAsset.Editor
public class AssetBundleCollectorWindow : EditorWindow
{
[MenuItem("YooAsset/AssetBundle Collector", false, 101)]
public static void ShowExample()
public static void OpenWindow()
{
AssetBundleCollectorWindow window = GetWindow<AssetBundleCollectorWindow>("资源包收集工具", true, WindowsDefine.DockedWindowTypes);
window.minSize = new Vector2(800, 600);
@@ -148,6 +148,7 @@ namespace YooAsset.Editor
{
selectPackage.PackageName = evt.newValue;
AssetBundleCollectorSettingData.ModifyPackage(selectPackage);
FillPackageViewData();
}
});
@@ -160,6 +161,7 @@ namespace YooAsset.Editor
{
selectPackage.PackageDesc = evt.newValue;
AssetBundleCollectorSettingData.ModifyPackage(selectPackage);
FillPackageViewData();
}
});

View File

@@ -60,8 +60,6 @@ namespace YooAsset.Editor
[DisplayName("资源包名: 父类文件夹路径")]
public class PackDirectory : IPackRule
{
public static PackDirectory StaticPackRule = new PackDirectory();
PackRuleResult IPackRule.GetPackRuleResult(PackRuleData data)
{
string bundleName = Path.GetDirectoryName(data.AssetPath);

View File

@@ -0,0 +1,16 @@
using System;
using System.IO;
using UnityEditor;
namespace YooAsset.Editor
{
public class DefaultShareAssetPackRule : IShareAssetPackRule
{
public PackRuleResult GetPackRuleResult(string assetPath)
{
string bundleName = Path.GetDirectoryName(assetPath);
PackRuleResult result = new PackRuleResult(bundleName, DefaultPackRule.AssetBundleFileExtension);
return result;
}
}
}

View File

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

View File

@@ -0,0 +1,14 @@

namespace YooAsset.Editor
{
/// <summary>
/// 共享资源的打包规则
/// </summary>
public interface IShareAssetPackRule
{
/// <summary>
/// 获取打包规则结果
/// </summary>
PackRuleResult GetPackRuleResult(string assetPath);
}
}

View File

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

View File

@@ -13,7 +13,7 @@ namespace YooAsset.Editor
public class AssetBundleDebuggerWindow : EditorWindow
{
[MenuItem("YooAsset/AssetBundle Debugger", false, 104)]
public static void ShowExample()
public static void OpenWindow()
{
AssetBundleDebuggerWindow wnd = GetWindow<AssetBundleDebuggerWindow>("资源包调试工具", true, WindowsDefine.DockedWindowTypes);
wnd.minSize = new Vector2(800, 600);

View File

@@ -10,7 +10,7 @@ namespace YooAsset.Editor
public class AssetBundleReporterWindow : EditorWindow
{
[MenuItem("YooAsset/AssetBundle Reporter", false, 103)]
public static void ShowExample()
public static void OpenWindow()
{
AssetBundleReporterWindow window = GetWindow<AssetBundleReporterWindow>("资源包报告工具", true, WindowsDefine.DockedWindowTypes);
window.minSize = new Vector2(800, 600);

View File

@@ -0,0 +1,17 @@
#if UNITY_2019_4_OR_NEWER
using System;
using UnityEditor;
using UnityEngine;
namespace YooAsset.Editor
{
internal class HomePageWindow
{
[MenuItem("YooAsset/Home Page", false, 1)]
public static void OpenWindow()
{
Application.OpenURL("https://www.yooasset.com/");
}
}
}
#endif

View File

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

View File

@@ -2,6 +2,7 @@
namespace YooAsset.Editor
{
[CreateAssetMenu(fileName = "ShaderVariantCollectorSetting", menuName = "YooAsset/Create ShaderVariant Collector Settings")]
public class ShaderVariantCollectorSetting : ScriptableObject
{
/// <summary>

View File

@@ -1,7 +1,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEditor;
@@ -20,6 +19,11 @@ namespace YooAsset.Editor
}
}
/// <summary>
/// 配置数据是否被修改
/// </summary>
public static bool IsDirty { set; get; } = false;
/// <summary>
/// 加载配置文件
/// </summary>
@@ -35,6 +39,7 @@ namespace YooAsset.Editor
{
if (Setting != null)
{
IsDirty = false;
EditorUtility.SetDirty(Setting);
AssetDatabase.SaveAssets();
Debug.Log($"{nameof(ShaderVariantCollectorSetting)}.asset is saved!");

View File

@@ -12,7 +12,7 @@ namespace YooAsset.Editor
public class ShaderVariantCollectorWindow : EditorWindow
{
[MenuItem("YooAsset/ShaderVariant Collector", false, 201)]
public static void ShowExample()
public static void OpenWindow()
{
ShaderVariantCollectorWindow window = GetWindow<ShaderVariantCollectorWindow>("着色器变种收集工具", true, WindowsDefine.DockedWindowTypes);
window.minSize = new Vector2(800, 600);
@@ -20,6 +20,7 @@ namespace YooAsset.Editor
private List<string> _packageNames;
private Button _saveButton;
private Button _collectButton;
private TextField _collectOutputField;
private Label _currentShaderCountField;
@@ -40,6 +41,10 @@ namespace YooAsset.Editor
visualAsset.CloneTree(root);
// 配置保存按钮
_saveButton = root.Q<Button>("SaveButton");
_saveButton.clicked += SaveBtn_clicked;
// 包裹名称列表
_packageNames = GetBuildPackageNames();
@@ -48,6 +53,7 @@ namespace YooAsset.Editor
_collectOutputField.SetValueWithoutNotify(ShaderVariantCollectorSettingData.Setting.SavePath);
_collectOutputField.RegisterValueChangedCallback(evt =>
{
ShaderVariantCollectorSettingData.IsDirty = true;
ShaderVariantCollectorSettingData.Setting.SavePath = _collectOutputField.value;
});
@@ -61,6 +67,7 @@ namespace YooAsset.Editor
_packageField.style.width = 350;
_packageField.RegisterValueChangedCallback(evt =>
{
ShaderVariantCollectorSettingData.IsDirty = true;
ShaderVariantCollectorSettingData.Setting.CollectPackage = _packageField.value;
});
packageContainer.Add(_packageField);
@@ -80,12 +87,14 @@ namespace YooAsset.Editor
_processCapacitySlider.label = $"Capacity ({_processCapacitySlider.value})";
_processCapacitySlider.RegisterValueChangedCallback(evt =>
{
ShaderVariantCollectorSettingData.IsDirty = true;
ShaderVariantCollectorSettingData.Setting.ProcessCapacity = _processCapacitySlider.value;
_processCapacitySlider.label = $"Capacity ({_processCapacitySlider.value})";
});
#else
_processCapacitySlider.RegisterValueChangedCallback(evt =>
{
ShaderVariantCollectorSettingData.IsDirty = true;
ShaderVariantCollectorSettingData.Setting.ProcessCapacity = _processCapacitySlider.value;
});
#endif
@@ -102,8 +111,27 @@ namespace YooAsset.Editor
Debug.LogError(e.ToString());
}
}
public void OnDestroy()
{
if (ShaderVariantCollectorSettingData.IsDirty)
ShaderVariantCollectorSettingData.SaveFile();
}
private void Update()
{
if (_saveButton != null)
{
if (ShaderVariantCollectorSettingData.IsDirty)
{
if (_saveButton.enabledSelf == false)
_saveButton.SetEnabled(true);
}
else
{
if (_saveButton.enabledSelf)
_saveButton.SetEnabled(false);
}
}
if (_currentShaderCountField != null)
{
int currentShaderCount = ShaderVariantCollectionHelper.GetCurrentShaderVariantCollectionShaderCount();
@@ -117,6 +145,10 @@ namespace YooAsset.Editor
}
}
private void SaveBtn_clicked()
{
ShaderVariantCollectorSettingData.SaveFile();
}
private void CollectButton_clicked()
{
string savePath = ShaderVariantCollectorSettingData.Setting.SavePath;

View File

@@ -1,6 +1,8 @@
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements">
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="False">
<uie:Toolbar name="Toolbar" style="display: flex; flex-direction: row-reverse;">
<ui:Button text="Save" display-tooltip-when-elided="true" name="SaveButton" style="background-color: rgb(40, 106, 42);" />
</uie:Toolbar>
<ui:VisualElement name="CollectContainer">
<uie:Toolbar name="Toolbar" style="display: flex; flex-direction: row-reverse;" />
<ui:TextField picking-mode="Ignore" label="文件保存路径" name="CollectOutput" style="height: 22px;" />
<ui:VisualElement name="PackageContainer" style="height: 24px;" />
<ui:Label text="Current Shader Count" display-tooltip-when-elided="true" name="CurrentShaderCount" style="height: 20px; padding-left: 4px;" />

View File

@@ -254,15 +254,15 @@ namespace TEngine
}
/// <summary>
/// 异步更新最新包的Manifest文件。
/// 向网络端请求并更新清单
/// </summary>
/// <param name="packageVersion">包版本信息。</param>
/// <param name="timeout">超时时间。</param>
/// <returns>向远端请求并更新清单操作句柄。</returns>
public UpdatePackageManifestOperation UpdatePackageManifestAsync(string packageVersion, int timeout = 60)
/// <param name="packageVersion">更新的包裹版本</param>
/// <param name="autoSaveVersion">更新成功后自动保存版本号,作为下次初始化的版本。</param>
/// <param name="timeout">超时时间默认值60秒</param>
public UpdatePackageManifestOperation UpdatePackageManifestAsync(string packageVersion, bool autoSaveVersion = true, int timeout = 60)
{
var package = YooAssets.GetPackage(packageName);
return package.UpdatePackageManifestAsync(packageVersion, timeout);
return package.UpdatePackageManifestAsync(packageVersion,autoSaveVersion, timeout);
}
/// <summary>

View File

@@ -297,9 +297,6 @@ namespace YooAsset
// 释放子场景句柄
_sceneHandles[providerGUID].ReleaseInternal();
_sceneHandles.Remove(providerGUID);
// 卸载未被使用的资源(包括场景)
UnloadUnusedAssets();
}
internal void UnloadAllScene()
{
@@ -309,9 +306,6 @@ namespace YooAsset
valuePair.Value.ReleaseInternal();
}
_sceneHandles.Clear();
// 卸载未被使用的资源(包括场景)
UnloadUnusedAssets();
}
internal void ClearSceneHandle()
{

View File

@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace YooAsset

View File

@@ -112,8 +112,6 @@ namespace YooAsset
var retObject = assetObject as TObject;
if (retObject != null)
ret.Add(retObject);
else
YooLogger.Warning($"The type conversion failed : {assetObject.name}");
}
return ret.ToArray();
}

View File

@@ -103,13 +103,14 @@ namespace YooAsset
else
{
_steps = ESteps.LoadFile;
return; //下载完毕等待一帧再去加载!
}
}
// 3. 内置文件解压
if (_steps == ESteps.Unpack)
{
int failedTryAgain = 1;
int failedTryAgain = Impl.DownloadFailedTryAgain;
var bundleInfo = ManifestTools.GetUnpackInfo(MainBundleInfo.Bundle);
_unpacker = DownloadSystem.BeginDownload(bundleInfo, failedTryAgain);
_steps = ESteps.CheckUnpack;

View File

@@ -92,6 +92,7 @@ namespace YooAsset
else
{
_steps = ESteps.LoadCacheFile;
return; //下载完毕等待一帧再去加载!
}
}

View File

@@ -91,7 +91,7 @@ namespace YooAsset
// 3. 解压内置文件
if (_steps == ESteps.Unpack)
{
int failedTryAgain = 1;
int failedTryAgain = Impl.DownloadFailedTryAgain;
var bundleInfo = ManifestTools.GetUnpackInfo(MainBundleInfo.Bundle);
_unpacker = DownloadSystem.BeginDownload(bundleInfo, failedTryAgain);
_steps = ESteps.CheckUnpack;

View File

@@ -89,7 +89,7 @@ namespace YooAsset
// 3. 从站点下载
if (_steps == ESteps.Website)
{
int failedTryAgain = 1;
int failedTryAgain = Impl.DownloadFailedTryAgain;
var bundleInfo = ManifestTools.GetUnpackInfo(MainBundleInfo.Bundle);
_website = DownloadSystem.BeginDownload(bundleInfo, failedTryAgain);
_steps = ESteps.CheckWebsite;

View File

@@ -103,13 +103,16 @@ namespace YooAsset
MainAssetInfo = assetInfo;
// 创建资源包加载器
OwnerBundle = impl.CreateOwnerAssetBundleLoader(assetInfo);
OwnerBundle.Reference();
OwnerBundle.AddProvider(this);
if (impl != null)
{
OwnerBundle = impl.CreateOwnerAssetBundleLoader(assetInfo);
OwnerBundle.Reference();
OwnerBundle.AddProvider(this);
var dependBundles = impl.CreateDependAssetBundleLoaders(assetInfo);
DependBundleGroup = new DependAssetBundleGroup(dependBundles);
DependBundleGroup.Reference();
var dependBundles = impl.CreateDependAssetBundleLoaders(assetInfo);
DependBundleGroup = new DependAssetBundleGroup(dependBundles);
DependBundleGroup.Reference();
}
}
/// <summary>
@@ -242,6 +245,7 @@ namespace YooAsset
Progress = 1f;
// 注意:创建临时列表是为了防止外部逻辑在回调函数内创建或者释放资源句柄。
// 注意:回调方法如果发生异常,会阻断列表里的后续回调方法!
List<OperationHandleBase> tempers = new List<OperationHandleBase>(_handles);
foreach (var hande in tempers)
{

View File

@@ -23,6 +23,15 @@ namespace YooAsset
_cachedDic.Clear();
}
/// <summary>
/// 清空指定包裹的所有缓存数据
/// </summary>
public static void ClearPackage(string packageName)
{
var cache = GetOrCreateCache(packageName);
cache.ClearAll();
}
/// <summary>
/// 获取缓存文件总数
/// </summary>
@@ -115,7 +124,7 @@ namespace YooAsset
{
return VerifyingInternal(element.TempDataFilePath, element.FileSize, element.FileCRC, EVerifyLevel.High);
}
/// <summary>
/// 验证记录文件(主线程内操作)
/// </summary>
@@ -148,6 +157,14 @@ namespace YooAsset
return result;
}
/// <summary>
/// 获取所有的缓存文件
/// </summary>
public static List<string> GetAllCacheGUIDs(ResourcePackage package)
{
var cache = GetOrCreateCache(package.PackageName);
return cache.GetAllKeys();
}
private static EVerifyResult VerifyingInternal(string filePath, long fileSize, string fileCRC, EVerifyLevel verifyLevel)
{

View File

@@ -6,6 +6,11 @@ namespace YooAsset
/// </summary>
internal enum EVerifyResult
{
/// <summary>
/// 验证异常
/// </summary>
Exception = -7,
/// <summary>
/// 未找到缓存信息
/// </summary>
@@ -37,9 +42,9 @@ namespace YooAsset
FileCrcError = -1,
/// <summary>
/// 验证异常
/// 默认状态(校验未完成)
/// </summary>
Exception = 0,
None = 0,
/// <summary>
/// 验证成功

View File

@@ -0,0 +1,71 @@
using System.Collections;
using System.Collections.Generic;
using System.IO;
namespace YooAsset
{
/// <summary>
/// 清理本地包裹所有的缓存文件
/// </summary>
public sealed class ClearAllCacheFilesOperation : AsyncOperationBase
{
private enum ESteps
{
None,
GetAllCacheFiles,
ClearAllCacheFiles,
Done,
}
private readonly ResourcePackage _package;
private List<string> _allCacheGUIDs;
private int _fileTotalCount = 0;
private ESteps _steps = ESteps.None;
internal ClearAllCacheFilesOperation(ResourcePackage package)
{
_package = package;
}
internal override void Start()
{
_steps = ESteps.GetAllCacheFiles;
}
internal override void Update()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.GetAllCacheFiles)
{
_allCacheGUIDs = CacheSystem.GetAllCacheGUIDs(_package);
_fileTotalCount = _allCacheGUIDs.Count;
YooLogger.Log($"Found all cache file count : {_fileTotalCount}");
_steps = ESteps.ClearAllCacheFiles;
}
if (_steps == ESteps.ClearAllCacheFiles)
{
for (int i = _allCacheGUIDs.Count - 1; i >= 0; i--)
{
string cacheGUID = _allCacheGUIDs[i];
CacheSystem.DiscardFile(_package.PackageName, cacheGUID);
_allCacheGUIDs.RemoveAt(i);
if (OperationSystem.IsBusy)
break;
}
if (_fileTotalCount == 0)
Progress = 1.0f;
else
Progress = 1.0f - (_allCacheGUIDs.Count / _fileTotalCount);
if (_allCacheGUIDs.Count == 0)
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
}
}
}
}

View File

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

View File

@@ -45,7 +45,7 @@ namespace YooAsset
{
// BundleFiles
{
string rootPath = PersistentHelper.GetCachedBundleFileFolderPath(_packageName);
string rootPath = PersistentTools.GetCachedBundleFileFolderPath(_packageName);
DirectoryInfo rootDirectory = new DirectoryInfo(rootPath);
if (rootDirectory.Exists)
{
@@ -56,7 +56,7 @@ namespace YooAsset
// RawFiles
{
string rootPath = PersistentHelper.GetCachedRawFileFolderPath(_packageName);
string rootPath = PersistentTools.GetCachedRawFileFolderPath(_packageName);
DirectoryInfo rootDirectory = new DirectoryInfo(rootPath);
if (rootDirectory.Exists)
{

View File

@@ -60,11 +60,12 @@ namespace YooAsset
if (_steps == ESteps.Waiting)
{
if (_element.IsDone == false)
int result = _element.Result;
if (result == 0)
return;
VerifyResult = _element.Result;
if (_element.Result == EVerifyResult.Succeed)
VerifyResult = (EVerifyResult)result;
if (VerifyResult == EVerifyResult.Succeed)
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
@@ -73,7 +74,7 @@ namespace YooAsset
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = $"Failed verify file : {_element.TempDataFilePath} ! ErrorCode : {_element.Result}";
Error = $"Failed verify file : {_element.TempDataFilePath} ! ErrorCode : {VerifyResult}";
}
}
}
@@ -85,8 +86,8 @@ namespace YooAsset
private void VerifyInThread(object obj)
{
VerifyTempElement element = (VerifyTempElement)obj;
element.Result = CacheSystem.VerifyingTempFile(element);
element.IsDone = true;
int result = (int)CacheSystem.VerifyingTempFile(element);
element.Result = result;
}
}
@@ -120,11 +121,10 @@ namespace YooAsset
if (_steps == ESteps.VerifyFile)
{
_element.Result = CacheSystem.VerifyingTempFile(_element);
_element.IsDone = true;
_element.Result = (int)CacheSystem.VerifyingTempFile(_element);
VerifyResult = _element.Result;
if (_element.Result == EVerifyResult.Succeed)
VerifyResult = (EVerifyResult)_element.Result;
if (VerifyResult == EVerifyResult.Succeed)
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
@@ -133,7 +133,7 @@ namespace YooAsset
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = $"Failed verify file : {_element.TempDataFilePath} ! ErrorCode : {_element.Result}";
Error = $"Failed verify file : {_element.TempDataFilePath} ! ErrorCode : {VerifyResult}";
}
}
}

View File

@@ -0,0 +1,204 @@
using System.IO;
using System.Collections.Generic;
namespace YooAsset
{
internal static class PersistentTools
{
private const string CacheFolderName = "CacheFiles";
private const string CachedBundleFileFolder = "BundleFiles";
private const string CachedRawFileFolder = "RawFiles";
private const string ManifestFolderName = "ManifestFiles";
private const string AppFootPrintFileName = "ApplicationFootPrint.bytes";
private static string _buildinPath;
private static string _sandboxPath;
/// <summary>
/// 重写沙盒跟路径
/// </summary>
public static void OverwriteSandboxPath(string sandboxPath)
{
_sandboxPath = sandboxPath;
}
/// <summary>
/// 获取沙盒文件夹路径
/// </summary>
public static string GetPersistentRootPath()
{
#if UNITY_EDITOR
// 注意:为了方便调试查看,编辑器下把存储目录放到项目里
if (string.IsNullOrEmpty(_sandboxPath))
{
string directory = Path.GetDirectoryName(UnityEngine.Application.dataPath);
string projectPath = GetRegularPath(directory);
_sandboxPath = StringUtility.Format("{0}/Sandbox", projectPath);
}
#elif UNITY_STANDALONE
if (string.IsNullOrEmpty(_sandboxPath))
{
_sandboxPath = StringUtility.Format("{0}/Sandbox", UnityEngine.Application.dataPath);
}
#else
if (string.IsNullOrEmpty(_sandboxPath))
{
_sandboxPath = StringUtility.Format("{0}/Sandbox", UnityEngine.Application.persistentDataPath);
}
#endif
return _sandboxPath;
}
private static string GetRegularPath(string path)
{
return path.Replace('\\', '/').Replace("\\", "/"); //替换为Linux路径格式
}
/// <summary>
/// 获取基于流文件夹的加载路径
/// </summary>
public static string MakeStreamingLoadPath(string path)
{
if (string.IsNullOrEmpty(_buildinPath))
{
_buildinPath = StringUtility.Format("{0}/{1}", UnityEngine.Application.streamingAssetsPath, YooAssetSettings.StreamingAssetsBuildinFolder);
}
return StringUtility.Format("{0}/{1}", _buildinPath, path);
}
/// <summary>
/// 获取基于沙盒文件夹的加载路径
/// </summary>
public static string MakePersistentLoadPath(string path)
{
string root = GetPersistentRootPath();
return StringUtility.Format("{0}/{1}", root, path);
}
/// <summary>
/// 获取WWW加载本地资源的路径
/// </summary>
public static string ConvertToWWWPath(string path)
{
#if UNITY_EDITOR
return StringUtility.Format("file:///{0}", path);
#elif UNITY_IPHONE
return StringUtility.Format("file://{0}", path);
#elif UNITY_ANDROID
return path;
#elif UNITY_STANDALONE
return StringUtility.Format("file:///{0}", path);
#elif UNITY_WEBGL
return path;
#endif
}
/// <summary>
/// 删除沙盒总目录
/// </summary>
public static void DeleteSandbox()
{
string directoryPath = MakePersistentLoadPath(string.Empty);
if (Directory.Exists(directoryPath))
Directory.Delete(directoryPath, true);
}
/// <summary>
/// 删除沙盒内的缓存文件夹
/// </summary>
public static void DeleteCacheFolder()
{
string root = MakePersistentLoadPath(CacheFolderName);
if (Directory.Exists(root))
Directory.Delete(root, true);
}
/// <summary>
/// 删除沙盒内的清单文件夹
/// </summary>
public static void DeleteManifestFolder()
{
string root = MakePersistentLoadPath(ManifestFolderName);
if (Directory.Exists(root))
Directory.Delete(root, true);
}
/// <summary>
/// 获取缓存的BundleFile文件夹路径
/// </summary>
private readonly static Dictionary<string, string> _cachedBundleFileFolder = new Dictionary<string, string>(100);
public static string GetCachedBundleFileFolderPath(string packageName)
{
if (_cachedBundleFileFolder.TryGetValue(packageName, out string value) == false)
{
string root = MakePersistentLoadPath(CacheFolderName);
value = $"{root}/{packageName}/{CachedBundleFileFolder}";
_cachedBundleFileFolder.Add(packageName, value);
}
return value;
}
/// <summary>
/// 获取缓存的RawFile文件夹路径
/// </summary>
private readonly static Dictionary<string, string> _cachedRawFileFolder = new Dictionary<string, string>(100);
public static string GetCachedRawFileFolderPath(string packageName)
{
if (_cachedRawFileFolder.TryGetValue(packageName, out string value) == false)
{
string root = MakePersistentLoadPath(CacheFolderName);
value = $"{root}/{packageName}/{CachedRawFileFolder}";
_cachedRawFileFolder.Add(packageName, value);
}
return value;
}
/// <summary>
/// 获取应用程序的水印文件路径
/// </summary>
public static string GetAppFootPrintFilePath()
{
return MakePersistentLoadPath(AppFootPrintFileName);
}
/// <summary>
/// 获取沙盒内清单文件的路径
/// </summary>
public static string GetCacheManifestFilePath(string packageName, string packageVersion)
{
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(packageName, packageVersion);
return MakePersistentLoadPath($"{ManifestFolderName}/{fileName}");
}
/// <summary>
/// 获取沙盒内包裹的哈希文件的路径
/// </summary>
public static string GetCachePackageHashFilePath(string packageName, string packageVersion)
{
string fileName = YooAssetSettingsData.GetPackageHashFileName(packageName, packageVersion);
return MakePersistentLoadPath($"{ManifestFolderName}/{fileName}");
}
/// <summary>
/// 获取沙盒内包裹的版本文件的路径
/// </summary>
public static string GetCachePackageVersionFilePath(string packageName)
{
string fileName = YooAssetSettingsData.GetPackageVersionFileName(packageName);
return MakePersistentLoadPath($"{ManifestFolderName}/{fileName}");
}
/// <summary>
/// 保存默认的包裹版本
/// </summary>
public static void SaveCachePackageVersionFile(string packageName, string version)
{
string filePath = GetCachePackageVersionFilePath(packageName);
FileUtility.CreateFile(filePath, version);
}
}
}

View File

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

View File

@@ -49,8 +49,7 @@ namespace YooAsset
public string FileCRC { private set; get; }
public long FileSize { private set; get; }
public bool IsDone = false;
public EVerifyResult Result;
public int Result = 0; // 注意:原子操作对象
public VerifyTempElement(string tempDataFilePath, string fileCRC, long fileSize)
{

View File

@@ -193,7 +193,7 @@ namespace YooAsset
public static BundleInfo GetUnpackInfo(PackageBundle packageBundle)
{
// 注意:我们把流加载路径指定为远端下载地址
string streamingPath = PathHelper.ConvertToWWWPath(packageBundle.StreamingFilePath);
string streamingPath = PersistentTools.ConvertToWWWPath(packageBundle.StreamingFilePath);
BundleInfo bundleInfo = new BundleInfo(packageBundle, BundleInfo.ELoadMode.LoadFromStreaming, streamingPath, streamingPath);
return bundleInfo;
}

View File

@@ -222,7 +222,7 @@ namespace YooAsset
// 如果水印发生变化,则说明覆盖安装后首次打开游戏
if (appFootPrint.IsDirty())
{
PersistentHelper.DeleteManifestFolder();
PersistentTools.DeleteManifestFolder();
appFootPrint.Coverage();
YooLogger.Log("Delete manifest files when application foot print dirty !");
}
@@ -376,7 +376,7 @@ namespace YooAsset
/// </summary>
public void Load()
{
string footPrintFilePath = PersistentHelper.GetAppFootPrintFilePath();
string footPrintFilePath = PersistentTools.GetAppFootPrintFilePath();
if (File.Exists(footPrintFilePath))
{
_footPrint = FileUtility.ReadAllText(footPrintFilePath);
@@ -409,7 +409,7 @@ namespace YooAsset
#else
_footPrint = Application.buildGUID;
#endif
string footPrintFilePath = PersistentHelper.GetAppFootPrintFilePath();
string footPrintFilePath = PersistentTools.GetAppFootPrintFilePath();
FileUtility.CreateFile(footPrintFilePath, _footPrint);
YooLogger.Log($"Save application foot print : {_footPrint}");
}

View File

@@ -41,7 +41,7 @@ namespace YooAsset
{
if (_downloader1 == null)
{
string savePath = PersistentHelper.GetCachePackageHashFilePath(_packageName, _packageVersion);
string savePath = PersistentTools.GetCachePackageHashFilePath(_packageName, _packageVersion);
string fileName = YooAssetSettingsData.GetPackageHashFileName(_packageName, _packageVersion);
string webURL = GetDownloadRequestURL(fileName);
YooLogger.Log($"Beginning to download package hash file : {webURL}");
@@ -71,7 +71,7 @@ namespace YooAsset
{
if (_downloader2 == null)
{
string savePath = PersistentHelper.GetCacheManifestFilePath(_packageName, _packageVersion);
string savePath = PersistentTools.GetCacheManifestFilePath(_packageName, _packageVersion);
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_packageName, _packageVersion);
string webURL = GetDownloadRequestURL(fileName);
YooLogger.Log($"Beginning to download manifest file : {webURL}");

View File

@@ -42,8 +42,8 @@ namespace YooAsset
if (_downloader == null)
{
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_buildinPackageName, _buildinPackageVersion);
string filePath = PathHelper.MakeStreamingLoadPath(fileName);
string url = PathHelper.ConvertToWWWPath(filePath);
string filePath = PersistentTools.MakeStreamingLoadPath(fileName);
string url = PersistentTools.ConvertToWWWPath(filePath);
_downloader = new UnityWebDataRequester();
_downloader.SendRequest(url);
}

View File

@@ -67,7 +67,7 @@ namespace YooAsset
if (_steps == ESteps.VerifyFileHash)
{
_manifestFilePath = PersistentHelper.GetCacheManifestFilePath(_packageName, _packageVersion);
_manifestFilePath = PersistentTools.GetCacheManifestFilePath(_packageName, _packageVersion);
if (File.Exists(_manifestFilePath) == false)
{
_steps = ESteps.Done;
@@ -131,7 +131,7 @@ namespace YooAsset
File.Delete(_manifestFilePath);
}
string hashFilePath = PersistentHelper.GetCachePackageHashFilePath(_packageName, _packageVersion);
string hashFilePath = PersistentTools.GetCachePackageHashFilePath(_packageName, _packageVersion);
if (File.Exists(hashFilePath))
{
File.Delete(hashFilePath);

View File

@@ -38,8 +38,8 @@ namespace YooAsset
if (_downloader == null)
{
string fileName = YooAssetSettingsData.GetPackageVersionFileName(_packageName);
string filePath = PathHelper.MakeStreamingLoadPath(fileName);
string url = PathHelper.ConvertToWWWPath(filePath);
string filePath = PersistentTools.MakeStreamingLoadPath(fileName);
string url = PersistentTools.ConvertToWWWPath(filePath);
_downloader = new UnityWebDataRequester();
_downloader.SendRequest(url);
}

View File

@@ -37,7 +37,7 @@ namespace YooAsset
if (_steps == ESteps.LoadCachePackageHashFile)
{
string filePath = PersistentHelper.GetCachePackageHashFilePath(_packageName, _packageVersion);
string filePath = PersistentTools.GetCachePackageHashFilePath(_packageName, _packageVersion);
if (File.Exists(filePath) == false)
{
_steps = ESteps.Done;

View File

@@ -35,7 +35,7 @@ namespace YooAsset
if (_steps == ESteps.LoadCachePackageVersionFile)
{
string filePath = PersistentHelper.GetCachePackageVersionFilePath(_packageName);
string filePath = PersistentTools.GetCachePackageVersionFilePath(_packageName);
if (File.Exists(filePath) == false)
{
_steps = ESteps.Done;

View File

@@ -35,10 +35,10 @@ namespace YooAsset
{
if (_downloader1 == null)
{
string savePath = PersistentHelper.GetCachePackageHashFilePath(_buildinPackageName, _buildinPackageVersion);
string savePath = PersistentTools.GetCachePackageHashFilePath(_buildinPackageName, _buildinPackageVersion);
string fileName = YooAssetSettingsData.GetPackageHashFileName(_buildinPackageName, _buildinPackageVersion);
string filePath = PathHelper.MakeStreamingLoadPath(fileName);
string url = PathHelper.ConvertToWWWPath(filePath);
string filePath = PersistentTools.MakeStreamingLoadPath(fileName);
string url = PersistentTools.ConvertToWWWPath(filePath);
_downloader1 = new UnityWebFileRequester();
_downloader1.SendRequest(url, savePath);
}
@@ -64,10 +64,10 @@ namespace YooAsset
{
if (_downloader2 == null)
{
string savePath = PersistentHelper.GetCacheManifestFilePath(_buildinPackageName, _buildinPackageVersion);
string savePath = PersistentTools.GetCacheManifestFilePath(_buildinPackageName, _buildinPackageVersion);
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_buildinPackageName, _buildinPackageVersion);
string filePath = PathHelper.MakeStreamingLoadPath(fileName);
string url = PathHelper.ConvertToWWWPath(filePath);
string filePath = PersistentTools.MakeStreamingLoadPath(fileName);
string url = PersistentTools.ConvertToWWWPath(filePath);
_downloader2 = new UnityWebFileRequester();
_downloader2.SendRequest(url, savePath);
}

View File

@@ -69,6 +69,7 @@ namespace YooAsset
private readonly HostPlayModeImpl _impl;
private readonly string _packageName;
private readonly string _packageVersion;
private readonly bool _autoSaveVersion;
private readonly int _timeout;
private LoadCacheManifestOperation _tryLoadCacheManifestOp;
private LoadCacheManifestOperation _loadCacheManifestOp;
@@ -76,11 +77,12 @@ namespace YooAsset
private ESteps _steps = ESteps.None;
internal HostPlayModeUpdatePackageManifestOperation(HostPlayModeImpl impl, string packageName, string packageVersion, int timeout)
internal HostPlayModeUpdatePackageManifestOperation(HostPlayModeImpl impl, string packageName, string packageVersion, bool autoSaveVersion, int timeout)
{
_impl = impl;
_packageName = packageName;
_packageVersion = packageVersion;
_autoSaveVersion = autoSaveVersion;
_timeout = timeout;
}
internal override void Start()
@@ -120,6 +122,8 @@ namespace YooAsset
if (_tryLoadCacheManifestOp.Status == EOperationStatus.Succeed)
{
_impl.ActiveManifest = _tryLoadCacheManifestOp.Manifest;
if (_autoSaveVersion)
SavePackageVersion();
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
@@ -166,6 +170,8 @@ namespace YooAsset
if (_loadCacheManifestOp.Status == EOperationStatus.Succeed)
{
_impl.ActiveManifest = _loadCacheManifestOp.Manifest;
if (_autoSaveVersion)
SavePackageVersion();
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}

View File

@@ -74,12 +74,12 @@ namespace YooAsset
string folderName = FileHash.Substring(0, 2);
if (IsRawFile)
{
string cacheRoot = PersistentHelper.GetCachedRawFileFolderPath(PackageName);
string cacheRoot = PersistentTools.GetCachedRawFileFolderPath(PackageName);
_cachedDataFilePath = $"{cacheRoot}/{folderName}/{CacheGUID}/{YooAssetSettings.CacheBundleDataFileName}{_fileExtension}";
}
else
{
string cacheRoot = PersistentHelper.GetCachedBundleFileFolderPath(PackageName);
string cacheRoot = PersistentTools.GetCachedBundleFileFolderPath(PackageName);
_cachedDataFilePath = $"{cacheRoot}/{folderName}/{CacheGUID}/{YooAssetSettings.CacheBundleDataFileName}";
}
return _cachedDataFilePath;
@@ -100,12 +100,12 @@ namespace YooAsset
string folderName = FileHash.Substring(0, 2);
if (IsRawFile)
{
string cacheRoot = PersistentHelper.GetCachedRawFileFolderPath(PackageName);
string cacheRoot = PersistentTools.GetCachedRawFileFolderPath(PackageName);
_cachedInfoFilePath = $"{cacheRoot}/{folderName}/{CacheGUID}/{YooAssetSettings.CacheBundleInfoFileName}";
}
else
{
string cacheRoot = PersistentHelper.GetCachedBundleFileFolderPath(PackageName);
string cacheRoot = PersistentTools.GetCachedBundleFileFolderPath(PackageName);
_cachedInfoFilePath = $"{cacheRoot}/{folderName}/{CacheGUID}/{YooAssetSettings.CacheBundleInfoFileName}";
}
return _cachedInfoFilePath;
@@ -139,7 +139,7 @@ namespace YooAsset
if (string.IsNullOrEmpty(_streamingFilePath) == false)
return _streamingFilePath;
_streamingFilePath = PathHelper.MakeStreamingLoadPath(FileName);
_streamingFilePath = PersistentTools.MakeStreamingLoadPath(FileName);
return _streamingFilePath;
}
}

View File

@@ -43,7 +43,7 @@ namespace YooAsset
OperationSystem.StartOperation(operation);
return operation;
}
UpdatePackageManifestOperation IPlayModeServices.UpdatePackageManifestAsync(string packageVersion, int timeout)
UpdatePackageManifestOperation IPlayModeServices.UpdatePackageManifestAsync(string packageVersion, bool autoSaveVersion, int timeout)
{
var operation = new EditorPlayModeUpdatePackageManifestOperation();
OperationSystem.StartOperation(operation);

View File

@@ -93,7 +93,7 @@ namespace YooAsset
public void FlushManifestVersionFile()
{
if (_activeManifest != null)
PersistentHelper.SaveCachePackageVersionFile(_packageName, _activeManifest.PackageVersion);
PersistentTools.SaveCachePackageVersionFile(_packageName, _activeManifest.PackageVersion);
}
private bool IsBuildinPackageBundle(PackageBundle packageBundle)
@@ -111,9 +111,9 @@ namespace YooAsset
OperationSystem.StartOperation(operation);
return operation;
}
UpdatePackageManifestOperation IPlayModeServices.UpdatePackageManifestAsync(string packageVersion, int timeout)
UpdatePackageManifestOperation IPlayModeServices.UpdatePackageManifestAsync(string packageVersion, bool autoSaveVersion, int timeout)
{
var operation = new HostPlayModeUpdatePackageManifestOperation(this, _packageName, packageVersion, timeout);
var operation = new HostPlayModeUpdatePackageManifestOperation(this, _packageName, packageVersion, autoSaveVersion, timeout);
OperationSystem.StartOperation(operation);
return operation;
}

View File

@@ -43,7 +43,7 @@ namespace YooAsset
OperationSystem.StartOperation(operation);
return operation;
}
UpdatePackageManifestOperation IPlayModeServices.UpdatePackageManifestAsync(string packageVersion, int timeout)
UpdatePackageManifestOperation IPlayModeServices.UpdatePackageManifestAsync(string packageVersion, bool autoSaveVersion, int timeout)
{
var operation = new OfflinePlayModeUpdatePackageManifestOperation();
OperationSystem.StartOperation(operation);

View File

@@ -220,13 +220,13 @@ namespace YooAsset
/// 向网络端请求并更新清单
/// </summary>
/// <param name="packageVersion">更新的包裹版本</param>
/// <param name="autoActiveManifest">自动激活清单</param>
/// <param name="autoSaveVersion">更新成功后自动保存版本号,作为下次初始化的版本。</param>
/// <param name="timeout">超时时间默认值60秒</param>
public UpdatePackageManifestOperation UpdatePackageManifestAsync(string packageVersion, int timeout = 60)
public UpdatePackageManifestOperation UpdatePackageManifestAsync(string packageVersion, bool autoSaveVersion = true, int timeout = 60)
{
DebugCheckInitialize();
DebugCheckUpdateManifest();
return _playModeServices.UpdatePackageManifestAsync(packageVersion, timeout);
return _playModeServices.UpdatePackageManifestAsync(packageVersion, autoSaveVersion, timeout);
}
/// <summary>
@@ -251,6 +251,17 @@ namespace YooAsset
return operation;
}
/// <summary>
/// 清理包裹本地所有的缓存文件
/// </summary>
public ClearAllCacheFilesOperation ClearAllCacheFilesAsync()
{
DebugCheckInitialize();
var operation = new ClearAllCacheFilesOperation(this);
OperationSystem.StartOperation(operation);
return operation;
}
/// <summary>
/// 获取本地包裹的版本信息
/// </summary>

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 6fcda791b973f5b4499e8bd3ede91312
guid: 5b46b75f6d04c3e48998ab98d402cdbe
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -1,4 +1,6 @@
using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("YooAsset.Editor")]
[assembly: InternalsVisibleTo("YooAsset.EditorExtension")]
[assembly: InternalsVisibleTo("YooAsset.RuntimeExtension")]
[assembly: InternalsVisibleTo("Assembly-CSharp-Editor")]

View File

@@ -21,7 +21,7 @@ namespace YooAsset
/// <summary>
/// 向网络端请求并更新清单
/// </summary>
UpdatePackageManifestOperation UpdatePackageManifestAsync(string packageVersion, int timeout);
UpdatePackageManifestOperation UpdatePackageManifestAsync(string packageVersion, bool autoSaveVersion, int timeout);
/// <summary>
/// 预下载指定版本的包裹内容

View File

@@ -2,7 +2,7 @@
namespace YooAsset
{
[CreateAssetMenu(fileName = "YooAssetSettings", menuName = "YooAsset/Create Settings")]
[CreateAssetMenu(fileName = "YooAssetSettings", menuName = "YooAsset/Create YooAsset Settings")]
internal class YooAssetSettings : ScriptableObject
{
/// <summary>

View File

@@ -19,7 +19,10 @@ namespace YooAsset
public static void Initialize(ILogger logger = null)
{
if (_isInitialize)
throw new Exception($"{nameof(YooAssets)} is initialized !");
{
UnityEngine.Debug.LogWarning($"{nameof(YooAssets)} is initialized !");
return;
}
if (_isInitialize == false)
{
@@ -99,6 +102,7 @@ namespace YooAsset
if (HasPackage(packageName))
throw new Exception($"Package {packageName} already existed !");
YooLogger.Log($"Create resource package : {packageName}");
ResourcePackage package = new ResourcePackage(packageName);
_packages.Add(package);
return package;
@@ -136,6 +140,24 @@ namespace YooAsset
return null;
}
/// <summary>
/// 销毁资源包
/// </summary>
/// <param name="packageName">资源包名称</param>
public static void DestroyPackage(string packageName)
{
ResourcePackage package = GetPackage(packageName);
if (package == null)
return;
YooLogger.Log($"Destroy resource package : {packageName}");
_packages.Remove(package);
package.DestroyPackage();
// 清空缓存
CacheSystem.ClearPackage(packageName);
}
/// <summary>
/// 检测资源包是否存在
/// </summary>
@@ -215,6 +237,27 @@ namespace YooAsset
{
CacheSystem.InitVerifyLevel = verifyLevel;
}
/// <summary>
/// 设置缓存系统参数,沙盒目录的存储路径
/// </summary>
public static void SetCacheSystemSandboxPath(string sandboxPath)
{
if (string.IsNullOrEmpty(sandboxPath))
{
YooLogger.Error($"Sandbox path is null or empty !");
return;
}
// 注意:需要确保没有任何资源系统起效之前才可以设置沙盒目录!
if (_packages.Count > 0)
{
YooLogger.Error($"Please call this method {nameof(SetCacheSystemSandboxPath)} before the package is created !");
return;
}
PersistentTools.OverwriteSandboxPath(sandboxPath);
}
#endregion
#region
@@ -231,15 +274,16 @@ namespace YooAsset
/// </summary>
public static string GetSandboxRoot()
{
return PathHelper.GetPersistentRootPath();
return PersistentTools.GetPersistentRootPath();
}
/// <summary>
/// 清空沙盒目录
/// 清空沙盒目录需要重启APP
/// </summary>
public static void ClearSandbox()
{
PersistentHelper.DeleteSandbox();
YooLogger.Warning("Clear sandbox folder files, Finally, restart the application !");
PersistentTools.DeleteSandbox();
}
#endregion

View File

@@ -405,9 +405,8 @@ namespace YooAsset
return _defaultPackage.CreateResourceUnpacker(unpackingMaxNumber, failedTryAgain);
}
#endregion
#region
#region
/// <summary>
/// 资源回收(卸载引用计数为零的资源)
/// </summary>
@@ -416,7 +415,6 @@ namespace YooAsset
DebugCheckDefaultPackageValid();
_defaultPackage.UnloadUnusedAssets();
}
/// <summary>
/// 强制回收所有资源
/// </summary>
@@ -425,9 +423,8 @@ namespace YooAsset
DebugCheckDefaultPackageValid();
_defaultPackage.ForceUnloadAllAssets();
}
#endregion
#region
[Conditional("DEBUG")]
private static void DebugCheckDefaultPackageValid()