mirror of
https://github.com/tuyoogame/YooAsset.git
synced 2026-05-14 19:40:47 +00:00
Compare commits
42 Commits
1.5.2-prev
...
1.5.4-prev
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
697a87721f | ||
|
|
09cf93d852 | ||
|
|
8725821a27 | ||
|
|
a2e57c6e90 | ||
|
|
6d37bca2a9 | ||
|
|
8471bb0f9a | ||
|
|
05cb57db09 | ||
|
|
064e9a1aa3 | ||
|
|
a618b6cf9e | ||
|
|
e3e810e702 | ||
|
|
b4f0d6bab8 | ||
|
|
44cb4168cf | ||
|
|
559ed95999 | ||
|
|
b766df1d31 | ||
|
|
057ff6b22b | ||
|
|
995b0c8050 | ||
|
|
a2d4691f04 | ||
|
|
ab2d7d4724 | ||
|
|
9b4abf86b6 | ||
|
|
0331b7b6e3 | ||
|
|
e31799e78b | ||
|
|
a8405eea6d | ||
|
|
c11f072c50 | ||
|
|
bd080eb19b | ||
|
|
ef231e213e | ||
|
|
a5900b5f99 | ||
|
|
b22bbd4e27 | ||
|
|
664866b627 | ||
|
|
ad9bdc6574 | ||
|
|
b93b993951 | ||
|
|
cb2cb4e556 | ||
|
|
ab32bd390d | ||
|
|
b34374adfa | ||
|
|
b53b6a4246 | ||
|
|
191fbff768 | ||
|
|
e8a4ddf331 | ||
|
|
aee6e2d2f8 | ||
|
|
b737b20602 | ||
|
|
b5df539392 | ||
|
|
36c53e5d94 | ||
|
|
15ce6b8c8c | ||
|
|
19aa82c131 |
17
.gitignore
vendored
17
.gitignore
vendored
@@ -10,8 +10,23 @@
|
||||
/[Ll]ogs/
|
||||
/[Mm]emoryCaptures/
|
||||
|
||||
|
||||
|
||||
/Bundles/
|
||||
/ProjectSettings/
|
||||
/App/
|
||||
/yoo/
|
||||
/Assets/StreamingAssets
|
||||
/Assets/StreamingAssets.meta
|
||||
/Assets/Samples
|
||||
/Assets/Samples.meta
|
||||
/Packages
|
||||
/UserSettings
|
||||
|
||||
|
||||
|
||||
# Asset meta data should only be ignored when the corresponding asset is also ignored
|
||||
!/[Aa]ssets/**/*.meta
|
||||
|
||||
|
||||
# Uncomment this line if you wish to ignore the asset store tools plugin
|
||||
# /[Aa]ssets/AssetStoreTools*
|
||||
|
||||
@@ -2,6 +2,76 @@
|
||||
|
||||
All notable changes to this package will be documented in this file.
|
||||
|
||||
## [1.5.4-preview] - 2023-08-25
|
||||
|
||||
优化了资源清单文件构建速度(极大提升构建体验)(感谢yingnierxiao同学)。
|
||||
|
||||
### Fixed
|
||||
|
||||
- (#130) 修复了打包路径无效问题bug
|
||||
- (#138) 修复了Unity不支持的格式的原生文件会报warning
|
||||
|
||||
### Added
|
||||
|
||||
- 新增了IBuildinQueryServices 接口。
|
||||
|
||||
### Changed
|
||||
|
||||
- 在开启可寻址模式下,默认支持通过资源路径加载资源对象。
|
||||
|
||||
- 优化了资源收集界面,增加了配置相关的警示提示。
|
||||
|
||||
- 优化了资源报告界面,增加了BundleView界面里的builtin资源的列表显示。
|
||||
|
||||
- IQueryServices接口变更为IBuildinQueryServices接口
|
||||
|
||||
- EOperationStatus增加了正在处理的状态。
|
||||
|
||||
```c#
|
||||
public enum EOperationStatus
|
||||
{
|
||||
None,
|
||||
Processing,
|
||||
Succeed,
|
||||
Failed
|
||||
}
|
||||
```
|
||||
|
||||
## [1.5.3-preview] - 2023-07-28
|
||||
|
||||
### Fixed
|
||||
|
||||
- 修复了Unity2020以下版本的编辑器提示找不到"autoLoadAssetBundle"的编译错误。
|
||||
|
||||
### Added
|
||||
|
||||
- 新增了支持开发者分发资源的功能。
|
||||
|
||||
```c#
|
||||
public interface IQueryServices
|
||||
{
|
||||
/// <summary>
|
||||
/// 查询应用程序里的内置资源是否存在
|
||||
/// </summary>
|
||||
bool QueryStreamingAssets(string packageName, string fileName);
|
||||
|
||||
/// <summary>
|
||||
/// 查询是否为开发者分发的资源
|
||||
/// </summary>
|
||||
bool QueryDeliveryFiles(string packageName, string fileName);
|
||||
|
||||
/// <summary>
|
||||
/// 获取开发者分发的资源信息
|
||||
/// </summary>
|
||||
DeliveryFileInfo GetDeliveryFileInfo(string packageName, string fileName);
|
||||
}
|
||||
```
|
||||
|
||||
### Changed
|
||||
|
||||
- 针对资源清单更新方法传入参数的合法性检测。
|
||||
- 编辑器下针对激活的资源清单有效性的检测。
|
||||
|
||||
## [1.5.2-preview] - 2023-07-18
|
||||
|
||||
重新设计了对WebGL平台的支持,新增加了专属模式:WebPlayMode
|
||||
|
||||
@@ -1,215 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Animations;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
public static class AssetBundleBuilderTools
|
||||
{
|
||||
/// <summary>
|
||||
/// 检测所有损坏的预制体文件
|
||||
/// </summary>
|
||||
public static void CheckCorruptionPrefab(List<string> searchDirectorys)
|
||||
{
|
||||
if (searchDirectorys.Count == 0)
|
||||
throw new Exception("路径列表不能为空!");
|
||||
|
||||
// 获取所有资源列表
|
||||
int checkCount = 0;
|
||||
int invalidCount = 0;
|
||||
string[] findAssets = EditorTools.FindAssets(EAssetSearchType.Prefab, searchDirectorys.ToArray());
|
||||
foreach (string assetPath in findAssets)
|
||||
{
|
||||
UnityEngine.Object prefab = AssetDatabase.LoadAssetAtPath(assetPath, typeof(UnityEngine.Object));
|
||||
if (prefab == null)
|
||||
{
|
||||
invalidCount++;
|
||||
Debug.LogError($"发现损坏预制件:{assetPath}");
|
||||
}
|
||||
EditorTools.DisplayProgressBar("检测预制件文件是否损坏", ++checkCount, findAssets.Length);
|
||||
}
|
||||
EditorTools.ClearProgressBar();
|
||||
|
||||
if (invalidCount == 0)
|
||||
Debug.Log($"没有发现损坏预制件");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检测所有动画控制器的冗余状态
|
||||
/// </summary>
|
||||
public static void FindRedundantAnimationState(List<string> searchDirectorys)
|
||||
{
|
||||
if (searchDirectorys.Count == 0)
|
||||
throw new Exception("路径列表不能为空!");
|
||||
|
||||
// 获取所有资源列表
|
||||
int checkCount = 0;
|
||||
int findCount = 0;
|
||||
string[] findAssets = EditorTools.FindAssets(EAssetSearchType.RuntimeAnimatorController, searchDirectorys.ToArray());
|
||||
foreach (string assetPath in findAssets)
|
||||
{
|
||||
AnimatorController animator= AssetDatabase.LoadAssetAtPath<AnimatorController>(assetPath);
|
||||
if (FindRedundantAnimationState(animator))
|
||||
{
|
||||
findCount++;
|
||||
Debug.LogWarning($"发现冗余的动画控制器:{assetPath}");
|
||||
}
|
||||
EditorTools.DisplayProgressBar("检测冗余的动画控制器", ++checkCount, findAssets.Length);
|
||||
}
|
||||
EditorTools.ClearProgressBar();
|
||||
|
||||
if (findCount == 0)
|
||||
Debug.Log($"没有发现冗余的动画控制器");
|
||||
else
|
||||
AssetDatabase.SaveAssets();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清理所有材质球的冗余属性
|
||||
/// </summary>
|
||||
public static void ClearMaterialUnusedProperty(List<string> searchDirectorys)
|
||||
{
|
||||
if (searchDirectorys.Count == 0)
|
||||
throw new Exception("路径列表不能为空!");
|
||||
|
||||
// 获取所有资源列表
|
||||
int checkCount = 0;
|
||||
int removedCount = 0;
|
||||
string[] findAssets = EditorTools.FindAssets(EAssetSearchType.Material, searchDirectorys.ToArray());
|
||||
foreach (string assetPath in findAssets)
|
||||
{
|
||||
Material mat = AssetDatabase.LoadAssetAtPath<Material>(assetPath);
|
||||
if (ClearMaterialUnusedProperty(mat))
|
||||
{
|
||||
removedCount++;
|
||||
Debug.LogWarning($"材质球已被处理:{assetPath}");
|
||||
}
|
||||
EditorTools.DisplayProgressBar("清理冗余的材质球", ++checkCount, findAssets.Length);
|
||||
}
|
||||
EditorTools.ClearProgressBar();
|
||||
|
||||
if (removedCount == 0)
|
||||
Debug.Log($"没有发现冗余的材质球");
|
||||
else
|
||||
AssetDatabase.SaveAssets();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 清理无用的材质球属性
|
||||
/// </summary>
|
||||
private static bool ClearMaterialUnusedProperty(Material mat)
|
||||
{
|
||||
bool removeUnused = false;
|
||||
SerializedObject so = new SerializedObject(mat);
|
||||
SerializedProperty sp = so.FindProperty("m_SavedProperties");
|
||||
|
||||
sp.Next(true);
|
||||
do
|
||||
{
|
||||
if (sp.isArray == false)
|
||||
continue;
|
||||
|
||||
for (int i = sp.arraySize - 1; i >= 0; --i)
|
||||
{
|
||||
var p1 = sp.GetArrayElementAtIndex(i);
|
||||
if (p1.isArray)
|
||||
{
|
||||
for (int ii = p1.arraySize - 1; ii >= 0; --ii)
|
||||
{
|
||||
var p2 = p1.GetArrayElementAtIndex(ii);
|
||||
var val = p2.FindPropertyRelative("first");
|
||||
if (mat.HasProperty(val.stringValue) == false)
|
||||
{
|
||||
Debug.Log($"Material {mat.name} remove unused property : {val.stringValue}");
|
||||
p1.DeleteArrayElementAtIndex(ii);
|
||||
removeUnused = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var val = p1.FindPropertyRelative("first");
|
||||
if (mat.HasProperty(val.stringValue) == false)
|
||||
{
|
||||
Debug.Log($"Material {mat.name} remove unused property : {val.stringValue}");
|
||||
sp.DeleteArrayElementAtIndex(i);
|
||||
removeUnused = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
while (sp.Next(false));
|
||||
so.ApplyModifiedProperties();
|
||||
return removeUnused;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找动画控制器里冗余的动画状态机
|
||||
/// </summary>
|
||||
private static bool FindRedundantAnimationState(AnimatorController animatorController)
|
||||
{
|
||||
if (animatorController == null)
|
||||
return false;
|
||||
|
||||
string assetPath = AssetDatabase.GetAssetPath(animatorController);
|
||||
|
||||
// 查找使用的状态机名称
|
||||
List<string> usedStateNames = new List<string>();
|
||||
foreach (var layer in animatorController.layers)
|
||||
{
|
||||
foreach (var state in layer.stateMachine.states)
|
||||
{
|
||||
usedStateNames.Add(state.state.name);
|
||||
}
|
||||
}
|
||||
|
||||
List<string> allLines = new List<string>();
|
||||
List<int> stateIndexList = new List<int>();
|
||||
using (StreamReader reader = File.OpenText(assetPath))
|
||||
{
|
||||
string content;
|
||||
while (null != (content = reader.ReadLine()))
|
||||
{
|
||||
allLines.Add(content);
|
||||
if (content.StartsWith("AnimatorState:"))
|
||||
{
|
||||
stateIndexList.Add(allLines.Count - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<string> allStateNames = new List<string>();
|
||||
foreach (var index in stateIndexList)
|
||||
{
|
||||
for (int i = index; i < allLines.Count; i++)
|
||||
{
|
||||
string content = allLines[i];
|
||||
content = content.Trim();
|
||||
if (content.StartsWith("m_Name"))
|
||||
{
|
||||
string[] splits = content.Split(':');
|
||||
string name = splits[1].TrimStart(' '); //移除前面的空格
|
||||
allStateNames.Add(name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool foundRedundantState = false;
|
||||
foreach (var stateName in allStateNames)
|
||||
{
|
||||
if (usedStateNames.Contains(stateName) == false)
|
||||
{
|
||||
Debug.LogWarning($"发现冗余的动画文件:{assetPath}={stateName}");
|
||||
foundRedundantState = true;
|
||||
}
|
||||
}
|
||||
return foundRedundantState;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d6268d725eec21b4aae819adc1553f0e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -40,7 +40,12 @@ namespace YooAsset.Editor
|
||||
manifest.OutputNameStyle = (int)buildParameters.OutputNameStyle;
|
||||
manifest.PackageName = buildParameters.PackageName;
|
||||
manifest.PackageVersion = buildParameters.PackageVersion;
|
||||
|
||||
// 填充资源包集合
|
||||
manifest.BundleList = GetAllPackageBundle(context);
|
||||
CacheBundleIDs(manifest);
|
||||
|
||||
// 填充主资源集合
|
||||
manifest.AssetList = GetAllPackageAsset(context, manifest);
|
||||
|
||||
// 更新Unity内置资源包的引用关系
|
||||
@@ -147,7 +152,7 @@ namespace YooAsset.Editor
|
||||
packageAsset.AssetPath = assetInfo.AssetPath;
|
||||
packageAsset.AssetGUID = buildMapContext.Command.IncludeAssetGUID ? assetInfo.AssetGUID : string.Empty;
|
||||
packageAsset.AssetTags = assetInfo.AssetTags.ToArray();
|
||||
packageAsset.BundleID = GetAssetBundleID(assetInfo.BundleName, manifest);
|
||||
packageAsset.BundleID = GetCachedBundleID(assetInfo.BundleName);
|
||||
packageAsset.DependIDs = GetAssetBundleDependIDs(packageAsset.BundleID, assetInfo, manifest);
|
||||
result.Add(packageAsset);
|
||||
}
|
||||
@@ -156,12 +161,12 @@ namespace YooAsset.Editor
|
||||
}
|
||||
private int[] GetAssetBundleDependIDs(int mainBundleID, BuildAssetInfo assetInfo, PackageManifest manifest)
|
||||
{
|
||||
List<int> result = new List<int>();
|
||||
HashSet<int> result = new HashSet<int>();
|
||||
foreach (var dependAssetInfo in assetInfo.AllDependAssetInfos)
|
||||
{
|
||||
if (dependAssetInfo.HasBundleName())
|
||||
{
|
||||
int bundleID = GetAssetBundleID(dependAssetInfo.BundleName, manifest);
|
||||
int bundleID = GetCachedBundleID(dependAssetInfo.BundleName);
|
||||
if (mainBundleID != bundleID)
|
||||
{
|
||||
if (result.Contains(bundleID) == false)
|
||||
@@ -171,15 +176,6 @@ namespace YooAsset.Editor
|
||||
}
|
||||
return result.ToArray();
|
||||
}
|
||||
private int GetAssetBundleID(string bundleName, PackageManifest manifest)
|
||||
{
|
||||
for (int index = 0; index < manifest.BundleList.Count; index++)
|
||||
{
|
||||
if (manifest.BundleList[index].BundleName == bundleName)
|
||||
return index;
|
||||
}
|
||||
throw new Exception($"Not found bundle name : {bundleName}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新Unity内置资源包的引用关系
|
||||
@@ -212,7 +208,7 @@ namespace YooAsset.Editor
|
||||
List<string> conflictAssetPathList = dependBundles.Intersect(shaderBundleReferenceList).ToList();
|
||||
if (conflictAssetPathList.Count > 0)
|
||||
{
|
||||
List<int> newDependIDs = new List<int>(packageAsset.DependIDs);
|
||||
HashSet<int> newDependIDs = new HashSet<int>(packageAsset.DependIDs);
|
||||
if (newDependIDs.Contains(shaderBundleId) == false)
|
||||
newDependIDs.Add(shaderBundleId);
|
||||
packageAsset.DependIDs = newDependIDs.ToArray();
|
||||
@@ -226,7 +222,7 @@ namespace YooAsset.Editor
|
||||
|
||||
// 更新资源包标签
|
||||
var packageBundle = manifest.BundleList[shaderBundleId];
|
||||
List<string> newTags = new List<string>(packageBundle.Tags);
|
||||
HashSet<string> newTags = new HashSet<string>(packageBundle.Tags);
|
||||
foreach (var tag in tagTemps)
|
||||
{
|
||||
if (newTags.Contains(tag) == false)
|
||||
@@ -250,23 +246,22 @@ namespace YooAsset.Editor
|
||||
#region 资源包引用关系相关
|
||||
private readonly Dictionary<string, int> _cachedBundleID = new Dictionary<string, int>(10000);
|
||||
private readonly Dictionary<string, string[]> _cachedBundleDepends = new Dictionary<string, string[]>(10000);
|
||||
|
||||
private void CacheBundleIDs(PackageManifest manifest)
|
||||
{
|
||||
UnityEngine.Debug.Assert(manifest.BundleList.Count != 0, "Manifest bundle list is empty !");
|
||||
for (int index = 0; index < manifest.BundleList.Count; index++)
|
||||
{
|
||||
string bundleName = manifest.BundleList[index].BundleName;
|
||||
_cachedBundleID.Add(bundleName, index);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateScriptPipelineReference(PackageManifest manifest, TaskBuilding_SBP.BuildResultContext buildResultContext)
|
||||
{
|
||||
int progressValue;
|
||||
int totalCount = manifest.BundleList.Count;
|
||||
|
||||
// 缓存资源包ID
|
||||
_cachedBundleID.Clear();
|
||||
progressValue = 0;
|
||||
foreach (var packageBundle in manifest.BundleList)
|
||||
{
|
||||
int bundleID = GetAssetBundleID(packageBundle.BundleName, manifest);
|
||||
_cachedBundleID.Add(packageBundle.BundleName, bundleID);
|
||||
EditorTools.DisplayProgressBar("缓存资源包索引", ++progressValue, totalCount);
|
||||
}
|
||||
EditorTools.ClearProgressBar();
|
||||
|
||||
// 缓存资源包依赖
|
||||
_cachedBundleDepends.Clear();
|
||||
progressValue = 0;
|
||||
@@ -283,7 +278,11 @@ namespace YooAsset.Editor
|
||||
|
||||
var depends = buildResultContext.Results.BundleInfos[packageBundle.BundleName].Dependencies;
|
||||
_cachedBundleDepends.Add(packageBundle.BundleName, depends);
|
||||
EditorTools.DisplayProgressBar("缓存资源包依赖列表", ++progressValue, totalCount);
|
||||
int pro = ++progressValue;
|
||||
if (pro % 100 == 0)
|
||||
{
|
||||
EditorTools.DisplayProgressBar("缓存资源包依赖列表", pro, totalCount);
|
||||
}
|
||||
}
|
||||
EditorTools.ClearProgressBar();
|
||||
|
||||
@@ -291,7 +290,11 @@ namespace YooAsset.Editor
|
||||
foreach (var packageBundle in manifest.BundleList)
|
||||
{
|
||||
packageBundle.ReferenceIDs = GetBundleRefrenceIDs(manifest, packageBundle);
|
||||
EditorTools.DisplayProgressBar("计算资源包引用关系", ++progressValue, totalCount);
|
||||
int pro = ++progressValue;
|
||||
if (pro % 100 == 0)
|
||||
{
|
||||
EditorTools.DisplayProgressBar("计算资源包引用关系", pro, totalCount);
|
||||
}
|
||||
}
|
||||
EditorTools.ClearProgressBar();
|
||||
}
|
||||
@@ -300,17 +303,6 @@ namespace YooAsset.Editor
|
||||
int progressValue;
|
||||
int totalCount = manifest.BundleList.Count;
|
||||
|
||||
// 缓存资源包ID
|
||||
_cachedBundleID.Clear();
|
||||
progressValue = 0;
|
||||
foreach (var packageBundle in manifest.BundleList)
|
||||
{
|
||||
int bundleID = GetAssetBundleID(packageBundle.BundleName, manifest);
|
||||
_cachedBundleID.Add(packageBundle.BundleName, bundleID);
|
||||
EditorTools.DisplayProgressBar("缓存资源包索引", ++progressValue, totalCount);
|
||||
}
|
||||
EditorTools.ClearProgressBar();
|
||||
|
||||
// 缓存资源包依赖
|
||||
_cachedBundleDepends.Clear();
|
||||
progressValue = 0;
|
||||
@@ -324,7 +316,11 @@ namespace YooAsset.Editor
|
||||
|
||||
var depends = buildResultContext.UnityManifest.GetDirectDependencies(packageBundle.BundleName);
|
||||
_cachedBundleDepends.Add(packageBundle.BundleName, depends);
|
||||
EditorTools.DisplayProgressBar("缓存资源包依赖列表", ++progressValue, totalCount);
|
||||
int pro = ++progressValue;
|
||||
if (pro % 100 == 0)
|
||||
{
|
||||
EditorTools.DisplayProgressBar("缓存资源包依赖列表", pro, totalCount);
|
||||
}
|
||||
}
|
||||
EditorTools.ClearProgressBar();
|
||||
|
||||
@@ -333,7 +329,11 @@ namespace YooAsset.Editor
|
||||
foreach (var packageBundle in manifest.BundleList)
|
||||
{
|
||||
packageBundle.ReferenceIDs = GetBundleRefrenceIDs(manifest, packageBundle);
|
||||
EditorTools.DisplayProgressBar("计算资源包引用关系", ++progressValue, totalCount);
|
||||
int pro = ++progressValue;
|
||||
if (pro % 100 == 0)
|
||||
{
|
||||
EditorTools.DisplayProgressBar("计算资源包引用关系", ++progressValue, totalCount);
|
||||
}
|
||||
}
|
||||
EditorTools.ClearProgressBar();
|
||||
}
|
||||
@@ -354,7 +354,7 @@ namespace YooAsset.Editor
|
||||
}
|
||||
}
|
||||
|
||||
List<int> result = new List<int>();
|
||||
HashSet<int> result = new HashSet<int>();
|
||||
foreach (var bundleName in referenceList)
|
||||
{
|
||||
int bundleID = GetCachedBundleID(bundleName);
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace YooAsset.Editor
|
||||
Dictionary<string, BuildAssetInfo> allBuildAssetInfoDic = new Dictionary<string, BuildAssetInfo>(1000);
|
||||
|
||||
// 1. 检测配置合法性
|
||||
AssetBundleCollectorSettingData.Setting.CheckConfigError();
|
||||
AssetBundleCollectorSettingData.Setting.CheckPackageConfigError(packageName);
|
||||
|
||||
// 2. 获取所有收集器收集的资源
|
||||
var collectResult = AssetBundleCollectorSettingData.Setting.GetPackageAssets(buildMode, packageName);
|
||||
|
||||
@@ -204,6 +204,10 @@ namespace YooAsset.Editor
|
||||
{
|
||||
string address = collectInfoPair.Value.Address;
|
||||
string assetPath = collectInfoPair.Value.AssetPath;
|
||||
|
||||
if (address.StartsWith("Assets/") || address.StartsWith("assets/"))
|
||||
throw new Exception($"The address can not set asset path in collector : {CollectPath} \nAssetPath: {assetPath}");
|
||||
|
||||
if (addressTemper.TryGetValue(address, out var existed) == false)
|
||||
addressTemper.Add(address, assetPath);
|
||||
else
|
||||
@@ -336,11 +340,13 @@ namespace YooAsset.Editor
|
||||
List<string> result = new List<string>(depends.Length);
|
||||
foreach (string assetPath in depends)
|
||||
{
|
||||
// 注意:排除主资源对象
|
||||
if (assetPath == mainAssetPath)
|
||||
continue;
|
||||
|
||||
if (IsValidateAsset(assetPath, false))
|
||||
{
|
||||
// 注意:排除主资源对象
|
||||
if (assetPath != mainAssetPath)
|
||||
result.Add(assetPath);
|
||||
result.Add(assetPath);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
||||
@@ -61,9 +61,18 @@ namespace YooAsset.Editor
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检测配置错误
|
||||
/// 检测包裹配置错误
|
||||
/// </summary>
|
||||
public void CheckConfigError()
|
||||
public void CheckPackageConfigError(string packageName)
|
||||
{
|
||||
var package = GetPackage(packageName);
|
||||
package.CheckConfigError();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检测所有配置错误
|
||||
/// </summary>
|
||||
public void CheckAllPackageConfigError()
|
||||
{
|
||||
foreach (var package in Packages)
|
||||
{
|
||||
@@ -72,9 +81,9 @@ namespace YooAsset.Editor
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修复配置错误
|
||||
/// 修复所有配置错误
|
||||
/// </summary>
|
||||
public bool FixConfigError()
|
||||
public bool FixAllPackageConfigError()
|
||||
{
|
||||
bool isFixed = false;
|
||||
foreach (var package in Packages)
|
||||
@@ -92,16 +101,8 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public List<string> GetPackageAllTags(string packageName)
|
||||
{
|
||||
foreach (var package in Packages)
|
||||
{
|
||||
if (package.PackageName == packageName)
|
||||
{
|
||||
return package.GetAllTags();
|
||||
}
|
||||
}
|
||||
|
||||
Debug.LogWarning($"Not found package : {packageName}");
|
||||
return new List<string>();
|
||||
var package = GetPackage(packageName);
|
||||
return package.GetAllTags();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -112,19 +113,25 @@ namespace YooAsset.Editor
|
||||
if (string.IsNullOrEmpty(packageName))
|
||||
throw new Exception("Build package name is null or mepty !");
|
||||
|
||||
var package = GetPackage(packageName);
|
||||
CollectCommand command = new CollectCommand(buildMode, packageName,
|
||||
EnableAddressable, LocationToLower, IncludeAssetGUID, UniqueBundleName);
|
||||
CollectResult collectResult = new CollectResult(command);
|
||||
collectResult.SetCollectAssets(package.GetAllCollectAssets(command));
|
||||
return collectResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取包裹类
|
||||
/// </summary>
|
||||
public AssetBundleCollectorPackage GetPackage(string packageName)
|
||||
{
|
||||
foreach (var package in Packages)
|
||||
{
|
||||
if (package.PackageName == packageName)
|
||||
{
|
||||
CollectCommand command = new CollectCommand(buildMode, packageName,
|
||||
EnableAddressable, LocationToLower, IncludeAssetGUID, UniqueBundleName);
|
||||
CollectResult collectResult = new CollectResult(command);
|
||||
collectResult.SetCollectAssets(package.GetAllCollectAssets(command));
|
||||
return collectResult;
|
||||
}
|
||||
return package;
|
||||
}
|
||||
|
||||
throw new Exception($"Not found collector pacakge : {packageName}");
|
||||
throw new Exception($"Not found pacakge : {packageName}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -161,7 +161,7 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public static void FixFile()
|
||||
{
|
||||
bool isFixed = Setting.FixConfigError();
|
||||
bool isFixed = Setting.FixAllPackageConfigError();
|
||||
if (isFixed)
|
||||
{
|
||||
IsDirty = true;
|
||||
|
||||
@@ -26,6 +26,7 @@ namespace YooAsset.Editor
|
||||
private List<RuleDisplayName> _filterRuleList;
|
||||
|
||||
private Button _settingsButton;
|
||||
private VisualElement _helpBoxContainer;
|
||||
private VisualElement _setting1Container;
|
||||
private VisualElement _setting2Container;
|
||||
private Toggle _showPackageToogle;
|
||||
@@ -82,6 +83,9 @@ namespace YooAsset.Editor
|
||||
|
||||
visualAsset.CloneTree(root);
|
||||
|
||||
// 警示栏
|
||||
_helpBoxContainer = root.Q("HelpBoxContainer");
|
||||
|
||||
// 公共设置相关
|
||||
_settingsButton = root.Q<Button>("SettingsButton");
|
||||
_settingsButton.clicked += SettingsBtn_clicked;
|
||||
@@ -328,6 +332,24 @@ namespace YooAsset.Editor
|
||||
_uniqueBundleNameToogle.SetValueWithoutNotify(AssetBundleCollectorSettingData.Setting.UniqueBundleName);
|
||||
_showEditorAliasToggle.SetValueWithoutNotify(AssetBundleCollectorSettingData.Setting.ShowEditorAlias);
|
||||
|
||||
// 警示框
|
||||
_helpBoxContainer.Clear();
|
||||
if (_enableAddressableToogle.value && _locationToLowerToogle.value)
|
||||
{
|
||||
var helpBox = new HelpBox("无法同时开启[Enable Addressable]选项和[Location To Lower]选项", HelpBoxMessageType.Error);
|
||||
_helpBoxContainer.Add(helpBox);
|
||||
}
|
||||
if (AssetBundleCollectorSettingData.Setting.Packages.Count > 1 && _uniqueBundleNameToogle.value == false)
|
||||
{
|
||||
var helpBox = new HelpBox("检测到当前配置存在多个Package,建议开启[Unique Bundle Name]选项", HelpBoxMessageType.Warning);
|
||||
_helpBoxContainer.Add(helpBox);
|
||||
}
|
||||
if (_helpBoxContainer.childCount > 0)
|
||||
_helpBoxContainer.style.display = DisplayStyle.Flex;
|
||||
else
|
||||
_helpBoxContainer.style.display = DisplayStyle.None;
|
||||
|
||||
// 设置栏
|
||||
if (_showSettings)
|
||||
{
|
||||
_setting1Container.style.display = DisplayStyle.Flex;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="False">
|
||||
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="True">
|
||||
<uie:Toolbar name="Toolbar" style="display: flex; flex-direction: row-reverse;">
|
||||
<ui:Button text="Save" display-tooltip-when-elided="true" name="SaveButton" style="width: 50px; background-color: rgb(56, 147, 58);" />
|
||||
<ui:Button text="导出" display-tooltip-when-elided="true" name="ExportButton" style="width: 50px; background-color: rgb(56, 147, 58);" />
|
||||
@@ -6,6 +6,7 @@
|
||||
<ui:Button text="修复" display-tooltip-when-elided="true" name="FixButton" style="width: 50px; background-color: rgb(56, 147, 58);" />
|
||||
</uie:Toolbar>
|
||||
<ui:VisualElement name="PublicContainer" style="background-color: rgb(79, 79, 79); flex-direction: column; border-left-width: 5px; border-right-width: 5px; border-top-width: 5px; border-bottom-width: 5px;">
|
||||
<ui:VisualElement name="HelpBoxContainer" style="flex-grow: 1;" />
|
||||
<ui:Button text="Settings" display-tooltip-when-elided="true" name="SettingsButton" />
|
||||
<ui:VisualElement name="PublicContainer1" style="flex-direction: row; flex-wrap: nowrap; height: 28px;">
|
||||
<ui:Toggle label="Show Packages" name="ShowPackages" style="width: 196px; -unity-text-align: middle-left;" />
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace YooAsset.Editor
|
||||
{
|
||||
string IAddressRule.GetAssetAddress(AddressRuleData data)
|
||||
{
|
||||
return data.AssetPath;
|
||||
throw new System.Exception("可寻址模式下已经默认支持通过资源路径加载!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -349,10 +349,24 @@ namespace YooAsset.Editor
|
||||
private void FillIncludeListView(ReportBundleInfo bundleInfo)
|
||||
{
|
||||
List<ReportAssetInfo> containsList = new List<ReportAssetInfo>();
|
||||
HashSet<string> mainAssetDic = new HashSet<string>();
|
||||
foreach (var assetInfo in _buildReport.AssetInfos)
|
||||
{
|
||||
if (assetInfo.MainBundleName == bundleInfo.BundleName)
|
||||
{
|
||||
mainAssetDic.Add(assetInfo.AssetPath);
|
||||
containsList.Add(assetInfo);
|
||||
}
|
||||
}
|
||||
foreach (string assetPath in bundleInfo.AllBuiltinAssets)
|
||||
{
|
||||
if (mainAssetDic.Contains(assetPath) == false)
|
||||
{
|
||||
var assetInfo = new ReportAssetInfo();
|
||||
assetInfo.AssetPath = assetPath;
|
||||
assetInfo.AssetGUID = "--";
|
||||
containsList.Add(assetInfo);
|
||||
}
|
||||
}
|
||||
|
||||
_includeListView.Clear();
|
||||
@@ -376,6 +390,16 @@ namespace YooAsset.Editor
|
||||
element.Add(label);
|
||||
}
|
||||
|
||||
{
|
||||
var label = new Label();
|
||||
label.name = "Label3";
|
||||
label.style.unityTextAlign = TextAnchor.MiddleLeft;
|
||||
label.style.marginLeft = 3f;
|
||||
//label.style.flexGrow = 1f;
|
||||
label.style.width = 100;
|
||||
element.Add(label);
|
||||
}
|
||||
|
||||
{
|
||||
var label = new Label();
|
||||
label.name = "Label2";
|
||||
@@ -397,6 +421,10 @@ namespace YooAsset.Editor
|
||||
var label1 = element.Q<Label>("Label1");
|
||||
label1.text = assetInfo.AssetPath;
|
||||
|
||||
// Asset Source
|
||||
var label3 = element.Q<Label>("Label3");
|
||||
label3.text = assetInfo.AssetGUID != "--" ? "Main Asset" : "Builtin Asset";
|
||||
|
||||
// GUID
|
||||
var label2 = element.Q<Label>("Label2");
|
||||
label2.text = assetInfo.AssetGUID;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a0319abb8eae03b4b88e8f900fe2276c
|
||||
guid: 8875000dff445624da4d6a2d6ef2f446
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
<ui:VisualElement name="BottomGroup" style="height: 200px; border-left-width: 1px; border-right-width: 1px; border-top-width: 1px; border-bottom-width: 1px; border-left-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); border-top-color: rgb(0, 0, 0); border-bottom-color: rgb(0, 0, 0); margin-left: 0; margin-right: 0; margin-top: 1px; margin-bottom: 1px; display: flex;">
|
||||
<uie:Toolbar name="BottomBar" style="height: 25px; margin-left: 1px; margin-right: 1px;">
|
||||
<uie:ToolbarButton text="Include Assets" display-tooltip-when-elided="true" name="BottomBar1" style="width: 280px; -unity-text-align: middle-left; flex-grow: 1;" />
|
||||
<uie:ToolbarButton text="Asset Source" display-tooltip-when-elided="true" name="BottomBar3" style="width: 100px; -unity-text-align: middle-left;" />
|
||||
<uie:ToolbarButton text="GUID" display-tooltip-when-elided="true" name="BottomBar2" style="width: 280px; -unity-text-align: middle-left;" />
|
||||
</uie:Toolbar>
|
||||
<ui:ListView focusable="true" name="BottomListView" item-height="18" virtualization-method="DynamicHeight" style="flex-grow: 1;" />
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 56d6dbe0d65ce334a8996beb19612989
|
||||
guid: cf2a9340bb457594d9bc1f80b84a89f6
|
||||
ScriptedImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
|
||||
@@ -153,7 +153,7 @@ namespace YooAsset.Editor
|
||||
guids = AssetDatabase.FindAssets($"t:{searchType}", searchInFolders);
|
||||
|
||||
// 注意:AssetDatabase.FindAssets()可能会获取到重复的资源
|
||||
List<string> result = new List<string>();
|
||||
HashSet<string> result = new HashSet<string>();
|
||||
for (int i = 0; i < guids.Length; i++)
|
||||
{
|
||||
string guid = guids[i];
|
||||
|
||||
@@ -30,17 +30,22 @@ namespace YooAsset.Editor
|
||||
public class ShaderVariantInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// Shader asset path in editor.
|
||||
/// 着色器资源路径.
|
||||
/// </summary>
|
||||
public string AssetPath;
|
||||
|
||||
/// <summary>
|
||||
/// Shader name.
|
||||
/// 着色器名称
|
||||
/// </summary>
|
||||
public string ShaderName;
|
||||
|
||||
/// <summary>
|
||||
/// Shader variants elements list.
|
||||
/// 着色器变种总数
|
||||
/// </summary>
|
||||
public int ShaderVariantCount = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 着色器变种列表
|
||||
/// </summary>
|
||||
public List<ShaderVariantElement> ShaderVariantElements = new List<ShaderVariantElement>(1000);
|
||||
}
|
||||
@@ -71,6 +76,7 @@ namespace YooAsset.Editor
|
||||
element.PassType = passType;
|
||||
element.Keywords = keywords;
|
||||
info.ShaderVariantElements.Add(element);
|
||||
info.ShaderVariantCount++;
|
||||
}
|
||||
private ShaderVariantInfo GetOrCreateShaderVariantInfo(string assetPath, string shaderName)
|
||||
{
|
||||
|
||||
@@ -128,11 +128,13 @@ namespace YooAsset
|
||||
#else
|
||||
foreach (var provider in _providerList)
|
||||
{
|
||||
provider.DestroySafely();
|
||||
provider.WaitForAsyncComplete();
|
||||
provider.Destroy();
|
||||
}
|
||||
foreach (var loader in _loaderList)
|
||||
{
|
||||
loader.DestroySafely();
|
||||
loader.WaitForAsyncComplete();
|
||||
loader.Destroy();
|
||||
}
|
||||
|
||||
_providerList.Clear();
|
||||
@@ -416,7 +418,7 @@ namespace YooAsset
|
||||
return null;
|
||||
}
|
||||
|
||||
#region 调试信息
|
||||
#region 调试信息
|
||||
internal List<DebugProviderInfo> GetDebugReportInfos()
|
||||
{
|
||||
List<DebugProviderInfo> result = new List<DebugProviderInfo>(_providerList.Count);
|
||||
@@ -444,6 +446,6 @@ namespace YooAsset
|
||||
}
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -44,12 +44,16 @@ namespace YooAsset
|
||||
{
|
||||
if (IsValidWithWarning == false)
|
||||
return EOperationStatus.None;
|
||||
if (Provider.Status == ProviderBase.EStatus.Failed)
|
||||
return EOperationStatus.Failed;
|
||||
else if (Provider.Status == ProviderBase.EStatus.Succeed)
|
||||
return EOperationStatus.Succeed;
|
||||
else
|
||||
|
||||
var status = Provider.Status;
|
||||
if (status == ProviderBase.EStatus.None)
|
||||
return EOperationStatus.None;
|
||||
else if (status == ProviderBase.EStatus.Succeed)
|
||||
return EOperationStatus.Succeed;
|
||||
else if (status == ProviderBase.EStatus.Failed)
|
||||
return EOperationStatus.Failed;
|
||||
else
|
||||
return EOperationStatus.Processing;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,8 @@ namespace YooAsset
|
||||
CheckDownload,
|
||||
Unpack,
|
||||
CheckUnpack,
|
||||
LoadFile,
|
||||
LoadBundleFile,
|
||||
LoadDeliveryFile,
|
||||
CheckLoadFile,
|
||||
Done,
|
||||
}
|
||||
@@ -59,19 +60,24 @@ namespace YooAsset
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.LoadFile;
|
||||
_steps = ESteps.LoadBundleFile;
|
||||
FileLoadPath = MainBundleInfo.Bundle.StreamingFilePath;
|
||||
}
|
||||
#else
|
||||
_steps = ESteps.LoadFile;
|
||||
_steps = ESteps.LoadBundleFile;
|
||||
FileLoadPath = MainBundleInfo.Bundle.StreamingFilePath;
|
||||
#endif
|
||||
}
|
||||
else if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromCache)
|
||||
{
|
||||
_steps = ESteps.LoadFile;
|
||||
_steps = ESteps.LoadBundleFile;
|
||||
FileLoadPath = MainBundleInfo.Bundle.CachedDataFilePath;
|
||||
}
|
||||
else if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromDelivery)
|
||||
{
|
||||
_steps = ESteps.LoadDeliveryFile;
|
||||
FileLoadPath = MainBundleInfo.DeliveryFilePath;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new System.NotImplementedException(MainBundleInfo.LoadMode.ToString());
|
||||
@@ -103,7 +109,7 @@ namespace YooAsset
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.LoadFile;
|
||||
_steps = ESteps.LoadBundleFile;
|
||||
return; //下载完毕等待一帧再去加载!
|
||||
}
|
||||
}
|
||||
@@ -134,12 +140,12 @@ namespace YooAsset
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.LoadFile;
|
||||
_steps = ESteps.LoadBundleFile;
|
||||
}
|
||||
}
|
||||
|
||||
// 5. 加载AssetBundle
|
||||
if (_steps == ESteps.LoadFile)
|
||||
if (_steps == ESteps.LoadBundleFile)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
// 注意:Unity2017.4编辑器模式下,如果AssetBundle文件不存在会导致编辑器崩溃,这里做了预判。
|
||||
@@ -214,7 +220,35 @@ namespace YooAsset
|
||||
_steps = ESteps.CheckLoadFile;
|
||||
}
|
||||
|
||||
// 6. 检测AssetBundle加载结果
|
||||
// 6. 加载AssetBundle
|
||||
if (_steps == ESteps.LoadDeliveryFile)
|
||||
{
|
||||
// 设置下载进度
|
||||
DownloadProgress = 1f;
|
||||
DownloadedBytes = (ulong)MainBundleInfo.Bundle.FileSize;
|
||||
|
||||
// Load assetBundle file
|
||||
var loadMethod = (EBundleLoadMethod)MainBundleInfo.Bundle.LoadMethod;
|
||||
if (loadMethod == EBundleLoadMethod.Normal)
|
||||
{
|
||||
ulong offset = MainBundleInfo.DeliveryFileOffset;
|
||||
if (_isWaitForAsyncComplete)
|
||||
CacheBundle = AssetBundle.LoadFromFile(FileLoadPath, 0, offset);
|
||||
else
|
||||
_createRequest = AssetBundle.LoadFromFileAsync(FileLoadPath, 0, offset);
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EStatus.Failed;
|
||||
LastError = $"Delivery file not support encryption : {MainBundleInfo.Bundle.BundleName}";
|
||||
YooLogger.Error(LastError);
|
||||
return;
|
||||
}
|
||||
_steps = ESteps.CheckLoadFile;
|
||||
}
|
||||
|
||||
// 7. 检测AssetBundle加载结果
|
||||
if (_steps == ESteps.CheckLoadFile)
|
||||
{
|
||||
if (_createRequest != null)
|
||||
|
||||
@@ -144,15 +144,6 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 销毁资源包(安全模式)
|
||||
/// </summary>
|
||||
public void DestroySafely()
|
||||
{
|
||||
WaitForAsyncComplete();
|
||||
Destroy();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 轮询更新
|
||||
|
||||
@@ -54,6 +54,11 @@ namespace YooAsset
|
||||
_steps = ESteps.CheckFile;
|
||||
FileLoadPath = MainBundleInfo.Bundle.CachedDataFilePath;
|
||||
}
|
||||
else if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromDelivery)
|
||||
{
|
||||
_steps = ESteps.CheckFile;
|
||||
FileLoadPath = MainBundleInfo.DeliveryFilePath;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new System.NotImplementedException(MainBundleInfo.LoadMode.ToString());
|
||||
|
||||
@@ -140,22 +140,6 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 销毁资源对象(安全模式)
|
||||
/// </summary>
|
||||
public void DestroySafely()
|
||||
{
|
||||
if (Status == EStatus.Loading || Status == EStatus.Checking)
|
||||
{
|
||||
WaitForAsyncComplete();
|
||||
Destroy();
|
||||
}
|
||||
else
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否可以销毁
|
||||
/// </summary>
|
||||
|
||||
@@ -51,6 +51,9 @@ namespace YooAsset
|
||||
// 准备下载
|
||||
if (_steps == ESteps.PrepareDownload)
|
||||
{
|
||||
// 获取请求地址
|
||||
_requestURL = GetRequestURL();
|
||||
|
||||
// 重置变量
|
||||
_downloadProgress = 0f;
|
||||
_downloadedBytes = 0;
|
||||
@@ -59,14 +62,16 @@ namespace YooAsset
|
||||
_isAbort = false;
|
||||
_latestDownloadBytes = 0;
|
||||
_latestDownloadRealtime = Time.realtimeSinceStartup;
|
||||
|
||||
// 重置计时器
|
||||
if(_tryAgainTimer > 0f)
|
||||
YooLogger.Warning($"Try again download : {_requestURL}");
|
||||
_tryAgainTimer = 0f;
|
||||
|
||||
// 删除临时文件
|
||||
if (File.Exists(_tempFilePath))
|
||||
File.Delete(_tempFilePath);
|
||||
|
||||
// 获取请求地址
|
||||
_requestURL = GetRequestURL();
|
||||
_steps = ESteps.CreateDownloader;
|
||||
}
|
||||
|
||||
@@ -197,7 +202,6 @@ namespace YooAsset
|
||||
_failedTryAgain--;
|
||||
_steps = ESteps.PrepareDownload;
|
||||
ReportWarning();
|
||||
YooLogger.Warning($"Try again download : {_requestURL}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,6 +91,9 @@ namespace YooAsset
|
||||
// 创建下载器
|
||||
if (_steps == ESteps.PrepareDownload)
|
||||
{
|
||||
// 获取请求地址
|
||||
_requestURL = GetRequestURL();
|
||||
|
||||
// 重置变量
|
||||
_downloadProgress = 0f;
|
||||
_downloadedBytes = 0;
|
||||
@@ -99,11 +102,13 @@ namespace YooAsset
|
||||
_isAbort = false;
|
||||
_latestDownloadBytes = 0;
|
||||
_latestDownloadRealtime = Time.realtimeSinceStartup;
|
||||
_tryAgainTimer = 0f;
|
||||
_fileOriginLength = 0;
|
||||
|
||||
// 获取请求地址
|
||||
_requestURL = GetRequestURL();
|
||||
// 重置计时器
|
||||
if (_tryAgainTimer > 0f)
|
||||
YooLogger.Warning($"Try again download : {_requestURL}");
|
||||
_tryAgainTimer = 0f;
|
||||
|
||||
_steps = ESteps.CreateDownloader;
|
||||
}
|
||||
|
||||
@@ -257,7 +262,6 @@ namespace YooAsset
|
||||
_failedTryAgain--;
|
||||
_steps = ESteps.PrepareDownload;
|
||||
ReportWarning();
|
||||
YooLogger.Warning($"Try again download : {_requestURL}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,14 +72,18 @@ namespace YooAsset
|
||||
{
|
||||
uint crc = _bundleInfo.Bundle.UnityCRC;
|
||||
_downloadhandler = new DownloadHandlerAssetBundle(_requestURL, crc);
|
||||
#if UNITY_2020_3_OR_NEWER
|
||||
_downloadhandler.autoLoadAssetBundle = false;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
uint crc = _bundleInfo.Bundle.UnityCRC;
|
||||
var hash = Hash128.Parse(_bundleInfo.Bundle.FileHash);
|
||||
_downloadhandler = new DownloadHandlerAssetBundle(_requestURL, hash, crc);
|
||||
#if UNITY_2020_3_OR_NEWER
|
||||
_downloadhandler.autoLoadAssetBundle = false;
|
||||
#endif
|
||||
}
|
||||
|
||||
_webRequest.downloadHandler = _downloadhandler;
|
||||
@@ -169,7 +173,7 @@ namespace YooAsset
|
||||
_steps = ESteps.Done;
|
||||
_lastError = "user abort";
|
||||
_lastCode = 0;
|
||||
|
||||
|
||||
DisposeRequest();
|
||||
DisposeHandler();
|
||||
}
|
||||
|
||||
@@ -88,7 +88,12 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 内置资源查询服务接口
|
||||
/// </summary>
|
||||
public IQueryServices QueryServices = null;
|
||||
public IBuildinQueryServices BuildinQueryServices = null;
|
||||
|
||||
/// <summary>
|
||||
/// 分发资源查询服务接口
|
||||
/// </summary>
|
||||
public IDeliveryQueryServices DeliveryQueryServices = null;
|
||||
|
||||
/// <summary>
|
||||
/// 远端资源地址查询服务类
|
||||
@@ -104,7 +109,7 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 内置资源查询服务接口
|
||||
/// </summary>
|
||||
public IQueryServices QueryServices = null;
|
||||
public IBuildinQueryServices BuildinQueryServices = null;
|
||||
|
||||
/// <summary>
|
||||
/// 远端资源地址查询服务类
|
||||
|
||||
@@ -73,13 +73,18 @@ namespace YooAsset
|
||||
|
||||
internal abstract void Start();
|
||||
internal abstract void Update();
|
||||
internal void Finish()
|
||||
|
||||
internal void SetFinish()
|
||||
{
|
||||
Progress = 1f;
|
||||
_callback?.Invoke(this);
|
||||
if (_taskCompletionSource != null)
|
||||
_taskCompletionSource.TrySetResult(null);
|
||||
}
|
||||
internal void SetStart()
|
||||
{
|
||||
Status = EOperationStatus.Processing;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清空完成回调
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace YooAsset
|
||||
public enum EOperationStatus
|
||||
{
|
||||
None,
|
||||
Processing,
|
||||
Succeed,
|
||||
Failed
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ namespace YooAsset
|
||||
if (operation.IsDone)
|
||||
{
|
||||
_removeList.Add(operation);
|
||||
operation.Finish();
|
||||
operation.SetFinish();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,6 +101,7 @@ namespace YooAsset
|
||||
public static void StartOperation(AsyncOperationBase operation)
|
||||
{
|
||||
_addList.Add(operation);
|
||||
operation.SetStart();
|
||||
operation.Start();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ namespace YooAsset
|
||||
public enum ELoadMode
|
||||
{
|
||||
None,
|
||||
LoadFromDelivery,
|
||||
LoadFromStreaming,
|
||||
LoadFromCache,
|
||||
LoadFromRemote,
|
||||
@@ -25,6 +26,16 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public string RemoteFallbackURL { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 开发者分发的文件地址
|
||||
/// </summary>
|
||||
public string DeliveryFilePath { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 开发者分发的文件偏移量
|
||||
/// </summary>
|
||||
public ulong DeliveryFileOffset { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 注意:该字段只用于帮助编辑器下的模拟模式。
|
||||
/// </summary>
|
||||
@@ -40,6 +51,17 @@ namespace YooAsset
|
||||
LoadMode = loadMode;
|
||||
RemoteMainURL = mainURL;
|
||||
RemoteFallbackURL = fallbackURL;
|
||||
DeliveryFilePath = string.Empty;
|
||||
DeliveryFileOffset = 0;
|
||||
}
|
||||
public BundleInfo(PackageBundle bundle, ELoadMode loadMode, string deliveryFilePath, ulong deliveryFileOffset)
|
||||
{
|
||||
Bundle = bundle;
|
||||
LoadMode = loadMode;
|
||||
RemoteMainURL = string.Empty;
|
||||
RemoteFallbackURL = string.Empty;
|
||||
DeliveryFilePath = deliveryFilePath;
|
||||
DeliveryFileOffset = deliveryFileOffset;
|
||||
}
|
||||
public BundleInfo(PackageBundle bundle, ELoadMode loadMode)
|
||||
{
|
||||
@@ -47,6 +69,8 @@ namespace YooAsset
|
||||
LoadMode = loadMode;
|
||||
RemoteMainURL = string.Empty;
|
||||
RemoteFallbackURL = string.Empty;
|
||||
DeliveryFilePath = string.Empty;
|
||||
DeliveryFileOffset = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -97,7 +97,7 @@ namespace YooAsset
|
||||
Manifest.AssetDic = new Dictionary<string, PackageAsset>(_packageAssetCount);
|
||||
|
||||
if (Manifest.EnableAddressable)
|
||||
Manifest.AssetPathMapping1 = new Dictionary<string, string>(_packageAssetCount);
|
||||
Manifest.AssetPathMapping1 = new Dictionary<string, string>(_packageAssetCount * 3);
|
||||
else
|
||||
Manifest.AssetPathMapping1 = new Dictionary<string, string>(_packageAssetCount * 2);
|
||||
|
||||
@@ -130,15 +130,6 @@ namespace YooAsset
|
||||
Manifest.AssetDic.Add(assetPath, packageAsset);
|
||||
|
||||
// 填充AssetPathMapping1
|
||||
if (Manifest.EnableAddressable)
|
||||
{
|
||||
string location = packageAsset.Address;
|
||||
if (Manifest.AssetPathMapping1.ContainsKey(location))
|
||||
throw new System.Exception($"Address have existed : {location}");
|
||||
else
|
||||
Manifest.AssetPathMapping1.Add(location, packageAsset.AssetPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
string location = packageAsset.AssetPath;
|
||||
if (Manifest.LocationToLower)
|
||||
@@ -146,7 +137,7 @@ namespace YooAsset
|
||||
|
||||
// 添加原生路径的映射
|
||||
if (Manifest.AssetPathMapping1.ContainsKey(location))
|
||||
throw new System.Exception($"AssetPath have existed : {location}");
|
||||
throw new System.Exception($"Location have existed : {location}");
|
||||
else
|
||||
Manifest.AssetPathMapping1.Add(location, packageAsset.AssetPath);
|
||||
|
||||
@@ -155,11 +146,19 @@ namespace YooAsset
|
||||
{
|
||||
string locationWithoutExtension = PathUtility.RemoveExtension(location);
|
||||
if (Manifest.AssetPathMapping1.ContainsKey(locationWithoutExtension))
|
||||
YooLogger.Warning($"AssetPath have existed : {locationWithoutExtension}");
|
||||
YooLogger.Warning($"Location have existed : {locationWithoutExtension}");
|
||||
else
|
||||
Manifest.AssetPathMapping1.Add(locationWithoutExtension, packageAsset.AssetPath);
|
||||
}
|
||||
}
|
||||
if (Manifest.EnableAddressable)
|
||||
{
|
||||
string location = packageAsset.Address;
|
||||
if (Manifest.AssetPathMapping1.ContainsKey(location))
|
||||
throw new System.Exception($"Location have existed : {location}");
|
||||
else
|
||||
Manifest.AssetPathMapping1.Add(location, packageAsset.AssetPath);
|
||||
}
|
||||
|
||||
// 填充AssetPathMapping2
|
||||
if (Manifest.IncludeAssetGUID)
|
||||
@@ -209,6 +208,10 @@ namespace YooAsset
|
||||
packageBundle.ParseBundle(Manifest.PackageName, Manifest.OutputNameStyle);
|
||||
Manifest.BundleDic.Add(packageBundle.BundleName, packageBundle);
|
||||
|
||||
// 注意:原始文件可能存在相同的CacheGUID
|
||||
if (Manifest.CacheGUIDs.Contains(packageBundle.CacheGUID) == false)
|
||||
Manifest.CacheGUIDs.Add(packageBundle.CacheGUID);
|
||||
|
||||
_packageBundleCount--;
|
||||
Progress = 1f - _packageBundleCount / _progressTotalValue;
|
||||
if (OperationSystem.IsBusy)
|
||||
|
||||
@@ -74,7 +74,7 @@ namespace YooAsset
|
||||
string savePath = PersistentTools.GetPersistent(_packageName).GetSandboxPackageManifestFilePath(_packageVersion);
|
||||
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_packageName, _packageVersion);
|
||||
string webURL = GetDownloadRequestURL(fileName);
|
||||
YooLogger.Log($"Beginning to download manifest file : {webURL}");
|
||||
YooLogger.Log($"Beginning to download package manifest file : {webURL}");
|
||||
_downloader2 = new UnityWebFileRequester();
|
||||
_downloader2.SendRequest(webURL, savePath, _timeout);
|
||||
}
|
||||
|
||||
@@ -58,6 +58,7 @@ namespace YooAsset
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
CheckParams,
|
||||
CheckActiveManifest,
|
||||
TryLoadCacheManifest,
|
||||
DownloadManifest,
|
||||
@@ -87,13 +88,34 @@ namespace YooAsset
|
||||
}
|
||||
internal override void Start()
|
||||
{
|
||||
_steps = ESteps.CheckActiveManifest;
|
||||
_steps = ESteps.CheckParams;
|
||||
}
|
||||
internal override void Update()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.CheckParams)
|
||||
{
|
||||
if (string.IsNullOrEmpty(_packageName))
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "Package name is null or empty.";
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(_packageVersion))
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "Package version is null or empty.";
|
||||
return;
|
||||
}
|
||||
|
||||
_steps = ESteps.CheckActiveManifest;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.CheckActiveManifest)
|
||||
{
|
||||
// 检测当前激活的清单对象
|
||||
@@ -198,6 +220,7 @@ namespace YooAsset
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
CheckParams,
|
||||
CheckActiveManifest,
|
||||
LoadRemoteManifest,
|
||||
Done,
|
||||
@@ -220,13 +243,34 @@ namespace YooAsset
|
||||
}
|
||||
internal override void Start()
|
||||
{
|
||||
_steps = ESteps.CheckActiveManifest;
|
||||
_steps = ESteps.CheckParams;
|
||||
}
|
||||
internal override void Update()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.CheckParams)
|
||||
{
|
||||
if (string.IsNullOrEmpty(_packageName))
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "Package name is null or empty.";
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(_packageVersion))
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "Package version is null or empty.";
|
||||
return;
|
||||
}
|
||||
|
||||
_steps = ESteps.CheckActiveManifest;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.CheckActiveManifest)
|
||||
{
|
||||
// 检测当前激活的清单对象
|
||||
|
||||
@@ -82,6 +82,12 @@ namespace YooAsset
|
||||
[NonSerialized]
|
||||
public Dictionary<string, string> AssetPathMapping2;
|
||||
|
||||
/// <summary>
|
||||
/// 该资源清单所有文件的缓存GUID集合
|
||||
/// </summary>
|
||||
[NonSerialized]
|
||||
public HashSet<string> CacheGUIDs = new HashSet<string>();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 尝试映射为资源路径
|
||||
@@ -191,12 +197,7 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public bool IsIncludeBundleFile(string cacheGUID)
|
||||
{
|
||||
foreach (var packageBundle in BundleList)
|
||||
{
|
||||
if (packageBundle.CacheGUID == cacheGUID)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return CacheGUIDs.Contains(cacheGUID);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -10,7 +10,8 @@ namespace YooAsset
|
||||
|
||||
// 参数相关
|
||||
private string _packageName;
|
||||
private IQueryServices _queryServices;
|
||||
private IBuildinQueryServices _buildinQueryServices;
|
||||
private IDeliveryQueryServices _deliveryQueryServices;
|
||||
private IRemoteServices _remoteServices;
|
||||
|
||||
public IRemoteServices RemoteServices
|
||||
@@ -21,10 +22,11 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 异步初始化
|
||||
/// </summary>
|
||||
public InitializationOperation InitializeAsync(string packageName, IQueryServices queryServices, IRemoteServices remoteServices)
|
||||
public InitializationOperation InitializeAsync(string packageName, IBuildinQueryServices buildinQueryServices, IDeliveryQueryServices deliveryQueryServices, IRemoteServices remoteServices)
|
||||
{
|
||||
_packageName = packageName;
|
||||
_queryServices = queryServices;
|
||||
_buildinQueryServices = buildinQueryServices;
|
||||
_deliveryQueryServices = deliveryQueryServices;
|
||||
_remoteServices = remoteServices;
|
||||
|
||||
var operation = new HostPlayModeInitializationOperation(this, packageName);
|
||||
@@ -51,6 +53,24 @@ namespace YooAsset
|
||||
return bundleInfo;
|
||||
}
|
||||
|
||||
// 查询相关
|
||||
private bool IsBuildinPackageBundle(PackageBundle packageBundle)
|
||||
{
|
||||
return _buildinQueryServices.QueryStreamingAssets(_packageName, packageBundle.FileName);
|
||||
}
|
||||
private bool IsCachedPackageBundle(PackageBundle packageBundle)
|
||||
{
|
||||
return CacheSystem.IsCached(packageBundle.PackageName, packageBundle.CacheGUID);
|
||||
}
|
||||
private bool IsDeliveryPackageBundle(PackageBundle packageBundle)
|
||||
{
|
||||
return _deliveryQueryServices.QueryDeliveryFiles(_packageName, packageBundle.FileName);
|
||||
}
|
||||
private DeliveryFileInfo GetDeiveryFileInfo(PackageBundle packageBundle)
|
||||
{
|
||||
return _deliveryQueryServices.GetDeliveryFileInfo(_packageName, packageBundle.FileName);
|
||||
}
|
||||
|
||||
#region IPlayModeServices接口
|
||||
public PackageManifest ActiveManifest
|
||||
{
|
||||
@@ -71,15 +91,6 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsBuildinPackageBundle(PackageBundle packageBundle)
|
||||
{
|
||||
return _queryServices.QueryStreamingAssets(_packageName, packageBundle.FileName);
|
||||
}
|
||||
private bool IsCachedPackageBundle(PackageBundle packageBundle)
|
||||
{
|
||||
return CacheSystem.IsCached(packageBundle.PackageName, packageBundle.CacheGUID);
|
||||
}
|
||||
|
||||
UpdatePackageVersionOperation IPlayModeServices.UpdatePackageVersionAsync(bool appendTimeTicks, int timeout)
|
||||
{
|
||||
var operation = new HostPlayModeUpdatePackageVersionOperation(this, _packageName, appendTimeTicks, timeout);
|
||||
@@ -110,6 +121,10 @@ namespace YooAsset
|
||||
List<PackageBundle> downloadList = new List<PackageBundle>(1000);
|
||||
foreach (var packageBundle in manifest.BundleList)
|
||||
{
|
||||
// 忽略分发文件
|
||||
if (IsDeliveryPackageBundle(packageBundle))
|
||||
continue;
|
||||
|
||||
// 忽略缓存文件
|
||||
if (IsCachedPackageBundle(packageBundle))
|
||||
continue;
|
||||
@@ -135,6 +150,10 @@ namespace YooAsset
|
||||
List<PackageBundle> downloadList = new List<PackageBundle>(1000);
|
||||
foreach (var packageBundle in manifest.BundleList)
|
||||
{
|
||||
// 忽略分发文件
|
||||
if (IsDeliveryPackageBundle(packageBundle))
|
||||
continue;
|
||||
|
||||
// 忽略缓存文件
|
||||
if (IsCachedPackageBundle(packageBundle))
|
||||
continue;
|
||||
@@ -196,6 +215,10 @@ namespace YooAsset
|
||||
List<PackageBundle> downloadList = new List<PackageBundle>(1000);
|
||||
foreach (var packageBundle in checkList)
|
||||
{
|
||||
// 忽略分发文件
|
||||
if (IsDeliveryPackageBundle(packageBundle))
|
||||
continue;
|
||||
|
||||
// 忽略缓存文件
|
||||
if (IsCachedPackageBundle(packageBundle))
|
||||
continue;
|
||||
@@ -269,6 +292,14 @@ namespace YooAsset
|
||||
if (packageBundle == null)
|
||||
throw new Exception("Should never get here !");
|
||||
|
||||
// 查询分发资源
|
||||
if (IsDeliveryPackageBundle(packageBundle))
|
||||
{
|
||||
DeliveryFileInfo deliveryFileInfo = GetDeiveryFileInfo(packageBundle);
|
||||
BundleInfo bundleInfo = new BundleInfo(packageBundle, BundleInfo.ELoadMode.LoadFromDelivery, deliveryFileInfo.DeliveryFilePath, deliveryFileInfo.DeliveryFileOffset);
|
||||
return bundleInfo;
|
||||
}
|
||||
|
||||
// 查询沙盒资源
|
||||
if (IsCachedPackageBundle(packageBundle))
|
||||
{
|
||||
|
||||
@@ -18,6 +18,12 @@ namespace YooAsset
|
||||
return operation;
|
||||
}
|
||||
|
||||
// 查询相关
|
||||
private bool IsCachedPackageBundle(PackageBundle packageBundle)
|
||||
{
|
||||
return CacheSystem.IsCached(packageBundle.PackageName, packageBundle.CacheGUID);
|
||||
}
|
||||
|
||||
#region IPlayModeServices接口
|
||||
public PackageManifest ActiveManifest
|
||||
{
|
||||
@@ -34,11 +40,6 @@ namespace YooAsset
|
||||
{
|
||||
}
|
||||
|
||||
private bool IsCachedPackageBundle(PackageBundle packageBundle)
|
||||
{
|
||||
return CacheSystem.IsCached(packageBundle.PackageName, packageBundle.CacheGUID);
|
||||
}
|
||||
|
||||
UpdatePackageVersionOperation IPlayModeServices.UpdatePackageVersionAsync(bool appendTimeTicks, int timeout)
|
||||
{
|
||||
var operation = new OfflinePlayModeUpdatePackageVersionOperation();
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace YooAsset
|
||||
|
||||
// 参数相关
|
||||
private string _packageName;
|
||||
private IQueryServices _queryServices;
|
||||
private IBuildinQueryServices _buildinQueryServices;
|
||||
private IRemoteServices _remoteServices;
|
||||
|
||||
public IRemoteServices RemoteServices
|
||||
@@ -21,10 +21,10 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 异步初始化
|
||||
/// </summary>
|
||||
public InitializationOperation InitializeAsync(string packageName, IQueryServices queryServices, IRemoteServices remoteServices)
|
||||
public InitializationOperation InitializeAsync(string packageName, IBuildinQueryServices buildinQueryServices, IRemoteServices remoteServices)
|
||||
{
|
||||
_packageName = packageName;
|
||||
_queryServices = queryServices;
|
||||
_buildinQueryServices = buildinQueryServices;
|
||||
_remoteServices = remoteServices;
|
||||
|
||||
var operation = new WebPlayModeInitializationOperation(this, packageName);
|
||||
@@ -41,6 +41,12 @@ namespace YooAsset
|
||||
return bundleInfo;
|
||||
}
|
||||
|
||||
// 查询相关
|
||||
private bool IsBuildinPackageBundle(PackageBundle packageBundle)
|
||||
{
|
||||
return _buildinQueryServices.QueryStreamingAssets(_packageName, packageBundle.FileName);
|
||||
}
|
||||
|
||||
#region IPlayModeServices接口
|
||||
public PackageManifest ActiveManifest
|
||||
{
|
||||
@@ -57,11 +63,6 @@ namespace YooAsset
|
||||
{
|
||||
}
|
||||
|
||||
private bool IsBuildinPackageBundle(PackageBundle packageBundle)
|
||||
{
|
||||
return _queryServices.QueryStreamingAssets(_packageName, packageBundle.FileName);
|
||||
}
|
||||
|
||||
UpdatePackageVersionOperation IPlayModeServices.UpdatePackageVersionAsync(bool appendTimeTicks, int timeout)
|
||||
{
|
||||
var operation = new WebPlayModeUpdatePackageVersionOperation(this, _packageName, appendTimeTicks, timeout);
|
||||
|
||||
@@ -122,7 +122,8 @@ namespace YooAsset
|
||||
var initializeParameters = parameters as HostPlayModeParameters;
|
||||
initializeOperation = hostPlayModeImpl.InitializeAsync(
|
||||
PackageName,
|
||||
initializeParameters.QueryServices,
|
||||
initializeParameters.BuildinQueryServices,
|
||||
initializeParameters.DeliveryQueryServices,
|
||||
initializeParameters.RemoteServices
|
||||
);
|
||||
}
|
||||
@@ -138,7 +139,7 @@ namespace YooAsset
|
||||
var initializeParameters = parameters as WebPlayModeParameters;
|
||||
initializeOperation = webPlayModeImpl.InitializeAsync(
|
||||
PackageName,
|
||||
initializeParameters.QueryServices,
|
||||
initializeParameters.BuildinQueryServices,
|
||||
initializeParameters.RemoteServices
|
||||
);
|
||||
}
|
||||
@@ -187,8 +188,10 @@ namespace YooAsset
|
||||
if (parameters is HostPlayModeParameters)
|
||||
{
|
||||
var hostPlayModeParameters = parameters as HostPlayModeParameters;
|
||||
if (hostPlayModeParameters.QueryServices == null)
|
||||
throw new Exception($"{nameof(IQueryServices)} is null.");
|
||||
if (hostPlayModeParameters.BuildinQueryServices == null)
|
||||
throw new Exception($"{nameof(IBuildinQueryServices)} is null.");
|
||||
if (hostPlayModeParameters.DeliveryQueryServices == null)
|
||||
throw new Exception($"{nameof(IDeliveryQueryServices)} is null.");
|
||||
if (hostPlayModeParameters.RemoteServices == null)
|
||||
throw new Exception($"{nameof(IRemoteServices)} is null.");
|
||||
}
|
||||
@@ -205,11 +208,19 @@ namespace YooAsset
|
||||
else
|
||||
throw new NotImplementedException();
|
||||
|
||||
// 检测运行平台
|
||||
if (_playMode == EPlayMode.HostPlayMode || _playMode == EPlayMode.OfflinePlayMode)
|
||||
// 检测运行时平台
|
||||
if (_playMode != EPlayMode.EditorSimulateMode)
|
||||
{
|
||||
#if UNITY_WEBGL
|
||||
throw new Exception($"WebGL plateform not support : {_playMode} ! Please use {nameof(EPlayMode.WebPlayMode)}");
|
||||
if (_playMode != EPlayMode.WebPlayMode)
|
||||
{
|
||||
throw new Exception($"{_playMode} can not support WebGL plateform ! Please use {nameof(EPlayMode.WebPlayMode)}");
|
||||
}
|
||||
#else
|
||||
if (_playMode == EPlayMode.WebPlayMode)
|
||||
{
|
||||
throw new Exception($"{nameof(EPlayMode.WebPlayMode)} only support WebGL plateform !");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -238,7 +249,7 @@ namespace YooAsset
|
||||
/// <param name="timeout">超时时间(默认值:60秒)</param>
|
||||
public UpdatePackageVersionOperation UpdatePackageVersionAsync(bool appendTimeTicks = true, int timeout = 60)
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
DebugCheckInitialize(false);
|
||||
return _playModeServices.UpdatePackageVersionAsync(appendTimeTicks, timeout);
|
||||
}
|
||||
|
||||
@@ -250,7 +261,7 @@ namespace YooAsset
|
||||
/// <param name="timeout">超时时间(默认值:60秒)</param>
|
||||
public UpdatePackageManifestOperation UpdatePackageManifestAsync(string packageVersion, bool autoSaveVersion = true, int timeout = 60)
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
DebugCheckInitialize(false);
|
||||
DebugCheckUpdateManifest();
|
||||
return _playModeServices.UpdatePackageManifestAsync(packageVersion, autoSaveVersion, timeout);
|
||||
}
|
||||
@@ -262,7 +273,7 @@ namespace YooAsset
|
||||
/// <param name="timeout">超时时间(默认值:60秒)</param>
|
||||
public PreDownloadContentOperation PreDownloadContentAsync(string packageVersion, int timeout = 60)
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
DebugCheckInitialize(false);
|
||||
return _playModeServices.PreDownloadContentAsync(packageVersion, timeout);
|
||||
}
|
||||
|
||||
@@ -294,8 +305,6 @@ namespace YooAsset
|
||||
public string GetPackageVersion()
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
if (_playModeServices.ActiveManifest == null)
|
||||
return string.Empty;
|
||||
return _playModeServices.ActiveManifest.PackageVersion;
|
||||
}
|
||||
|
||||
@@ -573,6 +582,18 @@ namespace YooAsset
|
||||
return LoadAssetInternal(assetInfo, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 同步加载资源对象
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址</param>
|
||||
public AssetOperationHandle LoadAssetSync(string location)
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
Type type = typeof(UnityEngine.Object);
|
||||
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, type);
|
||||
return LoadAssetInternal(assetInfo, true);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载资源对象
|
||||
@@ -608,6 +629,18 @@ namespace YooAsset
|
||||
return LoadAssetInternal(assetInfo, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载资源对象
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址</param>
|
||||
public AssetOperationHandle LoadAssetAsync(string location)
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
Type type = typeof(UnityEngine.Object);
|
||||
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, type);
|
||||
return LoadAssetInternal(assetInfo, false);
|
||||
}
|
||||
|
||||
|
||||
private AssetOperationHandle LoadAssetInternal(AssetInfo assetInfo, bool waitForAsyncComplete)
|
||||
{
|
||||
@@ -662,6 +695,18 @@ namespace YooAsset
|
||||
return LoadSubAssetsInternal(assetInfo, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 同步加载子资源对象
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址</param>
|
||||
public SubAssetsOperationHandle LoadSubAssetsSync(string location)
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
Type type = typeof(UnityEngine.Object);
|
||||
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, type);
|
||||
return LoadSubAssetsInternal(assetInfo, true);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载子资源对象
|
||||
@@ -697,6 +742,18 @@ namespace YooAsset
|
||||
return LoadSubAssetsInternal(assetInfo, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载子资源对象
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址</param>
|
||||
public SubAssetsOperationHandle LoadSubAssetsAsync(string location)
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
Type type = typeof(UnityEngine.Object);
|
||||
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, type);
|
||||
return LoadSubAssetsInternal(assetInfo, false);
|
||||
}
|
||||
|
||||
|
||||
private SubAssetsOperationHandle LoadSubAssetsInternal(AssetInfo assetInfo, bool waitForAsyncComplete)
|
||||
{
|
||||
@@ -751,6 +808,18 @@ namespace YooAsset
|
||||
return LoadAllAssetsInternal(assetInfo, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 同步加载资源包内所有资源对象
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址</param>
|
||||
public AllAssetsOperationHandle LoadAllAssetsSync(string location)
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
Type type = typeof(UnityEngine.Object);
|
||||
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, type);
|
||||
return LoadAllAssetsInternal(assetInfo, true);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载资源包内所有资源对象
|
||||
@@ -786,6 +855,18 @@ namespace YooAsset
|
||||
return LoadAllAssetsInternal(assetInfo, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载资源包内所有资源对象
|
||||
/// </summary>
|
||||
/// <param name="location">资源的定位地址</param>
|
||||
public AllAssetsOperationHandle LoadAllAssetsAsync(string location)
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
Type type = typeof(UnityEngine.Object);
|
||||
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, type);
|
||||
return LoadAllAssetsInternal(assetInfo, false);
|
||||
}
|
||||
|
||||
|
||||
private AllAssetsOperationHandle LoadAllAssetsInternal(AssetInfo assetInfo, bool waitForAsyncComplete)
|
||||
{
|
||||
@@ -967,12 +1048,18 @@ namespace YooAsset
|
||||
|
||||
#region 调试方法
|
||||
[Conditional("DEBUG")]
|
||||
private void DebugCheckInitialize()
|
||||
private void DebugCheckInitialize(bool checkActiveManifest = true)
|
||||
{
|
||||
if (_initializeStatus == EOperationStatus.None)
|
||||
throw new Exception("Package initialize not completed !");
|
||||
else if (_initializeStatus == EOperationStatus.Failed)
|
||||
throw new Exception($"Package initialize failed ! {_initializeError}");
|
||||
|
||||
if (checkActiveManifest)
|
||||
{
|
||||
if (_playModeServices.ActiveManifest == null)
|
||||
throw new Exception("Not found active manifest !");
|
||||
}
|
||||
}
|
||||
|
||||
[Conditional("DEBUG")]
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
public interface IQueryServices
|
||||
public interface IBuildinQueryServices
|
||||
{
|
||||
/// <summary>
|
||||
/// 查询内置资源
|
||||
/// 查询应用程序里的内置资源是否存在
|
||||
/// </summary>
|
||||
bool QueryStreamingAssets(string packageName, string fileName);
|
||||
}
|
||||
25
Assets/YooAsset/Runtime/Services/IDeliveryQueryServices.cs
Normal file
25
Assets/YooAsset/Runtime/Services/IDeliveryQueryServices.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 分发的资源信息
|
||||
/// </summary>
|
||||
public struct DeliveryFileInfo
|
||||
{
|
||||
public string DeliveryFilePath;
|
||||
public ulong DeliveryFileOffset;
|
||||
}
|
||||
|
||||
public interface IDeliveryQueryServices
|
||||
{
|
||||
/// <summary>
|
||||
/// 查询是否为开发者分发的资源
|
||||
/// </summary>
|
||||
bool QueryDeliveryFiles(string packageName, string fileName);
|
||||
|
||||
/// <summary>
|
||||
/// 获取开发者分发的资源信息
|
||||
/// </summary>
|
||||
DeliveryFileInfo GetDeliveryFileInfo(string packageName, string fileName);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fe50795c51a46884088139b840c1557f
|
||||
guid: 7edb4ad6b8dd5cf4bbe1b84a019f6303
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -1,5 +1,6 @@
|
||||
{
|
||||
"name": "YooAsset",
|
||||
"rootNamespace": "",
|
||||
"references": [],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
|
||||
@@ -69,19 +69,20 @@ internal class FsmInitialize : IStateNode
|
||||
string fallbackHostServer = GetHostServerURL();
|
||||
var createParameters = new HostPlayModeParameters();
|
||||
createParameters.DecryptionServices = new GameDecryptionServices();
|
||||
createParameters.QueryServices = new GameQueryServices();
|
||||
createParameters.BuildinQueryServices = new GameQueryServices();
|
||||
createParameters.DeliveryQueryServices = new DefaultDeliveryQueryServices();
|
||||
createParameters.RemoteServices = new RemoteServices(defaultHostServer, fallbackHostServer);
|
||||
initializationOperation = package.InitializeAsync(createParameters);
|
||||
}
|
||||
|
||||
// WebGL运行模式
|
||||
if(playMode == EPlayMode.WebPlayMode)
|
||||
if (playMode == EPlayMode.WebPlayMode)
|
||||
{
|
||||
string defaultHostServer = GetHostServerURL();
|
||||
string fallbackHostServer = GetHostServerURL();
|
||||
var createParameters = new WebPlayModeParameters();
|
||||
createParameters.DecryptionServices = new GameDecryptionServices();
|
||||
createParameters.QueryServices = new GameQueryServices();
|
||||
createParameters.BuildinQueryServices = new GameQueryServices();
|
||||
createParameters.RemoteServices = new RemoteServices(defaultHostServer, fallbackHostServer);
|
||||
initializationOperation = package.InitializeAsync(createParameters);
|
||||
}
|
||||
@@ -142,11 +143,11 @@ internal class FsmInitialize : IStateNode
|
||||
_defaultHostServer = defaultHostServer;
|
||||
_fallbackHostServer = fallbackHostServer;
|
||||
}
|
||||
string IRemoteServices.GetRemoteFallbackURL(string fileName)
|
||||
string IRemoteServices.GetRemoteMainURL(string fileName)
|
||||
{
|
||||
return $"{_defaultHostServer}/{fileName}";
|
||||
}
|
||||
string IRemoteServices.GetRemoteMainURL(string fileName)
|
||||
string IRemoteServices.GetRemoteFallbackURL(string fileName)
|
||||
{
|
||||
return $"{_fallbackHostServer}/{fileName}";
|
||||
}
|
||||
@@ -178,4 +179,19 @@ internal class FsmInitialize : IStateNode
|
||||
return 1024;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 默认的分发资源查询服务类
|
||||
/// </summary>
|
||||
private class DefaultDeliveryQueryServices : IDeliveryQueryServices
|
||||
{
|
||||
public DeliveryFileInfo GetDeliveryFileInfo(string packageName, string fileName)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
public bool QueryDeliveryFiles(string packageName, string fileName)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,9 +4,9 @@ using UnityEngine;
|
||||
using YooAsset;
|
||||
|
||||
/// <summary>
|
||||
/// 内置文件查询服务类
|
||||
/// 资源文件查询服务类
|
||||
/// </summary>
|
||||
public class GameQueryServices : IQueryServices
|
||||
public class GameQueryServices : IBuildinQueryServices
|
||||
{
|
||||
public bool QueryStreamingAssets(string packageName, string fileName)
|
||||
{
|
||||
|
||||
@@ -7,9 +7,9 @@ using YooAsset;
|
||||
|
||||
/*
|
||||
/// <summary>
|
||||
/// 内置文件查询服务类
|
||||
/// 资源文件查询服务类
|
||||
/// </summary>
|
||||
public class GameQueryServices2 : IQueryServices
|
||||
public class GameQueryServices2 : IBuildinQueryServices
|
||||
{
|
||||
public bool QueryStreamingAssets(string packageName, string fileName)
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "com.tuyoogame.yooasset",
|
||||
"displayName": "YooAsset",
|
||||
"version": "1.5.2-preview",
|
||||
"version": "1.5.4-preview",
|
||||
"unity": "2019.4",
|
||||
"description": "unity3d resources management system.",
|
||||
"author": {
|
||||
|
||||
Reference in New Issue
Block a user