Compare commits

...

42 Commits

Author SHA1 Message Date
hevinci
697a87721f Update CHANGELOG.md 2023-08-25 20:39:53 +08:00
hevinci
09cf93d852 Update package.json 2023-08-25 20:39:46 +08:00
hevinci
8725821a27 update download system 2023-08-25 20:15:58 +08:00
hevinci
a2e57c6e90 update operation system 2023-08-25 17:37:49 +08:00
hevinci
6d37bca2a9 update asset bundle builder 2023-08-25 17:37:34 +08:00
hevinci
8471bb0f9a update asset bundle builder
暂时移除xxHash
2023-08-25 17:19:57 +08:00
何冠峰
05cb57db09 Merge pull request #150 from yingnierxiao/main
优化打包速度,提示编辑器启动速度,md5替换xxhash,速度提升一倍以上
2023-08-25 15:17:49 +08:00
yingnierxiao
064e9a1aa3 优化打包速度,提示编辑器启动速度,md5替换xxhash,速度提升一倍以上 2023-08-25 14:53:59 +08:00
hevinci
a618b6cf9e update asset bundle reporter 2023-08-18 18:31:15 +08:00
何冠峰
e3e810e702 Merge pull request #134 from gepengmiss/main
bundle viewer 功能扩展
2023-08-18 17:58:43 +08:00
hevinci
b4f0d6bab8 fix #138 2023-08-18 17:40:55 +08:00
hevinci
44cb4168cf update asset bundle collector 2023-08-17 22:13:31 +08:00
hevinci
559ed95999 update asset bundle collector
增加在配置错误的时候警示提示。
2023-08-17 21:53:51 +08:00
hevinci
b766df1d31 update shader variant collector 2023-08-17 21:18:21 +08:00
hevinci
057ff6b22b fix #130 2023-08-17 21:05:21 +08:00
hevinci
995b0c8050 update space shooter 2023-08-15 18:19:07 +08:00
hevinci
a2d4691f04 update package system
IQueryServices接口变更为IBuildinQueryServices
2023-08-14 12:27:43 +08:00
hevinci
ab2d7d4724 update operation system
Operation状态增加Processing处理中状态
2023-08-11 16:20:38 +08:00
hevinci
9b4abf86b6 update runtime code
可寻址模式默认支持通过资源路径加载。
2023-08-09 20:15:55 +08:00
hevinci
0331b7b6e3 update editor code 2023-08-09 20:15:33 +08:00
hevinci
e31799e78b Update CHANGELOG.md 2023-07-28 17:32:44 +08:00
hevinci
a8405eea6d Update package.json 2023-07-28 17:32:38 +08:00
hevinci
c11f072c50 update asset system 2023-07-28 17:17:23 +08:00
YGP
bd080eb19b modify bundleViewer func 2023-07-27 16:12:21 +08:00
YGP
ef231e213e modify bundleViewer func 2023-07-27 16:06:09 +08:00
YGP
a5900b5f99 ignore 2023-07-27 16:04:59 +08:00
hevinci
b22bbd4e27 update editor code 2023-07-25 18:48:32 +08:00
hevinci
664866b627 update space shooter 2023-07-25 18:38:02 +08:00
hevinci
ad9bdc6574 update download system 2023-07-25 18:37:43 +08:00
hevinci
b93b993951 update package system 2023-07-20 14:28:22 +08:00
hevinci
cb2cb4e556 update package system 2023-07-20 11:27:56 +08:00
hevinci
ab32bd390d update space shooter 2023-07-20 11:08:52 +08:00
hevinci
b34374adfa update runtime code 2023-07-20 11:08:38 +08:00
hevinci
b53b6a4246 update runtime code 2023-07-20 11:08:28 +08:00
hevinci
191fbff768 update package system
增加对清单激活的检测
2023-07-19 18:18:03 +08:00
hevinci
e8a4ddf331 update runtime code 2023-07-19 17:48:26 +08:00
hevinci
aee6e2d2f8 update space shooter 2023-07-19 17:06:35 +08:00
hevinci
b737b20602 update runtime code
支持开发者资源分发和加载
2023-07-19 17:06:20 +08:00
hevinci
b5df539392 update package system
增加对UpdatePackageManifestOperation参数的检测
2023-07-19 15:57:34 +08:00
hevinci
36c53e5d94 update space shooter 2023-07-19 14:34:51 +08:00
hevinci
15ce6b8c8c update runtime code 2023-07-19 14:34:43 +08:00
hevinci
19aa82c131 update editor code 2023-07-19 11:22:59 +08:00
61 changed files with 638 additions and 427 deletions

17
.gitignore vendored
View File

@@ -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*

View File

@@ -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

View File

@@ -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;
}
}
}

View File

@@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: d6268d725eec21b4aae819adc1553f0e
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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);

View File

@@ -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);

View File

@@ -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;

View File

@@ -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}");
}
}
}

View File

@@ -161,7 +161,7 @@ namespace YooAsset.Editor
/// </summary>
public static void FixFile()
{
bool isFixed = Setting.FixConfigError();
bool isFixed = Setting.FixAllPackageConfigError();
if (isFixed)
{
IsDirty = true;

View File

@@ -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;

View File

@@ -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;" />

View File

@@ -16,7 +16,7 @@ namespace YooAsset.Editor
{
string IAddressRule.GetAssetAddress(AddressRuleData data)
{
return data.AssetPath;
throw new System.Exception("可寻址模式下已经默认支持通过资源路径加载!");
}
}

View File

@@ -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;

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: a0319abb8eae03b4b88e8f900fe2276c
guid: 8875000dff445624da4d6a2d6ef2f446
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -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;" />

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 56d6dbe0d65ce334a8996beb19612989
guid: cf2a9340bb457594d9bc1f80b84a89f6
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}

View File

@@ -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];

View File

@@ -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)
{

View File

@@ -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
}
}

View File

@@ -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;
}
}

View File

@@ -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)

View File

@@ -144,15 +144,6 @@ namespace YooAsset
}
}
/// <summary>
/// 销毁资源包(安全模式)
/// </summary>
public void DestroySafely()
{
WaitForAsyncComplete();
Destroy();
}
/// <summary>
/// 轮询更新

View File

@@ -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());

View File

@@ -140,22 +140,6 @@ namespace YooAsset
}
}
/// <summary>
/// 销毁资源对象(安全模式)
/// </summary>
public void DestroySafely()
{
if (Status == EStatus.Loading || Status == EStatus.Checking)
{
WaitForAsyncComplete();
Destroy();
}
else
{
Destroy();
}
}
/// <summary>
/// 是否可以销毁
/// </summary>

View File

@@ -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}");
}
}
}

View File

@@ -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}");
}
}
}

View File

@@ -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();
}

View File

@@ -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>
/// 远端资源地址查询服务类

View File

@@ -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>
/// 清空完成回调

View File

@@ -4,6 +4,7 @@ namespace YooAsset
public enum EOperationStatus
{
None,
Processing,
Succeed,
Failed
}

View File

@@ -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();
}
}

View File

@@ -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>

View File

@@ -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)

View File

@@ -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);
}

View File

@@ -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)
{
// 检测当前激活的清单对象

View File

@@ -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>

View File

@@ -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))
{

View File

@@ -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();

View File

@@ -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);

View File

@@ -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")]

View File

@@ -1,10 +1,10 @@

namespace YooAsset
{
public interface IQueryServices
public interface IBuildinQueryServices
{
/// <summary>
/// 查询内置资源
/// 查询应用程序里的内置资源是否存在
/// </summary>
bool QueryStreamingAssets(string packageName, string fileName);
}

View 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);
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: fe50795c51a46884088139b840c1557f
guid: 7edb4ad6b8dd5cf4bbe1b84a019f6303
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -1,5 +1,6 @@
{
"name": "YooAsset",
"rootNamespace": "",
"references": [],
"includePlatforms": [],
"excludePlatforms": [],

View File

@@ -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;
}
}
}

View File

@@ -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)
{

View File

@@ -7,9 +7,9 @@ using YooAsset;
/*
/// <summary>
/// 内置文件查询服务类
/// 资源文件查询服务类
/// </summary>
public class GameQueryServices2 : IQueryServices
public class GameQueryServices2 : IBuildinQueryServices
{
public bool QueryStreamingAssets(string packageName, string fileName)
{

View File

@@ -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": {