mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
yoo2.2,9
yoo2.2,9
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 167d849df37f45e42a77ab47464a9442
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,73 @@
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class AssetBundleResult : BundleResult
|
||||
{
|
||||
private readonly IFileSystem _fileSystem;
|
||||
private readonly PackageBundle _packageBundle;
|
||||
private readonly AssetBundle _assetBundle;
|
||||
private readonly Stream _managedStream;
|
||||
|
||||
public AssetBundleResult(IFileSystem fileSystem, PackageBundle packageBundle, AssetBundle assetBundle, Stream managedStream)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
_packageBundle = packageBundle;
|
||||
_assetBundle = assetBundle;
|
||||
_managedStream = managedStream;
|
||||
}
|
||||
|
||||
public override void UnloadBundleFile()
|
||||
{
|
||||
if (_assetBundle != null)
|
||||
{
|
||||
_assetBundle.Unload(true);
|
||||
}
|
||||
|
||||
if (_managedStream != null)
|
||||
{
|
||||
_managedStream.Close();
|
||||
_managedStream.Dispose();
|
||||
}
|
||||
}
|
||||
public override string GetBundleFilePath()
|
||||
{
|
||||
return _fileSystem.GetBundleFilePath(_packageBundle);
|
||||
}
|
||||
public override byte[] ReadBundleFileData()
|
||||
{
|
||||
return _fileSystem.ReadBundleFileData(_packageBundle);
|
||||
}
|
||||
public override string ReadBundleFileText()
|
||||
{
|
||||
return _fileSystem.ReadBundleFileText(_packageBundle);
|
||||
}
|
||||
|
||||
public override FSLoadAssetOperation LoadAssetAsync(AssetInfo assetInfo)
|
||||
{
|
||||
var operation = new AssetBundleLoadAssetOperation(_packageBundle, _assetBundle, assetInfo);
|
||||
OperationSystem.StartOperation(_fileSystem.PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
public override FSLoadAllAssetsOperation LoadAllAssetsAsync(AssetInfo assetInfo)
|
||||
{
|
||||
var operation = new AssetBundleLoadAllAssetsOperation(_packageBundle, _assetBundle, assetInfo);
|
||||
OperationSystem.StartOperation(_fileSystem.PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
public override FSLoadSubAssetsOperation LoadSubAssetsAsync(AssetInfo assetInfo)
|
||||
{
|
||||
var operation = new AssetBundleLoadSubAssetsOperation(_packageBundle, _assetBundle, assetInfo);
|
||||
OperationSystem.StartOperation(_fileSystem.PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
public override FSLoadSceneOperation LoadSceneOperation(AssetInfo assetInfo, LoadSceneParameters loadParams, bool suspendLoad)
|
||||
{
|
||||
var operation = new AssetBundleLoadSceneOperation(assetInfo, loadParams, suspendLoad);
|
||||
OperationSystem.StartOperation(_fileSystem.PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e30b4a882730b534e98d7d70821de979
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e310d20cf53709541bc66d1483afe627
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,121 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class AssetBundleLoadAllAssetsOperation : FSLoadAllAssetsOperation
|
||||
{
|
||||
protected enum ESteps
|
||||
{
|
||||
None,
|
||||
CheckBundle,
|
||||
LoadAsset,
|
||||
CheckResult,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly PackageBundle _packageBundle;
|
||||
private readonly AssetBundle _assetBundle;
|
||||
private readonly AssetInfo _assetInfo;
|
||||
private AssetBundleRequest _request;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
public AssetBundleLoadAllAssetsOperation(PackageBundle packageBundle, AssetBundle assetBundle, AssetInfo assetInfo)
|
||||
{
|
||||
_packageBundle = packageBundle;
|
||||
_assetBundle = assetBundle;
|
||||
_assetInfo = assetInfo;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
_steps = ESteps.CheckBundle;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.CheckBundle)
|
||||
{
|
||||
if (_assetBundle == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Error = $"The bundle {_packageBundle.BundleName} has been destroyed due to unity engine bugs !";
|
||||
Status = EOperationStatus.Failed;
|
||||
return;
|
||||
}
|
||||
|
||||
_steps = ESteps.LoadAsset;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.LoadAsset)
|
||||
{
|
||||
if (IsWaitForAsyncComplete)
|
||||
{
|
||||
if (_assetInfo.AssetType == null)
|
||||
Result = _assetBundle.LoadAllAssets();
|
||||
else
|
||||
Result = _assetBundle.LoadAllAssets(_assetInfo.AssetType);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_assetInfo.AssetType == null)
|
||||
_request = _assetBundle.LoadAllAssetsAsync();
|
||||
else
|
||||
_request = _assetBundle.LoadAllAssetsAsync(_assetInfo.AssetType);
|
||||
}
|
||||
|
||||
_steps = ESteps.CheckResult;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.CheckResult)
|
||||
{
|
||||
if (_request != null)
|
||||
{
|
||||
if (IsWaitForAsyncComplete)
|
||||
{
|
||||
// 强制挂起主线程(注意:该操作会很耗时)
|
||||
YooLogger.Warning("Suspend the main thread to load unity asset.");
|
||||
Result = _request.allAssets;
|
||||
}
|
||||
else
|
||||
{
|
||||
Progress = _request.progress;
|
||||
if (_request.isDone == false)
|
||||
return;
|
||||
Result = _request.allAssets;
|
||||
}
|
||||
}
|
||||
|
||||
if (Result == null)
|
||||
{
|
||||
string error;
|
||||
if (_assetInfo.AssetType == null)
|
||||
error = $"Failed to load all assets : {_assetInfo.AssetPath} AssetType : null AssetBundle : {_packageBundle.BundleName}";
|
||||
else
|
||||
error = $"Failed to load all assets : {_assetInfo.AssetPath} AssetType : {_assetInfo.AssetType} AssetBundle : {_packageBundle.BundleName}";
|
||||
YooLogger.Error(error);
|
||||
|
||||
_steps = ESteps.Done;
|
||||
Error = error;
|
||||
Status = EOperationStatus.Failed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
}
|
||||
}
|
||||
internal override void InternalWaitForAsyncComplete()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (ExecuteWhileDone())
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 15e73c9ca9f0a7143b155e87ef1a3ce4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,121 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class AssetBundleLoadAssetOperation : FSLoadAssetOperation
|
||||
{
|
||||
protected enum ESteps
|
||||
{
|
||||
None,
|
||||
CheckBundle,
|
||||
LoadAsset,
|
||||
CheckResult,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly PackageBundle _packageBundle;
|
||||
private readonly AssetBundle _assetBundle;
|
||||
private readonly AssetInfo _assetInfo;
|
||||
private AssetBundleRequest _request;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
public AssetBundleLoadAssetOperation(PackageBundle packageBundle, AssetBundle assetBundle, AssetInfo assetInfo)
|
||||
{
|
||||
_packageBundle = packageBundle;
|
||||
_assetBundle = assetBundle;
|
||||
_assetInfo = assetInfo;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
_steps = ESteps.CheckBundle;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.CheckBundle)
|
||||
{
|
||||
if (_assetBundle == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Error = $"The bundle {_packageBundle.BundleName} has been destroyed due to unity engine bugs !";
|
||||
Status = EOperationStatus.Failed;
|
||||
return;
|
||||
}
|
||||
|
||||
_steps = ESteps.LoadAsset;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.LoadAsset)
|
||||
{
|
||||
if (IsWaitForAsyncComplete)
|
||||
{
|
||||
if (_assetInfo.AssetType == null)
|
||||
Result = _assetBundle.LoadAsset(_assetInfo.AssetPath);
|
||||
else
|
||||
Result = _assetBundle.LoadAsset(_assetInfo.AssetPath, _assetInfo.AssetType);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_assetInfo.AssetType == null)
|
||||
_request = _assetBundle.LoadAssetAsync(_assetInfo.AssetPath);
|
||||
else
|
||||
_request = _assetBundle.LoadAssetAsync(_assetInfo.AssetPath, _assetInfo.AssetType);
|
||||
}
|
||||
|
||||
_steps = ESteps.CheckResult;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.CheckResult)
|
||||
{
|
||||
if (_request != null)
|
||||
{
|
||||
if (IsWaitForAsyncComplete)
|
||||
{
|
||||
// 强制挂起主线程(注意:该操作会很耗时)
|
||||
YooLogger.Warning("Suspend the main thread to load unity asset.");
|
||||
Result = _request.asset;
|
||||
}
|
||||
else
|
||||
{
|
||||
Progress = _request.progress;
|
||||
if (_request.isDone == false)
|
||||
return;
|
||||
Result = _request.asset;
|
||||
}
|
||||
}
|
||||
|
||||
if (Result == null)
|
||||
{
|
||||
string error;
|
||||
if (_assetInfo.AssetType == null)
|
||||
error = $"Failed to load asset : {_assetInfo.AssetPath} AssetType : null AssetBundle : {_packageBundle.BundleName}";
|
||||
else
|
||||
error = $"Failed to load asset : {_assetInfo.AssetPath} AssetType : {_assetInfo.AssetType} AssetBundle : {_packageBundle.BundleName}";
|
||||
YooLogger.Error(error);
|
||||
|
||||
_steps = ESteps.Done;
|
||||
Error = error;
|
||||
Status = EOperationStatus.Failed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
}
|
||||
}
|
||||
internal override void InternalWaitForAsyncComplete()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (ExecuteWhileDone())
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 88d19b84940f37a4c9814e60cfaff893
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,117 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class AssetBundleLoadSceneOperation : FSLoadSceneOperation
|
||||
{
|
||||
protected enum ESteps
|
||||
{
|
||||
None,
|
||||
LoadScene,
|
||||
CheckResult,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly AssetInfo _assetInfo;
|
||||
private readonly LoadSceneParameters _loadParams;
|
||||
private bool _suspendLoad;
|
||||
private AsyncOperation _asyncOperation;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
public AssetBundleLoadSceneOperation(AssetInfo assetInfo, LoadSceneParameters loadParams, bool suspendLoad)
|
||||
{
|
||||
_assetInfo = assetInfo;
|
||||
_loadParams = loadParams;
|
||||
_suspendLoad = suspendLoad;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
_steps = ESteps.LoadScene;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.LoadScene)
|
||||
{
|
||||
if (IsWaitForAsyncComplete)
|
||||
{
|
||||
// 注意:场景同步加载方法不会立即加载场景,而是在下一帧加载。
|
||||
Result = SceneManager.LoadScene(_assetInfo.AssetPath, _loadParams);
|
||||
_steps = ESteps.CheckResult;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 注意:如果场景不存在异步加载方法返回NULL
|
||||
// 注意:即使是异步加载也要在当帧获取到场景对象
|
||||
_asyncOperation = SceneManager.LoadSceneAsync(_assetInfo.AssetPath, _loadParams);
|
||||
if (_asyncOperation != null)
|
||||
{
|
||||
_asyncOperation.allowSceneActivation = !_suspendLoad;
|
||||
_asyncOperation.priority = 100;
|
||||
Result = SceneManager.GetSceneAt(SceneManager.sceneCount - 1);
|
||||
_steps = ESteps.CheckResult;
|
||||
}
|
||||
else
|
||||
{
|
||||
string error = $"Failed to load scene : {_assetInfo.AssetPath}";
|
||||
YooLogger.Error(error);
|
||||
_steps = ESteps.Done;
|
||||
Error = error;
|
||||
Status = EOperationStatus.Failed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.CheckResult)
|
||||
{
|
||||
if (_asyncOperation != null)
|
||||
{
|
||||
if (IsWaitForAsyncComplete)
|
||||
{
|
||||
//注意:场景加载无法强制异步转同步
|
||||
YooLogger.Error("The scene is loading asyn !");
|
||||
}
|
||||
else
|
||||
{
|
||||
// 注意:在业务层中途可以取消挂起
|
||||
if (_asyncOperation.allowSceneActivation == false)
|
||||
{
|
||||
if (_suspendLoad == false)
|
||||
_asyncOperation.allowSceneActivation = true;
|
||||
}
|
||||
|
||||
Progress = _asyncOperation.progress;
|
||||
if (_asyncOperation.isDone == false)
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (Result.IsValid())
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
string error = $"The loaded scene is invalid : {_assetInfo.AssetPath}";
|
||||
YooLogger.Error(error);
|
||||
_steps = ESteps.Done;
|
||||
Error = error;
|
||||
Status = EOperationStatus.Failed;
|
||||
}
|
||||
}
|
||||
}
|
||||
internal override void InternalWaitForAsyncComplete()
|
||||
{
|
||||
//TODO 场景加载不支持异步转同步,为了支持同步加载方法需要实现该方法!
|
||||
InternalOnUpdate();
|
||||
}
|
||||
public override void UnSuspendLoad()
|
||||
{
|
||||
_suspendLoad = false;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 797fb02af35f2414a8b4bdb937c68ae2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,121 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class AssetBundleLoadSubAssetsOperation : FSLoadSubAssetsOperation
|
||||
{
|
||||
protected enum ESteps
|
||||
{
|
||||
None,
|
||||
CheckBundle,
|
||||
LoadAsset,
|
||||
CheckResult,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly PackageBundle _packageBundle;
|
||||
private readonly AssetBundle _assetBundle;
|
||||
private readonly AssetInfo _assetInfo;
|
||||
private AssetBundleRequest _request;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
public AssetBundleLoadSubAssetsOperation(PackageBundle packageBundle, AssetBundle assetBundle, AssetInfo assetInfo)
|
||||
{
|
||||
_packageBundle = packageBundle;
|
||||
_assetBundle = assetBundle;
|
||||
_assetInfo = assetInfo;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
_steps = ESteps.CheckBundle;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.CheckBundle)
|
||||
{
|
||||
if (_assetBundle == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Error = $"The bundle {_packageBundle.BundleName} has been destroyed due to unity engine bugs !";
|
||||
Status = EOperationStatus.Failed;
|
||||
return;
|
||||
}
|
||||
|
||||
_steps = ESteps.LoadAsset;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.LoadAsset)
|
||||
{
|
||||
if (IsWaitForAsyncComplete)
|
||||
{
|
||||
if (_assetInfo.AssetType == null)
|
||||
Result = _assetBundle.LoadAssetWithSubAssets(_assetInfo.AssetPath);
|
||||
else
|
||||
Result = _assetBundle.LoadAssetWithSubAssets(_assetInfo.AssetPath, _assetInfo.AssetType);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_assetInfo.AssetType == null)
|
||||
_request = _assetBundle.LoadAssetWithSubAssetsAsync(_assetInfo.AssetPath);
|
||||
else
|
||||
_request = _assetBundle.LoadAssetWithSubAssetsAsync(_assetInfo.AssetPath, _assetInfo.AssetType);
|
||||
}
|
||||
|
||||
_steps = ESteps.CheckResult;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.CheckResult)
|
||||
{
|
||||
if (_request != null)
|
||||
{
|
||||
if (IsWaitForAsyncComplete)
|
||||
{
|
||||
// 强制挂起主线程(注意:该操作会很耗时)
|
||||
YooLogger.Warning("Suspend the main thread to load unity asset.");
|
||||
Result = _request.allAssets;
|
||||
}
|
||||
else
|
||||
{
|
||||
Progress = _request.progress;
|
||||
if (_request.isDone == false)
|
||||
return;
|
||||
Result = _request.allAssets;
|
||||
}
|
||||
}
|
||||
|
||||
if (Result == null)
|
||||
{
|
||||
string error;
|
||||
if (_assetInfo.AssetType == null)
|
||||
error = $"Failed to load sub assets : {_assetInfo.AssetPath} AssetType : null AssetBundle : {_packageBundle.BundleName}";
|
||||
else
|
||||
error = $"Failed to load sub assets : {_assetInfo.AssetPath} AssetType : {_assetInfo.AssetType} AssetBundle : {_packageBundle.BundleName}";
|
||||
YooLogger.Error(error);
|
||||
|
||||
_steps = ESteps.Done;
|
||||
Error = error;
|
||||
Status = EOperationStatus.Failed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
}
|
||||
}
|
||||
internal override void InternalWaitForAsyncComplete()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (ExecuteWhileDone())
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f0ff91311450bc44b8e9fc46637dcc4f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,48 @@
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal abstract class BundleResult
|
||||
{
|
||||
/// <summary>
|
||||
/// 卸载资源包文件
|
||||
/// </summary>
|
||||
public abstract void UnloadBundleFile();
|
||||
|
||||
/// <summary>
|
||||
/// 获取资源包文件的路径
|
||||
/// </summary>
|
||||
public abstract string GetBundleFilePath();
|
||||
|
||||
/// <summary>
|
||||
/// 读取资源包文件的二进制数据
|
||||
/// </summary>
|
||||
public abstract byte[] ReadBundleFileData();
|
||||
|
||||
/// <summary>
|
||||
/// 读取资源包文件的文本数据
|
||||
/// </summary>
|
||||
public abstract string ReadBundleFileText();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 加载资源包内的资源对象
|
||||
/// </summary>
|
||||
public abstract FSLoadAssetOperation LoadAssetAsync(AssetInfo assetInfo);
|
||||
|
||||
/// <summary>
|
||||
/// 加载资源包内的所有资源对象
|
||||
/// </summary>
|
||||
public abstract FSLoadAllAssetsOperation LoadAllAssetsAsync(AssetInfo assetInfo);
|
||||
|
||||
/// <summary>
|
||||
/// 加载资源包内的资源对象及所有子资源对象
|
||||
/// </summary>
|
||||
public abstract FSLoadSubAssetsOperation LoadSubAssetsAsync(AssetInfo assetInfo);
|
||||
|
||||
/// <summary>
|
||||
/// 加载资源包内的场景对象
|
||||
/// </summary>
|
||||
public abstract FSLoadSceneOperation LoadSceneOperation(AssetInfo assetInfo, LoadSceneParameters loadParams, bool suspendLoad);
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 773d121e67073ec44adaa843ebcb01a0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 87cc377fd18e5f948ba2b1f3e5175781
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 436e50c3a761f854d990f680fdf277ad
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,15 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class RawBundleLoadAllAssetsOperation : FSLoadAllAssetsOperation
|
||||
{
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
Error = $"{nameof(RawBundleLoadAllAssetsOperation)} not support load all assets !";
|
||||
Status = EOperationStatus.Failed;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 11c2a5a73d3ce674fbe95f014c5f17c7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,15 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class RawBundleLoadAssetOperation : FSLoadAssetOperation
|
||||
{
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
Error = $"{nameof(RawBundleLoadAssetOperation)} not support load asset !";
|
||||
Status = EOperationStatus.Failed;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f2a4519177358454695404c8af876509
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,18 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class RawBundleLoadSceneOperation : FSLoadSceneOperation
|
||||
{
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
Error = $"{nameof(RawBundleLoadSceneOperation)} not support load scene !";
|
||||
Status = EOperationStatus.Failed;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
}
|
||||
public override void UnSuspendLoad()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2e4c5d4b0b12d7045bf0c371f9efe0ce
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,15 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class RawBundleLoadSubAssetsOperation : FSLoadSubAssetsOperation
|
||||
{
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
Error = $"{nameof(RawBundleLoadSubAssetsOperation)} not support load sub assets !";
|
||||
Status = EOperationStatus.Failed;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a6227d1a6e648e04d8b2e50a456c98bb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,57 @@
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class RawBundleResult : BundleResult
|
||||
{
|
||||
private readonly IFileSystem _fileSystem;
|
||||
private readonly PackageBundle _packageBundle;
|
||||
|
||||
public RawBundleResult(IFileSystem fileSystem, PackageBundle packageBundle)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
_packageBundle = packageBundle;
|
||||
}
|
||||
|
||||
public override void UnloadBundleFile()
|
||||
{
|
||||
}
|
||||
public override string GetBundleFilePath()
|
||||
{
|
||||
return _fileSystem.GetBundleFilePath(_packageBundle);
|
||||
}
|
||||
public override byte[] ReadBundleFileData()
|
||||
{
|
||||
return _fileSystem.ReadBundleFileData(_packageBundle);
|
||||
}
|
||||
public override string ReadBundleFileText()
|
||||
{
|
||||
return _fileSystem.ReadBundleFileText(_packageBundle);
|
||||
}
|
||||
|
||||
public override FSLoadAssetOperation LoadAssetAsync(AssetInfo assetInfo)
|
||||
{
|
||||
var operation = new RawBundleLoadAssetOperation();
|
||||
OperationSystem.StartOperation(_fileSystem.PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
public override FSLoadAllAssetsOperation LoadAllAssetsAsync(AssetInfo assetInfo)
|
||||
{
|
||||
var operation = new RawBundleLoadAllAssetsOperation();
|
||||
OperationSystem.StartOperation(_fileSystem.PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
public override FSLoadSubAssetsOperation LoadSubAssetsAsync(AssetInfo assetInfo)
|
||||
{
|
||||
var operation = new RawBundleLoadSubAssetsOperation();
|
||||
OperationSystem.StartOperation(_fileSystem.PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
public override FSLoadSceneOperation LoadSceneOperation(AssetInfo assetInfo, LoadSceneParameters loadParams, bool suspendLoad)
|
||||
{
|
||||
var operation = new RawBundleLoadSceneOperation();
|
||||
OperationSystem.StartOperation(_fileSystem.PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c6e71c986d2a8c74d981deeed7b5a8ef
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2e49e0ae672b9944783571b2ad737df9
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 81e8e8c03e8b3f840aa8ffef751d5207
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,122 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class VirtualBundleLoadAllAssetsOperation : FSLoadAllAssetsOperation
|
||||
{
|
||||
protected enum ESteps
|
||||
{
|
||||
None,
|
||||
CheckBundle,
|
||||
LoadAsset,
|
||||
CheckResult,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly PackageBundle _packageBundle;
|
||||
private readonly AssetInfo _assetInfo;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
public VirtualBundleLoadAllAssetsOperation(PackageBundle packageBundle, AssetInfo assetInfo)
|
||||
{
|
||||
_packageBundle = packageBundle;
|
||||
_assetInfo = assetInfo;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
_steps = ESteps.CheckBundle;
|
||||
#else
|
||||
_steps = ESteps.Done;
|
||||
Error = $"{nameof(VirtualBundleLoadAllAssetsOperation)} only support unity editor platform !";
|
||||
Status = EOperationStatus.Failed;
|
||||
#endif
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.CheckBundle)
|
||||
{
|
||||
// 检测资源文件是否存在
|
||||
string guid = UnityEditor.AssetDatabase.AssetPathToGUID(_assetInfo.AssetPath);
|
||||
if (string.IsNullOrEmpty(guid))
|
||||
{
|
||||
string error = $"Not found asset : {_assetInfo.AssetPath}";
|
||||
YooLogger.Error(error);
|
||||
_steps = ESteps.Done;
|
||||
Error = error;
|
||||
Status = EOperationStatus.Failed;
|
||||
return;
|
||||
}
|
||||
|
||||
_steps = ESteps.LoadAsset;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.LoadAsset)
|
||||
{
|
||||
if (_assetInfo.AssetType == null)
|
||||
{
|
||||
List<UnityEngine.Object> result = new List<UnityEngine.Object>();
|
||||
foreach (var packageAsset in _packageBundle.IncludeMainAssets)
|
||||
{
|
||||
string assetPath = packageAsset.AssetPath;
|
||||
UnityEngine.Object mainAsset = UnityEditor.AssetDatabase.LoadMainAssetAtPath(assetPath);
|
||||
if (mainAsset != null)
|
||||
result.Add(mainAsset);
|
||||
}
|
||||
Result = result.ToArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
List<UnityEngine.Object> result = new List<UnityEngine.Object>();
|
||||
foreach (var packageAsset in _packageBundle.IncludeMainAssets)
|
||||
{
|
||||
string assetPath = packageAsset.AssetPath;
|
||||
UnityEngine.Object mainAsset = UnityEditor.AssetDatabase.LoadAssetAtPath(assetPath, _assetInfo.AssetType);
|
||||
if (mainAsset != null)
|
||||
result.Add(mainAsset);
|
||||
}
|
||||
Result = result.ToArray();
|
||||
}
|
||||
_steps = ESteps.CheckResult;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.CheckResult)
|
||||
{
|
||||
if (Result == null)
|
||||
{
|
||||
string error;
|
||||
if (_assetInfo.AssetType == null)
|
||||
error = $"Failed to load all assets : {_assetInfo.AssetPath} AssetType : null";
|
||||
else
|
||||
error = $"Failed to load all assets : {_assetInfo.AssetPath} AssetType : {_assetInfo.AssetType}";
|
||||
YooLogger.Error(error);
|
||||
|
||||
_steps = ESteps.Done;
|
||||
Error = error;
|
||||
Status = EOperationStatus.Failed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
internal override void InternalWaitForAsyncComplete()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (ExecuteWhileDone())
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f357dc3f2b24d0a478e4f01d4464bf8f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,101 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class VirtualBundleLoadAssetOperation : FSLoadAssetOperation
|
||||
{
|
||||
protected enum ESteps
|
||||
{
|
||||
None,
|
||||
CheckBundle,
|
||||
LoadAsset,
|
||||
CheckResult,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly PackageBundle _packageBundle;
|
||||
private readonly AssetInfo _assetInfo;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
public VirtualBundleLoadAssetOperation(PackageBundle packageBundle, AssetInfo assetInfo)
|
||||
{
|
||||
_packageBundle = packageBundle;
|
||||
_assetInfo = assetInfo;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
_steps = ESteps.CheckBundle;
|
||||
#else
|
||||
_steps = ESteps.Done;
|
||||
Error = $"{nameof(VirtualBundleLoadAssetOperation)} only support unity editor platform !";
|
||||
Status = EOperationStatus.Failed;
|
||||
#endif
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.CheckBundle)
|
||||
{
|
||||
// 检测资源文件是否存在
|
||||
string guid = UnityEditor.AssetDatabase.AssetPathToGUID(_assetInfo.AssetPath);
|
||||
if (string.IsNullOrEmpty(guid))
|
||||
{
|
||||
string error = $"Not found asset : {_assetInfo.AssetPath}";
|
||||
YooLogger.Error(error);
|
||||
_steps = ESteps.Done;
|
||||
Error = error;
|
||||
Status = EOperationStatus.Failed;
|
||||
return;
|
||||
}
|
||||
|
||||
_steps = ESteps.LoadAsset;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.LoadAsset)
|
||||
{
|
||||
if (_assetInfo.AssetType == null)
|
||||
Result = UnityEditor.AssetDatabase.LoadMainAssetAtPath(_assetInfo.AssetPath);
|
||||
else
|
||||
Result = UnityEditor.AssetDatabase.LoadAssetAtPath(_assetInfo.AssetPath, _assetInfo.AssetType);
|
||||
_steps = ESteps.CheckResult;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.CheckResult)
|
||||
{
|
||||
if (Result == null)
|
||||
{
|
||||
string error;
|
||||
if (_assetInfo.AssetType == null)
|
||||
error = $"Failed to load asset object : {_assetInfo.AssetPath} AssetType : null";
|
||||
else
|
||||
error = $"Failed to load asset object : {_assetInfo.AssetPath} AssetType : {_assetInfo.AssetType}";
|
||||
YooLogger.Error(error);
|
||||
|
||||
_steps = ESteps.Done;
|
||||
Error = error;
|
||||
Status = EOperationStatus.Failed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
internal override void InternalWaitForAsyncComplete()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (ExecuteWhileDone())
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 03615d03f7c5f1a4cb20309d7cce231d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,123 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class VirtualBundleLoadSceneOperation : FSLoadSceneOperation
|
||||
{
|
||||
protected enum ESteps
|
||||
{
|
||||
None,
|
||||
LoadScene,
|
||||
CheckResult,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly AssetInfo _assetInfo;
|
||||
private readonly LoadSceneParameters _loadParams;
|
||||
private bool _suspendLoad;
|
||||
private AsyncOperation _asyncOperation;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
public VirtualBundleLoadSceneOperation(AssetInfo assetInfo, LoadSceneParameters loadParams, bool suspendLoad)
|
||||
{
|
||||
_assetInfo = assetInfo;
|
||||
_loadParams = loadParams;
|
||||
_suspendLoad = suspendLoad;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
_steps = ESteps.LoadScene;
|
||||
#else
|
||||
_steps = ESteps.Done;
|
||||
Error = $"{nameof(VirtualBundleLoadSceneOperation)} only support unity editor platform !";
|
||||
Status = EOperationStatus.Failed;
|
||||
#endif
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.LoadScene)
|
||||
{
|
||||
if (IsWaitForAsyncComplete)
|
||||
{
|
||||
Result = UnityEditor.SceneManagement.EditorSceneManager.LoadSceneInPlayMode(_assetInfo.AssetPath, _loadParams);
|
||||
_steps = ESteps.CheckResult;
|
||||
}
|
||||
else
|
||||
{
|
||||
_asyncOperation = UnityEditor.SceneManagement.EditorSceneManager.LoadSceneAsyncInPlayMode(_assetInfo.AssetPath, _loadParams);
|
||||
if (_asyncOperation != null)
|
||||
{
|
||||
_asyncOperation.allowSceneActivation = !_suspendLoad;
|
||||
_asyncOperation.priority = 100;
|
||||
Result = SceneManager.GetSceneAt(SceneManager.sceneCount - 1);
|
||||
_steps = ESteps.CheckResult;
|
||||
}
|
||||
else
|
||||
{
|
||||
string error = $"Failed to load scene : {_assetInfo.AssetPath}";
|
||||
YooLogger.Error(error);
|
||||
_steps = ESteps.Done;
|
||||
Error = error;
|
||||
Status = EOperationStatus.Failed;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.CheckResult)
|
||||
{
|
||||
if (_asyncOperation != null)
|
||||
{
|
||||
if (IsWaitForAsyncComplete)
|
||||
{
|
||||
// 注意:场景加载无法强制异步转同步
|
||||
YooLogger.Error("The scene is loading asyn !");
|
||||
}
|
||||
else
|
||||
{
|
||||
// 注意:在业务层中途可以取消挂起
|
||||
if (_asyncOperation.allowSceneActivation == false)
|
||||
{
|
||||
if (_suspendLoad == false)
|
||||
_asyncOperation.allowSceneActivation = true;
|
||||
}
|
||||
|
||||
Progress = _asyncOperation.progress;
|
||||
if (_asyncOperation.isDone == false)
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (Result.IsValid())
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
string error = $"The loaded scene is invalid : {_assetInfo.AssetPath}";
|
||||
YooLogger.Error(error);
|
||||
_steps = ESteps.Done;
|
||||
Error = error;
|
||||
Status = EOperationStatus.Failed;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
internal override void InternalWaitForAsyncComplete()
|
||||
{
|
||||
//TODO 场景加载不支持异步转同步,为了支持同步加载方法需要实现该方法!
|
||||
InternalOnUpdate();
|
||||
}
|
||||
public override void UnSuspendLoad()
|
||||
{
|
||||
_suspendLoad = false;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8b8822604da5ad44db43c220ab019a3d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,113 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class VirtualBundleLoadSubAssetsOperation : FSLoadSubAssetsOperation
|
||||
{
|
||||
protected enum ESteps
|
||||
{
|
||||
None,
|
||||
CheckBundle,
|
||||
LoadAsset,
|
||||
CheckResult,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly PackageBundle _packageBundle;
|
||||
private readonly AssetInfo _assetInfo;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
public VirtualBundleLoadSubAssetsOperation(PackageBundle packageBundle, AssetInfo assetInfo)
|
||||
{
|
||||
_packageBundle = packageBundle;
|
||||
_assetInfo = assetInfo;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
_steps = ESteps.CheckBundle;
|
||||
#else
|
||||
_steps = ESteps.Done;
|
||||
Error = $"{nameof(VirtualBundleLoadSubAssetsOperation)} only support unity editor platform !";
|
||||
Status = EOperationStatus.Failed;
|
||||
#endif
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.CheckBundle)
|
||||
{
|
||||
// 检测资源文件是否存在
|
||||
string guid = UnityEditor.AssetDatabase.AssetPathToGUID(_assetInfo.AssetPath);
|
||||
if (string.IsNullOrEmpty(guid))
|
||||
{
|
||||
string error = $"Not found asset : {_assetInfo.AssetPath}";
|
||||
YooLogger.Error(error);
|
||||
_steps = ESteps.Done;
|
||||
Error = error;
|
||||
Status = EOperationStatus.Failed;
|
||||
return;
|
||||
}
|
||||
|
||||
_steps = ESteps.LoadAsset;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.LoadAsset)
|
||||
{
|
||||
if (_assetInfo.AssetType == null)
|
||||
{
|
||||
Result = UnityEditor.AssetDatabase.LoadAllAssetRepresentationsAtPath(_assetInfo.AssetPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
UnityEngine.Object[] findAssets = UnityEditor.AssetDatabase.LoadAllAssetRepresentationsAtPath(_assetInfo.AssetPath);
|
||||
List<UnityEngine.Object> result = new List<UnityEngine.Object>(findAssets.Length);
|
||||
foreach (var findAsset in findAssets)
|
||||
{
|
||||
if (_assetInfo.AssetType.IsAssignableFrom(findAsset.GetType()))
|
||||
result.Add(findAsset);
|
||||
}
|
||||
Result = result.ToArray();
|
||||
}
|
||||
_steps = ESteps.CheckResult;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.CheckResult)
|
||||
{
|
||||
if (Result == null)
|
||||
{
|
||||
string error;
|
||||
if (_assetInfo.AssetType == null)
|
||||
error = $"Failed to load sub assets : {_assetInfo.AssetPath} AssetType : null";
|
||||
else
|
||||
error = $"Failed to load sub assets : {_assetInfo.AssetPath} AssetType : {_assetInfo.AssetType}";
|
||||
YooLogger.Error(error);
|
||||
|
||||
_steps = ESteps.Done;
|
||||
Error = error;
|
||||
Status = EOperationStatus.Failed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
internal override void InternalWaitForAsyncComplete()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (ExecuteWhileDone())
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: afdd738603565e6499dc48e4f00ca178
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,57 @@
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class VirtualBundleResult : BundleResult
|
||||
{
|
||||
private readonly IFileSystem _fileSystem;
|
||||
private readonly PackageBundle _packageBundle;
|
||||
|
||||
public VirtualBundleResult(IFileSystem fileSystem, PackageBundle bundle)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
_packageBundle = bundle;
|
||||
}
|
||||
|
||||
public override void UnloadBundleFile()
|
||||
{
|
||||
}
|
||||
public override string GetBundleFilePath()
|
||||
{
|
||||
return _fileSystem.GetBundleFilePath(_packageBundle);
|
||||
}
|
||||
public override byte[] ReadBundleFileData()
|
||||
{
|
||||
return _fileSystem.ReadBundleFileData(_packageBundle);
|
||||
}
|
||||
public override string ReadBundleFileText()
|
||||
{
|
||||
return _fileSystem.ReadBundleFileText(_packageBundle);
|
||||
}
|
||||
|
||||
public override FSLoadAssetOperation LoadAssetAsync(AssetInfo assetInfo)
|
||||
{
|
||||
var operation = new VirtualBundleLoadAssetOperation(_packageBundle, assetInfo);
|
||||
OperationSystem.StartOperation(_fileSystem.PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
public override FSLoadAllAssetsOperation LoadAllAssetsAsync(AssetInfo assetInfo)
|
||||
{
|
||||
var operation = new VirtualBundleLoadAllAssetsOperation(_packageBundle, assetInfo);
|
||||
OperationSystem.StartOperation(_fileSystem.PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
public override FSLoadSubAssetsOperation LoadSubAssetsAsync(AssetInfo assetInfo)
|
||||
{
|
||||
var operation = new VirtualBundleLoadSubAssetsOperation(_packageBundle, assetInfo);
|
||||
OperationSystem.StartOperation(_fileSystem.PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
public override FSLoadSceneOperation LoadSceneOperation(AssetInfo assetInfo, LoadSceneParameters loadParams, bool suspendLoad)
|
||||
{
|
||||
var operation = new VirtualBundleLoadSceneOperation(assetInfo, loadParams, suspendLoad);
|
||||
OperationSystem.StartOperation(_fileSystem.PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 822bb85f05144d842977dda341174db2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user