Compare commits

...

19 Commits

Author SHA1 Message Date
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
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
34 changed files with 352 additions and 309 deletions

View File

@@ -2,6 +2,41 @@
All notable changes to this package will be documented in this file.
## [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,11 +0,0 @@
fileFormatVersion: 2
guid: fe50795c51a46884088139b840c1557f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

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

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

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

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

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

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

@@ -51,6 +51,24 @@ namespace YooAsset
return bundleInfo;
}
// 查询相关
private bool IsBuildinPackageBundle(PackageBundle packageBundle)
{
return _queryServices.QueryStreamingAssets(_packageName, packageBundle.FileName);
}
private bool IsCachedPackageBundle(PackageBundle packageBundle)
{
return CacheSystem.IsCached(packageBundle.PackageName, packageBundle.CacheGUID);
}
private bool IsDeliveryPackageBundle(PackageBundle packageBundle)
{
return _queryServices.QueryDeliveryFiles(_packageName, packageBundle.FileName);
}
private DeliveryFileInfo GetDeiveryFileInfo(PackageBundle packageBundle)
{
return _queryServices.GetDeliveryFileInfo(_packageName, packageBundle.FileName);
}
#region IPlayModeServices接口
public PackageManifest ActiveManifest
{
@@ -71,15 +89,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 +119,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 +148,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 +213,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 +290,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

@@ -41,6 +41,12 @@ namespace YooAsset
return bundleInfo;
}
// 查询相关
private bool IsBuildinPackageBundle(PackageBundle packageBundle)
{
return _queryServices.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

@@ -205,11 +205,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 +246,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 +258,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 +270,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 +302,6 @@ namespace YooAsset
public string GetPackageVersion()
{
DebugCheckInitialize();
if (_playModeServices.ActiveManifest == null)
return string.Empty;
return _playModeServices.ActiveManifest.PackageVersion;
}
@@ -573,6 +579,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 +626,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 +692,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 +739,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 +805,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 +852,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 +1045,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,11 +1,30 @@

namespace YooAsset
{
/// <summary>
/// 分发的资源信息
/// </summary>
public struct DeliveryFileInfo
{
public string DeliveryFilePath;
public ulong DeliveryFileOffset;
}
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);
}
}

View File

@@ -142,11 +142,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}";
}

View File

@@ -4,10 +4,20 @@ using UnityEngine;
using YooAsset;
/// <summary>
/// 内置文件查询服务类
/// 资源文件查询服务类
/// </summary>
public class GameQueryServices : IQueryServices
{
public DeliveryFileInfo GetDeliveryFileInfo(string packageName, string fileName)
{
throw new System.NotImplementedException();
}
public bool QueryDeliveryFiles(string packageName, string fileName)
{
return false;
}
public bool QueryStreamingAssets(string packageName, string fileName)
{
// 注意fileName包含文件格式

View File

@@ -7,10 +7,20 @@ using YooAsset;
/*
/// <summary>
/// 内置文件查询服务类
/// 资源文件查询服务类
/// </summary>
public class GameQueryServices2 : IQueryServices
{
public DeliveryFileInfo GetDeliveryFileInfo(string packageName, string fileName)
{
throw new System.NotImplementedException();
}
public bool QueryDeliveryFiles(string packageName, string fileName)
{
return false;
}
public bool QueryStreamingAssets(string packageName, string fileName)
{
return StreamingAssetsHelper2.FileExists($"{StreamingAssetsDefine.RootFolderName}/{packageName}/{fileName}");

View File

@@ -1,7 +1,7 @@
{
"name": "com.tuyoogame.yooasset",
"displayName": "YooAsset",
"version": "1.5.2-preview",
"version": "1.5.3-preview",
"unity": "2019.4",
"description": "unity3d resources management system.",
"author": {