Compare commits
40 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8686c32ada | ||
|
|
f043c6710a | ||
|
|
acd27e36fa | ||
|
|
37f0d1e5a1 | ||
|
|
e6397559ff | ||
|
|
812c46adeb | ||
|
|
4d7fb6301a | ||
|
|
f0951f2a25 | ||
|
|
7d2defedb7 | ||
|
|
17ab618bed | ||
|
|
0f9e932616 | ||
|
|
20b0bd26ae | ||
|
|
3b395861d9 | ||
|
|
d5d1f851ab | ||
|
|
c2e2a33af1 | ||
|
|
9a729f921e | ||
|
|
1b75f4b6e9 | ||
|
|
aaab6692c3 | ||
|
|
70fc85e456 | ||
|
|
29358a7b4b | ||
|
|
b1b0563d84 | ||
|
|
21b1e5bee7 | ||
|
|
c02eeef846 | ||
|
|
e84e50708b | ||
|
|
1471ca06f3 | ||
|
|
60b04c19dc | ||
|
|
4490c99eee | ||
|
|
9a84cdef9f | ||
|
|
62bbf110fb | ||
|
|
fd282d96d1 | ||
|
|
4e4da4440b | ||
|
|
5651d6dd9d | ||
|
|
e0499993a4 | ||
|
|
5c59cfe983 | ||
|
|
396ec7121c | ||
|
|
e403c80d51 | ||
|
|
aac315826e | ||
|
|
567c34d4d1 | ||
|
|
896681df87 | ||
|
|
e278883958 |
@@ -2,6 +2,116 @@
|
||||
|
||||
All notable changes to this package will be documented in this file.
|
||||
|
||||
## [1.4.13] - 2023-05-12
|
||||
|
||||
### Changed
|
||||
|
||||
- 可寻址地址冲突时,打印冲突地址的资源路径。
|
||||
- 销毁Package的时候清空该Package的缓存记录。
|
||||
|
||||
### Added
|
||||
|
||||
- 新增方法ResoucePackage.ClearAllCacheFilesAsync()
|
||||
|
||||
```c#
|
||||
public class ResoucePackage
|
||||
{
|
||||
/// <summary>
|
||||
/// 清理包裹本地所有的缓存文件
|
||||
/// </summary>
|
||||
public ClearAllCacheFilesOperation ClearAllCacheFilesAsync();
|
||||
}
|
||||
```
|
||||
|
||||
- 新增方法YooAssets.SetCacheSystemSandboxPath()
|
||||
|
||||
```c#
|
||||
public class YooAssets
|
||||
{
|
||||
/// <summary>
|
||||
/// 设置缓存系统参数,沙盒目录的存储路径
|
||||
/// </summary>
|
||||
public static void SetCacheSystemSandboxPath(string sandboxPath);
|
||||
}
|
||||
```
|
||||
|
||||
## [1.4.12] - 2023-04-22
|
||||
|
||||
### Changed
|
||||
|
||||
- 增加了对WEBGL平台加密选项的检测。
|
||||
|
||||
- 增加了YooAsset/Home Page菜单栏。
|
||||
|
||||
- 增加了鼠标右键创建配置的菜单。
|
||||
|
||||
- 增加了YooAssets.DestroyPackage()方法。
|
||||
|
||||
```c#
|
||||
class YooAssets
|
||||
{
|
||||
/// <summary>
|
||||
/// 销毁资源包
|
||||
/// </summary>
|
||||
/// <param name="package">资源包对象</param>
|
||||
public static void DestroyPackage(string packageName);
|
||||
}
|
||||
```
|
||||
|
||||
- UpdatePackageManifestAsync方法增加了新参数autoSaveVersion
|
||||
|
||||
```c#
|
||||
class ResourcePackage
|
||||
{
|
||||
/// <summary>
|
||||
/// 向网络端请求并更新清单
|
||||
/// </summary>
|
||||
/// <param name="packageVersion">更新的包裹版本</param>
|
||||
/// <param name="autoSaveVersion">更新成功后自动保存版本号,作为下次初始化的版本。</param>
|
||||
/// <param name="timeout">超时时间(默认值:60秒)</param>
|
||||
public UpdatePackageManifestOperation UpdatePackageManifestAsync(string packageVersion, bool autoSaveVersion = true, int timeout = 60)
|
||||
}
|
||||
```
|
||||
|
||||
- BuildParameters类增加了新字段。
|
||||
|
||||
可以自定义共享资源文件的打包规则。
|
||||
|
||||
```c#
|
||||
class BuildParameters
|
||||
{
|
||||
/// <summary>
|
||||
/// 共享资源的打包规则
|
||||
/// </summary>
|
||||
public IShareAssetPackRule ShareAssetPackRule = null;
|
||||
}
|
||||
```
|
||||
|
||||
## [1.4.11] - 2023-04-14
|
||||
|
||||
### Fixed
|
||||
|
||||
- (#97)修复了着色器变种收集配置无法保存的问题。
|
||||
- (#83)修复了资源收集界面Package列表没有实时刷新的问题。
|
||||
- (#48)优化了场景卸载机制,在切换场景的时候不在主动卸载资源。
|
||||
|
||||
### Changed
|
||||
|
||||
- 增加了扩展属性
|
||||
|
||||
```c#
|
||||
[assembly: InternalsVisibleTo("YooAsset.EditorExtension")]
|
||||
[assembly: InternalsVisibleTo("YooAsset.RuntimeExtension")]
|
||||
```
|
||||
|
||||
## [1.4.10] - 2023-04-08
|
||||
|
||||
### Fixed
|
||||
|
||||
- 修复了资源文件路径无效导致异常的问题。
|
||||
- 修复了原生文件不支持ini格式文件的问题。
|
||||
- 修复了通过代码途径导入XML配置的报错问题。
|
||||
|
||||
## [1.4.9] - 2023-03-29
|
||||
|
||||
### Fixed
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -3,6 +3,7 @@ using UnityEngine;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
[CreateAssetMenu(fileName = "AssetBundleBuilderSetting", menuName = "YooAsset/Create AssetBundle Builder Settings")]
|
||||
public class AssetBundleBuilderSetting : ScriptableObject
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -76,9 +76,14 @@ namespace YooAsset.Editor
|
||||
/// 验证构建结果
|
||||
/// </summary>
|
||||
public bool VerifyBuildingResult = false;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 加密类
|
||||
/// 共享资源的打包规则
|
||||
/// </summary>
|
||||
public IShareAssetPackRule ShareAssetPackRule = null;
|
||||
|
||||
/// <summary>
|
||||
/// 资源的加密接口
|
||||
/// </summary>
|
||||
public IEncryptionServices EncryptionServices = null;
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace YooAsset.Editor
|
||||
/// <summary>
|
||||
/// 构建失败的信息
|
||||
/// </summary>
|
||||
public string FailedInfo;
|
||||
public string ErrorInfo;
|
||||
|
||||
/// <summary>
|
||||
/// 输出的补丁包目录
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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. 移除不参与构建的资源
|
||||
|
||||
@@ -40,6 +40,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))
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ using UnityEngine;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
[CreateAssetMenu(fileName = "AssetBundleCollectorSetting", menuName = "YooAsset/Create AssetBundle Collector Settings")]
|
||||
public class AssetBundleCollectorSetting : ScriptableObject
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3b8606481370397489cb3aa21e726d9a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,14 @@
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 共享资源的打包规则
|
||||
/// </summary>
|
||||
public interface IShareAssetPackRule
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取打包规则结果
|
||||
/// </summary>
|
||||
PackRuleResult GetPackRuleResult(string assetPath);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1ed930b0cc1db1742b0a131ca476bd82
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
17
Assets/YooAsset/Editor/HomePage.cs
Normal 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
|
||||
11
Assets/YooAsset/Editor/HomePage.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 901fc6964e7d483428830e2681899473
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
[CreateAssetMenu(fileName = "ShaderVariantCollectorSetting", menuName = "YooAsset/Create ShaderVariant Collector Settings")]
|
||||
public class ShaderVariantCollectorSetting : ScriptableObject
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
@@ -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!");
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;" />
|
||||
|
||||
@@ -187,7 +187,7 @@
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright 2018-2021 何冠峰
|
||||
Copyright 2021-2022 TuYoo Games
|
||||
Copyright 2021-2023 TuYoo Games
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4eb0b0eafee709d478ab6d81faacb304
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -3,14 +3,59 @@ using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 资源路径帮助类
|
||||
/// </summary>
|
||||
internal static class PathHelper
|
||||
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>
|
||||
@@ -32,33 +77,6 @@ namespace YooAsset
|
||||
return StringUtility.Format("{0}/{1}", root, path);
|
||||
}
|
||||
|
||||
/// <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);
|
||||
}
|
||||
return _sandboxPath;
|
||||
#else
|
||||
if (string.IsNullOrEmpty(_sandboxPath))
|
||||
{
|
||||
_sandboxPath = StringUtility.Format("{0}/Sandbox", UnityEngine.Application.persistentDataPath);
|
||||
}
|
||||
return _sandboxPath;
|
||||
#endif
|
||||
}
|
||||
private static string GetRegularPath(string path)
|
||||
{
|
||||
return path.Replace('\\', '/').Replace("\\", "/"); //替换为Linux路径格式
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取WWW加载本地资源的路径
|
||||
/// </summary>
|
||||
@@ -76,18 +94,6 @@ namespace YooAsset
|
||||
return path;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 持久化目录帮助类
|
||||
/// </summary>
|
||||
internal static class PersistentHelper
|
||||
{
|
||||
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";
|
||||
|
||||
|
||||
/// <summary>
|
||||
@@ -95,7 +101,7 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public static void DeleteSandbox()
|
||||
{
|
||||
string directoryPath = PathHelper.MakePersistentLoadPath(string.Empty);
|
||||
string directoryPath = MakePersistentLoadPath(string.Empty);
|
||||
if (Directory.Exists(directoryPath))
|
||||
Directory.Delete(directoryPath, true);
|
||||
}
|
||||
@@ -105,7 +111,7 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public static void DeleteCacheFolder()
|
||||
{
|
||||
string root = PathHelper.MakePersistentLoadPath(CacheFolderName);
|
||||
string root = MakePersistentLoadPath(CacheFolderName);
|
||||
if (Directory.Exists(root))
|
||||
Directory.Delete(root, true);
|
||||
}
|
||||
@@ -115,7 +121,7 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public static void DeleteManifestFolder()
|
||||
{
|
||||
string root = PathHelper.MakePersistentLoadPath(ManifestFolderName);
|
||||
string root = MakePersistentLoadPath(ManifestFolderName);
|
||||
if (Directory.Exists(root))
|
||||
Directory.Delete(root, true);
|
||||
}
|
||||
@@ -129,7 +135,7 @@ namespace YooAsset
|
||||
{
|
||||
if (_cachedBundleFileFolder.TryGetValue(packageName, out string value) == false)
|
||||
{
|
||||
string root = PathHelper.MakePersistentLoadPath(CacheFolderName);
|
||||
string root = MakePersistentLoadPath(CacheFolderName);
|
||||
value = $"{root}/{packageName}/{CachedBundleFileFolder}";
|
||||
_cachedBundleFileFolder.Add(packageName, value);
|
||||
}
|
||||
@@ -144,7 +150,7 @@ namespace YooAsset
|
||||
{
|
||||
if (_cachedRawFileFolder.TryGetValue(packageName, out string value) == false)
|
||||
{
|
||||
string root = PathHelper.MakePersistentLoadPath(CacheFolderName);
|
||||
string root = MakePersistentLoadPath(CacheFolderName);
|
||||
value = $"{root}/{packageName}/{CachedRawFileFolder}";
|
||||
_cachedRawFileFolder.Add(packageName, value);
|
||||
}
|
||||
@@ -156,7 +162,7 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public static string GetAppFootPrintFilePath()
|
||||
{
|
||||
return PathHelper.MakePersistentLoadPath(AppFootPrintFileName);
|
||||
return MakePersistentLoadPath(AppFootPrintFileName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -165,7 +171,7 @@ namespace YooAsset
|
||||
public static string GetCacheManifestFilePath(string packageName, string packageVersion)
|
||||
{
|
||||
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(packageName, packageVersion);
|
||||
return PathHelper.MakePersistentLoadPath($"{ManifestFolderName}/{fileName}");
|
||||
return MakePersistentLoadPath($"{ManifestFolderName}/{fileName}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -174,7 +180,7 @@ namespace YooAsset
|
||||
public static string GetCachePackageHashFilePath(string packageName, string packageVersion)
|
||||
{
|
||||
string fileName = YooAssetSettingsData.GetPackageHashFileName(packageName, packageVersion);
|
||||
return PathHelper.MakePersistentLoadPath($"{ManifestFolderName}/{fileName}");
|
||||
return MakePersistentLoadPath($"{ManifestFolderName}/{fileName}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -183,7 +189,7 @@ namespace YooAsset
|
||||
public static string GetCachePackageVersionFilePath(string packageName)
|
||||
{
|
||||
string fileName = YooAssetSettingsData.GetPackageVersionFileName(packageName);
|
||||
return PathHelper.MakePersistentLoadPath($"{ManifestFolderName}/{fileName}");
|
||||
return MakePersistentLoadPath($"{ManifestFolderName}/{fileName}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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}");
|
||||
}
|
||||
|
||||
@@ -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}");
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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>
|
||||
@@ -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")]
|
||||
@@ -21,7 +21,7 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 向网络端请求并更新清单
|
||||
/// </summary>
|
||||
UpdatePackageManifestOperation UpdatePackageManifestAsync(string packageVersion, int timeout);
|
||||
UpdatePackageManifestOperation UpdatePackageManifestAsync(string packageVersion, bool autoSaveVersion, int timeout);
|
||||
|
||||
/// <summary>
|
||||
/// 预下载指定版本的包裹内容
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -99,6 +99,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 +137,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 +234,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 +271,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
|
||||
|
||||
|
||||
@@ -35,13 +35,13 @@ internal class FsmSceneBattle : IStateNode
|
||||
|
||||
private IEnumerator Prepare()
|
||||
{
|
||||
yield return UniWindow.OpenWindowAsync<UILoadingWindow>("UILoading");
|
||||
yield return YooAssets.LoadSceneAsync("scene_battle");
|
||||
|
||||
_battleRoom = new BattleRoom();
|
||||
yield return _battleRoom.LoadRoom();
|
||||
|
||||
// 等所有数据准备完毕后,关闭加载界面。
|
||||
UniWindow.CloseWindow<UILoadingWindow>();
|
||||
// 释放资源
|
||||
var package = YooAssets.GetPackage("DefaultPackage");
|
||||
package.UnloadUnusedAssets();
|
||||
}
|
||||
}
|
||||
@@ -28,14 +28,11 @@ internal class FsmSceneHome : IStateNode
|
||||
|
||||
private IEnumerator Prepare()
|
||||
{
|
||||
if (_machine.PreviousNode != typeof(FsmInitGame).FullName)
|
||||
yield return UniWindow.OpenWindowAsync<UILoadingWindow>("UILoading");
|
||||
|
||||
yield return YooAssets.LoadSceneAsync("scene_home");
|
||||
yield return UniWindow.OpenWindowAsync<UIHomeWindow>("UIHome");
|
||||
yield return new WaitForSeconds(0.5f);
|
||||
|
||||
// 等所有数据准备完毕后,关闭加载界面。
|
||||
UniWindow.CloseWindow<UILoadingWindow>();
|
||||
|
||||
// 释放资源
|
||||
var package = YooAssets.GetPackage("DefaultPackage");
|
||||
package.UnloadUnusedAssets();
|
||||
}
|
||||
}
|
||||
@@ -32,13 +32,13 @@ public class FsmUpdateManifest : IStateNode
|
||||
{
|
||||
yield return new WaitForSecondsRealtime(0.5f);
|
||||
|
||||
bool savePackageVersion = true;
|
||||
var package = YooAssets.GetPackage("DefaultPackage");
|
||||
var operation = package.UpdatePackageManifestAsync(PatchManager.Instance.PackageVersion);
|
||||
var operation = package.UpdatePackageManifestAsync(PatchManager.Instance.PackageVersion, savePackageVersion);
|
||||
yield return operation;
|
||||
|
||||
if(operation.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
operation.SavePackageVersion();
|
||||
_machine.ChangeState<FsmCreateDownloader>();
|
||||
}
|
||||
else
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// 作者:Stark
|
||||
//-------------------------------------
|
||||
|
||||
#if UNITY_ANDROID
|
||||
#if UNITY_ANDROID && UNITY_EDITOR
|
||||
/// <summary>
|
||||
/// 为Github对开发者的友好,采用自动补充UnityPlayerActivity.java文件的通用姿势满足各个开发者
|
||||
/// </summary>
|
||||
@@ -30,7 +30,6 @@ internal class AndroidPost : UnityEditor.Android.IPostGenerateGradleAndroidProje
|
||||
" } \n" +
|
||||
" catch(java.io.IOException e) \n" +
|
||||
" { \n" +
|
||||
" e.printStackTrace(); \n" +
|
||||
" } \n" +
|
||||
" return false; \n" +
|
||||
" } \n" +
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "com.tuyoogame.yooasset",
|
||||
"displayName": "YooAsset",
|
||||
"version": "1.4.9",
|
||||
"version": "1.4.13",
|
||||
"unity": "2019.4",
|
||||
"description": "unity3d resources management system.",
|
||||
"author": {
|
||||
|
||||
@@ -1,163 +0,0 @@
|
||||
# 资源构建
|
||||
|
||||

|
||||
|
||||
### 界面介绍
|
||||
|
||||
- **Build Output**
|
||||
|
||||
构建输出的目录,会根据Unity编辑器当前切换的平台自动划分构建结果。
|
||||
|
||||
- **Build Pipeline**
|
||||
|
||||
构建管线
|
||||
|
||||
(1) BuiltinBuildPipeline: 传统的内置构建管线。
|
||||
|
||||
(2) ScriptableBuildPipeline: 可编程构建管线。
|
||||
|
||||
- **Build Mode**
|
||||
|
||||
构建模式
|
||||
|
||||
(1) 强制构建模式:会删除指定构建平台下的所有构建记录,重新构建所有资源包。
|
||||
|
||||
(2) 增量构建模式:以上一次构建结果为基础,对于发生变化的资源进行增量构建。
|
||||
|
||||
(3) 演练构建模式:在不生成AssetBundle文件的前提下,进行演练构建并快速生成构建报告和补丁清单。
|
||||
|
||||
(4) 模拟构建模式:在编辑器下配合EditorSimulateMode运行模式,来模拟真实运行的环境。
|
||||
|
||||
- **Build Version**
|
||||
|
||||
构建的资源包版本。
|
||||
|
||||
- **Build Package**
|
||||
|
||||
构建的资源包名称。
|
||||
|
||||
- **Encryption**
|
||||
|
||||
加密类列表。
|
||||
|
||||
- **Compression**
|
||||
|
||||
资源包的压缩方式。
|
||||
|
||||
- **Output Name Style**
|
||||
|
||||
输出的资源包文件名称样式
|
||||
|
||||
HashName:哈希值
|
||||
|
||||
BundleName_HashName:资源包名+哈希值
|
||||
|
||||
- **Copy Buildin File Option**
|
||||
|
||||
首包资源文件的拷贝方式
|
||||
|
||||
(1) None:不拷贝任何文件
|
||||
|
||||
(2) ClearAndCopyAll:先清空已有文件,然后拷贝所有文件
|
||||
|
||||
(3) ClearAndCopyByTags:先清空已有文件,然后按照资源标签拷贝文件
|
||||
|
||||
(4) OnlyCopyAll:不清空已有文件,直接拷贝所有文件
|
||||
|
||||
(5) OnlyCopyByTags:不清空已有文件,直接按照资源标签拷贝文件
|
||||
|
||||
- **构建**
|
||||
|
||||
点击构建按钮会开始构建流程,构建流程分为多个节点顺序执行,如果某个节点发生错误,会导致构建失败。错误信息可以在控制台查看。
|
||||
|
||||
### 补丁包
|
||||
|
||||
构建成功后会在输出目录下找到补丁包文件夹,该文件夹名称为本次构建时指定的资源版本号。
|
||||
|
||||
补丁包文件夹里包含补丁清单文件,资源包文件,构建报告文件等。
|
||||
|
||||

|
||||
|
||||
### 补丁清单
|
||||
|
||||
补丁清单文件是上图中以PatchManifest开头命名的文件。
|
||||
|
||||
- PatchManifest_DefaultPackage_xxxxxx.hash
|
||||
|
||||
记录了补丁清单文件的哈希值。
|
||||
|
||||
- PatchManifest_DefaultPackage_xxxxxx.json
|
||||
|
||||
该文件为Json文本格式,主要用于开发者预览信息。
|
||||
|
||||
- PatchManifest_DefaultPackage_xxxxxx.bytes
|
||||
|
||||
该文件为二进制格式,主要用于程序内读取加载。
|
||||
|
||||
### Jenkins支持
|
||||
|
||||
如果需要自动化构建,可以参考如下代码范例:
|
||||
|
||||
使用内置构建管线来构建资源包。
|
||||
|
||||
````c#
|
||||
private static void BuildInternal(BuildTarget buildTarget)
|
||||
{
|
||||
Debug.Log($"开始构建 : {buildTarget}");
|
||||
|
||||
// 构建参数
|
||||
string defaultOutputRoot = AssetBundleBuilderHelper.GetDefaultOutputRoot();
|
||||
BuildParameters buildParameters = new BuildParameters();
|
||||
buildParameters.OutputRoot = defaultOutputRoot;
|
||||
buildParameters.BuildTarget = buildTarget;
|
||||
buildParameters.BuildPipeline = EBuildPipeline.BuiltinBuildPipeline;
|
||||
buildParameters.BuildMode = EBuildMode.ForceRebuild;
|
||||
buildParameters.PackageName = "DefaultPackage";
|
||||
buildParameters.PackageVersion = "1.0";
|
||||
buildParameters.VerifyBuildingResult = true;
|
||||
buildParameters.CompressOption = ECompressOption.LZ4;
|
||||
buildParameters.OutputNameStyle = EOutputNameStyle.HashName;
|
||||
buildParameters.CopyBuildinFileOption = ECopyBuildinFileOption.None;
|
||||
|
||||
// 执行构建
|
||||
AssetBundleBuilder builder = new AssetBundleBuilder();
|
||||
var buildResult = builder.Run(buildParameters);
|
||||
if (buildResult.Success)
|
||||
{
|
||||
Debug.Log($"构建成功 : {buildResult.OutputPackageDirectory}");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"构建失败 : {buildResult.FailedInfo}");
|
||||
}
|
||||
}
|
||||
|
||||
// 从构建命令里获取参数示例
|
||||
private static string GetBuildPackageName()
|
||||
{
|
||||
foreach (string arg in System.Environment.GetCommandLineArgs())
|
||||
{
|
||||
if (arg.StartsWith("buildPackage"))
|
||||
return arg.Split("="[0])[1];
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
````
|
||||
|
||||
### 重要概念
|
||||
|
||||
- **增量构建**
|
||||
|
||||
增量构建是在Unity的帮助下实现的一种快速打包机制。主要是利用资源构建相关的缓存文件来避免二次构建,以此来提高打包效率。
|
||||
|
||||
- **强制构建**
|
||||
|
||||
强制构建是每次构建之前,都会清空之前构建的所有缓存文件,以此来重新构建资源包。
|
||||
|
||||
- **首包资源**
|
||||
|
||||
在构建应用程序的时候,我们希望将某些资源打进首包里,首包资源拷贝至StreamingAssets/BuildinFiles/目录下。首包资源如果发生变化,也可以通过热更新来更新资源。
|
||||
|
||||
- **补丁包**
|
||||
|
||||
无论是通过增量构建还是强制构建,在构建完成后都会生成一个以包裹版本(PackageVersion)命名的文件夹,我们把这个文件夹统称为补丁包。补丁包里包含了游戏运行需要的所有资源,我们可以无脑的将补丁包内容覆盖到CDN目录下,也可以通过编写差异分析工具,来筛选出和线上最新版本之间的差异文件,然后将差异文件上传到CDN目录里。
|
||||
@@ -1,165 +0,0 @@
|
||||
# 资源收集
|
||||
|
||||

|
||||
|
||||
左侧为分组列表,右侧为该分组的配置界面。
|
||||
|
||||
导入按钮:可以导入保存的XML文件。
|
||||
|
||||
导出按钮:可以将配置数据导出为XML文件。
|
||||
|
||||
修复按钮:在配置里的文件夹挪动位置之后,可以通过该按钮按钮来修正。
|
||||
|
||||
**注意**:该工具仅支持Unity2019.4+
|
||||
|
||||
#### 公共设置
|
||||
|
||||
- Show Packages
|
||||
|
||||
是否展示资源包列表视图。
|
||||
|
||||
- Show Editor Alias
|
||||
|
||||
是否显示为中文模式。
|
||||
|
||||
- Enable Addressable
|
||||
|
||||
启用可寻址资源定位系统。
|
||||
|
||||
- Unique Bundle Name
|
||||
|
||||
资源包名追加PackageName作为前缀。
|
||||
|
||||
#### 资源分组
|
||||
|
||||
- Active Rule
|
||||
|
||||
激活规则,规则可以自定义扩展。下面是内置规则:
|
||||
|
||||
- EnableGroup 启用分组。
|
||||
|
||||
- DisableGroup 禁用分组。
|
||||
|
||||
````c#
|
||||
//自定义扩展范例
|
||||
public class DisableGroup : IActiveRule
|
||||
{
|
||||
public bool IsActiveGroup()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
````
|
||||
|
||||
- Grouper Name
|
||||
|
||||
分组名称
|
||||
|
||||
- Grouper Desc
|
||||
|
||||
分组备注信息
|
||||
|
||||
- Asset Tags
|
||||
|
||||
资源分类标签列表,该分组下收集的资源会全部被打上该标签。
|
||||
|
||||
注意:多个标签用分号隔开,例如 level1;level2;level3
|
||||
|
||||
#### 资源搜集器
|
||||
|
||||
- **Collect Path**
|
||||
|
||||
收集路径,可以指定文件夹或单个资源文件。
|
||||
|
||||
- **Collector Type**
|
||||
|
||||
收集器类型:
|
||||
|
||||
- MainAssetCollector 收集参与打包的主资源对象,并写入到资源清单的资源列表里(可以通过代码加载)。
|
||||
- StaticAssetCollector 收集参与打包的主资源对象,但不写入到资源清单的资源列表里(无法通过代码加载)。
|
||||
- DependAssetCollector 收集参与打包的依赖资源对象,但不写入到资源清单的资源列表里(无法通过代码加载)(当依赖资源没有被任何主资源引用的时候,则会在打包的时候自动剔除)。
|
||||
|
||||
StaticAssetCollector收集器和DependAssetCollector收集器适合对资源进行定制化打包策略。
|
||||
|
||||
示例1:一个游戏的粒子特效的纹理会非常多,通常特效制作师会把这些纹理放到一个文件夹内管理。如果我们把这些纹理打进一个AssetBundle文件内,当下次更新的时候,如果新增或改动了一个纹理,那么就要上传整个纹理的AssetBundle文件。我们可以把特效纹理通过DependAssetCollector收集器进行收集并自定义打包规则,通过文件名称的首字母进行小粒度打包,这样一个AssetBundle文件会被拆分为26个AssetBundle文件。
|
||||
|
||||
示例2:当我们需要严格控制某个文件夹内的依赖资源打进同一个AssetBundle文件内,那么StaticAssetCollector收集器是最佳选择,该收集器收集的资源,无论是否被其它资源引用或被多个资源引用,这些资源都会按照设定的打包规则打包,且这些资源不会被处理为share资源包。
|
||||
|
||||
- **AddressRule**
|
||||
|
||||
可寻址规则,规则可以自定义扩展。下面是内置规则:
|
||||
|
||||
- AddressByFileName 以文件名为定位地址。
|
||||
|
||||
- AddressByGrouperAndFileName 以分组名+文件名为定位地址。
|
||||
|
||||
- AddressByFolderAndFileName 以文件夹名+文件名为定位地址。
|
||||
|
||||
````c#
|
||||
//自定义扩展范例
|
||||
public class AddressByFileName : IAddressRule
|
||||
{
|
||||
string IAddressRule.GetAssetAddress(AddressRuleData data)
|
||||
{
|
||||
return Path.GetFileNameWithoutExtension(data.AssetPath);
|
||||
}
|
||||
}
|
||||
````
|
||||
|
||||
- **PackRule**
|
||||
|
||||
打包规则,规则可以自定义扩展。下面是内置规则:
|
||||
|
||||
- PackSeparately 以文件路径作为资源包名,每个资源文件单独打包。
|
||||
- PackDirectory 以文件所在的文件夹路径作为资源包名,该文件夹下所有文件打进一个资源包。
|
||||
- PackTopDirectory 以收集器下顶级文件夹为资源包名,该文件夹下所有文件打进一个资源包。
|
||||
- PackCollector 以收集器路径作为资源包名,收集的所有文件打进一个资源包。
|
||||
- PackGroup 以分组名称作为资源包名,收集的所有文件打进一个资源包。
|
||||
- PackRawFile 目录下的资源文件会被处理为原生资源包。
|
||||
|
||||
````c#
|
||||
//自定义扩展范例
|
||||
public class PackDirectory : IPackRule
|
||||
{
|
||||
PackRuleResult IPackRule.GetBundleName(PackRuleData data)
|
||||
{
|
||||
//"Assets/Config/test.txt" --> "Assets/Config"
|
||||
string bundleName = Path.GetDirectoryName(data.AssetPath);
|
||||
PackRuleResult result = new PackRuleResult(bundleName, DefaultPackRule.AssetBundleFileExtension);
|
||||
return result;
|
||||
}
|
||||
bool IPackRule.IsRawFilePackRule()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
````
|
||||
|
||||
- **FilterRule**
|
||||
|
||||
过滤规则,规则可以自定义扩展。下面是内置规则:
|
||||
|
||||
- CollectAll 收集目录下的所有资源文件
|
||||
- CollectScene 只收集目录下的场景文件
|
||||
- CollectPrefab 只收集目录下的预制体文件
|
||||
- CollectSprite 只收集目录下的精灵类型的文件
|
||||
|
||||
````c#
|
||||
//自定义扩展范例
|
||||
public class CollectScene : IFilterRule
|
||||
{
|
||||
public bool IsCollectAsset(FilterRuleData data)
|
||||
{
|
||||
return Path.GetExtension(data.AssetPath) == ".unity";
|
||||
}
|
||||
}
|
||||
````
|
||||
|
||||
- **UserData**
|
||||
|
||||
用户自定义数据,可以帮助定制化AddressRule和PackRule。
|
||||
|
||||
- **AssetTags**
|
||||
|
||||
资源分类标签列表,该收集器下收集的资源会全部被打上该标签。
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
# 调试器
|
||||
|
||||
调试器是在游戏运行时,帮助我们查看资源包加载信息的工具,通过该工具可以发现潜在的资源泄漏。
|
||||
|
||||
可以查看资源对象列表信息(AssetView),资源包列表信息(BundleView)。
|
||||
|
||||
**注意**:该工具仅支持Unity2019.4+
|
||||
|
||||
### 真机远程调试注意事项
|
||||
|
||||
在构建安装包的时候,需要勾选上Development Build和Autoconnect Profiler
|
||||
|
||||
### 资源对象列表视图
|
||||
|
||||

|
||||
|
||||
### 资源包列表视图
|
||||
|
||||

|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
# 资源部署
|
||||
|
||||
在资源补丁包构建成功之后,需要将补丁包传输到CDN服务器上。
|
||||
|
||||
如果是本地测试,可以在本地创建一个WEB服务器,然后将补丁包拷贝到WEB服务器下。
|
||||
|
||||
**部署目录**
|
||||
|
||||
在业务开发过程中,发版本之前都会创建一个SVN或GIT分支,以分支工程为基础去构建APP。
|
||||
|
||||
````
|
||||
CDN
|
||||
└─android
|
||||
├─v1.0(APP版本)
|
||||
├─v1.1(APP版本)
|
||||
└─v2.0(APP版本)
|
||||
└─iphone
|
||||
├─v1.0(APP版本)
|
||||
├─v1.1(APP版本)
|
||||
└─v2.0(APP版本)
|
||||
````
|
||||
|
||||
**APP版本说明**
|
||||
|
||||
v1.0 代表的是APP版本,不是资源版本。在没有更换安装包的情况下,不需要新增加APP版本目录。
|
||||
|
||||
例如:我们游戏的当前APP版本是v1.0,那么每次生成的补丁文件全部覆盖到v1.0的目录下即可。
|
||||
|
||||
下面的示例里一共上传过2次补丁包。第二次上传的补丁包会把第一次的版本记录文件(PatchManifest_DefaultPackage.version)覆盖掉。当我们想回退资源版本的时候,把第一次生成的版本记录文件覆盖到同目录下即可。
|
||||
|
||||
````
|
||||
v1.0(游戏版本)
|
||||
├─PatchManifest_DefaultPackage.version
|
||||
├─PatchManifest_DefaultPackage_2023-02-01-654.hash
|
||||
├─PatchManifest_DefaultPackage_2023-02-01-654.bytes
|
||||
├─PatchManifest_DefaultPackage_2023-02-12-789.hash
|
||||
├─PatchManifest_DefaultPackage_2023-02-12-789.bytes
|
||||
├─2bb5a28d37dabf27df8bc6a4706b8f80.bundle
|
||||
├─2dbea9c3056c8839bc03d80a2aebd105.bundle
|
||||
├─6e8c3003a64ead36a0bd2d5cdebfbcf4.bundle
|
||||
...
|
||||
````
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
# 构建报告
|
||||
|
||||
报告工具,可以查看概览信息(Summary),资源对象列表信息(AssetView),资源包列表信息(BundleView)。
|
||||
|
||||
**注意**:该工具仅支持Unity2019.4+
|
||||
|
||||
### 概览视图
|
||||
|
||||

|
||||
|
||||
### 资源对象列表视图
|
||||
|
||||
可以查看资源对象列表以及每个资源对象所依赖的资源包。
|
||||
|
||||

|
||||
|
||||
### 资源包列表视图
|
||||
|
||||
可以查看资源包列表以及每个资源包所包含的资源对象。
|
||||
|
||||

|
||||
@@ -1,147 +0,0 @@
|
||||
# 代码贡献
|
||||
|
||||
代码贡献请遵循下面的规范。
|
||||
|
||||
### 提交规范
|
||||
|
||||
每个PR只针对一项内容的改进或修复,请勿合并提交。
|
||||
|
||||
PR标题尽量选择英文,备注内容可选中文。
|
||||
|
||||
### 对齐规范
|
||||
|
||||
Tab键对齐(可以在VS里设置)
|
||||
|
||||
### 命名规范
|
||||
|
||||
[规则1-1] 英文单词命名。禁止使用拼音或无意义的字母命名。
|
||||
|
||||
[规则1-2] 直观易懂。使用能够描述其功能或有意义的英文单词或词组。
|
||||
|
||||
[规则1-3] 不要采用下划线命名法。
|
||||
|
||||
```C#
|
||||
int car_type //错误:下划线命名。
|
||||
```
|
||||
|
||||
[规则1-4] 常量、静态字段、类、结构体、非私有字段、方法等名称采用**大驼峰式命名法**
|
||||
|
||||
```C#
|
||||
public const float MaxSpeed = 100f; //常量
|
||||
public static float MaxSpeed = 100f; //静态字段
|
||||
public class GameClass; //类
|
||||
public struct GameStruct; //结构体
|
||||
public string FirstName; //public字段
|
||||
protected string FirstName; //protected字段
|
||||
public void SendMessage(string message) {} //方法
|
||||
```
|
||||
|
||||
[规则1-5] 私有字段、方法形参、局部变量采用 **小驼峰式命名法**
|
||||
|
||||
注意:私有字段以下划线开头
|
||||
|
||||
```C#
|
||||
private string _firstName; //私有字段
|
||||
public void FindByFirstName(string firstName) {} //方法参数
|
||||
string firstName; //局部变量
|
||||
```
|
||||
|
||||
[规则1-6] 接口命名
|
||||
|
||||
注意:接口以大写字母I开头
|
||||
|
||||
```C#
|
||||
public interface IState; //接口
|
||||
```
|
||||
|
||||
[规则1-7] 枚举命名
|
||||
|
||||
注意:枚举以大写字母E开头
|
||||
|
||||
```C#
|
||||
public enum EGameType {Simple, Hard}//枚举及枚举值
|
||||
```
|
||||
|
||||
### 编码规范
|
||||
|
||||
[规则2-1] 声明变量时,一行只声明一个变量。
|
||||
|
||||
```C#
|
||||
private string _firstName;
|
||||
private string _lastName;
|
||||
```
|
||||
|
||||
[规则2-2] 类的字段声明统一放置于类的最前端。
|
||||
|
||||
```C#
|
||||
public class Student
|
||||
{
|
||||
private string _firstName;
|
||||
private string _lastName;
|
||||
|
||||
public string GetFirstName()
|
||||
{
|
||||
return _firstFiled;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
[规则2-3] 一行代码长度不要超过屏幕宽度。如果超过了,将超过部分换行。
|
||||
|
||||
### 注释规范
|
||||
|
||||
[规则3-1] 公共方法注释,采用 /// 形式自动产生XML标签格式的注释。包括方法介绍,参数含义,返回内容。
|
||||
|
||||
注意:私有方法可以不用注释。
|
||||
|
||||
```C#
|
||||
/// <summary>
|
||||
/// 设置场景名称
|
||||
/// </summary>
|
||||
/// <param name="sceneName">场景名</param>
|
||||
/// <returns>如果设置成功返回True</returns>
|
||||
public bool SetSceneName(string sceneName)
|
||||
{
|
||||
}
|
||||
```
|
||||
|
||||
[规则3-2] 公共字段注释,采用 /// 形式自动产生XML标签格式的注释。
|
||||
|
||||
注意:私有字段可以不用注释。
|
||||
|
||||
```C#
|
||||
public class SceneManager
|
||||
{
|
||||
/// <summary>
|
||||
/// 场景的名字
|
||||
/// </summary>
|
||||
public string SceneName;
|
||||
}
|
||||
```
|
||||
|
||||
[规则3-3] 私有字段注释,注释位于代码后面,中间Space键隔开。
|
||||
|
||||
```C#
|
||||
public class Student
|
||||
{
|
||||
private string _firstName; //姓氏
|
||||
private string _lastName; //姓名
|
||||
}
|
||||
```
|
||||
|
||||
[规则3-4] 方法内的代码块注释。
|
||||
|
||||
```C#
|
||||
public void UpdateHost
|
||||
{
|
||||
// 和服务器通信
|
||||
...
|
||||
|
||||
// 检测通信结果
|
||||
...
|
||||
|
||||
// 分析数据
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
@@ -1,103 +0,0 @@
|
||||
# 初始化
|
||||
|
||||
初始化资源系统
|
||||
|
||||
```c#
|
||||
// 初始化资源系统
|
||||
YooAssets.Initialize();
|
||||
|
||||
// 创建默认的资源包
|
||||
var package = YooAssets.CreateAssetsPackage("DefaultPackage");
|
||||
|
||||
// 设置该资源包为默认的资源包,可以使用YooAssets相关加载接口加载该资源包内容。
|
||||
YooAssets.SetDefaultAssetsPackage(package);
|
||||
```
|
||||
|
||||
资源系统的运行模式支持三种:编辑器模拟模式,单机运行模式,联机运行模式。
|
||||
|
||||
**编辑器模拟模式**
|
||||
|
||||
在编辑器下,不需要构建资源包,来模拟运行游戏。
|
||||
|
||||
注意:该模式只在编辑器下起效
|
||||
|
||||
````c#
|
||||
private IEnumerator InitializeYooAsset()
|
||||
{
|
||||
var initParameters = new EditorSimulateModeParameters();
|
||||
initParameters.SimulatePatchManifestPath = EditorSimulateModeHelper.SimulateBuild("DefaultPackage");
|
||||
yield return defaultPackage.InitializeAsync(initParameters);
|
||||
}
|
||||
````
|
||||
|
||||
**单机运行模式**
|
||||
|
||||
对于不需要热更新资源的游戏,可以使用单机运行模式。
|
||||
|
||||
注意:该模式需要构建资源包
|
||||
|
||||
````c#
|
||||
private IEnumerator InitializeYooAsset()
|
||||
{
|
||||
var initParameters = new OfflinePlayModeParameters();
|
||||
yield return defaultPackage.InitializeAsync(initParameters);
|
||||
}
|
||||
````
|
||||
|
||||
**联机运行模式**
|
||||
|
||||
对于需要热更新资源的游戏,可以使用联机运行模式,该模式下初始化参数会很多。
|
||||
|
||||
注意:该模式需要构建资源包
|
||||
|
||||
- DecryptionServices : 如果资源包在构建的时候有加密,需要提供实现IDecryptionServices接口的实例类。
|
||||
|
||||
- QueryServices:内置资源查询服务接口。
|
||||
|
||||
- DefaultHostServer : 默认的资源服务器IP地址。
|
||||
|
||||
- FallbackHostServer : 备用的资源服务器IP地址。
|
||||
|
||||
````c#
|
||||
private IEnumerator InitializeYooAsset()
|
||||
{
|
||||
var initParameters = new HostPlayModeParameters();
|
||||
initParameters.QueryServices = new QueryStreamingAssetsFileServices();
|
||||
initParameters.DefaultHostServer = "http://127.0.0.1/CDN1/Android/v1.0";
|
||||
initParameters.FallbackHostServer = "http://127.0.0.1/CDN2/Android/v1.0";
|
||||
yield return defaultPackage.InitializeAsync(initParameters);
|
||||
}
|
||||
|
||||
// 内置文件查询服务类
|
||||
private class QueryStreamingAssetsFileServices : IQueryServices
|
||||
{
|
||||
public bool QueryStreamingAssets(string fileName)
|
||||
{
|
||||
// StreamingAssetsHelper.cs是太空战机里提供的一个查询脚本。
|
||||
string buildinFolderName = YooAssets.GetStreamingAssetBuildinFolderName();
|
||||
return StreamingAssetsHelper.FileExists($"{buildinFolderName}/{fileName}");
|
||||
}
|
||||
}
|
||||
````
|
||||
|
||||
### 源代码解析
|
||||
|
||||
Package.InitializeAsync()方法解析。
|
||||
|
||||
- 编辑器模拟模式
|
||||
|
||||
每次启动调用EditorSimulateModeHelper.SimulateBuild()方法,都会在底层执行一次模拟构建(Simulate Build)。
|
||||
|
||||
如果参与构建的资源对象数量级很大的话则会有卡顿现象,可以通过直接指定已有的清单路径来避免每次都重复执行模拟构建。
|
||||
|
||||
- 单机运行模式
|
||||
|
||||
在初始化的时候,会直接读取内置清单文件(StreamingAssets文件夹里的文件),最后初始化缓存系统。
|
||||
|
||||
- 联机运行模式
|
||||
|
||||
在初始化的时候,会优先从沙盒里加载清单,如果沙盒里不存在,则会尝试加载内置清单并将其拷贝到沙盒里。最后初始化缓存系统。
|
||||
|
||||
**注意**:如果沙盒清单和内置清单都不存在,初始化也会被判定为成功!
|
||||
|
||||
|
||||
@@ -1,167 +0,0 @@
|
||||
# 资源更新
|
||||
|
||||
**获取资源版本**
|
||||
|
||||
对于联机运行模式,在更新补丁清单之前,需要获取一个资源版本。
|
||||
|
||||
该资源版本可以通过YooAssets提供的接口来更新,也可以通过HTTP访问游戏服务器来获取。
|
||||
|
||||
````c#
|
||||
private IEnumerator UpdateStaticVersion()
|
||||
{
|
||||
var package = YooAssets.GetAssetsPackage("DefaultPackage");
|
||||
var operation = package.UpdatePackageVersionAsync();
|
||||
yield return operation;
|
||||
|
||||
if (operation.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
//更新成功
|
||||
string packageVersion = operation.PackageVersion;
|
||||
Debug.Log($"Updated package Version : {packageVersion}");
|
||||
}
|
||||
else
|
||||
{
|
||||
//更新失败
|
||||
Debug.LogError(operation.Error);
|
||||
}
|
||||
}
|
||||
````
|
||||
|
||||
**更新补丁清单**
|
||||
|
||||
对于联机运行模式,在获取到资源版本号之后,就可以更新资源清单了。
|
||||
|
||||
````c#
|
||||
private IEnumerator UpdatePatchManifest()
|
||||
{
|
||||
var package = YooAssets.GetAssetsPackage("DefaultPackage");
|
||||
var operation = package.UpdatePackageManifestAsync(packageVersion);
|
||||
yield return operation;
|
||||
|
||||
if (operation.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
//更新成功
|
||||
}
|
||||
else
|
||||
{
|
||||
//更新失败
|
||||
Debug.LogError(operation.Error);
|
||||
}
|
||||
}
|
||||
````
|
||||
|
||||
**补丁包下载**
|
||||
|
||||
在补丁清单更新完毕后,就可以更新资源文件了。
|
||||
|
||||
根据产品需求,可以选择更新全部资源,或者只更新部分资源。
|
||||
|
||||
补丁包下载接口:
|
||||
|
||||
- YooAssets.CreatePatchDownloader(int downloadingMaxNumber, int failedTryAgain, int timeout)
|
||||
|
||||
用于下载更新当前资源版本所有的资源包文件。
|
||||
|
||||
- YooAssets.CreatePatchDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout)
|
||||
|
||||
用于下载更新资源标签指定的资源包文件。
|
||||
|
||||
- YooAssets.CreateBundleDownloader(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain, int timeout)
|
||||
|
||||
用于下载更新指定的资源列表依赖的资源包文件。
|
||||
|
||||
````c#
|
||||
IEnumerator Download()
|
||||
{
|
||||
int downloadingMaxNum = 10;
|
||||
int failedTryAgain = 3;
|
||||
int timeout = 60;
|
||||
var package = YooAssets.GetAssetsPackage("DefaultPackage");
|
||||
var downloader = package.CreatePatchDownloader(downloadingMaxNum, failedTryAgain, timeout);
|
||||
|
||||
//没有需要下载的资源
|
||||
if (downloader.TotalDownloadCount == 0)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
|
||||
//需要下载的文件总数和总大小
|
||||
int totalDownloadCount = downloader.TotalDownloadCount;
|
||||
long totalDownloadBytes = downloader.TotalDownloadBytes;
|
||||
|
||||
//注册回调方法
|
||||
downloader.OnDownloadErrorCallback = OnDownloadErrorFunction;
|
||||
downloader.OnDownloadProgressCallback = OnDownloadProgressUpdateFunction;
|
||||
downloader.OnDownloadOverCallback = OnDownloadOverFunction;
|
||||
downloader.OnStartDownloadFileCallback = OnStartDownloadFileFunction;
|
||||
|
||||
//开启下载
|
||||
downloader.BeginDownload();
|
||||
yield return downloader;
|
||||
|
||||
//检测下载结果
|
||||
if (downloader.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
//下载成功
|
||||
}
|
||||
else
|
||||
{
|
||||
//下载失败
|
||||
}
|
||||
}
|
||||
````
|
||||
|
||||
**弱联网环境解决方案**
|
||||
|
||||
对于偏单机但是也有资源热更需求的项目。当玩家在无网络的时候,我们又不希望玩家卡在资源更新步骤而不能正常游戏。所以当玩家本地网络有问题的时候,我们可以跳过资源更新的步骤。
|
||||
|
||||
````c#
|
||||
private IEnumerator Start()
|
||||
{
|
||||
var package = YooAssets.GetAssetsPackage("DefaultPackage");
|
||||
var operation = package.UpdatePackageVersionAsync(30);
|
||||
yield return operation;
|
||||
if (operation.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
// 如果获取远端资源版本成功,说明当前网络连接通畅,可以走正常更新流程。
|
||||
......
|
||||
}
|
||||
else
|
||||
{
|
||||
// 如果获取远端资源版本失败,说明当前网络无连接。
|
||||
// 在正常开始游戏之前,需要验证本地清单内容的完整性。
|
||||
string packageVersion = package.GetPackageVersion();
|
||||
var operation = package.PreDownloadPackageAsync(packageVersion);
|
||||
yield return operation;
|
||||
if (operation.Status != EOperationStatus.Succeed)
|
||||
{
|
||||
ShowMessageBox("请检查本地网络,有新的游戏内容需要更新!");
|
||||
yield break;
|
||||
}
|
||||
|
||||
int downloadingMaxNum = 10;
|
||||
int failedTryAgain = 3;
|
||||
int timeout = 60;
|
||||
var downloader = operation.CreatePatchDownloader(downloadingMaxNum, failedTryAgain, timeout);
|
||||
if (downloader.TotalDownloadCount > 0)
|
||||
{
|
||||
// 资源内容本地并不完整,需要提示玩家联网更新。
|
||||
ShowMessageBox("请检查本地网络,有新的游戏内容需要更新!");
|
||||
yield break;
|
||||
}
|
||||
|
||||
// 开始游戏
|
||||
StartGame();
|
||||
}
|
||||
}
|
||||
````
|
||||
|
||||
### 源代码解析
|
||||
|
||||
Package.UpdatePackageManifestAsync()方法解析。
|
||||
|
||||
- 联机运行模式
|
||||
|
||||
通过传入的清单版本,优先比对当前激活清单的版本,如果相同就直接返回成功。如果有差异就从缓存里去查找匹配的清单,如果缓存里不存在,就去远端下载并保存到沙盒里。最后加载沙盒内匹配的清单文件。
|
||||
|
||||
|
||||
@@ -1,175 +0,0 @@
|
||||
# 资源加载
|
||||
|
||||
**加载方法**
|
||||
|
||||
- LoadAssetSync() 同步加载资源对象
|
||||
- LoadAssetAsync() 异步加载资源对象
|
||||
- LoadSubAssetsSync() 同步加载子资源对象
|
||||
- LoadSubAssetsAsync() 异步加载子资源对象
|
||||
- LoadSceneSync() 同步加载场景
|
||||
- LoadSceneAsync() 异步加载场景
|
||||
- LoadRawFileSync() 同步获取原生文件
|
||||
- LoadRawFileAsync() 异步获取原生文件
|
||||
|
||||
**统一约定**
|
||||
|
||||
**Location**为资源的定位地址,也是加载资源对象的唯一标识符。
|
||||
|
||||
- 在未开启可寻址模式下,location代表的是资源对象的完整路径。
|
||||
|
||||
```c#
|
||||
// 以工程内的音频文件为例:"Assets/GameRes/Audio/bgMusic.mp3"
|
||||
package.LoadAssetAsync<AudioClip>("Assets/GameRes/Audio/bgMusic");
|
||||
```
|
||||
|
||||
- 在开启可寻址模式下,location代表的是资源对象可寻址地址。
|
||||
|
||||
````c#
|
||||
// 以工程内的音频文件为例:"Assets/GameRes/Audio/bgMusic.mp3"
|
||||
// 需要在资源配置界面启用可寻址功能(Enable Addressable)。
|
||||
// 配置界面的可寻址规则为AddressByFileName,那么资源定位地址填写文件名称:"bgMusic"
|
||||
package.LoadAssetAsync<AudioClip>("bgMusic");
|
||||
````
|
||||
|
||||
**加载路径的匹配方式**
|
||||
|
||||
````C#
|
||||
// 不带扩展名的模糊匹配
|
||||
package.LoadAssetAsync<AudioClip>("Assets/GameRes/Audio/bgMusic");
|
||||
|
||||
// 带扩展名的精准匹配
|
||||
package.LoadAssetAsync<AudioClip>("Assets/GameRes/Audio/bgMusic.mp3");
|
||||
````
|
||||
|
||||
**异步加载范例**
|
||||
|
||||
````C#
|
||||
// 委托加载方式
|
||||
void Start()
|
||||
{
|
||||
AssetOperationHandle handle = package.LoadAssetAsync<AudioClip>("Assets/GameRes/Audio/bgMusic.mp3");
|
||||
handle.Completed += Handle_Completed;
|
||||
}
|
||||
void Handle_Completed(AssetOperationHandle handle)
|
||||
{
|
||||
AudioClip audioClip = handle.AssetObject as AudioClip;
|
||||
}
|
||||
````
|
||||
````C#
|
||||
// 协程加载方式
|
||||
IEnumerator Start()
|
||||
{
|
||||
AssetOperationHandle handle = package.LoadAssetAsync<AudioClip>("Assets/GameRes/Audio/bgMusic.mp3");
|
||||
yield return handle;
|
||||
AudioClip audioClip = handle.AssetObject as AudioClip;
|
||||
}
|
||||
````
|
||||
````C#
|
||||
// Task加载方式
|
||||
async void Start()
|
||||
{
|
||||
AssetOperationHandle handle = package.LoadAssetAsync<AudioClip>("Assets/GameRes/Audio/bgMusic.mp3");
|
||||
await handle.Task;
|
||||
AudioClip audioClip = handle.AssetObject as AudioClip;
|
||||
}
|
||||
````
|
||||
|
||||
**资源卸载范例**
|
||||
|
||||
````C#
|
||||
IEnumerator Start()
|
||||
{
|
||||
AssetOperationHandle handle = package.LoadAssetAsync<AudioClip>("Assets/GameRes/Audio/bgMusic.mp3");
|
||||
yield return handle;
|
||||
...
|
||||
handle.Release();
|
||||
}
|
||||
````
|
||||
|
||||
**资源释放范例**
|
||||
|
||||
可以在切换场景之后调用资源释放方法或者写定时器间隔时间去释放。
|
||||
|
||||
注意:只有调用资源释放方法,资源对象才会在内存里被移除。
|
||||
|
||||
````c#
|
||||
private void UnloadAssets()
|
||||
{
|
||||
var package = YooAssets.GetAssetsPackage("DefaultPackage");
|
||||
package.UnloadUnusedAssets();
|
||||
}
|
||||
````
|
||||
|
||||
**预制体加载范例**
|
||||
|
||||
````C#
|
||||
IEnumerator Start()
|
||||
{
|
||||
AssetOperationHandle handle = package.LoadAssetAsync<GameObject>("Assets/GameRes/Panel/login.prefab");
|
||||
yield return handle;
|
||||
GameObject go = handle.InstantiateSync();
|
||||
Debug.Log($"Prefab name is {go.name}");
|
||||
}
|
||||
````
|
||||
|
||||
**子对象加载范例**
|
||||
|
||||
例如:通过TexturePacker创建的图集,如果需要访问图集的精灵对象,可以通过子对象加载接口。
|
||||
|
||||
````c#
|
||||
IEnumerator Start()
|
||||
{
|
||||
SubAssetsOperationHandle handle = package.LoadSubAssetsAsync<Sprite>(location);
|
||||
yield return handle;
|
||||
var sprite = handle.GetSubAssetObject<Sprite>("spriteName");
|
||||
Debug.Log($"Sprite name is {sprite.name}");
|
||||
}
|
||||
````
|
||||
|
||||
**场景异步加载范例**
|
||||
|
||||
注意:当加载新的主场景的时候,会自动释放之前加载的主场景以及附加场景。
|
||||
|
||||
````c#
|
||||
IEnumerator Start()
|
||||
{
|
||||
string location = "Assets/GameRes/Scene/Login";
|
||||
var sceneMode = UnityEngine.SceneManagement.LoadSceneMode.Single;
|
||||
bool activateOnLoad = true;
|
||||
SceneOperationHandle handle = package.LoadSceneAsync(location, sceneMode, activateOnLoad);
|
||||
yield return handle;
|
||||
Debug.Log($"Scene name is {handle.Scene.name}");
|
||||
}
|
||||
````
|
||||
|
||||
**原生文件加载范例**
|
||||
|
||||
例如:wwise的初始化文件
|
||||
|
||||
````c#
|
||||
IEnumerator Start()
|
||||
{
|
||||
string location = "Assets/GameRes/wwise/init.bnk";
|
||||
RawFileOperationHandle handle = package.LoadRawFileAsync(location);
|
||||
yield return handle;
|
||||
byte[] fileData = handle.GetRawFileData();
|
||||
string fileText = handle.GetRawFileText();
|
||||
string filePath = handle.GetRawFilePath();
|
||||
}
|
||||
````
|
||||
|
||||
**获取资源信息列表**
|
||||
|
||||
通过资源标签来获取资源信息列表。
|
||||
|
||||
````c#
|
||||
void GetAssetInfosByTag(string tag)
|
||||
{
|
||||
AssetInfo[] assetInfos = package.GetAssetInfos(tag);
|
||||
foreach (var assetInfo in assetInfos)
|
||||
{
|
||||
Debug.Log(assetInfo.AssetPath);
|
||||
}
|
||||
}
|
||||
````
|
||||
|
||||
@@ -1,80 +0,0 @@
|
||||
# 解决方案
|
||||
|
||||
### FairyGUI支持解决方案
|
||||
|
||||
注意:在FairyGUI的面板销毁的时候,将资源句柄列表释放,否则会造成资源泄漏。
|
||||
|
||||
````c#
|
||||
// 资源句柄列表
|
||||
private List<AssetOperationHandle> _handles = new List<AssetOperationHandle>(100);
|
||||
|
||||
// 加载方法
|
||||
private object LoadFunc(string name, string extension, System.Type type, out DestroyMethod method)
|
||||
{
|
||||
method = DestroyMethod.None; //注意:这里一定要设置为None
|
||||
string location = $"Assets/FairyRes/{name}{extension}";
|
||||
var assetPackage = YooAssets.GetAssetsPackage("DefaultPackage");
|
||||
var handle = assetPackage.LoadAssetSync(location , type);
|
||||
_handles.Add(handle);
|
||||
return handle.AssetObject;
|
||||
}
|
||||
|
||||
// 执行FairyGUI的添加包函数
|
||||
UIPackage.AddPackage(name, LoadFunc);
|
||||
|
||||
// 释放资源句柄列表
|
||||
private void ReleaseHandles()
|
||||
{
|
||||
foreach(var handle in _handles)
|
||||
{
|
||||
handle.Release();
|
||||
}
|
||||
_handles.Clear();
|
||||
}
|
||||
````
|
||||
|
||||
### UniTask支持解决方案
|
||||
|
||||
详情参考 [UniTask 配置教程](../Assets/YooAsset/Samples~/UniTask%20Sample/README.md)
|
||||
|
||||
### 分布式构建解决方案
|
||||
|
||||
**1.3.0+版本升级指南**
|
||||
|
||||
在升级之前请导出AssetBundleCollector的配置为XML文件,然后升级YooAssets库。
|
||||
|
||||
首次需要打开AssetBundleCollector窗口,然后导入之前保存的XML文件。
|
||||
|
||||
在运行游戏之前,请保证资源包可以构建成功!
|
||||
|
||||
```c#
|
||||
IEnumerator Start()
|
||||
{
|
||||
// 初始化YooAssets资源系统(必须代码)
|
||||
YooAssets.Initialize();
|
||||
|
||||
// 创建资源包实例
|
||||
var package = YooAssets.CreateAssetPackage("DefaultPackage");
|
||||
|
||||
// 初始化资源包
|
||||
......
|
||||
yield return package.InitializeAsync(createParameters);
|
||||
|
||||
// 更新资源包版本
|
||||
......
|
||||
var operation = package.UpdatePackageManifestAsync(packageCRC);
|
||||
yield return operation;
|
||||
|
||||
// 下载更新文件
|
||||
var downloader = package.CreatePatchDownloader(downloadingMaxNum, failedTryAgain);
|
||||
downloader.BeginDownload();
|
||||
yield return downloader;
|
||||
|
||||
// 加载资源对象
|
||||
var assetHandle = package.LoadAssetAsync("Assets/GameRes/npc.prefab");
|
||||
yield return assetHandle;
|
||||
......
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
# 感谢所有支持YooAsset的小伙伴们!
|
||||
|
||||
**特别感谢以下QQ社区的小伙伴**
|
||||
|
||||
他们帮忙协助解决了很多BUG以及提出了很多宝贵的意见!
|
||||
|
||||
- 黄色幻想 (793301844)
|
||||
- 新乞丐王子 (82470934)
|
||||
- Wales-丁 (709501148)
|
||||
- L (401419353)
|
||||
- 秀 (1025466218)
|
||||
- martin (643087149)
|
||||
101
Docs/FAQ.md
@@ -1,101 +0,0 @@
|
||||
# 常见问题解答
|
||||
|
||||
#### 问题:在编辑器下,用离线模式或联机模式运行游戏,为什么游戏里的模型会变成紫色?
|
||||
|
||||
如果在打AssetBundle的时候,选定的构建目标是安卓。那么在windows操作系统下,编辑器的默认渲染模式为DX11,我们需要修改编辑器的渲染模式,可以通过UnityHub来修改启动项目的编辑器渲染模式,[参考官方文档](https://docs.unity3d.com/cn/2019.4/Manual/CommandLineArguments.html)。
|
||||
|
||||
在Vulkan下打包的编辑器需要加个command -force-vulkan
|
||||
|
||||
windows平台添加命令: **-force-gles**
|
||||
|
||||
#### 问题:Unity2021编辑器运行游戏提示YooAssets is initialized !
|
||||
|
||||
尝试关闭:Project Setting ---> Editor ---> Enter Play Mode Options
|
||||
|
||||
#### 问题:YooAsset的DLL引用丢失导致编译报错了
|
||||
|
||||
1. 请在PlayerSetting里修改API Level为.NET 4.x或者.NET Framework
|
||||
2. 关闭游戏工程后,删除Assets同级目录下所有的csproj文件和sln文件。
|
||||
3. 删除Library/ScriptAssemblies文件夹。
|
||||
4. 重新打开游戏工程,然后点击某个脚本重新编译。
|
||||
|
||||
#### 问题:UnityEditor.Build.Pipeline引用丢失问题
|
||||
|
||||
YooAsset依赖于ScriptBuildPipeline(SBP),在PackageManager里找到SBP插件安装就可以了。
|
||||
|
||||
#### 问题:使用FileZilla等FTP上传工具后,文件下载总是验证失败
|
||||
|
||||
把传输类型修改为二进制就可以了。
|
||||
|
||||
#### 问题:打包的时候报错:Cannot mark assets and scenes in one AssetBundle. AssetBundle name is "assets_xxxx_scenes.bundle
|
||||
|
||||
Unity引擎不允许把场景文件和其它资源文件一起打包。
|
||||
|
||||
#### 问题:WebGL平台运行时报错:Failed to decompress data for the AssetBundle.
|
||||
|
||||
WebGL平台不支持资源文件加密。在构建选项里,可以将加密方法设置为空
|
||||
|
||||
#### 问题:有个别手机每次启动执行YooAsset初始化,都执行了有8秒钟,其它手机倒是没事。
|
||||
|
||||
检查下手机沙盒内容是否存储在SD卡里。
|
||||
|
||||
#### 问题:ClearCacheWhenDirty参数没了吗?
|
||||
|
||||
不是很必须的一个功能,已经移除了。可以使用以下方法代替:
|
||||
|
||||
````c#
|
||||
// 参考DEMO的代码
|
||||
internal class FsmClearCache : IFsmNode
|
||||
{
|
||||
void IFsmNode.OnEnter()
|
||||
{
|
||||
Debug.Log("清理未使用的缓存文件!");
|
||||
var package = YooAssets.GetPackage("DefaultPackage");
|
||||
var operation = package.ClearUnusedCacheFiles();
|
||||
operation.Completed += Operation_Completed;
|
||||
}
|
||||
|
||||
private void Operation_Completed(YooAsset.AsyncOperationBase obj)
|
||||
{
|
||||
Debug.Log("开始游戏!");
|
||||
......
|
||||
}
|
||||
}
|
||||
````
|
||||
|
||||
#### 问题:YooAsset支持Unity2018吗
|
||||
|
||||
YooAsset分俩部分,编辑器代码和运行时代码。因为工具界面是使用UIElements编写的,所以在Unity2019以前的版本是使用不了界面化工具。但是这并没有影响我们使用YooAsset,以下提供一种解决方案。
|
||||
|
||||
请先通过Package Manager安装Scriptable Build Pipeline插件。
|
||||
|
||||
1. 资源包收集工具替代方案
|
||||
|
||||
````C#
|
||||
// 推荐直接手动编辑资源收集配置文件,在Sample工程里可以找到AssetBundleCollectorConfig.xml的文件,我们直接拿过来做模板。
|
||||
// 然后通过以下代码来导入配置文件,成功之后AssetBundleCollectorSetting.asset文件会被刷新,就可以运行游戏了。
|
||||
// 注意:每次修改完XML文件,都需要导入配置文件。
|
||||
AssetBundleCollectorConfig.ImportXmlConfig("C://Demo//Assets//AssetBundleCollectorConfig.xml");
|
||||
````
|
||||
|
||||
2. 资源包构建工具替代方案
|
||||
|
||||
````c#
|
||||
// 资源包构建可以直接参考教程文档,在文档的最下面有Jenkins支持介绍。
|
||||
````
|
||||
|
||||
资源构建教程:https://github.com/tuyoogame/YooAsset/blob/main/Docs/AssetBundleBuilder.md
|
||||
|
||||
3. 资源包报告工具替代方案
|
||||
|
||||
````c#
|
||||
// 我们可以使用Unity2019或更高版本来创建一个包含YooAsset的工程查看构建报告。
|
||||
````
|
||||
|
||||
4. 资源包调试工具替代方案
|
||||
|
||||
````c#
|
||||
// YooAsset支持真机远程调试,我们可以使用Unity2019或更高版本来创建一个包含YooAsset的工程调试。
|
||||
// 如果想在编辑器下调试,可以仿照编写一个调试界面。
|
||||
````
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
# 全局配置
|
||||
|
||||

|
||||
|
||||
通过右键创建配置文件(Project窗体内右键 -> Create -> YooAsset -> Create Setting)
|
||||
|
||||
**注意**:请将配置文件放在Resources文件夹下
|
||||
|
||||
配置说明:
|
||||
|
||||
- **Patch Manifest File Name** : 补丁清单文件名称
|
||||
|
||||
|
Before Width: | Height: | Size: 60 KiB |
|
Before Width: | Height: | Size: 89 KiB |
|
Before Width: | Height: | Size: 166 KiB |
|
Before Width: | Height: | Size: 88 KiB |
|
Before Width: | Height: | Size: 81 KiB |
|
Before Width: | Height: | Size: 107 KiB |
|
Before Width: | Height: | Size: 161 KiB |
|
Before Width: | Height: | Size: 168 KiB |
|
Before Width: | Height: | Size: 35 KiB |
|
Before Width: | Height: | Size: 67 KiB |
|
Before Width: | Height: | Size: 64 KiB |
|
Before Width: | Height: | Size: 73 KiB |
|
Before Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 44 KiB |
@@ -1,66 +0,0 @@
|
||||
# 快速开始
|
||||
|
||||
#### **下载安装**
|
||||
|
||||
1. **通过PackageManager安装**
|
||||
|
||||
打开管理界面 **Edit/Project Settings/Package Manager**
|
||||
|
||||
````
|
||||
// 输入以下内容
|
||||
Name: package.openupm.cn
|
||||
URL: https://package.openupm.cn
|
||||
Scope(s): com.tuyoogame.yooasset
|
||||
````
|
||||
|
||||

|
||||
|
||||
打开管理界面 **Edit/Windows/Package Manager**
|
||||
|
||||

|
||||
|
||||
2. **通过Packages清单安装**
|
||||
|
||||
直接修改Packages文件夹下的清单文件manifest.json
|
||||
|
||||
````json
|
||||
{
|
||||
"dependencies": {
|
||||
"com.tuyoogame.yooasset": "0.0.1-preview",
|
||||
......
|
||||
},
|
||||
"scopedRegistries": [
|
||||
{
|
||||
"name": "package.openupm.cn",
|
||||
"url": "https://package.openupm.cn",
|
||||
"scopes": [
|
||||
"com.tuyoogame.yooasset"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
````
|
||||
|
||||
3. **通过Github下载安装**
|
||||
|
||||
在发布的Release版本中,选择最新版本下载Source Code压缩包。
|
||||
|
||||
#### **系统需求**
|
||||
|
||||
支持版本: Unity2019.4+
|
||||
|
||||
支持平台: Windows、OSX、Android、iOS
|
||||
|
||||
开发环境: .NET4.x
|
||||
|
||||
#### **目录结构**
|
||||
|
||||
````
|
||||
Assets
|
||||
└─ YooAsset
|
||||
├─ Editor 编辑器源码目录
|
||||
├─ Runtime 运行时源码目录
|
||||
├─ LICENSE 版权文档
|
||||
└─ README 说明文档
|
||||
````
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
# 示例教程
|
||||
|
||||

|
||||
|
||||
#### 示例内容
|
||||
|
||||
**Space Shooter** 太空战机DEMO,包含资源热更和加载的示例。
|
||||
|
||||
**Extension Sample** 包含编辑器扩展代码的示例。
|
||||
|
||||
**UniTask Sample** 包含支持UniTask代码的示例。
|
||||
|
||||
#### 导入流程注意事项
|
||||
|
||||

|
||||
|
||||
1. Space Shooter在导入完成后,打开YooAsset->AssetBundle Collector窗口。
|
||||
1. 点击修复按钮,然后点击Save按钮保存配置,最后关闭窗口。
|
||||
3. 找到Boot.scene场景启动游戏。
|
||||
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
# 着色器变种收集
|
||||
|
||||

|
||||
|
||||
点击搜集变种按钮开始收集,请耐心等待结束。
|
||||
|
||||
**注意:在收集完成之后,需要将生成的shadervariants文件配置到收集界面(AssetBundle Collector)。**
|
||||
|
||||
### Jenkins支持
|
||||
|
||||
```c#
|
||||
public static void CollectSVC()
|
||||
{
|
||||
string savePath = ShaderVariantCollectorSettingData.Setting.SavePath;
|
||||
System.Action completedCallback = () =>
|
||||
{
|
||||
ShaderVariantCollection collection =
|
||||
AssetDatabase.LoadAssetAtPath<ShaderVariantCollection>(savePath);
|
||||
if (collection != null)
|
||||
{
|
||||
Debug.Log($"ShaderCount : {collection.shaderCount}");
|
||||
Debug.Log($"VariantCount : {collection.variantCount}");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Failed to Collect shader Variants.");
|
||||
}
|
||||
|
||||
EditorTools.CloseUnityGameWindow();
|
||||
EditorApplication.Exit(0);
|
||||
};
|
||||
ShaderVariantCollector.Run(savePath, completedCallback);
|
||||
}
|
||||
```
|
||||
|
||||
```c#
|
||||
// 命令行调用
|
||||
%Projects_UnityEngine_Path% -batchmode -projectPath %Projects_UnityProject_Path% -executeMethod ET.CIHelper.CollectSVC -logFile %Projects_UnityProject_Path%/Logs/CIBuildSVC.log
|
||||
```
|
||||
49
README.md
@@ -1,5 +1,3 @@
|
||||

|
||||
|
||||
# YooAsset
|
||||
|
||||
[](https://github.com/tuyoogame/YooAsset/blob/master/LICENSE)[](https://openupm.cn/packages/com.tuyoogame.yooasset/)
|
||||
@@ -8,9 +6,7 @@
|
||||
|
||||
它可以满足商业化游戏的各类需求,并且经历多款百万DAU游戏产品的验证。
|
||||
|
||||
## 介绍
|
||||
|
||||
YooAsset可以满足以下任何需求:
|
||||
**YooAsset可以满足以下任何需求:**
|
||||
|
||||
- 我想发布一个不包含任何游戏资源的安装包,然后玩家边玩边下载。
|
||||
- 我想发布一个可以保证前期体验的安装包,然后玩家自己选择下载关卡内容。
|
||||
@@ -19,7 +15,7 @@ YooAsset可以满足以下任何需求:
|
||||
- 我想发布一个MOD游戏安装包,玩家可以把自己制作的MOD内容上传到服务器,其它玩家可以下载游玩。
|
||||
- 我们在制作一个超大体量的项目,有上百GB的资源内容,每次构建都花费大量时间,是否可以分工程构建?
|
||||
|
||||
## 系统特点
|
||||
### 系统特点
|
||||
|
||||
- **构建管线无缝切换**
|
||||
|
||||
@@ -31,7 +27,7 @@ YooAsset可以满足以下任何需求:
|
||||
|
||||
- **支持可寻址资源定位**
|
||||
|
||||
默认支持相对路径的资源定位,也支持可寻址资源定位,不需要繁琐的过程即可高效的配置寻址路径。
|
||||
默认支持完整路径的资源定位,也支持可寻址资源定位,不需要繁琐的过程即可高效的配置寻址路径。
|
||||
|
||||
- **安全高效的分包方案**
|
||||
|
||||
@@ -65,42 +61,7 @@ YooAsset可以满足以下任何需求:
|
||||
|
||||
支持线上版本快速回退,支持区分审核版本,测试版本,线上版本,支持灰度更新及测试。
|
||||
|
||||
## 入门教程
|
||||
1. [快速开始](./Docs/QuickStart.md)
|
||||
2. [全局配置](./Docs/GlobalSettings.md)
|
||||
3. [资源配置](./Docs/AssetBundleCollector.md)
|
||||
4. [资源打包](./Docs/AssetBundleBuilder.md)
|
||||
5. [资源部署](./Docs/AssetBundleDeployer.md)
|
||||
5. [构建报告](./Docs/AssetBundleReporter.md)
|
||||
5. [调试器](./Docs/AssetBundleDebugger.md)
|
||||
5. [着色器](./Docs/ShaderVariantCollector.md)
|
||||
5. [FAQ](./Docs/FAQ.md)
|
||||
### 官方主页(教程文档)
|
||||
|
||||
## 代码教程
|
||||
1. [初始化](./Docs/CodeTutorial1.md)
|
||||
2. [资源更新](./Docs/CodeTutorial2.md)
|
||||
3. [资源加载](./Docs/CodeTutorial3.md)
|
||||
3. [解决方案](./Docs/CodeTutorial4.md)
|
||||
https://www.yooasset.com/
|
||||
|
||||
## 其它教程
|
||||
|
||||
[视频教程](https://space.bilibili.com/328590743/channel/seriesdetail?sid=2207858)
|
||||
|
||||
[示例教程](./Docs/Samples.md)
|
||||
|
||||
## 社区
|
||||
|
||||
QQ群:**963240451**
|
||||
|
||||
[致谢名单](./Docs/Contributor.md)👯
|
||||
|
||||
[代码贡献](./Docs/CodeStyle.md)
|
||||
|
||||
## 友情链接
|
||||
[ET Framework](https://github.com/wqaetly/ET/tree/et7_fgui_yooasset_luban_huatuo): ET 7.0 + FGUI + luban + huatuo + YooAsset + NKGMoba + UniTask,并提供常用的编辑器工具。
|
||||
|
||||
[ETPro](https://github.com/526077247/ETPro) ET6+YooAsset+HybridCLR
|
||||
|
||||
[YooAssetEx](https://gitee.com/liu_zhongxiu/yoo-asset-ex/tree/master): YooAsset Odin扩展工具,用于支持Unity2017和Unity2018版本。
|
||||
|
||||
[GameFramework-at-YooAsset](https://github.com/ALEXTANGXIAO/GameFramework-at-YooAsset) GameFramework +luban + hybridclr + YooAsset + UniTask
|
||||
|
||||