mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
TEngine 6
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
public struct DownloadStatus
|
||||
{
|
||||
/// <summary>
|
||||
/// 下载是否已经完成
|
||||
/// </summary>
|
||||
public bool IsDone;
|
||||
|
||||
/// <summary>
|
||||
/// 下载进度(0-1f)
|
||||
/// </summary>
|
||||
public float Progress;
|
||||
|
||||
/// <summary>
|
||||
/// 下载文件的总大小
|
||||
/// </summary>
|
||||
public long TotalBytes;
|
||||
|
||||
/// <summary>
|
||||
/// 已经下载的文件大小
|
||||
/// </summary>
|
||||
public long DownloadedBytes;
|
||||
|
||||
public static DownloadStatus CreateDefaultStatus()
|
||||
{
|
||||
DownloadStatus status = new DownloadStatus();
|
||||
return status;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b7eeccc96e4c31c45bd105b0dbc3fd6e
|
||||
guid: 26dbf3c6610209e40bcf31c9c66739bc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
@@ -1,13 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
public sealed class AllAssetsHandle : HandleBase, IDisposable
|
||||
public sealed class AllAssetsHandle : HandleBase
|
||||
{
|
||||
private System.Action<AllAssetsHandle> _callback;
|
||||
|
||||
internal AllAssetsHandle(ProviderBase provider) : base(provider)
|
||||
internal AllAssetsHandle(ProviderOperation provider) : base(provider)
|
||||
{
|
||||
}
|
||||
internal override void InvokeCallback()
|
||||
@@ -47,27 +46,10 @@ namespace YooAsset
|
||||
Provider.WaitForAsyncComplete();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 释放资源句柄
|
||||
/// </summary>
|
||||
public void Release()
|
||||
{
|
||||
this.ReleaseInternal();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 释放资源句柄
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
this.ReleaseInternal();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 子资源对象集合
|
||||
/// </summary>
|
||||
public UnityEngine.Object[] AllAssetObjects
|
||||
public IReadOnlyList<UnityEngine.Object> AllAssetObjects
|
||||
{
|
||||
get
|
||||
{
|
||||
|
@@ -1,14 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
public sealed class AssetHandle : HandleBase, IDisposable
|
||||
public sealed class AssetHandle : HandleBase
|
||||
{
|
||||
private System.Action<AssetHandle> _callback;
|
||||
|
||||
internal AssetHandle(ProviderBase provider) : base(provider)
|
||||
internal AssetHandle(ProviderOperation provider) : base(provider)
|
||||
{
|
||||
}
|
||||
internal override void InvokeCallback()
|
||||
@@ -48,22 +46,6 @@ namespace YooAsset
|
||||
Provider.WaitForAsyncComplete();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 释放资源句柄
|
||||
/// </summary>
|
||||
public void Release()
|
||||
{
|
||||
this.ReleaseInternal();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 释放资源句柄
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
this.ReleaseInternal();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 资源对象
|
||||
@@ -116,25 +98,25 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 异步初始化游戏对象
|
||||
/// </summary>
|
||||
public InstantiateOperation InstantiateAsync()
|
||||
public InstantiateOperation InstantiateAsync(bool actived = true)
|
||||
{
|
||||
return InstantiateAsyncInternal(false, Vector3.zero, Quaternion.identity, null, false);
|
||||
return InstantiateAsyncInternal(false, Vector3.zero, Quaternion.identity, null, false, actived);
|
||||
}
|
||||
public InstantiateOperation InstantiateAsync(Transform parent)
|
||||
public InstantiateOperation InstantiateAsync(Transform parent, bool actived = true)
|
||||
{
|
||||
return InstantiateAsyncInternal(false, Vector3.zero, Quaternion.identity, parent, false);
|
||||
return InstantiateAsyncInternal(false, Vector3.zero, Quaternion.identity, parent, false, actived);
|
||||
}
|
||||
public InstantiateOperation InstantiateAsync(Transform parent, bool worldPositionStays)
|
||||
public InstantiateOperation InstantiateAsync(Transform parent, bool worldPositionStays, bool actived = true)
|
||||
{
|
||||
return InstantiateAsyncInternal(false, Vector3.zero, Quaternion.identity, parent, worldPositionStays);
|
||||
return InstantiateAsyncInternal(false, Vector3.zero, Quaternion.identity, parent, worldPositionStays, actived);
|
||||
}
|
||||
public InstantiateOperation InstantiateAsync(Vector3 position, Quaternion rotation)
|
||||
public InstantiateOperation InstantiateAsync(Vector3 position, Quaternion rotation, bool actived = true)
|
||||
{
|
||||
return InstantiateAsyncInternal(true, position, rotation, null, false);
|
||||
return InstantiateAsyncInternal(true, position, rotation, null, false, actived);
|
||||
}
|
||||
public InstantiateOperation InstantiateAsync(Vector3 position, Quaternion rotation, Transform parent)
|
||||
public InstantiateOperation InstantiateAsync(Vector3 position, Quaternion rotation, Transform parent, bool actived = true)
|
||||
{
|
||||
return InstantiateAsyncInternal(true, position, rotation, parent, false);
|
||||
return InstantiateAsyncInternal(true, position, rotation, parent, false, actived);
|
||||
}
|
||||
|
||||
private GameObject InstantiateSyncInternal(bool setPositionAndRotation, Vector3 position, Quaternion rotation, Transform parent, bool worldPositionStays)
|
||||
@@ -146,10 +128,10 @@ namespace YooAsset
|
||||
|
||||
return InstantiateOperation.InstantiateInternal(Provider.AssetObject, setPositionAndRotation, position, rotation, parent, worldPositionStays);
|
||||
}
|
||||
private InstantiateOperation InstantiateAsyncInternal(bool setPositionAndRotation, Vector3 position, Quaternion rotation, Transform parent, bool worldPositionStays)
|
||||
private InstantiateOperation InstantiateAsyncInternal(bool setPositionAndRotation, Vector3 position, Quaternion rotation, Transform parent, bool worldPositionStays, bool actived)
|
||||
{
|
||||
string packageName = GetAssetInfo().PackageName;
|
||||
InstantiateOperation operation = new InstantiateOperation(this, setPositionAndRotation, position, rotation, parent, worldPositionStays);
|
||||
InstantiateOperation operation = new InstantiateOperation(this, setPositionAndRotation, position, rotation, parent, worldPositionStays, actived);
|
||||
OperationSystem.StartOperation(packageName, operation);
|
||||
return operation;
|
||||
}
|
||||
|
@@ -3,18 +3,37 @@ using System.Collections;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
public abstract class HandleBase : IEnumerator
|
||||
public abstract class HandleBase : IEnumerator, IDisposable
|
||||
{
|
||||
private readonly AssetInfo _assetInfo;
|
||||
internal ProviderBase Provider { private set; get; }
|
||||
internal ProviderOperation Provider { private set; get; }
|
||||
|
||||
internal HandleBase(ProviderBase provider)
|
||||
internal HandleBase(ProviderOperation provider)
|
||||
{
|
||||
Provider = provider;
|
||||
_assetInfo = provider.MainAssetInfo;
|
||||
}
|
||||
internal abstract void InvokeCallback();
|
||||
|
||||
/// <summary>
|
||||
/// 释放资源句柄
|
||||
/// </summary>
|
||||
public void Release()
|
||||
{
|
||||
if (IsValidWithWarning == false)
|
||||
return;
|
||||
Provider.ReleaseHandle(this);
|
||||
Provider = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 释放资源句柄
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
this.Release();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取资源信息
|
||||
/// </summary>
|
||||
@@ -29,9 +48,7 @@ namespace YooAsset
|
||||
public DownloadStatus GetDownloadStatus()
|
||||
{
|
||||
if (IsValidWithWarning == false)
|
||||
{
|
||||
return DownloadStatus.CreateDefaultStatus();
|
||||
}
|
||||
return Provider.GetDownloadStatus();
|
||||
}
|
||||
|
||||
@@ -44,7 +61,6 @@ namespace YooAsset
|
||||
{
|
||||
if (IsValidWithWarning == false)
|
||||
return EOperationStatus.None;
|
||||
|
||||
return Provider.Status;
|
||||
}
|
||||
}
|
||||
@@ -83,7 +99,7 @@ namespace YooAsset
|
||||
get
|
||||
{
|
||||
if (IsValidWithWarning == false)
|
||||
return false;
|
||||
return true;
|
||||
return Provider.IsDone;
|
||||
}
|
||||
}
|
||||
@@ -124,24 +140,18 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 释放句柄
|
||||
/// </summary>
|
||||
internal void ReleaseInternal()
|
||||
{
|
||||
if (IsValidWithWarning == false)
|
||||
return;
|
||||
Provider.ReleaseHandle(this);
|
||||
Provider = null;
|
||||
}
|
||||
|
||||
#region 异步操作相关
|
||||
/// <summary>
|
||||
/// 异步操作任务
|
||||
/// </summary>
|
||||
public System.Threading.Tasks.Task Task
|
||||
{
|
||||
get { return Provider.Task; }
|
||||
get
|
||||
{
|
||||
if (IsValidWithWarning == false)
|
||||
return null;
|
||||
return Provider.Task;
|
||||
}
|
||||
}
|
||||
|
||||
// 协程相关
|
||||
|
@@ -1,14 +1,11 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
public class RawFileHandle : HandleBase, IDisposable
|
||||
public class RawFileHandle : HandleBase
|
||||
{
|
||||
private System.Action<RawFileHandle> _callback;
|
||||
|
||||
internal RawFileHandle(ProviderBase provider) : base(provider)
|
||||
internal RawFileHandle(ProviderOperation provider) : base(provider)
|
||||
{
|
||||
}
|
||||
internal override void InvokeCallback()
|
||||
@@ -48,22 +45,6 @@ namespace YooAsset
|
||||
Provider.WaitForAsyncComplete();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 释放资源句柄
|
||||
/// </summary>
|
||||
public void Release()
|
||||
{
|
||||
this.ReleaseInternal();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 释放资源句柄
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
this.ReleaseInternal();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取原生文件的二进制数据
|
||||
@@ -72,8 +53,7 @@ namespace YooAsset
|
||||
{
|
||||
if (IsValidWithWarning == false)
|
||||
return null;
|
||||
string filePath = Provider.RawFilePath;
|
||||
return FileUtility.ReadAllBytes(filePath);
|
||||
return Provider.BundleResultObject.ReadBundleFileData();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -83,8 +63,7 @@ namespace YooAsset
|
||||
{
|
||||
if (IsValidWithWarning == false)
|
||||
return null;
|
||||
string filePath = Provider.RawFilePath;
|
||||
return FileUtility.ReadAllText(filePath);
|
||||
return Provider.BundleResultObject.ReadBundleFileText();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -94,7 +73,7 @@ namespace YooAsset
|
||||
{
|
||||
if (IsValidWithWarning == false)
|
||||
return string.Empty;
|
||||
return Provider.RawFilePath;
|
||||
return Provider.BundleResultObject.GetBundleFilePath();
|
||||
}
|
||||
}
|
||||
}
|
@@ -7,7 +7,7 @@ namespace YooAsset
|
||||
private System.Action<SceneHandle> _callback;
|
||||
internal string PackageName { set; get; }
|
||||
|
||||
internal SceneHandle(ProviderBase provider) : base(provider)
|
||||
internal SceneHandle(ProviderOperation provider) : base(provider)
|
||||
{
|
||||
}
|
||||
internal override void InvokeCallback()
|
||||
@@ -23,7 +23,7 @@ namespace YooAsset
|
||||
add
|
||||
{
|
||||
if (IsValidWithWarning == false)
|
||||
throw new System.Exception($"{nameof(SceneHandle)} is invalid");
|
||||
throw new System.Exception($"{nameof(SceneHandle)} is invalid !");
|
||||
if (Provider.IsDone)
|
||||
value.Invoke(this);
|
||||
else
|
||||
@@ -32,7 +32,7 @@ namespace YooAsset
|
||||
remove
|
||||
{
|
||||
if (IsValidWithWarning == false)
|
||||
throw new System.Exception($"{nameof(SceneHandle)} is invalid");
|
||||
throw new System.Exception($"{nameof(SceneHandle)} is invalid !");
|
||||
_callback -= value;
|
||||
}
|
||||
}
|
||||
@@ -100,14 +100,9 @@ namespace YooAsset
|
||||
if (IsValidWithWarning == false)
|
||||
return false;
|
||||
|
||||
if (Provider is DatabaseSceneProvider)
|
||||
if (Provider is SceneProvider)
|
||||
{
|
||||
var provider = Provider as DatabaseSceneProvider;
|
||||
provider.UnSuspendLoad();
|
||||
}
|
||||
else if (Provider is BundledSceneProvider)
|
||||
{
|
||||
var provider = Provider as BundledSceneProvider;
|
||||
var provider = Provider as SceneProvider;
|
||||
provider.UnSuspendLoad();
|
||||
}
|
||||
else
|
||||
@@ -118,31 +113,8 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否为主场景
|
||||
/// </summary>
|
||||
public bool IsMainScene()
|
||||
{
|
||||
if (IsValidWithWarning == false)
|
||||
return false;
|
||||
|
||||
if (Provider is DatabaseSceneProvider)
|
||||
{
|
||||
var temp = Provider as DatabaseSceneProvider;
|
||||
return temp.SceneMode == LoadSceneMode.Single;
|
||||
}
|
||||
else if (Provider is BundledSceneProvider)
|
||||
{
|
||||
var temp = Provider as BundledSceneProvider;
|
||||
return temp.SceneMode == LoadSceneMode.Single;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步卸载子场景
|
||||
/// 异步卸载场景对象
|
||||
/// 注意:场景卸载成功后,会自动释放该handle的引用计数!
|
||||
/// </summary>
|
||||
public UnloadSceneOperation UnloadAsync()
|
||||
{
|
||||
@@ -157,24 +129,12 @@ namespace YooAsset
|
||||
return operation;
|
||||
}
|
||||
|
||||
// 如果是主场景
|
||||
if (IsMainScene())
|
||||
{
|
||||
string error = $"Cannot unload main scene. Use {nameof(YooAssets.LoadSceneAsync)} method to change the main scene !";
|
||||
YooLogger.Error(error);
|
||||
var operation = new UnloadSceneOperation(error);
|
||||
OperationSystem.StartOperation(packageName, operation);
|
||||
return operation;
|
||||
}
|
||||
|
||||
// 卸载子场景
|
||||
// 注意:如果场景正在加载过程,必须等待加载完成后才可以卸载该场景。
|
||||
{
|
||||
var operation = new UnloadSceneOperation(Provider);
|
||||
OperationSystem.StartOperation(packageName, operation);
|
||||
return operation;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@@ -1,13 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
public sealed class SubAssetsHandle : HandleBase, IDisposable
|
||||
public sealed class SubAssetsHandle : HandleBase
|
||||
{
|
||||
private System.Action<SubAssetsHandle> _callback;
|
||||
|
||||
internal SubAssetsHandle(ProviderBase provider) : base(provider)
|
||||
internal SubAssetsHandle(ProviderOperation provider) : base(provider)
|
||||
{
|
||||
}
|
||||
internal override void InvokeCallback()
|
||||
@@ -47,33 +46,17 @@ namespace YooAsset
|
||||
Provider.WaitForAsyncComplete();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 释放资源句柄
|
||||
/// </summary>
|
||||
public void Release()
|
||||
{
|
||||
this.ReleaseInternal();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 释放资源句柄
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
this.ReleaseInternal();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 子资源对象集合
|
||||
/// </summary>
|
||||
public UnityEngine.Object[] AllAssetObjects
|
||||
public IReadOnlyList<UnityEngine.Object> SubAssetObjects
|
||||
{
|
||||
get
|
||||
{
|
||||
if (IsValidWithWarning == false)
|
||||
return null;
|
||||
return Provider.AllAssetObjects;
|
||||
return Provider.SubAssetObjects;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,9 +70,9 @@ namespace YooAsset
|
||||
if (IsValidWithWarning == false)
|
||||
return null;
|
||||
|
||||
foreach (var assetObject in Provider.AllAssetObjects)
|
||||
foreach (var assetObject in Provider.SubAssetObjects)
|
||||
{
|
||||
if (assetObject.name == assetName)
|
||||
if (assetObject.name == assetName && assetObject is TObject)
|
||||
return assetObject as TObject;
|
||||
}
|
||||
|
||||
@@ -106,14 +89,14 @@ namespace YooAsset
|
||||
if (IsValidWithWarning == false)
|
||||
return null;
|
||||
|
||||
List<TObject> ret = new List<TObject>(Provider.AllAssetObjects.Length);
|
||||
foreach (var assetObject in Provider.AllAssetObjects)
|
||||
List<TObject> result = new List<TObject>(Provider.SubAssetObjects.Length);
|
||||
foreach (var assetObject in Provider.SubAssetObjects)
|
||||
{
|
||||
var retObject = assetObject as TObject;
|
||||
if (retObject != null)
|
||||
ret.Add(retObject);
|
||||
result.Add(retObject);
|
||||
}
|
||||
return ret.ToArray();
|
||||
return result.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,294 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal sealed class AssetBundleFileLoader : BundleLoaderBase
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None = 0,
|
||||
Download,
|
||||
CheckDownload,
|
||||
Unpack,
|
||||
CheckUnpack,
|
||||
LoadBundleFile,
|
||||
LoadDeliveryFile,
|
||||
CheckLoadFile,
|
||||
Done,
|
||||
}
|
||||
|
||||
private ESteps _steps = ESteps.None;
|
||||
private bool _isWaitForAsyncComplete = false;
|
||||
private bool _isShowWaitForAsyncError = false;
|
||||
private DownloaderBase _unpacker;
|
||||
private DownloaderBase _downloader;
|
||||
private AssetBundleCreateRequest _createRequest;
|
||||
private Stream _managedStream;
|
||||
|
||||
|
||||
public AssetBundleFileLoader(ResourceManager impl, BundleInfo bundleInfo) : base(impl, bundleInfo)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 轮询更新
|
||||
/// </summary>
|
||||
public override void Update()
|
||||
{
|
||||
if (_steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.None)
|
||||
{
|
||||
if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromRemote)
|
||||
{
|
||||
_steps = ESteps.Download;
|
||||
FileLoadPath = MainBundleInfo.CachedDataFilePath;
|
||||
}
|
||||
else if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromStreaming)
|
||||
{
|
||||
#if UNITY_ANDROID
|
||||
if (MainBundleInfo.Bundle.Encrypted)
|
||||
{
|
||||
_steps = ESteps.Unpack;
|
||||
FileLoadPath = MainBundleInfo.CachedDataFilePath;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.LoadBundleFile;
|
||||
FileLoadPath = MainBundleInfo.BuildinFilePath;
|
||||
}
|
||||
#else
|
||||
_steps = ESteps.LoadBundleFile;
|
||||
FileLoadPath = MainBundleInfo.BuildinFilePath;
|
||||
#endif
|
||||
}
|
||||
else if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromCache)
|
||||
{
|
||||
_steps = ESteps.LoadBundleFile;
|
||||
FileLoadPath = MainBundleInfo.CachedDataFilePath;
|
||||
}
|
||||
else if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromDelivery)
|
||||
{
|
||||
_steps = ESteps.LoadDeliveryFile;
|
||||
FileLoadPath = MainBundleInfo.DeliveryFilePath;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new System.NotImplementedException(MainBundleInfo.LoadMode.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
// 1. 从服务器下载
|
||||
if (_steps == ESteps.Download)
|
||||
{
|
||||
_downloader = MainBundleInfo.CreateDownloader(int.MaxValue);
|
||||
_downloader.SendRequest();
|
||||
_steps = ESteps.CheckDownload;
|
||||
}
|
||||
|
||||
// 2. 检测服务器下载结果
|
||||
if (_steps == ESteps.CheckDownload)
|
||||
{
|
||||
DownloadProgress = _downloader.DownloadProgress;
|
||||
DownloadedBytes = _downloader.DownloadedBytes;
|
||||
if (_downloader.IsDone() == false)
|
||||
return;
|
||||
|
||||
if (_downloader.HasError())
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EStatus.Failed;
|
||||
LastError = _downloader.GetLastError();
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.LoadBundleFile;
|
||||
return; //下载完毕等待一帧再去加载!
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 内置文件解压
|
||||
if (_steps == ESteps.Unpack)
|
||||
{
|
||||
int failedTryAgain = 1;
|
||||
_unpacker = MainBundleInfo.CreateUnpacker(failedTryAgain);
|
||||
_unpacker.SendRequest();
|
||||
_steps = ESteps.CheckUnpack;
|
||||
}
|
||||
|
||||
// 4.检测内置文件解压结果
|
||||
if (_steps == ESteps.CheckUnpack)
|
||||
{
|
||||
DownloadProgress = _unpacker.DownloadProgress;
|
||||
DownloadedBytes = _unpacker.DownloadedBytes;
|
||||
if (_unpacker.IsDone() == false)
|
||||
return;
|
||||
|
||||
if (_unpacker.HasError())
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EStatus.Failed;
|
||||
LastError = _unpacker.GetLastError();
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.LoadBundleFile;
|
||||
}
|
||||
}
|
||||
|
||||
// 5. 加载AssetBundle
|
||||
if (_steps == ESteps.LoadBundleFile)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
// 注意:Unity2017.4编辑器模式下,如果AssetBundle文件不存在会导致编辑器崩溃,这里做了预判。
|
||||
if (System.IO.File.Exists(FileLoadPath) == false)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EStatus.Failed;
|
||||
LastError = $"Not found assetBundle file : {FileLoadPath}";
|
||||
YooLogger.Error(LastError);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
// 设置下载进度
|
||||
DownloadProgress = 1f;
|
||||
DownloadedBytes = (ulong)MainBundleInfo.Bundle.FileSize;
|
||||
|
||||
// 加载AssetBundle资源对象
|
||||
// 注意:解密服务类可能会返回空的对象。
|
||||
if (_isWaitForAsyncComplete)
|
||||
CacheBundle = MainBundleInfo.LoadAssetBundle(FileLoadPath, out _managedStream);
|
||||
else
|
||||
_createRequest = MainBundleInfo.LoadAssetBundleAsync(FileLoadPath, out _managedStream);
|
||||
|
||||
_steps = ESteps.CheckLoadFile;
|
||||
}
|
||||
|
||||
// 6. 加载AssetBundle
|
||||
if (_steps == ESteps.LoadDeliveryFile)
|
||||
{
|
||||
// 设置下载进度
|
||||
DownloadProgress = 1f;
|
||||
DownloadedBytes = (ulong)MainBundleInfo.Bundle.FileSize;
|
||||
|
||||
// Load assetBundle file
|
||||
if (_isWaitForAsyncComplete)
|
||||
CacheBundle = MainBundleInfo.LoadDeliveryAssetBundle(FileLoadPath);
|
||||
else
|
||||
_createRequest = MainBundleInfo.LoadDeliveryAssetBundleAsync(FileLoadPath);
|
||||
|
||||
_steps = ESteps.CheckLoadFile;
|
||||
}
|
||||
|
||||
// 7. 检测AssetBundle加载结果
|
||||
if (_steps == ESteps.CheckLoadFile)
|
||||
{
|
||||
if (_createRequest != null)
|
||||
{
|
||||
if (_isWaitForAsyncComplete || IsForceDestroyComplete)
|
||||
{
|
||||
// 强制挂起主线程(注意:该操作会很耗时)
|
||||
YooLogger.Warning("Suspend the main thread to load unity bundle.");
|
||||
CacheBundle = _createRequest.assetBundle;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_createRequest.isDone == false)
|
||||
return;
|
||||
CacheBundle = _createRequest.assetBundle;
|
||||
}
|
||||
}
|
||||
|
||||
// Check error
|
||||
if (CacheBundle == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EStatus.Failed;
|
||||
LastError = $"Failed to load assetBundle : {MainBundleInfo.Bundle.BundleName}";
|
||||
YooLogger.Error(LastError);
|
||||
|
||||
// 注意:当缓存文件的校验等级为Low的时候,并不能保证缓存文件的完整性。
|
||||
// 在AssetBundle文件加载失败的情况下,我们需要重新验证文件的完整性!
|
||||
if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromCache)
|
||||
{
|
||||
var result = MainBundleInfo.VerifySelf();
|
||||
if (result != EVerifyResult.Succeed)
|
||||
{
|
||||
YooLogger.Error($"Found possibly corrupt file ! {MainBundleInfo.Bundle.CacheGUID} Verify result : {result}");
|
||||
MainBundleInfo.CacheDiscard();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EStatus.Succeed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 销毁
|
||||
/// </summary>
|
||||
public override void Destroy()
|
||||
{
|
||||
base.Destroy();
|
||||
|
||||
if (_managedStream != null)
|
||||
{
|
||||
_managedStream.Close();
|
||||
_managedStream.Dispose();
|
||||
_managedStream = null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 主线程等待异步操作完毕
|
||||
/// </summary>
|
||||
public override void WaitForAsyncComplete()
|
||||
{
|
||||
_isWaitForAsyncComplete = true;
|
||||
|
||||
int frame = 1000;
|
||||
while (true)
|
||||
{
|
||||
// 文件解压
|
||||
if (_unpacker != null)
|
||||
{
|
||||
if (_unpacker.IsDone() == false)
|
||||
{
|
||||
_unpacker.WaitForAsyncComplete = true;
|
||||
_unpacker.Update();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// 保险机制
|
||||
// 注意:如果需要从WEB端下载资源,可能会触发保险机制!
|
||||
frame--;
|
||||
if (frame == 0)
|
||||
{
|
||||
if (_isShowWaitForAsyncError == false)
|
||||
{
|
||||
_isShowWaitForAsyncError = true;
|
||||
YooLogger.Error($"{nameof(WaitForAsyncComplete)} failed ! Try load bundle : {MainBundleInfo.Bundle.BundleName} from remote with sync load method !");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// 驱动流程
|
||||
Update();
|
||||
|
||||
// 完成后退出
|
||||
if (IsDone())
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,111 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// WebGL平台加载器
|
||||
/// </summary>
|
||||
internal sealed class AssetBundleWebLoader : BundleLoaderBase
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None = 0,
|
||||
LoadWebSiteFile,
|
||||
LoadRemoteFile,
|
||||
CheckLoadFile,
|
||||
Done,
|
||||
}
|
||||
|
||||
private ESteps _steps = ESteps.None;
|
||||
private DownloaderBase _downloader;
|
||||
|
||||
|
||||
public AssetBundleWebLoader(ResourceManager impl, BundleInfo bundleInfo) : base(impl, bundleInfo)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 轮询更新
|
||||
/// </summary>
|
||||
public override void Update()
|
||||
{
|
||||
if (_steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.None)
|
||||
{
|
||||
if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromRemote)
|
||||
{
|
||||
_steps = ESteps.LoadRemoteFile;
|
||||
FileLoadPath = string.Empty;
|
||||
}
|
||||
else if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromStreaming)
|
||||
{
|
||||
_steps = ESteps.LoadWebSiteFile;
|
||||
FileLoadPath = string.Empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new System.NotImplementedException(MainBundleInfo.LoadMode.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
// 1. 跨域获取资源包
|
||||
if (_steps == ESteps.LoadRemoteFile)
|
||||
{
|
||||
_downloader = MainBundleInfo.CreateDownloader(int.MaxValue);
|
||||
_downloader.SendRequest(true);
|
||||
_steps = ESteps.CheckLoadFile;
|
||||
}
|
||||
|
||||
// 2. 从站点获取资源包
|
||||
if (_steps == ESteps.LoadWebSiteFile)
|
||||
{
|
||||
_downloader = MainBundleInfo.CreateUnpacker(int.MaxValue);
|
||||
_downloader.SendRequest(true);
|
||||
_steps = ESteps.CheckLoadFile;
|
||||
}
|
||||
|
||||
// 3. 检测加载结果
|
||||
if (_steps == ESteps.CheckLoadFile)
|
||||
{
|
||||
DownloadProgress = _downloader.DownloadProgress;
|
||||
DownloadedBytes = _downloader.DownloadedBytes;
|
||||
if (_downloader.IsDone() == false)
|
||||
return;
|
||||
|
||||
CacheBundle = _downloader.GetAssetBundle();
|
||||
if (CacheBundle == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EStatus.Failed;
|
||||
LastError = $"AssetBundle file is invalid : {MainBundleInfo.Bundle.BundleName}";
|
||||
YooLogger.Error(LastError);
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EStatus.Succeed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 主线程等待异步操作完毕
|
||||
/// </summary>
|
||||
public override void WaitForAsyncComplete()
|
||||
{
|
||||
if (IsDone() == false)
|
||||
{
|
||||
Status = EStatus.Failed;
|
||||
LastError = $"{nameof(WaitForAsyncComplete)} failed ! WebGL platform not support sync load method !";
|
||||
YooLogger.Error(LastError);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,181 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal abstract class BundleLoaderBase
|
||||
{
|
||||
public enum EStatus
|
||||
{
|
||||
None = 0,
|
||||
Succeed,
|
||||
Failed
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 所属资源系统
|
||||
/// </summary>
|
||||
public ResourceManager Impl { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 资源包文件信息
|
||||
/// </summary>
|
||||
public BundleInfo MainBundleInfo { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 引用计数
|
||||
/// </summary>
|
||||
public int RefCount { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 加载状态
|
||||
/// </summary>
|
||||
public EStatus Status { protected set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 最近的错误信息
|
||||
/// </summary>
|
||||
public string LastError { protected set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否已经销毁
|
||||
/// </summary>
|
||||
public bool IsDestroyed { private set; get; } = false;
|
||||
|
||||
private readonly List<ProviderBase> _providers = new List<ProviderBase>(100);
|
||||
private readonly List<ProviderBase> _removeList = new List<ProviderBase>(100);
|
||||
protected bool IsForceDestroyComplete { private set; get; } = false;
|
||||
internal AssetBundle CacheBundle { set; get; }
|
||||
internal string FileLoadPath { set; get; }
|
||||
internal float DownloadProgress { set; get; }
|
||||
internal ulong DownloadedBytes { set; get; }
|
||||
|
||||
|
||||
public BundleLoaderBase(ResourceManager impl, BundleInfo bundleInfo)
|
||||
{
|
||||
Impl = impl;
|
||||
MainBundleInfo = bundleInfo;
|
||||
RefCount = 0;
|
||||
Status = EStatus.None;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 引用(引用计数递加)
|
||||
/// </summary>
|
||||
public void Reference()
|
||||
{
|
||||
RefCount++;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 释放(引用计数递减)
|
||||
/// </summary>
|
||||
public void Release()
|
||||
{
|
||||
RefCount--;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否完毕(无论成功或失败)
|
||||
/// </summary>
|
||||
public bool IsDone()
|
||||
{
|
||||
return Status == EStatus.Succeed || Status == EStatus.Failed;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否可以销毁
|
||||
/// </summary>
|
||||
public bool CanDestroy()
|
||||
{
|
||||
if (IsDone() == false)
|
||||
return false;
|
||||
|
||||
return RefCount <= 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加附属的资源提供者
|
||||
/// </summary>
|
||||
public void AddProvider(ProviderBase provider)
|
||||
{
|
||||
if (_providers.Contains(provider) == false)
|
||||
_providers.Add(provider);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 尝试销毁资源提供者
|
||||
/// </summary>
|
||||
public void TryDestroyProviders()
|
||||
{
|
||||
// 获取移除列表
|
||||
_removeList.Clear();
|
||||
foreach (var provider in _providers)
|
||||
{
|
||||
if (provider.CanDestroy())
|
||||
{
|
||||
_removeList.Add(provider);
|
||||
}
|
||||
}
|
||||
|
||||
// 销毁资源提供者
|
||||
foreach (var provider in _removeList)
|
||||
{
|
||||
_providers.Remove(provider);
|
||||
provider.Destroy();
|
||||
}
|
||||
|
||||
// 移除资源提供者
|
||||
if (_removeList.Count > 0)
|
||||
{
|
||||
Impl.RemoveBundleProviders(_removeList);
|
||||
_removeList.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 轮询更新
|
||||
/// </summary>
|
||||
public abstract void Update();
|
||||
|
||||
/// <summary>
|
||||
/// 销毁
|
||||
/// </summary>
|
||||
public virtual void Destroy()
|
||||
{
|
||||
IsDestroyed = true;
|
||||
|
||||
// Check fatal
|
||||
if (RefCount > 0)
|
||||
throw new Exception($"Bundle file loader ref is not zero : {MainBundleInfo.Bundle.BundleName}");
|
||||
if (IsDone() == false)
|
||||
throw new Exception($"Bundle file loader is not done : {MainBundleInfo.Bundle.BundleName}");
|
||||
|
||||
if (CacheBundle != null)
|
||||
{
|
||||
CacheBundle.Unload(true);
|
||||
CacheBundle = null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 强制销毁资源提供者
|
||||
/// </summary>
|
||||
public void ForceDestroyComplete()
|
||||
{
|
||||
IsForceDestroyComplete = true;
|
||||
|
||||
// 注意:主动轮询更新完成同步加载
|
||||
// 说明:如果正在下载或解压也可以放心销毁。
|
||||
Update();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 主线程等待异步操作完毕
|
||||
/// </summary>
|
||||
public abstract void WaitForAsyncComplete();
|
||||
}
|
||||
}
|
@@ -1,112 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class DependAssetBundles
|
||||
{
|
||||
/// <summary>
|
||||
/// 依赖的资源包加载器列表
|
||||
/// </summary>
|
||||
internal readonly List<BundleLoaderBase> DependList;
|
||||
|
||||
|
||||
public DependAssetBundles(List<BundleLoaderBase> dpendList)
|
||||
{
|
||||
DependList = dpendList;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否已经完成(无论成功或失败)
|
||||
/// </summary>
|
||||
public bool IsDone()
|
||||
{
|
||||
foreach (var loader in DependList)
|
||||
{
|
||||
if (loader.IsDone() == false)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 依赖资源包是否全部加载成功
|
||||
/// </summary>
|
||||
public bool IsSucceed()
|
||||
{
|
||||
foreach (var loader in DependList)
|
||||
{
|
||||
if (loader.Status != BundleLoaderBase.EStatus.Succeed)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取某个加载失败的资源包错误信息
|
||||
/// </summary>
|
||||
public string GetLastError()
|
||||
{
|
||||
foreach (var loader in DependList)
|
||||
{
|
||||
if (loader.Status != BundleLoaderBase.EStatus.Succeed)
|
||||
{
|
||||
return loader.LastError;
|
||||
}
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 主线程等待异步操作完毕
|
||||
/// </summary>
|
||||
public void WaitForAsyncComplete()
|
||||
{
|
||||
foreach (var loader in DependList)
|
||||
{
|
||||
if (loader.IsDone() == false)
|
||||
loader.WaitForAsyncComplete();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 增加引用计数
|
||||
/// </summary>
|
||||
public void Reference()
|
||||
{
|
||||
foreach (var loader in DependList)
|
||||
{
|
||||
loader.Reference();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 减少引用计数
|
||||
/// </summary>
|
||||
public void Release()
|
||||
{
|
||||
foreach (var loader in DependList)
|
||||
{
|
||||
loader.Release();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取资源包的调试信息列表
|
||||
/// </summary>
|
||||
internal void GetBundleDebugInfos(List<DebugBundleInfo> output)
|
||||
{
|
||||
foreach (var loader in DependList)
|
||||
{
|
||||
var bundleInfo = new DebugBundleInfo();
|
||||
bundleInfo.BundleName = loader.MainBundleInfo.Bundle.BundleName;
|
||||
bundleInfo.RefCount = loader.RefCount;
|
||||
bundleInfo.Status = loader.Status.ToString();
|
||||
output.Add(bundleInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,188 +0,0 @@
|
||||
using System.IO;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class RawBundleFileLoader : BundleLoaderBase
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
Download,
|
||||
CheckDownload,
|
||||
Unpack,
|
||||
CheckUnpack,
|
||||
CheckFile,
|
||||
Done,
|
||||
}
|
||||
|
||||
private ESteps _steps = ESteps.None;
|
||||
private DownloaderBase _unpacker;
|
||||
private DownloaderBase _downloader;
|
||||
|
||||
|
||||
public RawBundleFileLoader(ResourceManager impl, BundleInfo bundleInfo) : base(impl, bundleInfo)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 轮询更新
|
||||
/// </summary>
|
||||
public override void Update()
|
||||
{
|
||||
if (_steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.None)
|
||||
{
|
||||
if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromRemote)
|
||||
{
|
||||
_steps = ESteps.Download;
|
||||
FileLoadPath = MainBundleInfo.CachedDataFilePath;
|
||||
}
|
||||
else if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromStreaming)
|
||||
{
|
||||
#if UNITY_ANDROID
|
||||
_steps = ESteps.Unpack;
|
||||
FileLoadPath = MainBundleInfo.CachedDataFilePath;
|
||||
#else
|
||||
_steps = ESteps.CheckFile;
|
||||
FileLoadPath = MainBundleInfo.BuildinFilePath;
|
||||
#endif
|
||||
}
|
||||
else if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromCache)
|
||||
{
|
||||
_steps = ESteps.CheckFile;
|
||||
FileLoadPath = MainBundleInfo.CachedDataFilePath;
|
||||
}
|
||||
else if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromDelivery)
|
||||
{
|
||||
_steps = ESteps.CheckFile;
|
||||
FileLoadPath = MainBundleInfo.DeliveryFilePath;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new System.NotImplementedException(MainBundleInfo.LoadMode.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
// 1. 下载远端文件
|
||||
if (_steps == ESteps.Download)
|
||||
{
|
||||
_downloader = MainBundleInfo.CreateDownloader(int.MaxValue);
|
||||
_downloader.SendRequest();
|
||||
_steps = ESteps.CheckDownload;
|
||||
}
|
||||
|
||||
// 2. 检测下载结果
|
||||
if (_steps == ESteps.CheckDownload)
|
||||
{
|
||||
DownloadProgress = _downloader.DownloadProgress;
|
||||
DownloadedBytes = _downloader.DownloadedBytes;
|
||||
if (_downloader.IsDone() == false)
|
||||
return;
|
||||
|
||||
if (_downloader.HasError())
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EStatus.Failed;
|
||||
LastError = _downloader.GetLastError();
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.CheckFile;
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 解压内置文件
|
||||
if (_steps == ESteps.Unpack)
|
||||
{
|
||||
int failedTryAgain = 1;
|
||||
_unpacker = MainBundleInfo.CreateUnpacker(failedTryAgain);
|
||||
_unpacker.SendRequest();
|
||||
_steps = ESteps.CheckUnpack;
|
||||
}
|
||||
|
||||
// 4. 检测解压结果
|
||||
if (_steps == ESteps.CheckUnpack)
|
||||
{
|
||||
DownloadProgress = _unpacker.DownloadProgress;
|
||||
DownloadedBytes = _unpacker.DownloadedBytes;
|
||||
if (_unpacker.IsDone() == false)
|
||||
return;
|
||||
|
||||
if (_unpacker.HasError())
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EStatus.Failed;
|
||||
LastError = _unpacker.GetLastError();
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.CheckFile;
|
||||
}
|
||||
}
|
||||
|
||||
// 5. 检测结果
|
||||
if (_steps == ESteps.CheckFile)
|
||||
{
|
||||
// 设置下载进度
|
||||
DownloadProgress = 1f;
|
||||
DownloadedBytes = (ulong)MainBundleInfo.Bundle.FileSize;
|
||||
|
||||
if (File.Exists(FileLoadPath))
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EStatus.Failed;
|
||||
LastError = $"Raw file not found : {FileLoadPath}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 主线程等待异步操作完毕
|
||||
/// </summary>
|
||||
public override void WaitForAsyncComplete()
|
||||
{
|
||||
int frame = 1000;
|
||||
while (true)
|
||||
{
|
||||
// 文件解压
|
||||
if (_unpacker != null)
|
||||
{
|
||||
if (_unpacker.IsDone() == false)
|
||||
{
|
||||
_unpacker.WaitForAsyncComplete = true;
|
||||
_unpacker.Update();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// 保险机制
|
||||
// 注意:如果需要从远端下载资源,可能会触发保险机制!
|
||||
frame--;
|
||||
if (frame == 0)
|
||||
{
|
||||
if (IsDone() == false)
|
||||
{
|
||||
Status = EStatus.Failed;
|
||||
LastError = $"WaitForAsyncComplete failed ! Try load bundle : {MainBundleInfo.Bundle.BundleName} from remote with sync load method !";
|
||||
YooLogger.Error(LastError);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// 驱动流程
|
||||
Update();
|
||||
|
||||
// 完成后退出
|
||||
if (IsDone())
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fa39f24727abe514093f18787c0c7e27
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,145 +0,0 @@
|
||||
using System.IO;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// WebGL平台加载器
|
||||
/// </summary>
|
||||
internal class RawBundleWebLoader : BundleLoaderBase
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
Download,
|
||||
CheckDownload,
|
||||
Website,
|
||||
CheckWebsite,
|
||||
CheckFile,
|
||||
Done,
|
||||
}
|
||||
|
||||
private ESteps _steps = ESteps.None;
|
||||
private DownloaderBase _website;
|
||||
private DownloaderBase _downloader;
|
||||
|
||||
|
||||
public RawBundleWebLoader(ResourceManager impl, BundleInfo bundleInfo) : base(impl, bundleInfo)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 轮询更新
|
||||
/// </summary>
|
||||
public override void Update()
|
||||
{
|
||||
if (_steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.None)
|
||||
{
|
||||
if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromRemote)
|
||||
{
|
||||
_steps = ESteps.Download;
|
||||
FileLoadPath = MainBundleInfo.CachedDataFilePath;
|
||||
}
|
||||
else if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromStreaming)
|
||||
{
|
||||
_steps = ESteps.Website;
|
||||
FileLoadPath = MainBundleInfo.CachedDataFilePath;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new System.NotImplementedException(MainBundleInfo.LoadMode.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
// 1. 下载远端文件
|
||||
if (_steps == ESteps.Download)
|
||||
{
|
||||
_downloader = MainBundleInfo.CreateDownloader(int.MaxValue);
|
||||
_downloader.SendRequest();
|
||||
_steps = ESteps.CheckDownload;
|
||||
}
|
||||
|
||||
// 2. 检测下载结果
|
||||
if (_steps == ESteps.CheckDownload)
|
||||
{
|
||||
DownloadProgress = _downloader.DownloadProgress;
|
||||
DownloadedBytes = _downloader.DownloadedBytes;
|
||||
if (_downloader.IsDone() == false)
|
||||
return;
|
||||
|
||||
if (_downloader.HasError())
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EStatus.Failed;
|
||||
LastError = _downloader.GetLastError();
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.CheckFile;
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 从站点下载
|
||||
if (_steps == ESteps.Website)
|
||||
{
|
||||
_website = MainBundleInfo.CreateUnpacker(int.MaxValue);
|
||||
_website.SendRequest();
|
||||
_steps = ESteps.CheckWebsite;
|
||||
}
|
||||
|
||||
// 4. 检测站点下载
|
||||
if (_steps == ESteps.CheckWebsite)
|
||||
{
|
||||
DownloadProgress = _website.DownloadProgress;
|
||||
DownloadedBytes = _website.DownloadedBytes;
|
||||
if (_website.IsDone() == false)
|
||||
return;
|
||||
|
||||
if (_website.HasError())
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EStatus.Failed;
|
||||
LastError = _website.GetLastError();
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.CheckFile;
|
||||
}
|
||||
}
|
||||
|
||||
// 5. 检测结果
|
||||
if (_steps == ESteps.CheckFile)
|
||||
{
|
||||
// 设置下载进度
|
||||
DownloadProgress = 1f;
|
||||
DownloadedBytes = (ulong)MainBundleInfo.Bundle.FileSize;
|
||||
|
||||
_steps = ESteps.Done;
|
||||
if (File.Exists(FileLoadPath))
|
||||
{
|
||||
Status = EStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
Status = EStatus.Failed;
|
||||
LastError = $"Raw file not found : {FileLoadPath}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 主线程等待异步操作完毕
|
||||
/// </summary>
|
||||
public override void WaitForAsyncComplete()
|
||||
{
|
||||
if (IsDone() == false)
|
||||
{
|
||||
Status = EStatus.Failed;
|
||||
LastError = $"{nameof(WaitForAsyncComplete)} failed ! WebGL platform not support sync load method !";
|
||||
YooLogger.Error(LastError);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1d16b689f73611e44bd01a4cc429a6ac
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,82 +0,0 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class VirtualBundleFileLoader : BundleLoaderBase
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
CheckFile,
|
||||
Done,
|
||||
}
|
||||
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
public VirtualBundleFileLoader(ResourceManager impl, BundleInfo bundleInfo) : base(impl, bundleInfo)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 轮询更新
|
||||
/// </summary>
|
||||
public override void Update()
|
||||
{
|
||||
if (_steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.None)
|
||||
{
|
||||
if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromEditor)
|
||||
{
|
||||
_steps = ESteps.CheckFile;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new System.NotImplementedException(MainBundleInfo.LoadMode.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
// 1. 检测结果
|
||||
if (_steps == ESteps.CheckFile)
|
||||
{
|
||||
// 设置下载进度
|
||||
DownloadProgress = 1f;
|
||||
DownloadedBytes = (ulong)MainBundleInfo.Bundle.FileSize;
|
||||
|
||||
_steps = ESteps.Done;
|
||||
Status = EStatus.Succeed;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 主线程等待异步操作完毕
|
||||
/// </summary>
|
||||
public override void WaitForAsyncComplete()
|
||||
{
|
||||
int frame = 1000;
|
||||
while (true)
|
||||
{
|
||||
// 保险机制
|
||||
// 注意:如果需要从远端下载资源,可能会触发保险机制!
|
||||
frame--;
|
||||
if (frame == 0)
|
||||
{
|
||||
if (IsDone() == false)
|
||||
{
|
||||
Status = EStatus.Failed;
|
||||
LastError = $"WaitForAsyncComplete failed ! Try load bundle : {MainBundleInfo.Bundle.BundleName} from remote with sync load method !";
|
||||
YooLogger.Error(LastError);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// 驱动流程
|
||||
Update();
|
||||
|
||||
// 完成后退出
|
||||
if (IsDone())
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7b9023a940b496549894d9d8872219fb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -7,7 +7,9 @@ namespace YooAsset
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
Clone,
|
||||
LoadObject,
|
||||
CloneSync,
|
||||
CloneAsync,
|
||||
Done,
|
||||
}
|
||||
|
||||
@@ -17,15 +19,21 @@ namespace YooAsset
|
||||
private readonly Quaternion _rotation;
|
||||
private readonly Transform _parent;
|
||||
private readonly bool _worldPositionStays;
|
||||
private readonly bool _actived;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
#if UNITY_2023_3_OR_NEWER
|
||||
private AsyncInstantiateOperation _instantiateAsync;
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// 实例化的游戏对象
|
||||
/// </summary>
|
||||
public GameObject Result = null;
|
||||
|
||||
|
||||
internal InstantiateOperation(AssetHandle handle, bool setPositionAndRotation, Vector3 position, Quaternion rotation, Transform parent, bool worldPositionStays)
|
||||
internal InstantiateOperation(AssetHandle handle, bool setPositionAndRotation, Vector3 position, Quaternion rotation,
|
||||
Transform parent, bool worldPositionStays, bool actived)
|
||||
{
|
||||
_handle = handle;
|
||||
_setPositionAndRotation = setPositionAndRotation;
|
||||
@@ -33,17 +41,18 @@ namespace YooAsset
|
||||
_rotation = rotation;
|
||||
_parent = parent;
|
||||
_worldPositionStays = worldPositionStays;
|
||||
_actived = actived;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
internal override void InternalStart()
|
||||
{
|
||||
_steps = ESteps.Clone;
|
||||
_steps = ESteps.LoadObject;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
internal override void InternalUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.Clone)
|
||||
if (_steps == ESteps.LoadObject)
|
||||
{
|
||||
if (_handle.IsValidWithWarning == false)
|
||||
{
|
||||
@@ -64,12 +73,88 @@ namespace YooAsset
|
||||
return;
|
||||
}
|
||||
|
||||
#if UNITY_2023_3_OR_NEWER
|
||||
//TODO 官方BUG
|
||||
// BUG环境:Windows平台,Unity2022.3.41f1版本,编辑器模式。
|
||||
// BUG描述:异步实例化Prefab预制体,有概率丢失Mono脚本里序列化的数组里某个成员!
|
||||
//_steps = ESteps.CloneAsync;
|
||||
_steps = ESteps.CloneSync;
|
||||
#else
|
||||
_steps = ESteps.CloneSync;
|
||||
#endif
|
||||
}
|
||||
|
||||
if (_steps == ESteps.CloneSync)
|
||||
{
|
||||
// 实例化游戏对象
|
||||
Result = InstantiateInternal(_handle.AssetObject, _setPositionAndRotation, _position, _rotation, _parent, _worldPositionStays);
|
||||
if (_actived == false)
|
||||
Result.SetActive(false);
|
||||
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
|
||||
#if UNITY_2023_3_OR_NEWER
|
||||
if (_steps == ESteps.CloneAsync)
|
||||
{
|
||||
if (_instantiateAsync == null)
|
||||
{
|
||||
_instantiateAsync = InstantiateAsyncInternal(_handle.AssetObject, _setPositionAndRotation, _position, _rotation, _parent, _worldPositionStays);
|
||||
}
|
||||
|
||||
if (IsWaitForAsyncComplete)
|
||||
_instantiateAsync.WaitForCompletion();
|
||||
|
||||
if (_instantiateAsync.isDone == false)
|
||||
return;
|
||||
|
||||
if (_instantiateAsync.Result != null && _instantiateAsync.Result.Length > 0)
|
||||
{
|
||||
Result = _instantiateAsync.Result[0] as GameObject;
|
||||
if (Result != null)
|
||||
{
|
||||
if (_actived == false)
|
||||
Result.SetActive(false);
|
||||
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Instantiate game object is null !";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Instantiate async results is null !";
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
internal override void InternalWaitForAsyncComplete()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
// 等待句柄完成
|
||||
if (_handle != null)
|
||||
_handle.WaitForAsyncComplete();
|
||||
|
||||
if (ExecuteWhileDone())
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
internal override string InternalGetDesc()
|
||||
{
|
||||
var assetInfo = _handle.GetAssetInfo();
|
||||
return $"AssetPath : {assetInfo.AssetPath}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -77,25 +162,17 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public void Cancel()
|
||||
{
|
||||
if (IsDone == false)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"User cancelled !";
|
||||
}
|
||||
#if UNITY_2023_3_OR_NEWER
|
||||
if (_instantiateAsync != null && _instantiateAsync.isDone == false)
|
||||
_instantiateAsync.Cancel();
|
||||
#endif
|
||||
|
||||
AbortOperation();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 等待异步实例化结束
|
||||
/// 同步实例化
|
||||
/// </summary>
|
||||
public void WaitForAsyncComplete()
|
||||
{
|
||||
if (_steps == ESteps.Done)
|
||||
return;
|
||||
_handle.WaitForAsyncComplete();
|
||||
InternalOnUpdate();
|
||||
}
|
||||
|
||||
internal static GameObject InstantiateInternal(UnityEngine.Object assetObject, bool setPositionAndRotation, Vector3 position, Quaternion rotation, Transform parent, bool worldPositionStays)
|
||||
{
|
||||
if (assetObject == null)
|
||||
@@ -104,29 +181,42 @@ namespace YooAsset
|
||||
if (setPositionAndRotation)
|
||||
{
|
||||
if (parent != null)
|
||||
{
|
||||
GameObject clone = UnityEngine.Object.Instantiate(assetObject as GameObject, position, rotation, parent);
|
||||
return clone;
|
||||
}
|
||||
return UnityEngine.Object.Instantiate(assetObject as GameObject, position, rotation, parent);
|
||||
else
|
||||
{
|
||||
GameObject clone = UnityEngine.Object.Instantiate(assetObject as GameObject, position, rotation);
|
||||
return clone;
|
||||
}
|
||||
return UnityEngine.Object.Instantiate(assetObject as GameObject, position, rotation);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (parent != null)
|
||||
{
|
||||
GameObject clone = UnityEngine.Object.Instantiate(assetObject as GameObject, parent, worldPositionStays);
|
||||
return clone;
|
||||
}
|
||||
return UnityEngine.Object.Instantiate(assetObject as GameObject, parent, worldPositionStays);
|
||||
else
|
||||
{
|
||||
GameObject clone = UnityEngine.Object.Instantiate(assetObject as GameObject);
|
||||
return clone;
|
||||
}
|
||||
return UnityEngine.Object.Instantiate(assetObject as GameObject);
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_2023_3_OR_NEWER
|
||||
/// <summary>
|
||||
/// 异步实例化
|
||||
/// 注意:Unity2022.3.20f1及以上版本生效
|
||||
/// https://docs.unity3d.com/2022.3/Documentation/ScriptReference/Object.InstantiateAsync.html
|
||||
/// </summary>
|
||||
internal static AsyncInstantiateOperation InstantiateAsyncInternal(UnityEngine.Object assetObject, bool setPositionAndRotation, Vector3 position, Quaternion rotation, Transform parent, bool worldPositionStays)
|
||||
{
|
||||
if (setPositionAndRotation)
|
||||
{
|
||||
if (parent != null)
|
||||
return UnityEngine.Object.InstantiateAsync(assetObject as GameObject, parent, position, rotation);
|
||||
else
|
||||
return UnityEngine.Object.InstantiateAsync(assetObject as GameObject, position, rotation);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (parent != null)
|
||||
return UnityEngine.Object.InstantiateAsync(assetObject as GameObject, parent);
|
||||
else
|
||||
return UnityEngine.Object.InstantiateAsync(assetObject as GameObject);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 58462a7dcef164e43878a037395d4417
|
||||
guid: dfb81dc2664ed4d4db4bd2b95caadae4
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
@@ -0,0 +1,222 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class LoadBundleFileOperation : AsyncOperationBase
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
LoadFile,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly ResourceManager _resourceManager;
|
||||
private readonly List<ProviderOperation> _providers = new List<ProviderOperation>(100);
|
||||
private readonly List<ProviderOperation> _removeList = new List<ProviderOperation>(100);
|
||||
private FSLoadBundleOperation _loadBundleOp;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
/// <summary>
|
||||
/// 资源包文件信息
|
||||
/// </summary>
|
||||
public BundleInfo LoadBundleInfo { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否已经销毁
|
||||
/// </summary>
|
||||
public bool IsDestroyed { private set; get; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// 引用计数
|
||||
/// </summary>
|
||||
public int RefCount { private set; get; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 下载进度
|
||||
/// </summary>
|
||||
public float DownloadProgress { set; get; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 下载大小
|
||||
/// </summary>
|
||||
public long DownloadedBytes { set; get; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 加载结果
|
||||
/// </summary>
|
||||
public BundleResult Result { set; get; }
|
||||
|
||||
|
||||
internal LoadBundleFileOperation(ResourceManager resourceManager, BundleInfo bundleInfo)
|
||||
{
|
||||
_resourceManager = resourceManager;
|
||||
LoadBundleInfo = bundleInfo;
|
||||
}
|
||||
internal override void InternalStart()
|
||||
{
|
||||
_steps = ESteps.LoadFile;
|
||||
}
|
||||
internal override void InternalUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.LoadFile)
|
||||
{
|
||||
if (_loadBundleOp == null)
|
||||
{
|
||||
_loadBundleOp = LoadBundleInfo.LoadBundleFile();
|
||||
_loadBundleOp.StartOperation();
|
||||
AddChildOperation(_loadBundleOp);
|
||||
}
|
||||
|
||||
if (IsWaitForAsyncComplete)
|
||||
_loadBundleOp.WaitForAsyncComplete();
|
||||
|
||||
_loadBundleOp.UpdateOperation();
|
||||
DownloadProgress = _loadBundleOp.DownloadProgress;
|
||||
DownloadedBytes = _loadBundleOp.DownloadedBytes;
|
||||
if (_loadBundleOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_loadBundleOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
if (_loadBundleOp.Result == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"The bundle loader result is null ! {LoadBundleInfo.Bundle.BundleName}";
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Result = _loadBundleOp.Result;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _loadBundleOp.Error;
|
||||
}
|
||||
}
|
||||
}
|
||||
internal override void InternalWaitForAsyncComplete()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (ExecuteWhileDone())
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
internal override string InternalGetDesc()
|
||||
{
|
||||
return $"BundleName : {LoadBundleInfo.Bundle.BundleName}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 引用(引用计数递加)
|
||||
/// </summary>
|
||||
public void Reference()
|
||||
{
|
||||
RefCount++;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 释放(引用计数递减)
|
||||
/// </summary>
|
||||
public void Release()
|
||||
{
|
||||
RefCount--;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 销毁
|
||||
/// </summary>
|
||||
public void DestroyLoader()
|
||||
{
|
||||
IsDestroyed = true;
|
||||
|
||||
// Check fatal
|
||||
if (RefCount > 0)
|
||||
throw new Exception($"Bundle file loader ref is not zero : {LoadBundleInfo.Bundle.BundleName}");
|
||||
if (IsDone == false)
|
||||
throw new Exception($"Bundle file loader is not done : {LoadBundleInfo.Bundle.BundleName}");
|
||||
|
||||
if (Result != null)
|
||||
Result.UnloadBundleFile();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否可以销毁
|
||||
/// </summary>
|
||||
public bool CanDestroyLoader()
|
||||
{
|
||||
if (IsDone == false)
|
||||
return false;
|
||||
|
||||
if (RefCount > 0)
|
||||
return false;
|
||||
|
||||
// YOOASSET_LEGACY_DEPENDENCY
|
||||
// 检查引用链上的资源包是否已经全部销毁
|
||||
// 注意:互相引用的资源包无法卸载!
|
||||
if (LoadBundleInfo.Bundle.ReferenceBundleIDs.Count > 0)
|
||||
{
|
||||
foreach (var bundleID in LoadBundleInfo.Bundle.ReferenceBundleIDs)
|
||||
{
|
||||
if (_resourceManager.CheckBundleDestroyed(bundleID) == false)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加附属的资源提供者
|
||||
/// </summary>
|
||||
public void AddProvider(ProviderOperation provider)
|
||||
{
|
||||
if (_providers.Contains(provider) == false)
|
||||
_providers.Add(provider);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 尝试销毁资源提供者
|
||||
/// </summary>
|
||||
public void TryDestroyProviders()
|
||||
{
|
||||
// 获取移除列表
|
||||
_removeList.Clear();
|
||||
foreach (var provider in _providers)
|
||||
{
|
||||
if (provider.CanDestroyProvider())
|
||||
{
|
||||
_removeList.Add(provider);
|
||||
}
|
||||
}
|
||||
|
||||
// 销毁资源提供者
|
||||
foreach (var provider in _removeList)
|
||||
{
|
||||
_providers.Remove(provider);
|
||||
provider.DestroyProvider();
|
||||
}
|
||||
|
||||
// 移除资源提供者
|
||||
if (_removeList.Count > 0)
|
||||
{
|
||||
_resourceManager.RemoveBundleProviders(_removeList);
|
||||
_removeList.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bd1ad395c62c5804589ec9b267ea0484
|
||||
guid: 031287bf937f83e4fa18a0db797abb42
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
@@ -0,0 +1,132 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
public sealed class UnloadAllAssetsOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// 释放所有资源句柄,防止卸载过程中触发完成回调!
|
||||
/// </summary>
|
||||
public bool ReleaseAllHandles = false;
|
||||
|
||||
/// <summary>
|
||||
/// 卸载过程中锁定加载操作,防止新的任务请求!
|
||||
/// </summary>
|
||||
public bool LockLoadOperation = false;
|
||||
}
|
||||
|
||||
public sealed class UnloadAllAssetsOperation : AsyncOperationBase
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
CheckOptions,
|
||||
ReleaseAll,
|
||||
AbortDownload,
|
||||
CheckLoading,
|
||||
DestroyAll,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly ResourceManager _resManager;
|
||||
private readonly UnloadAllAssetsOptions _options;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
internal UnloadAllAssetsOperation(ResourceManager resourceManager, UnloadAllAssetsOptions options)
|
||||
{
|
||||
_resManager = resourceManager;
|
||||
_options = options;
|
||||
}
|
||||
internal override void InternalStart()
|
||||
{
|
||||
_steps = ESteps.CheckOptions;
|
||||
}
|
||||
internal override void InternalUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.CheckOptions)
|
||||
{
|
||||
if (_options == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"{nameof(UnloadAllAssetsOptions)} is null.";
|
||||
return;
|
||||
}
|
||||
|
||||
// 设置锁定状态
|
||||
if (_options.LockLoadOperation)
|
||||
_resManager.LockLoadOperation = true;
|
||||
|
||||
_steps = ESteps.ReleaseAll;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.ReleaseAll)
|
||||
{
|
||||
// 清空所有场景句柄
|
||||
_resManager.SceneHandles.Clear();
|
||||
|
||||
// 释放所有资源句柄
|
||||
if (_options.ReleaseAllHandles)
|
||||
{
|
||||
foreach (var provider in _resManager.ProviderDic.Values)
|
||||
{
|
||||
provider.ReleaseAllHandles();
|
||||
}
|
||||
}
|
||||
|
||||
_steps = ESteps.AbortDownload;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.AbortDownload)
|
||||
{
|
||||
// 注意:终止所有下载任务
|
||||
foreach (var loader in _resManager.LoaderDic.Values)
|
||||
{
|
||||
loader.AbortOperation();
|
||||
}
|
||||
_steps = ESteps.CheckLoading;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.CheckLoading)
|
||||
{
|
||||
// 注意:等待所有任务完成
|
||||
foreach (var provider in _resManager.ProviderDic.Values)
|
||||
{
|
||||
if (provider.IsDone == false)
|
||||
return;
|
||||
}
|
||||
_steps = ESteps.DestroyAll;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.DestroyAll)
|
||||
{
|
||||
// 强制销毁资源提供者
|
||||
foreach (var provider in _resManager.ProviderDic.Values)
|
||||
{
|
||||
provider.DestroyProvider();
|
||||
}
|
||||
|
||||
// 强制销毁文件加载器
|
||||
foreach (var loader in _resManager.LoaderDic.Values)
|
||||
{
|
||||
loader.DestroyLoader();
|
||||
}
|
||||
|
||||
// 清空数据
|
||||
_resManager.ProviderDic.Clear();
|
||||
_resManager.LoaderDic.Clear();
|
||||
_resManager.LockLoadOperation = false;
|
||||
|
||||
// 注意:调用底层接口释放所有资源
|
||||
Resources.UnloadUnusedAssets();
|
||||
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 64d0a51f59c2a964eaf97b87db47428f
|
||||
guid: 97b5f55d30137a4438d3cbed93819c6b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
@@ -12,35 +12,29 @@ namespace YooAsset
|
||||
{
|
||||
None,
|
||||
CheckError,
|
||||
PrepareDone,
|
||||
WaitDone,
|
||||
UnLoadScene,
|
||||
Checking,
|
||||
Done,
|
||||
}
|
||||
|
||||
private ESteps _steps = ESteps.None;
|
||||
private readonly string _error;
|
||||
private readonly ProviderBase _provider;
|
||||
private AsyncOperation _asyncOp;
|
||||
private readonly ProviderOperation _provider;
|
||||
private AsyncOperation _asyncOp = null;
|
||||
|
||||
internal UnloadSceneOperation(string error)
|
||||
{
|
||||
_error = error;
|
||||
}
|
||||
internal UnloadSceneOperation(ProviderBase provider)
|
||||
internal UnloadSceneOperation(ProviderOperation provider)
|
||||
{
|
||||
_error = null;
|
||||
_provider = provider;
|
||||
|
||||
// 注意:卸载场景前必须先解除挂起操作
|
||||
if (provider is DatabaseSceneProvider)
|
||||
if (provider is SceneProvider)
|
||||
{
|
||||
var temp = provider as DatabaseSceneProvider;
|
||||
temp.UnSuspendLoad();
|
||||
}
|
||||
else if (provider is BundledSceneProvider)
|
||||
{
|
||||
var temp = provider as BundledSceneProvider;
|
||||
var temp = provider as SceneProvider;
|
||||
temp.UnSuspendLoad();
|
||||
}
|
||||
else
|
||||
@@ -48,11 +42,11 @@ namespace YooAsset
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
internal override void InternalStart()
|
||||
{
|
||||
_steps = ESteps.CheckError;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
internal override void InternalUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
@@ -67,10 +61,10 @@ namespace YooAsset
|
||||
return;
|
||||
}
|
||||
|
||||
_steps = ESteps.PrepareDone;
|
||||
_steps = ESteps.WaitDone;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.PrepareDone)
|
||||
if (_steps == ESteps.WaitDone)
|
||||
{
|
||||
if (_provider.IsDone == false)
|
||||
return;
|
||||
@@ -96,20 +90,29 @@ namespace YooAsset
|
||||
|
||||
if (_steps == ESteps.UnLoadScene)
|
||||
{
|
||||
_asyncOp = SceneManager.UnloadSceneAsync(_provider.SceneObject);
|
||||
_provider.ResourceMgr.UnloadSubScene(_provider.SceneName);
|
||||
_steps = ESteps.Checking;
|
||||
}
|
||||
if (_asyncOp == null)
|
||||
{
|
||||
_asyncOp = SceneManager.UnloadSceneAsync(_provider.SceneObject);
|
||||
if (_asyncOp == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "Unload scene failed, see the console logs !";
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.Checking)
|
||||
{
|
||||
Progress = _asyncOp.progress;
|
||||
if (_asyncOp.isDone == false)
|
||||
return;
|
||||
_provider.ResourceMgr.TryUnloadUnusedAsset(_provider.MainAssetInfo);
|
||||
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
}
|
||||
internal override string InternalGetDesc()
|
||||
{
|
||||
return $"SceneName : {_provider.SceneName}";
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,92 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
public sealed class UnloadUnusedAssetsOperation : AsyncOperationBase
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
UnloadUnused,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly ResourceManager _resManager;
|
||||
private readonly int _loopCount;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
internal UnloadUnusedAssetsOperation(ResourceManager resourceManager, int loopCount)
|
||||
{
|
||||
_resManager = resourceManager;
|
||||
_loopCount = loopCount;
|
||||
}
|
||||
internal override void InternalStart()
|
||||
{
|
||||
_steps = ESteps.UnloadUnused;
|
||||
}
|
||||
internal override void InternalUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.UnloadUnused)
|
||||
{
|
||||
for (int i = 0; i < _loopCount; i++)
|
||||
{
|
||||
LoopUnloadUnused();
|
||||
}
|
||||
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
}
|
||||
internal override void InternalWaitForAsyncComplete()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (ExecuteWhileDone())
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
internal override string InternalGetDesc()
|
||||
{
|
||||
return $"LoopCount : {_loopCount}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 说明:资源包之间会有深层的依赖链表,需要多次迭代才可以在单帧内卸载!
|
||||
/// </summary>
|
||||
private void LoopUnloadUnused()
|
||||
{
|
||||
var removeList = new List<LoadBundleFileOperation>(_resManager.LoaderDic.Count);
|
||||
|
||||
// 注意:优先销毁资源提供者
|
||||
foreach (var loader in _resManager.LoaderDic.Values)
|
||||
{
|
||||
loader.TryDestroyProviders();
|
||||
}
|
||||
|
||||
// 获取销毁列表
|
||||
foreach (var loader in _resManager.LoaderDic.Values)
|
||||
{
|
||||
if (loader.CanDestroyLoader())
|
||||
{
|
||||
removeList.Add(loader);
|
||||
}
|
||||
}
|
||||
|
||||
// 销毁文件加载器
|
||||
foreach (var loader in removeList)
|
||||
{
|
||||
string bundleName = loader.LoadBundleInfo.Bundle.BundleName;
|
||||
loader.DestroyLoader();
|
||||
_resManager.LoaderDic.Remove(bundleName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b8aaabc43e74af14d8eb3c7c85e19cda
|
||||
guid: 90a7cd6101e04ac48ae6aa383572d2c4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
@@ -0,0 +1,39 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal sealed class AllAssetsProvider : ProviderOperation
|
||||
{
|
||||
private FSLoadAllAssetsOperation _loadAllAssetsOp;
|
||||
|
||||
public AllAssetsProvider(ResourceManager manager, string providerGUID, AssetInfo assetInfo) : base(manager, providerGUID, assetInfo)
|
||||
{
|
||||
}
|
||||
protected override void ProcessBundleResult()
|
||||
{
|
||||
if (_loadAllAssetsOp == null)
|
||||
{
|
||||
_loadAllAssetsOp = BundleResultObject.LoadAllAssetsAsync(MainAssetInfo);
|
||||
_loadAllAssetsOp.StartOperation();
|
||||
AddChildOperation(_loadAllAssetsOp);
|
||||
}
|
||||
|
||||
if (IsWaitForAsyncComplete)
|
||||
_loadAllAssetsOp.WaitForAsyncComplete();
|
||||
|
||||
_loadAllAssetsOp.UpdateOperation();
|
||||
Progress = _loadAllAssetsOp.Progress;
|
||||
if (_loadAllAssetsOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_loadAllAssetsOp.Status != EOperationStatus.Succeed)
|
||||
{
|
||||
InvokeCompletion(_loadAllAssetsOp.Error, EOperationStatus.Failed);
|
||||
}
|
||||
else
|
||||
{
|
||||
AllAssetObjects = _loadAllAssetsOp.Result;
|
||||
InvokeCompletion(string.Empty, EOperationStatus.Succeed);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 33f2d909fd8d9ab4eaedcded2519d1d8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,39 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal sealed class AssetProvider : ProviderOperation
|
||||
{
|
||||
private FSLoadAssetOperation _loadAssetOp;
|
||||
|
||||
public AssetProvider(ResourceManager manager, string providerGUID, AssetInfo assetInfo) : base(manager, providerGUID, assetInfo)
|
||||
{
|
||||
}
|
||||
protected override void ProcessBundleResult()
|
||||
{
|
||||
if (_loadAssetOp == null)
|
||||
{
|
||||
_loadAssetOp = BundleResultObject.LoadAssetAsync(MainAssetInfo);
|
||||
_loadAssetOp.StartOperation();
|
||||
AddChildOperation(_loadAssetOp);
|
||||
}
|
||||
|
||||
if (IsWaitForAsyncComplete)
|
||||
_loadAssetOp.WaitForAsyncComplete();
|
||||
|
||||
_loadAssetOp.UpdateOperation();
|
||||
Progress = _loadAssetOp.Progress;
|
||||
if (_loadAssetOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_loadAssetOp.Status != EOperationStatus.Succeed)
|
||||
{
|
||||
InvokeCompletion(_loadAssetOp.Error, EOperationStatus.Failed);
|
||||
}
|
||||
else
|
||||
{
|
||||
AssetObject = _loadAssetOp.Result;
|
||||
InvokeCompletion(string.Empty, EOperationStatus.Succeed);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e6adffc18dc473141ad72e0f5da5dada
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,122 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal sealed class BundledAllAssetsProvider : ProviderBase
|
||||
{
|
||||
private AssetBundleRequest _cacheRequest;
|
||||
|
||||
public BundledAllAssetsProvider(ResourceManager manager, string providerGUID, AssetInfo assetInfo) : base(manager, providerGUID, assetInfo)
|
||||
{
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
DebugBeginRecording();
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
if (IsDone)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.None)
|
||||
{
|
||||
_steps = ESteps.CheckBundle;
|
||||
}
|
||||
|
||||
// 1. 检测资源包
|
||||
if (_steps == ESteps.CheckBundle)
|
||||
{
|
||||
if (IsWaitForAsyncComplete)
|
||||
{
|
||||
DependBundles.WaitForAsyncComplete();
|
||||
OwnerBundle.WaitForAsyncComplete();
|
||||
}
|
||||
|
||||
if (DependBundles.IsDone() == false)
|
||||
return;
|
||||
if (OwnerBundle.IsDone() == false)
|
||||
return;
|
||||
|
||||
if (DependBundles.IsSucceed() == false)
|
||||
{
|
||||
string error = DependBundles.GetLastError();
|
||||
InvokeCompletion(error, EOperationStatus.Failed);
|
||||
return;
|
||||
}
|
||||
|
||||
if (OwnerBundle.Status != BundleLoaderBase.EStatus.Succeed)
|
||||
{
|
||||
string error = OwnerBundle.LastError;
|
||||
InvokeCompletion(error, EOperationStatus.Failed);
|
||||
return;
|
||||
}
|
||||
|
||||
if (OwnerBundle.CacheBundle == null)
|
||||
{
|
||||
ProcessCacheBundleException();
|
||||
return;
|
||||
}
|
||||
|
||||
_steps = ESteps.Loading;
|
||||
}
|
||||
|
||||
// 2. 加载资源对象
|
||||
if (_steps == ESteps.Loading)
|
||||
{
|
||||
if (IsWaitForAsyncComplete || IsForceDestroyComplete)
|
||||
{
|
||||
if (MainAssetInfo.AssetType == null)
|
||||
AllAssetObjects = OwnerBundle.CacheBundle.LoadAllAssets();
|
||||
else
|
||||
AllAssetObjects = OwnerBundle.CacheBundle.LoadAllAssets(MainAssetInfo.AssetType);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (MainAssetInfo.AssetType == null)
|
||||
_cacheRequest = OwnerBundle.CacheBundle.LoadAllAssetsAsync();
|
||||
else
|
||||
_cacheRequest = OwnerBundle.CacheBundle.LoadAllAssetsAsync(MainAssetInfo.AssetType);
|
||||
}
|
||||
_steps = ESteps.Checking;
|
||||
}
|
||||
|
||||
// 3. 检测加载结果
|
||||
if (_steps == ESteps.Checking)
|
||||
{
|
||||
if (_cacheRequest != null)
|
||||
{
|
||||
if (IsWaitForAsyncComplete || IsForceDestroyComplete)
|
||||
{
|
||||
// 强制挂起主线程(注意:该操作会很耗时)
|
||||
YooLogger.Warning("Suspend the main thread to load unity asset.");
|
||||
AllAssetObjects = _cacheRequest.allAssets;
|
||||
}
|
||||
else
|
||||
{
|
||||
Progress = _cacheRequest.progress;
|
||||
if (_cacheRequest.isDone == false)
|
||||
return;
|
||||
AllAssetObjects = _cacheRequest.allAssets;
|
||||
}
|
||||
}
|
||||
|
||||
if (AllAssetObjects == null)
|
||||
{
|
||||
string error;
|
||||
if (MainAssetInfo.AssetType == null)
|
||||
error = $"Failed to load all assets : {MainAssetInfo.AssetPath} AssetType : null AssetBundle : {OwnerBundle.MainBundleInfo.Bundle.BundleName}";
|
||||
else
|
||||
error = $"Failed to load all assets : {MainAssetInfo.AssetPath} AssetType : {MainAssetInfo.AssetType} AssetBundle : {OwnerBundle.MainBundleInfo.Bundle.BundleName}";
|
||||
YooLogger.Error(error);
|
||||
InvokeCompletion(error, EOperationStatus.Failed);
|
||||
}
|
||||
else
|
||||
{
|
||||
InvokeCompletion(string.Empty, EOperationStatus.Succeed);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9b0e966838827284a9266a9f2237a460
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,122 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal sealed class BundledAssetProvider : ProviderBase
|
||||
{
|
||||
private AssetBundleRequest _cacheRequest;
|
||||
|
||||
public BundledAssetProvider(ResourceManager manager, string providerGUID, AssetInfo assetInfo) : base(manager, providerGUID, assetInfo)
|
||||
{
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
DebugBeginRecording();
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
if (IsDone)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.None)
|
||||
{
|
||||
_steps = ESteps.CheckBundle;
|
||||
}
|
||||
|
||||
// 1. 检测资源包
|
||||
if (_steps == ESteps.CheckBundle)
|
||||
{
|
||||
if (IsWaitForAsyncComplete)
|
||||
{
|
||||
DependBundles.WaitForAsyncComplete();
|
||||
OwnerBundle.WaitForAsyncComplete();
|
||||
}
|
||||
|
||||
if (DependBundles.IsDone() == false)
|
||||
return;
|
||||
if (OwnerBundle.IsDone() == false)
|
||||
return;
|
||||
|
||||
if (DependBundles.IsSucceed() == false)
|
||||
{
|
||||
string error = DependBundles.GetLastError();
|
||||
InvokeCompletion(error, EOperationStatus.Failed);
|
||||
return;
|
||||
}
|
||||
|
||||
if (OwnerBundle.Status != BundleLoaderBase.EStatus.Succeed)
|
||||
{
|
||||
string error = OwnerBundle.LastError;
|
||||
InvokeCompletion(error, EOperationStatus.Failed);
|
||||
return;
|
||||
}
|
||||
|
||||
if (OwnerBundle.CacheBundle == null)
|
||||
{
|
||||
ProcessCacheBundleException();
|
||||
return;
|
||||
}
|
||||
|
||||
_steps = ESteps.Loading;
|
||||
}
|
||||
|
||||
// 2. 加载资源对象
|
||||
if (_steps == ESteps.Loading)
|
||||
{
|
||||
if (IsWaitForAsyncComplete || IsForceDestroyComplete)
|
||||
{
|
||||
if (MainAssetInfo.AssetType == null)
|
||||
AssetObject = OwnerBundle.CacheBundle.LoadAsset(MainAssetInfo.AssetPath);
|
||||
else
|
||||
AssetObject = OwnerBundle.CacheBundle.LoadAsset(MainAssetInfo.AssetPath, MainAssetInfo.AssetType);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (MainAssetInfo.AssetType == null)
|
||||
_cacheRequest = OwnerBundle.CacheBundle.LoadAssetAsync(MainAssetInfo.AssetPath);
|
||||
else
|
||||
_cacheRequest = OwnerBundle.CacheBundle.LoadAssetAsync(MainAssetInfo.AssetPath, MainAssetInfo.AssetType);
|
||||
}
|
||||
_steps = ESteps.Checking;
|
||||
}
|
||||
|
||||
// 3. 检测加载结果
|
||||
if (_steps == ESteps.Checking)
|
||||
{
|
||||
if (_cacheRequest != null)
|
||||
{
|
||||
if (IsWaitForAsyncComplete || IsForceDestroyComplete)
|
||||
{
|
||||
// 强制挂起主线程(注意:该操作会很耗时)
|
||||
YooLogger.Warning("Suspend the main thread to load unity asset.");
|
||||
AssetObject = _cacheRequest.asset;
|
||||
}
|
||||
else
|
||||
{
|
||||
Progress = _cacheRequest.progress;
|
||||
if (_cacheRequest.isDone == false)
|
||||
return;
|
||||
AssetObject = _cacheRequest.asset;
|
||||
}
|
||||
}
|
||||
|
||||
if (AssetObject == null)
|
||||
{
|
||||
string error;
|
||||
if (MainAssetInfo.AssetType == null)
|
||||
error = $"Failed to load asset : {MainAssetInfo.AssetPath} AssetType : null AssetBundle : {OwnerBundle.MainBundleInfo.Bundle.BundleName}";
|
||||
else
|
||||
error = $"Failed to load asset : {MainAssetInfo.AssetPath} AssetType : {MainAssetInfo.AssetType} AssetBundle : {OwnerBundle.MainBundleInfo.Bundle.BundleName}";
|
||||
YooLogger.Error(error);
|
||||
InvokeCompletion(error, EOperationStatus.Failed);
|
||||
}
|
||||
else
|
||||
{
|
||||
InvokeCompletion(string.Empty, EOperationStatus.Succeed);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ca5e4bf0c3efe6742bb57b494487be52
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,52 +0,0 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class BundledRawFileProvider : ProviderBase
|
||||
{
|
||||
public BundledRawFileProvider(ResourceManager manager, string providerGUID, AssetInfo assetInfo) : base(manager, providerGUID, assetInfo)
|
||||
{
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
DebugBeginRecording();
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
if (IsDone)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.None)
|
||||
{
|
||||
_steps = ESteps.CheckBundle;
|
||||
}
|
||||
|
||||
// 1. 检测资源包
|
||||
if (_steps == ESteps.CheckBundle)
|
||||
{
|
||||
if (IsWaitForAsyncComplete)
|
||||
{
|
||||
OwnerBundle.WaitForAsyncComplete();
|
||||
}
|
||||
|
||||
if (OwnerBundle.IsDone() == false)
|
||||
return;
|
||||
|
||||
if (OwnerBundle.Status != BundleLoaderBase.EStatus.Succeed)
|
||||
{
|
||||
string error = OwnerBundle.LastError;
|
||||
InvokeCompletion(error, EOperationStatus.Failed);
|
||||
return;
|
||||
}
|
||||
|
||||
_steps = ESteps.Checking;
|
||||
}
|
||||
|
||||
// 2. 检测加载结果
|
||||
if (_steps == ESteps.Checking)
|
||||
{
|
||||
RawFilePath = OwnerBundle.FileLoadPath;
|
||||
InvokeCompletion(string.Empty, EOperationStatus.Succeed);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8a00889582fd95446b103af1074fa6ba
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,146 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal sealed class BundledSceneProvider : ProviderBase
|
||||
{
|
||||
public readonly LoadSceneMode SceneMode;
|
||||
private AsyncOperation _asyncOperation;
|
||||
private bool _suspendLoadMode;
|
||||
|
||||
public BundledSceneProvider(ResourceManager manager, string providerGUID, AssetInfo assetInfo, LoadSceneMode sceneMode, bool suspendLoad) : base(manager, providerGUID, assetInfo)
|
||||
{
|
||||
SceneMode = sceneMode;
|
||||
SceneName = Path.GetFileNameWithoutExtension(assetInfo.AssetPath);
|
||||
_suspendLoadMode = suspendLoad;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
DebugBeginRecording();
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
if (IsDone)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.None)
|
||||
{
|
||||
_steps = ESteps.CheckBundle;
|
||||
}
|
||||
|
||||
// 1. 检测资源包
|
||||
if (_steps == ESteps.CheckBundle)
|
||||
{
|
||||
if (IsWaitForAsyncComplete)
|
||||
{
|
||||
DependBundles.WaitForAsyncComplete();
|
||||
OwnerBundle.WaitForAsyncComplete();
|
||||
}
|
||||
|
||||
if (DependBundles.IsDone() == false)
|
||||
return;
|
||||
if (OwnerBundle.IsDone() == false)
|
||||
return;
|
||||
|
||||
if (DependBundles.IsSucceed() == false)
|
||||
{
|
||||
string error = DependBundles.GetLastError();
|
||||
InvokeCompletion(error, EOperationStatus.Failed);
|
||||
return;
|
||||
}
|
||||
|
||||
if (OwnerBundle.Status != BundleLoaderBase.EStatus.Succeed)
|
||||
{
|
||||
string error = OwnerBundle.LastError;
|
||||
InvokeCompletion(error, EOperationStatus.Failed);
|
||||
return;
|
||||
}
|
||||
|
||||
_steps = ESteps.Loading;
|
||||
}
|
||||
|
||||
// 2. 加载场景
|
||||
if (_steps == ESteps.Loading)
|
||||
{
|
||||
if (IsWaitForAsyncComplete || IsForceDestroyComplete)
|
||||
{
|
||||
// 注意:场景同步加载方法不会立即加载场景,而是在下一帧加载。
|
||||
LoadSceneParameters parameters = new LoadSceneParameters(SceneMode);
|
||||
SceneObject = SceneManager.LoadScene(MainAssetInfo.AssetPath, parameters);
|
||||
_steps = ESteps.Checking;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 注意:如果场景不存在异步加载方法返回NULL
|
||||
// 注意:即使是异步加载也要在当帧获取到场景对象
|
||||
_asyncOperation = SceneManager.LoadSceneAsync(MainAssetInfo.AssetPath, SceneMode);
|
||||
if (_asyncOperation != null)
|
||||
{
|
||||
_asyncOperation.allowSceneActivation = !_suspendLoadMode;
|
||||
_asyncOperation.priority = 100;
|
||||
SceneObject = SceneManager.GetSceneAt(SceneManager.sceneCount - 1);
|
||||
_steps = ESteps.Checking;
|
||||
}
|
||||
else
|
||||
{
|
||||
string error = $"Failed to load scene : {MainAssetInfo.AssetPath}";
|
||||
YooLogger.Error(error);
|
||||
InvokeCompletion(error, EOperationStatus.Failed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 检测加载结果
|
||||
if (_steps == ESteps.Checking)
|
||||
{
|
||||
if (_asyncOperation != null)
|
||||
{
|
||||
if (IsWaitForAsyncComplete || IsForceDestroyComplete)
|
||||
{
|
||||
// 场景加载无法强制异步转同步
|
||||
YooLogger.Error("The scene is loading asyn !");
|
||||
}
|
||||
else
|
||||
{
|
||||
// 注意:在业务层中途可以取消挂起
|
||||
if (_asyncOperation.allowSceneActivation == false)
|
||||
{
|
||||
if (_suspendLoadMode == false)
|
||||
_asyncOperation.allowSceneActivation = true;
|
||||
}
|
||||
|
||||
Progress = _asyncOperation.progress;
|
||||
if (_asyncOperation.isDone == false)
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (SceneObject.IsValid())
|
||||
{
|
||||
InvokeCompletion(string.Empty, EOperationStatus.Succeed);
|
||||
}
|
||||
else
|
||||
{
|
||||
string error = $"The loaded scene is invalid : {MainAssetInfo.AssetPath}";
|
||||
YooLogger.Error(error);
|
||||
InvokeCompletion(error, EOperationStatus.Failed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解除场景加载挂起操作
|
||||
/// </summary>
|
||||
public void UnSuspendLoad()
|
||||
{
|
||||
if (IsDone == false)
|
||||
{
|
||||
_suspendLoadMode = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 38b1b77cff590ca4e808c5068c9bf88b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,122 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal sealed class BundledSubAssetsProvider : ProviderBase
|
||||
{
|
||||
private AssetBundleRequest _cacheRequest;
|
||||
|
||||
public BundledSubAssetsProvider(ResourceManager manager, string providerGUID, AssetInfo assetInfo) : base(manager, providerGUID, assetInfo)
|
||||
{
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
DebugBeginRecording();
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
if (IsDone)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.None)
|
||||
{
|
||||
_steps = ESteps.CheckBundle;
|
||||
}
|
||||
|
||||
// 1. 检测资源包
|
||||
if (_steps == ESteps.CheckBundle)
|
||||
{
|
||||
if (IsWaitForAsyncComplete)
|
||||
{
|
||||
DependBundles.WaitForAsyncComplete();
|
||||
OwnerBundle.WaitForAsyncComplete();
|
||||
}
|
||||
|
||||
if (DependBundles.IsDone() == false)
|
||||
return;
|
||||
if (OwnerBundle.IsDone() == false)
|
||||
return;
|
||||
|
||||
if (DependBundles.IsSucceed() == false)
|
||||
{
|
||||
string error = DependBundles.GetLastError();
|
||||
InvokeCompletion(error, EOperationStatus.Failed);
|
||||
return;
|
||||
}
|
||||
|
||||
if (OwnerBundle.Status != BundleLoaderBase.EStatus.Succeed)
|
||||
{
|
||||
string error = OwnerBundle.LastError;
|
||||
InvokeCompletion(error, EOperationStatus.Failed);
|
||||
return;
|
||||
}
|
||||
|
||||
if (OwnerBundle.CacheBundle == null)
|
||||
{
|
||||
ProcessCacheBundleException();
|
||||
return;
|
||||
}
|
||||
|
||||
_steps = ESteps.Loading;
|
||||
}
|
||||
|
||||
// 2. 加载资源对象
|
||||
if (_steps == ESteps.Loading)
|
||||
{
|
||||
if (IsWaitForAsyncComplete || IsForceDestroyComplete)
|
||||
{
|
||||
if (MainAssetInfo.AssetType == null)
|
||||
AllAssetObjects = OwnerBundle.CacheBundle.LoadAssetWithSubAssets(MainAssetInfo.AssetPath);
|
||||
else
|
||||
AllAssetObjects = OwnerBundle.CacheBundle.LoadAssetWithSubAssets(MainAssetInfo.AssetPath, MainAssetInfo.AssetType);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (MainAssetInfo.AssetType == null)
|
||||
_cacheRequest = OwnerBundle.CacheBundle.LoadAssetWithSubAssetsAsync(MainAssetInfo.AssetPath);
|
||||
else
|
||||
_cacheRequest = OwnerBundle.CacheBundle.LoadAssetWithSubAssetsAsync(MainAssetInfo.AssetPath, MainAssetInfo.AssetType);
|
||||
}
|
||||
_steps = ESteps.Checking;
|
||||
}
|
||||
|
||||
// 3. 检测加载结果
|
||||
if (_steps == ESteps.Checking)
|
||||
{
|
||||
if (_cacheRequest != null)
|
||||
{
|
||||
if (IsWaitForAsyncComplete || IsForceDestroyComplete)
|
||||
{
|
||||
// 强制挂起主线程(注意:该操作会很耗时)
|
||||
YooLogger.Warning("Suspend the main thread to load unity asset.");
|
||||
AllAssetObjects = _cacheRequest.allAssets;
|
||||
}
|
||||
else
|
||||
{
|
||||
Progress = _cacheRequest.progress;
|
||||
if (_cacheRequest.isDone == false)
|
||||
return;
|
||||
AllAssetObjects = _cacheRequest.allAssets;
|
||||
}
|
||||
}
|
||||
|
||||
if (AllAssetObjects == null)
|
||||
{
|
||||
string error;
|
||||
if (MainAssetInfo.AssetType == null)
|
||||
error = $"Failed to load sub assets : {MainAssetInfo.AssetPath} AssetType : null AssetBundle : {OwnerBundle.MainBundleInfo.Bundle.BundleName}";
|
||||
else
|
||||
error = $"Failed to load sub assets : {MainAssetInfo.AssetPath} AssetType : {MainAssetInfo.AssetType} AssetBundle : {OwnerBundle.MainBundleInfo.Bundle.BundleName}";
|
||||
YooLogger.Error(error);
|
||||
InvokeCompletion(error, EOperationStatus.Failed);
|
||||
}
|
||||
else
|
||||
{
|
||||
InvokeCompletion(string.Empty, EOperationStatus.Succeed);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b3763bf52bde23b41a756f0d015cb30d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,25 +1,18 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal sealed class CompletedProvider : ProviderBase
|
||||
internal sealed class CompletedProvider : ProviderOperation
|
||||
{
|
||||
public CompletedProvider(AssetInfo assetInfo) : base(null, string.Empty, assetInfo)
|
||||
public CompletedProvider(ResourceManager manager, AssetInfo assetInfo) : base(manager, string.Empty, assetInfo)
|
||||
{
|
||||
}
|
||||
protected override void ProcessBundleResult()
|
||||
{
|
||||
}
|
||||
|
||||
internal override void InternalOnStart()
|
||||
public void SetCompletedWithError(string error)
|
||||
{
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
}
|
||||
|
||||
public void SetCompleted(string error)
|
||||
{
|
||||
if (_steps == ESteps.None)
|
||||
{
|
||||
InvokeCompletion(error, EOperationStatus.Failed);
|
||||
}
|
||||
InvokeCompletion(error, EOperationStatus.Failed);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,111 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal sealed class DatabaseAllAssetsProvider : ProviderBase
|
||||
{
|
||||
public DatabaseAllAssetsProvider(ResourceManager manager, string providerGUID, AssetInfo assetInfo) : base(manager, providerGUID, assetInfo)
|
||||
{
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
DebugBeginRecording();
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (IsDone)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.None)
|
||||
{
|
||||
// 检测资源文件是否存在
|
||||
string guid = UnityEditor.AssetDatabase.AssetPathToGUID(MainAssetInfo.AssetPath);
|
||||
if (string.IsNullOrEmpty(guid))
|
||||
{
|
||||
string error = $"Not found asset : {MainAssetInfo.AssetPath}";
|
||||
YooLogger.Error(error);
|
||||
InvokeCompletion(error, EOperationStatus.Failed);
|
||||
return;
|
||||
}
|
||||
|
||||
_steps = ESteps.CheckBundle;
|
||||
|
||||
// 注意:模拟异步加载效果提前返回
|
||||
if (IsWaitForAsyncComplete == false)
|
||||
return;
|
||||
}
|
||||
|
||||
// 1. 检测资源包
|
||||
if (_steps == ESteps.CheckBundle)
|
||||
{
|
||||
if (IsWaitForAsyncComplete)
|
||||
{
|
||||
OwnerBundle.WaitForAsyncComplete();
|
||||
}
|
||||
|
||||
if (OwnerBundle.IsDone() == false)
|
||||
return;
|
||||
|
||||
if (OwnerBundle.Status != BundleLoaderBase.EStatus.Succeed)
|
||||
{
|
||||
string error = OwnerBundle.LastError;
|
||||
InvokeCompletion(error, EOperationStatus.Failed);
|
||||
return;
|
||||
}
|
||||
|
||||
_steps = ESteps.Loading;
|
||||
}
|
||||
|
||||
// 2. 加载资源对象
|
||||
if (_steps == ESteps.Loading)
|
||||
{
|
||||
if (MainAssetInfo.AssetType == null)
|
||||
{
|
||||
List<UnityEngine.Object> result = new List<Object>();
|
||||
foreach (var assetPath in OwnerBundle.MainBundleInfo.IncludeAssetsInEditor)
|
||||
{
|
||||
UnityEngine.Object mainAsset = UnityEditor.AssetDatabase.LoadMainAssetAtPath(assetPath);
|
||||
if (mainAsset != null)
|
||||
result.Add(mainAsset);
|
||||
}
|
||||
AllAssetObjects = result.ToArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
List<UnityEngine.Object> result = new List<Object>();
|
||||
foreach (var assetPath in OwnerBundle.MainBundleInfo.IncludeAssetsInEditor)
|
||||
{
|
||||
UnityEngine.Object mainAsset = UnityEditor.AssetDatabase.LoadAssetAtPath(assetPath, MainAssetInfo.AssetType);
|
||||
if (mainAsset != null)
|
||||
result.Add(mainAsset);
|
||||
}
|
||||
AllAssetObjects = result.ToArray();
|
||||
}
|
||||
_steps = ESteps.Checking;
|
||||
}
|
||||
|
||||
// 3. 检测加载结果
|
||||
if (_steps == ESteps.Checking)
|
||||
{
|
||||
if (AllAssetObjects == null)
|
||||
{
|
||||
string error;
|
||||
if (MainAssetInfo.AssetType == null)
|
||||
error = $"Failed to load all assets : {MainAssetInfo.AssetPath} AssetType : null";
|
||||
else
|
||||
error = $"Failed to load all assets : {MainAssetInfo.AssetPath} AssetType : {MainAssetInfo.AssetType}";
|
||||
YooLogger.Error(error);
|
||||
InvokeCompletion(error, EOperationStatus.Failed);
|
||||
}
|
||||
else
|
||||
{
|
||||
InvokeCompletion(string.Empty, EOperationStatus.Succeed);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c72eb6001f903de46bc72dea0d8b39c5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,93 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal sealed class DatabaseAssetProvider : ProviderBase
|
||||
{
|
||||
public DatabaseAssetProvider(ResourceManager manager, string providerGUID, AssetInfo assetInfo) : base(manager, providerGUID, assetInfo)
|
||||
{
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
DebugBeginRecording();
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (IsDone)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.None)
|
||||
{
|
||||
// 检测资源文件是否存在
|
||||
string guid = UnityEditor.AssetDatabase.AssetPathToGUID(MainAssetInfo.AssetPath);
|
||||
if (string.IsNullOrEmpty(guid))
|
||||
{
|
||||
string error = $"Not found asset : {MainAssetInfo.AssetPath}";
|
||||
YooLogger.Error(error);
|
||||
InvokeCompletion(error, EOperationStatus.Failed);
|
||||
return;
|
||||
}
|
||||
|
||||
_steps = ESteps.CheckBundle;
|
||||
|
||||
// 注意:模拟异步加载效果提前返回
|
||||
if (IsWaitForAsyncComplete == false)
|
||||
return;
|
||||
}
|
||||
|
||||
// 1. 检测资源包
|
||||
if (_steps == ESteps.CheckBundle)
|
||||
{
|
||||
if (IsWaitForAsyncComplete)
|
||||
{
|
||||
OwnerBundle.WaitForAsyncComplete();
|
||||
}
|
||||
|
||||
if (OwnerBundle.IsDone() == false)
|
||||
return;
|
||||
|
||||
if (OwnerBundle.Status != BundleLoaderBase.EStatus.Succeed)
|
||||
{
|
||||
string error = OwnerBundle.LastError;
|
||||
InvokeCompletion(error, EOperationStatus.Failed);
|
||||
return;
|
||||
}
|
||||
|
||||
_steps = ESteps.Loading;
|
||||
}
|
||||
|
||||
// 2. 加载资源对象
|
||||
if (_steps == ESteps.Loading)
|
||||
{
|
||||
if (MainAssetInfo.AssetType == null)
|
||||
AssetObject = UnityEditor.AssetDatabase.LoadMainAssetAtPath(MainAssetInfo.AssetPath);
|
||||
else
|
||||
AssetObject = UnityEditor.AssetDatabase.LoadAssetAtPath(MainAssetInfo.AssetPath, MainAssetInfo.AssetType);
|
||||
_steps = ESteps.Checking;
|
||||
}
|
||||
|
||||
// 3. 检测加载结果
|
||||
if (_steps == ESteps.Checking)
|
||||
{
|
||||
if (AssetObject == null)
|
||||
{
|
||||
string error;
|
||||
if (MainAssetInfo.AssetType == null)
|
||||
error = $"Failed to load asset object : {MainAssetInfo.AssetPath} AssetType : null";
|
||||
else
|
||||
error = $"Failed to load asset object : {MainAssetInfo.AssetPath} AssetType : {MainAssetInfo.AssetType}";
|
||||
YooLogger.Error(error);
|
||||
InvokeCompletion(error, EOperationStatus.Failed);
|
||||
}
|
||||
else
|
||||
{
|
||||
InvokeCompletion(string.Empty, EOperationStatus.Succeed);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d4022dd2ea39af5458fb1d61ec997347
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,68 +0,0 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class DatabaseRawFileProvider : ProviderBase
|
||||
{
|
||||
public DatabaseRawFileProvider(ResourceManager manager, string providerGUID, AssetInfo assetInfo) : base(manager, providerGUID, assetInfo)
|
||||
{
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
DebugBeginRecording();
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (IsDone)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.None)
|
||||
{
|
||||
// 检测资源文件是否存在
|
||||
string guid = UnityEditor.AssetDatabase.AssetPathToGUID(MainAssetInfo.AssetPath);
|
||||
if (string.IsNullOrEmpty(guid))
|
||||
{
|
||||
string error = $"Not found asset : {MainAssetInfo.AssetPath}";
|
||||
YooLogger.Error(error);
|
||||
InvokeCompletion(error, EOperationStatus.Failed);
|
||||
return;
|
||||
}
|
||||
|
||||
_steps = ESteps.CheckBundle;
|
||||
|
||||
// 注意:模拟异步加载效果提前返回
|
||||
if (IsWaitForAsyncComplete == false)
|
||||
return;
|
||||
}
|
||||
|
||||
// 1. 检测资源包
|
||||
if (_steps == ESteps.CheckBundle)
|
||||
{
|
||||
if (IsWaitForAsyncComplete)
|
||||
{
|
||||
OwnerBundle.WaitForAsyncComplete();
|
||||
}
|
||||
|
||||
if (OwnerBundle.IsDone() == false)
|
||||
return;
|
||||
|
||||
if (OwnerBundle.Status != BundleLoaderBase.EStatus.Succeed)
|
||||
{
|
||||
string error = OwnerBundle.LastError;
|
||||
InvokeCompletion(error, EOperationStatus.Failed);
|
||||
return;
|
||||
}
|
||||
|
||||
_steps = ESteps.Checking;
|
||||
}
|
||||
|
||||
// 2. 检测加载结果
|
||||
if (_steps == ESteps.Checking)
|
||||
{
|
||||
RawFilePath = MainAssetInfo.AssetPath;
|
||||
InvokeCompletion(string.Empty, EOperationStatus.Succeed);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 41d0e9bbc5a3a5b4e8b05d60d40d495a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,136 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal sealed class DatabaseSceneProvider : ProviderBase
|
||||
{
|
||||
public readonly LoadSceneMode SceneMode;
|
||||
private bool _suspendLoadMode;
|
||||
private AsyncOperation _asyncOperation;
|
||||
|
||||
public DatabaseSceneProvider(ResourceManager manager, string providerGUID, AssetInfo assetInfo, LoadSceneMode sceneMode, bool suspendLoad) : base(manager, providerGUID, assetInfo)
|
||||
{
|
||||
SceneMode = sceneMode;
|
||||
SceneName = Path.GetFileNameWithoutExtension(assetInfo.AssetPath);
|
||||
_suspendLoadMode = suspendLoad;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
DebugBeginRecording();
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (IsDone)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.None)
|
||||
{
|
||||
_steps = ESteps.CheckBundle;
|
||||
}
|
||||
|
||||
// 1. 检测资源包
|
||||
if (_steps == ESteps.CheckBundle)
|
||||
{
|
||||
if (IsWaitForAsyncComplete)
|
||||
{
|
||||
OwnerBundle.WaitForAsyncComplete();
|
||||
}
|
||||
|
||||
if (OwnerBundle.IsDone() == false)
|
||||
return;
|
||||
|
||||
if (OwnerBundle.Status != BundleLoaderBase.EStatus.Succeed)
|
||||
{
|
||||
string error = OwnerBundle.LastError;
|
||||
InvokeCompletion(error, EOperationStatus.Failed);
|
||||
return;
|
||||
}
|
||||
|
||||
_steps = ESteps.Loading;
|
||||
}
|
||||
|
||||
// 2. 加载资源对象
|
||||
if (_steps == ESteps.Loading)
|
||||
{
|
||||
if (IsWaitForAsyncComplete || IsForceDestroyComplete)
|
||||
{
|
||||
LoadSceneParameters loadSceneParameters = new LoadSceneParameters(SceneMode);
|
||||
SceneObject = UnityEditor.SceneManagement.EditorSceneManager.LoadSceneInPlayMode(MainAssetInfo.AssetPath, loadSceneParameters);
|
||||
_steps = ESteps.Checking;
|
||||
}
|
||||
else
|
||||
{
|
||||
LoadSceneParameters loadSceneParameters = new LoadSceneParameters(SceneMode);
|
||||
_asyncOperation = UnityEditor.SceneManagement.EditorSceneManager.LoadSceneAsyncInPlayMode(MainAssetInfo.AssetPath, loadSceneParameters);
|
||||
if (_asyncOperation != null)
|
||||
{
|
||||
_asyncOperation.allowSceneActivation = !_suspendLoadMode;
|
||||
_asyncOperation.priority = 100;
|
||||
SceneObject = SceneManager.GetSceneAt(SceneManager.sceneCount - 1);
|
||||
_steps = ESteps.Checking;
|
||||
}
|
||||
else
|
||||
{
|
||||
string error = $"Failed to load scene : {MainAssetInfo.AssetPath}";
|
||||
YooLogger.Error(error);
|
||||
InvokeCompletion(error, EOperationStatus.Failed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 检测加载结果
|
||||
if (_steps == ESteps.Checking)
|
||||
{
|
||||
if (_asyncOperation != null)
|
||||
{
|
||||
if (IsWaitForAsyncComplete || IsForceDestroyComplete)
|
||||
{
|
||||
// 场景加载无法强制异步转同步
|
||||
YooLogger.Error("The scene is loading asyn !");
|
||||
}
|
||||
else
|
||||
{
|
||||
// 注意:在业务层中途可以取消挂起
|
||||
if (_asyncOperation.allowSceneActivation == false)
|
||||
{
|
||||
if (_suspendLoadMode == false)
|
||||
_asyncOperation.allowSceneActivation = true;
|
||||
}
|
||||
|
||||
Progress = _asyncOperation.progress;
|
||||
if (_asyncOperation.isDone == false)
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (SceneObject.IsValid())
|
||||
{
|
||||
InvokeCompletion(string.Empty, EOperationStatus.Succeed);
|
||||
}
|
||||
else
|
||||
{
|
||||
string error = $"The loaded scene is invalid : {MainAssetInfo.AssetPath}";
|
||||
YooLogger.Error(error);
|
||||
InvokeCompletion(error, EOperationStatus.Failed);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解除场景加载挂起操作
|
||||
/// </summary>
|
||||
public void UnSuspendLoad()
|
||||
{
|
||||
if (IsDone == false)
|
||||
{
|
||||
_suspendLoadMode = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8252a639423064f498ed22f14912adae
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,104 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal sealed class DatabaseSubAssetsProvider : ProviderBase
|
||||
{
|
||||
public DatabaseSubAssetsProvider(ResourceManager manager, string providerGUID, AssetInfo assetInfo) : base(manager, providerGUID, assetInfo)
|
||||
{
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
DebugBeginRecording();
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (IsDone)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.None)
|
||||
{
|
||||
// 检测资源文件是否存在
|
||||
string guid = UnityEditor.AssetDatabase.AssetPathToGUID(MainAssetInfo.AssetPath);
|
||||
if (string.IsNullOrEmpty(guid))
|
||||
{
|
||||
string error = $"Not found asset : {MainAssetInfo.AssetPath}";
|
||||
YooLogger.Error(error);
|
||||
InvokeCompletion(error, EOperationStatus.Failed);
|
||||
return;
|
||||
}
|
||||
|
||||
_steps = ESteps.CheckBundle;
|
||||
|
||||
// 注意:模拟异步加载效果提前返回
|
||||
if (IsWaitForAsyncComplete == false)
|
||||
return;
|
||||
}
|
||||
|
||||
// 1. 检测资源包
|
||||
if (_steps == ESteps.CheckBundle)
|
||||
{
|
||||
if (IsWaitForAsyncComplete)
|
||||
{
|
||||
OwnerBundle.WaitForAsyncComplete();
|
||||
}
|
||||
|
||||
if (OwnerBundle.IsDone() == false)
|
||||
return;
|
||||
|
||||
if (OwnerBundle.Status != BundleLoaderBase.EStatus.Succeed)
|
||||
{
|
||||
string error = OwnerBundle.LastError;
|
||||
InvokeCompletion(error, EOperationStatus.Failed);
|
||||
return;
|
||||
}
|
||||
|
||||
_steps = ESteps.Loading;
|
||||
}
|
||||
|
||||
// 2. 加载资源对象
|
||||
if (_steps == ESteps.Loading)
|
||||
{
|
||||
if (MainAssetInfo.AssetType == null)
|
||||
{
|
||||
AllAssetObjects = UnityEditor.AssetDatabase.LoadAllAssetRepresentationsAtPath(MainAssetInfo.AssetPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
UnityEngine.Object[] findAssets = UnityEditor.AssetDatabase.LoadAllAssetRepresentationsAtPath(MainAssetInfo.AssetPath);
|
||||
List<UnityEngine.Object> result = new List<Object>(findAssets.Length);
|
||||
foreach (var findAsset in findAssets)
|
||||
{
|
||||
if (MainAssetInfo.AssetType.IsAssignableFrom(findAsset.GetType()))
|
||||
result.Add(findAsset);
|
||||
}
|
||||
AllAssetObjects = result.ToArray();
|
||||
}
|
||||
_steps = ESteps.Checking;
|
||||
}
|
||||
|
||||
// 3. 检测加载结果
|
||||
if (_steps == ESteps.Checking)
|
||||
{
|
||||
if (AllAssetObjects == null)
|
||||
{
|
||||
string error;
|
||||
if (MainAssetInfo.AssetType == null)
|
||||
error = $"Failed to load sub assets : {MainAssetInfo.AssetPath} AssetType : null";
|
||||
else
|
||||
error = $"Failed to load sub assets : {MainAssetInfo.AssetPath} AssetType : {MainAssetInfo.AssetType}";
|
||||
YooLogger.Error(error);
|
||||
InvokeCompletion(error, EOperationStatus.Failed);
|
||||
}
|
||||
else
|
||||
{
|
||||
InvokeCompletion(string.Empty, EOperationStatus.Succeed);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3837962b901d7ba4abf02a9991ac4c4a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,19 +1,18 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
using System;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal abstract class ProviderBase : AsyncOperationBase
|
||||
internal abstract class ProviderOperation : AsyncOperationBase
|
||||
{
|
||||
protected enum ESteps
|
||||
{
|
||||
None = 0,
|
||||
CheckBundle,
|
||||
Loading,
|
||||
Checking,
|
||||
StartBundleLoader,
|
||||
WaitBundleLoader,
|
||||
ProcessBundleResult,
|
||||
Done,
|
||||
}
|
||||
|
||||
@@ -22,11 +21,6 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public string ProviderGUID { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 所属资源系统
|
||||
/// </summary>
|
||||
public ResourceManager ResourceMgr { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 资源信息
|
||||
/// </summary>
|
||||
@@ -42,21 +36,26 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public UnityEngine.Object[] AllAssetObjects { protected set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取的资源对象集合
|
||||
/// </summary>
|
||||
public UnityEngine.Object[] SubAssetObjects { protected set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取的场景对象
|
||||
/// </summary>
|
||||
public UnityEngine.SceneManagement.Scene SceneObject { protected set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取的资源包对象
|
||||
/// </summary>
|
||||
public BundleResult BundleResultObject { protected set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 加载的场景名称
|
||||
/// </summary>
|
||||
public string SceneName { protected set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 原生文件路径
|
||||
/// </summary>
|
||||
public string RawFilePath { protected set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 引用计数
|
||||
/// </summary>
|
||||
@@ -68,37 +67,122 @@ namespace YooAsset
|
||||
public bool IsDestroyed { private set; get; } = false;
|
||||
|
||||
|
||||
protected ESteps _steps = ESteps.None;
|
||||
protected BundleLoaderBase OwnerBundle { private set; get; }
|
||||
protected DependAssetBundles DependBundles { private set; get; }
|
||||
protected bool IsWaitForAsyncComplete { private set; get; } = false;
|
||||
protected bool IsForceDestroyComplete { private set; get; } = false;
|
||||
private ESteps _steps = ESteps.None;
|
||||
private readonly LoadBundleFileOperation _mainBundleLoader;
|
||||
private readonly List<LoadBundleFileOperation> _bundleLoaders = new List<LoadBundleFileOperation>();
|
||||
private readonly List<HandleBase> _handles = new List<HandleBase>();
|
||||
|
||||
|
||||
public ProviderBase(ResourceManager manager, string providerGUID, AssetInfo assetInfo)
|
||||
public ProviderOperation(ResourceManager manager, string providerGUID, AssetInfo assetInfo)
|
||||
{
|
||||
ResourceMgr = manager;
|
||||
ProviderGUID = providerGUID;
|
||||
MainAssetInfo = assetInfo;
|
||||
|
||||
// 创建资源包加载器
|
||||
if (manager != null)
|
||||
if (string.IsNullOrEmpty(providerGUID) == false)
|
||||
{
|
||||
OwnerBundle = manager.CreateOwnerAssetBundleLoader(assetInfo);
|
||||
OwnerBundle.Reference();
|
||||
OwnerBundle.AddProvider(this);
|
||||
// 主资源包加载器
|
||||
_mainBundleLoader = manager.CreateMainBundleFileLoader(assetInfo);
|
||||
_mainBundleLoader.AddProvider(this);
|
||||
_bundleLoaders.Add(_mainBundleLoader);
|
||||
|
||||
var dependList = manager.CreateDependAssetBundleLoaders(assetInfo);
|
||||
DependBundles = new DependAssetBundles(dependList);
|
||||
DependBundles.Reference();
|
||||
// 依赖资源包加载器集合
|
||||
var dependLoaders = manager.CreateDependBundleFileLoaders(assetInfo);
|
||||
if (dependLoaders.Count > 0)
|
||||
_bundleLoaders.AddRange(dependLoaders);
|
||||
|
||||
// 增加引用计数
|
||||
foreach (var bundleLoader in _bundleLoaders)
|
||||
{
|
||||
bundleLoader.Reference();
|
||||
}
|
||||
}
|
||||
}
|
||||
internal override void InternalStart()
|
||||
{
|
||||
_steps = ESteps.StartBundleLoader;
|
||||
}
|
||||
internal override void InternalUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.StartBundleLoader)
|
||||
{
|
||||
foreach (var bundleLoader in _bundleLoaders)
|
||||
{
|
||||
bundleLoader.StartOperation();
|
||||
AddChildOperation(bundleLoader);
|
||||
}
|
||||
_steps = ESteps.WaitBundleLoader;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.WaitBundleLoader)
|
||||
{
|
||||
if (IsWaitForAsyncComplete)
|
||||
{
|
||||
foreach (var bundleLoader in _bundleLoaders)
|
||||
{
|
||||
bundleLoader.WaitForAsyncComplete();
|
||||
}
|
||||
}
|
||||
|
||||
// 更新资源包加载器
|
||||
foreach (var bundleLoader in _bundleLoaders)
|
||||
{
|
||||
bundleLoader.UpdateOperation();
|
||||
}
|
||||
|
||||
// 检测加载是否完成
|
||||
foreach (var bundleLoader in _bundleLoaders)
|
||||
{
|
||||
if (bundleLoader.IsDone == false)
|
||||
return;
|
||||
|
||||
if (bundleLoader.Status != EOperationStatus.Succeed)
|
||||
{
|
||||
InvokeCompletion(bundleLoader.Error, EOperationStatus.Failed);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 检测加载结果
|
||||
BundleResultObject = _mainBundleLoader.Result;
|
||||
if (BundleResultObject == null)
|
||||
{
|
||||
string error = $"Loaded bundle result is null !";
|
||||
InvokeCompletion(error, EOperationStatus.Failed);
|
||||
return;
|
||||
}
|
||||
|
||||
_steps = ESteps.ProcessBundleResult;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.ProcessBundleResult)
|
||||
{
|
||||
ProcessBundleResult();
|
||||
}
|
||||
}
|
||||
internal override void InternalWaitForAsyncComplete()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (ExecuteWhileDone())
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
internal override string InternalGetDesc()
|
||||
{
|
||||
return $"AssetPath : {MainAssetInfo.AssetPath}";
|
||||
}
|
||||
protected abstract void ProcessBundleResult();
|
||||
|
||||
/// <summary>
|
||||
/// 销毁资源提供者
|
||||
/// </summary>
|
||||
public void Destroy()
|
||||
public void DestroyProvider()
|
||||
{
|
||||
IsDestroyed = true;
|
||||
|
||||
@@ -109,26 +193,20 @@ namespace YooAsset
|
||||
Status = EOperationStatus.Failed;
|
||||
}
|
||||
|
||||
// 释放资源包加载器
|
||||
if (OwnerBundle != null)
|
||||
// 减少引用计数
|
||||
foreach (var bundleLoader in _bundleLoaders)
|
||||
{
|
||||
OwnerBundle.Release();
|
||||
OwnerBundle = null;
|
||||
}
|
||||
if (DependBundles != null)
|
||||
{
|
||||
DependBundles.Release();
|
||||
DependBundles = null;
|
||||
bundleLoader.Release();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否可以销毁
|
||||
/// </summary>
|
||||
public bool CanDestroy()
|
||||
public bool CanDestroyProvider()
|
||||
{
|
||||
// 注意:在进行资源加载过程时不可以销毁
|
||||
if (_steps == ESteps.Loading || _steps == ESteps.Checking)
|
||||
if (_steps == ESteps.ProcessBundleResult)
|
||||
return false;
|
||||
|
||||
return RefCount <= 0;
|
||||
@@ -183,59 +261,15 @@ namespace YooAsset
|
||||
for (int i = _handles.Count - 1; i >= 0; i--)
|
||||
{
|
||||
var handle = _handles[i];
|
||||
handle.ReleaseInternal();
|
||||
handle.Release();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 等待异步执行完毕
|
||||
/// </summary>
|
||||
public void WaitForAsyncComplete()
|
||||
{
|
||||
IsWaitForAsyncComplete = true;
|
||||
|
||||
// 注意:主动轮询更新完成同步加载
|
||||
InternalOnUpdate();
|
||||
|
||||
// 验证结果
|
||||
if (IsDone == false)
|
||||
{
|
||||
YooLogger.Warning($"{nameof(WaitForAsyncComplete)} failed to loading : {MainAssetInfo.AssetPath}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 强制销毁资源提供者
|
||||
/// </summary>
|
||||
public void ForceDestroyComplete()
|
||||
{
|
||||
IsForceDestroyComplete = true;
|
||||
|
||||
// 注意:主动轮询更新完成同步加载
|
||||
// 说明:如果资源包未准备完毕也可以放心销毁。
|
||||
InternalOnUpdate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 处理特殊异常
|
||||
/// </summary>
|
||||
protected void ProcessCacheBundleException()
|
||||
{
|
||||
if (OwnerBundle.IsDestroyed)
|
||||
throw new System.Exception("Should never get here !");
|
||||
|
||||
string error = $"The bundle {OwnerBundle.MainBundleInfo.Bundle.BundleName} has been destroyed by unity bugs !";
|
||||
YooLogger.Error(error);
|
||||
InvokeCompletion(Error, EOperationStatus.Failed);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 结束流程
|
||||
/// </summary>
|
||||
protected void InvokeCompletion(string error, EOperationStatus status)
|
||||
{
|
||||
DebugEndRecording();
|
||||
|
||||
_steps = ESteps.Done;
|
||||
Error = error;
|
||||
Status = status;
|
||||
@@ -252,70 +286,16 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
|
||||
#region 调试信息相关
|
||||
/// <summary>
|
||||
/// 出生的场景
|
||||
/// </summary>
|
||||
public string SpawnScene = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 出生的时间
|
||||
/// </summary>
|
||||
public string SpawnTime = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 加载耗时(单位:毫秒)
|
||||
/// </summary>
|
||||
public long LoadingTime { protected set; get; }
|
||||
|
||||
// 加载耗时统计
|
||||
private Stopwatch _watch = null;
|
||||
|
||||
[Conditional("DEBUG")]
|
||||
public void InitSpawnDebugInfo()
|
||||
{
|
||||
SpawnScene = UnityEngine.SceneManagement.SceneManager.GetActiveScene().name; ;
|
||||
SpawnTime = SpawnTimeToString(UnityEngine.Time.realtimeSinceStartup);
|
||||
}
|
||||
private string SpawnTimeToString(float spawnTime)
|
||||
{
|
||||
float h = UnityEngine.Mathf.FloorToInt(spawnTime / 3600f);
|
||||
float m = UnityEngine.Mathf.FloorToInt(spawnTime / 60f - h * 60f);
|
||||
float s = UnityEngine.Mathf.FloorToInt(spawnTime - m * 60f - h * 3600f);
|
||||
return h.ToString("00") + ":" + m.ToString("00") + ":" + s.ToString("00");
|
||||
}
|
||||
|
||||
[Conditional("DEBUG")]
|
||||
protected void DebugBeginRecording()
|
||||
{
|
||||
if (_watch == null)
|
||||
{
|
||||
_watch = Stopwatch.StartNew();
|
||||
}
|
||||
}
|
||||
|
||||
[Conditional("DEBUG")]
|
||||
private void DebugEndRecording()
|
||||
{
|
||||
if (_watch != null)
|
||||
{
|
||||
LoadingTime = _watch.ElapsedMilliseconds;
|
||||
_watch = null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取下载报告
|
||||
/// </summary>
|
||||
internal DownloadStatus GetDownloadStatus()
|
||||
public DownloadStatus GetDownloadStatus()
|
||||
{
|
||||
DownloadStatus status = new DownloadStatus();
|
||||
status.TotalBytes = (ulong)OwnerBundle.MainBundleInfo.Bundle.FileSize;
|
||||
status.DownloadedBytes = OwnerBundle.DownloadedBytes;
|
||||
foreach (var dependBundle in DependBundles.DependList)
|
||||
foreach (var bundleLoader in _bundleLoaders)
|
||||
{
|
||||
status.TotalBytes += (ulong)dependBundle.MainBundleInfo.Bundle.FileSize;
|
||||
status.DownloadedBytes += dependBundle.DownloadedBytes;
|
||||
status.TotalBytes += bundleLoader.LoadBundleInfo.Bundle.FileSize;
|
||||
status.DownloadedBytes += bundleLoader.DownloadedBytes;
|
||||
}
|
||||
|
||||
if (status.TotalBytes == 0)
|
||||
@@ -326,18 +306,30 @@ namespace YooAsset
|
||||
return status;
|
||||
}
|
||||
|
||||
#region 调试信息
|
||||
/// <summary>
|
||||
/// 出生的场景
|
||||
/// </summary>
|
||||
public string SpawnScene = string.Empty;
|
||||
|
||||
[Conditional("DEBUG")]
|
||||
public void InitProviderDebugInfo()
|
||||
{
|
||||
SpawnScene = UnityEngine.SceneManagement.SceneManager.GetActiveScene().name;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取资源包的调试信息列表
|
||||
/// </summary>
|
||||
internal void GetBundleDebugInfos(List<DebugBundleInfo> output)
|
||||
internal List<string> GetDebugDependBundles()
|
||||
{
|
||||
var bundleInfo = new DebugBundleInfo();
|
||||
bundleInfo.BundleName = OwnerBundle.MainBundleInfo.Bundle.BundleName;
|
||||
bundleInfo.RefCount = OwnerBundle.RefCount;
|
||||
bundleInfo.Status = OwnerBundle.Status.ToString();
|
||||
output.Add(bundleInfo);
|
||||
|
||||
DependBundles.GetBundleDebugInfos(output);
|
||||
List<string> result = new List<string>(_bundleLoaders.Count);
|
||||
foreach (var bundleLoader in _bundleLoaders)
|
||||
{
|
||||
var packageBundle = bundleLoader.LoadBundleInfo.Bundle;
|
||||
result.Add(packageBundle.BundleName);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
}
|
@@ -0,0 +1,14 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class RawFileProvider : ProviderOperation
|
||||
{
|
||||
public RawFileProvider(ResourceManager manager, string providerGUID, AssetInfo assetInfo) : base(manager, providerGUID, assetInfo)
|
||||
{
|
||||
}
|
||||
protected override void ProcessBundleResult()
|
||||
{
|
||||
InvokeCompletion(string.Empty, EOperationStatus.Succeed);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 49b6e666518da98479966a5cf0504d59
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,61 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal sealed class SceneProvider : ProviderOperation
|
||||
{
|
||||
private readonly LoadSceneParameters _loadParams;
|
||||
private bool _suspendLoad;
|
||||
private FSLoadSceneOperation _loadSceneOp;
|
||||
|
||||
public SceneProvider(ResourceManager manager, string providerGUID, AssetInfo assetInfo, LoadSceneParameters loadParams, bool suspendLoad) : base(manager, providerGUID, assetInfo)
|
||||
{
|
||||
_loadParams = loadParams;
|
||||
_suspendLoad = suspendLoad;
|
||||
SceneName = Path.GetFileNameWithoutExtension(assetInfo.AssetPath);
|
||||
}
|
||||
protected override void ProcessBundleResult()
|
||||
{
|
||||
if (_loadSceneOp == null)
|
||||
{
|
||||
_loadSceneOp = BundleResultObject.LoadSceneOperation(MainAssetInfo, _loadParams, _suspendLoad);
|
||||
_loadSceneOp.StartOperation();
|
||||
AddChildOperation(_loadSceneOp);
|
||||
}
|
||||
|
||||
if (IsWaitForAsyncComplete)
|
||||
_loadSceneOp.WaitForAsyncComplete();
|
||||
|
||||
// 注意:场景加载中途可以取消挂起
|
||||
if (_suspendLoad == false)
|
||||
_loadSceneOp.UnSuspendLoad();
|
||||
|
||||
_loadSceneOp.UpdateOperation();
|
||||
Progress = _loadSceneOp.Progress;
|
||||
if (_loadSceneOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_loadSceneOp.Status != EOperationStatus.Succeed)
|
||||
{
|
||||
InvokeCompletion(_loadSceneOp.Error, EOperationStatus.Failed);
|
||||
}
|
||||
else
|
||||
{
|
||||
SceneObject = _loadSceneOp.Result;
|
||||
InvokeCompletion(string.Empty, EOperationStatus.Succeed);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解除场景加载挂起操作
|
||||
/// </summary>
|
||||
public void UnSuspendLoad()
|
||||
{
|
||||
_suspendLoad = false;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8586015105ad65f438e2f2e9c64c3df1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,39 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal sealed class SubAssetsProvider : ProviderOperation
|
||||
{
|
||||
private FSLoadSubAssetsOperation _loadSubAssetsOp;
|
||||
|
||||
public SubAssetsProvider(ResourceManager manager, string providerGUID, AssetInfo assetInfo) : base(manager, providerGUID, assetInfo)
|
||||
{
|
||||
}
|
||||
protected override void ProcessBundleResult()
|
||||
{
|
||||
if (_loadSubAssetsOp == null)
|
||||
{
|
||||
_loadSubAssetsOp = BundleResultObject.LoadSubAssetsAsync(MainAssetInfo);
|
||||
_loadSubAssetsOp.StartOperation();
|
||||
AddChildOperation(_loadSubAssetsOp);
|
||||
}
|
||||
|
||||
if (IsWaitForAsyncComplete)
|
||||
_loadSubAssetsOp.WaitForAsyncComplete();
|
||||
|
||||
_loadSubAssetsOp.UpdateOperation();
|
||||
Progress = _loadSubAssetsOp.Progress;
|
||||
if (_loadSubAssetsOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_loadSubAssetsOp.Status != EOperationStatus.Succeed)
|
||||
{
|
||||
InvokeCompletion(_loadSubAssetsOp.Error, EOperationStatus.Failed);
|
||||
}
|
||||
else
|
||||
{
|
||||
SubAssetObjects = _loadSubAssetsOp.Result;
|
||||
InvokeCompletion(string.Empty, EOperationStatus.Succeed);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0cef140e594c94640abfcd439f6b8be3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,103 +0,0 @@
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class ResourceLoader
|
||||
{
|
||||
private IDecryptionServices _decryption;
|
||||
private IDeliveryLoadServices _delivery;
|
||||
|
||||
public void Init(IDecryptionServices decryption, IDeliveryLoadServices delivery)
|
||||
{
|
||||
_decryption = decryption;
|
||||
_delivery = delivery;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 同步加载资源包对象
|
||||
/// </summary>
|
||||
public AssetBundle LoadAssetBundle(BundleInfo bundleInfo, string fileLoadPath, out Stream managedStream)
|
||||
{
|
||||
managedStream = null;
|
||||
if (bundleInfo.Bundle.Encrypted)
|
||||
{
|
||||
if (_decryption == null)
|
||||
{
|
||||
YooLogger.Error($"{nameof(IDecryptionServices)} is null ! when load asset bundle {bundleInfo.Bundle.BundleName}!");
|
||||
return null;
|
||||
}
|
||||
|
||||
DecryptFileInfo fileInfo = new DecryptFileInfo();
|
||||
fileInfo.BundleName = bundleInfo.Bundle.BundleName;
|
||||
fileInfo.FileLoadPath = fileLoadPath;
|
||||
fileInfo.ConentCRC = bundleInfo.Bundle.UnityCRC;
|
||||
return _decryption.LoadAssetBundle(fileInfo, out managedStream);
|
||||
}
|
||||
else
|
||||
{
|
||||
return AssetBundle.LoadFromFile(fileLoadPath);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载资源包对象
|
||||
/// </summary>
|
||||
public AssetBundleCreateRequest LoadAssetBundleAsync(BundleInfo bundleInfo, string fileLoadPath, out Stream managedStream)
|
||||
{
|
||||
managedStream = null;
|
||||
if (bundleInfo.Bundle.Encrypted)
|
||||
{
|
||||
if (_decryption == null)
|
||||
{
|
||||
YooLogger.Error($"{nameof(IDecryptionServices)} is null ! when load asset bundle {bundleInfo.Bundle.BundleName}!");
|
||||
return null;
|
||||
}
|
||||
|
||||
DecryptFileInfo fileInfo = new DecryptFileInfo();
|
||||
fileInfo.BundleName = bundleInfo.Bundle.BundleName;
|
||||
fileInfo.FileLoadPath = fileLoadPath;
|
||||
fileInfo.ConentCRC = bundleInfo.Bundle.UnityCRC;
|
||||
return _decryption.LoadAssetBundleAsync(fileInfo, out managedStream);
|
||||
}
|
||||
else
|
||||
{
|
||||
return AssetBundle.LoadFromFileAsync(fileLoadPath);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 同步加载分发的资源包对象
|
||||
/// </summary>
|
||||
public AssetBundle LoadDeliveryAssetBundle(BundleInfo bundleInfo, string fileLoadPath)
|
||||
{
|
||||
if (_delivery == null)
|
||||
throw new System.Exception("Should never get here !");
|
||||
|
||||
// 注意:对于已经加密的资源包,需要开发者自行解密。
|
||||
DeliveryFileInfo fileInfo = new DeliveryFileInfo();
|
||||
fileInfo.BundleName = bundleInfo.Bundle.BundleName;
|
||||
fileInfo.FileLoadPath = fileLoadPath;
|
||||
fileInfo.ConentCRC = bundleInfo.Bundle.UnityCRC;
|
||||
fileInfo.Encrypted = bundleInfo.Bundle.Encrypted;
|
||||
return _delivery.LoadAssetBundle(fileInfo);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载分发的资源包对象
|
||||
/// </summary>
|
||||
public AssetBundleCreateRequest LoadDeliveryAssetBundleAsync(BundleInfo bundleInfo, string fileLoadPath)
|
||||
{
|
||||
if (_delivery == null)
|
||||
throw new System.Exception("Should never get here !");
|
||||
|
||||
// 注意:对于已经加密的资源包,需要开发者自行解密。
|
||||
DeliveryFileInfo fileInfo = new DeliveryFileInfo();
|
||||
fileInfo.BundleName = bundleInfo.Bundle.BundleName;
|
||||
fileInfo.FileLoadPath = fileLoadPath;
|
||||
fileInfo.ConentCRC = bundleInfo.Bundle.UnityCRC;
|
||||
fileInfo.Encrypted = bundleInfo.Bundle.Encrypted;
|
||||
return _delivery.LoadAssetBundleAsync(fileInfo);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3818e5adef4eaea4a85b112f953c4f7b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -9,16 +9,10 @@ namespace YooAsset
|
||||
{
|
||||
internal class ResourceManager
|
||||
{
|
||||
// 全局场景句柄集合
|
||||
private readonly static Dictionary<string, SceneHandle> _sceneHandles = new Dictionary<string, SceneHandle>(100);
|
||||
private static long _sceneCreateCount = 0;
|
||||
|
||||
private readonly Dictionary<string, ProviderBase> _providerDic = new Dictionary<string, ProviderBase>(5000);
|
||||
private readonly Dictionary<string, BundleLoaderBase> _loaderDic = new Dictionary<string, BundleLoaderBase>(5000);
|
||||
private readonly List<BundleLoaderBase> _loaderList = new List<BundleLoaderBase>(5000);
|
||||
|
||||
private bool _simulationOnEditor;
|
||||
private bool _autoDestroyAssetProvider;
|
||||
internal readonly Dictionary<string, ProviderOperation> ProviderDic = new Dictionary<string, ProviderOperation>(5000);
|
||||
internal readonly Dictionary<string, LoadBundleFileOperation> LoaderDic = new Dictionary<string, LoadBundleFileOperation>(5000);
|
||||
internal readonly List<SceneHandle> SceneHandles = new List<SceneHandle>(100);
|
||||
private long _sceneCreateIndex = 0;
|
||||
private IBundleQuery _bundleQuery;
|
||||
|
||||
/// <summary>
|
||||
@@ -26,6 +20,11 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public readonly string PackageName;
|
||||
|
||||
/// <summary>
|
||||
/// 锁定加载操作
|
||||
/// </summary>
|
||||
public bool LockLoadOperation = false;
|
||||
|
||||
|
||||
public ResourceManager(string packageName)
|
||||
{
|
||||
@@ -35,49 +34,18 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 初始化
|
||||
/// </summary>
|
||||
public void Initialize(bool simulationOnEditor, bool autoDestroyAssetProvider, IBundleQuery bundleServices)
|
||||
public void Initialize(IBundleQuery bundleServices)
|
||||
{
|
||||
_simulationOnEditor = simulationOnEditor;
|
||||
_autoDestroyAssetProvider = autoDestroyAssetProvider;
|
||||
_bundleQuery = bundleServices;
|
||||
SceneManager.sceneUnloaded += OnSceneUnloaded;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新
|
||||
/// 销毁管理器
|
||||
/// </summary>
|
||||
public void Update()
|
||||
public void Destroy()
|
||||
{
|
||||
foreach (var loader in _loaderList)
|
||||
{
|
||||
loader.Update();
|
||||
|
||||
if (_autoDestroyAssetProvider)
|
||||
loader.TryDestroyProviders();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 资源回收(卸载引用计数为零的资源)
|
||||
/// </summary>
|
||||
public void UnloadUnusedAssets()
|
||||
{
|
||||
for (int i = _loaderList.Count - 1; i >= 0; i--)
|
||||
{
|
||||
BundleLoaderBase loader = _loaderList[i];
|
||||
loader.TryDestroyProviders();
|
||||
}
|
||||
|
||||
for (int i = _loaderList.Count - 1; i >= 0; i--)
|
||||
{
|
||||
BundleLoaderBase loader = _loaderList[i];
|
||||
if (loader.CanDestroy())
|
||||
{
|
||||
string bundleName = loader.MainBundleInfo.Bundle.BundleName;
|
||||
loader.Destroy();
|
||||
_loaderList.RemoveAt(i);
|
||||
_loaderDic.Remove(bundleName);
|
||||
}
|
||||
}
|
||||
SceneManager.sceneUnloaded -= OnSceneUnloaded;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -92,17 +60,16 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
// 卸载主资源包加载器
|
||||
string manBundleName = _bundleQuery.GetMainBundleName(assetInfo);
|
||||
var mainLoader = TryGetAssetBundleLoader(manBundleName);
|
||||
string mainBundleName = _bundleQuery.GetMainBundleName(assetInfo);
|
||||
var mainLoader = TryGetBundleFileLoader(mainBundleName);
|
||||
if (mainLoader != null)
|
||||
{
|
||||
mainLoader.TryDestroyProviders();
|
||||
if (mainLoader.CanDestroy())
|
||||
if (mainLoader.CanDestroyLoader())
|
||||
{
|
||||
string bundleName = mainLoader.MainBundleInfo.Bundle.BundleName;
|
||||
mainLoader.Destroy();
|
||||
_loaderList.Remove(mainLoader);
|
||||
_loaderDic.Remove(bundleName);
|
||||
string bundleName = mainLoader.LoadBundleInfo.Bundle.BundleName;
|
||||
mainLoader.DestroyLoader();
|
||||
LoaderDic.Remove(bundleName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,109 +77,57 @@ namespace YooAsset
|
||||
string[] dependBundleNames = _bundleQuery.GetDependBundleNames(assetInfo);
|
||||
foreach (var dependBundleName in dependBundleNames)
|
||||
{
|
||||
var dependLoader = TryGetAssetBundleLoader(dependBundleName);
|
||||
var dependLoader = TryGetBundleFileLoader(dependBundleName);
|
||||
if (dependLoader != null)
|
||||
{
|
||||
if (dependLoader.CanDestroy())
|
||||
if (dependLoader.CanDestroyLoader())
|
||||
{
|
||||
string bundleName = dependLoader.MainBundleInfo.Bundle.BundleName;
|
||||
dependLoader.Destroy();
|
||||
_loaderList.Remove(dependLoader);
|
||||
_loaderDic.Remove(bundleName);
|
||||
string bundleName = dependLoader.LoadBundleInfo.Bundle.BundleName;
|
||||
dependLoader.DestroyLoader();
|
||||
LoaderDic.Remove(bundleName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 强制回收所有资源
|
||||
/// 注意:加载器在销毁后关联的下载器还会继续下载!
|
||||
/// </summary>
|
||||
public void ForceUnloadAllAssets()
|
||||
{
|
||||
#if UNITY_WEBGL
|
||||
throw new Exception($"WebGL not support invoke {nameof(ForceUnloadAllAssets)}");
|
||||
#else
|
||||
// 注意:因为场景无法异步转同步,需要等待所有场景加载完毕!
|
||||
foreach (var sceneHandlePair in _sceneHandles)
|
||||
{
|
||||
var sceneHandle = sceneHandlePair.Value;
|
||||
if (sceneHandle.PackageName == PackageName)
|
||||
{
|
||||
if (sceneHandle.IsDone == false)
|
||||
throw new Exception($"{nameof(ForceUnloadAllAssets)} cannot be called when loading the scene !");
|
||||
}
|
||||
}
|
||||
|
||||
// 释放所有资源句柄
|
||||
foreach (var provider in _providerDic.Values)
|
||||
{
|
||||
provider.ReleaseAllHandles();
|
||||
}
|
||||
|
||||
// 强制销毁资源提供者
|
||||
foreach (var provider in _providerDic.Values)
|
||||
{
|
||||
provider.ForceDestroyComplete();
|
||||
provider.Destroy();
|
||||
}
|
||||
|
||||
// 强制销毁资源加载器
|
||||
foreach (var loader in _loaderList)
|
||||
{
|
||||
loader.ForceDestroyComplete();
|
||||
loader.Destroy();
|
||||
}
|
||||
|
||||
// 清空数据
|
||||
_providerDic.Clear();
|
||||
_loaderList.Clear();
|
||||
_loaderDic.Clear();
|
||||
ClearSceneHandle();
|
||||
|
||||
// 注意:调用底层接口释放所有资源
|
||||
Resources.UnloadUnusedAssets();
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载场景对象
|
||||
/// 注意:返回的场景句柄是唯一的,每个场景句柄对应自己的场景提供者对象。
|
||||
/// 注意:业务逻辑层应该避免同时加载一个子场景。
|
||||
/// </summary>
|
||||
public SceneHandle LoadSceneAsync(AssetInfo assetInfo, LoadSceneMode sceneMode, bool suspendLoad, uint priority)
|
||||
public SceneHandle LoadSceneAsync(AssetInfo assetInfo, LoadSceneParameters loadSceneParams, bool suspendLoad, uint priority)
|
||||
{
|
||||
if (assetInfo.IsInvalid)
|
||||
if (LockLoadOperation)
|
||||
{
|
||||
YooLogger.Error($"Failed to load scene ! {assetInfo.Error}");
|
||||
CompletedProvider completedProvider = new CompletedProvider(assetInfo);
|
||||
completedProvider.SetCompleted(assetInfo.Error);
|
||||
string error = $"The load operation locked !";
|
||||
YooLogger.Error(error);
|
||||
CompletedProvider completedProvider = new CompletedProvider(this, assetInfo);
|
||||
completedProvider.SetCompletedWithError(error);
|
||||
return completedProvider.CreateHandle<SceneHandle>();
|
||||
}
|
||||
|
||||
// 如果加载的是主场景,则卸载所有缓存的场景
|
||||
if (sceneMode == LoadSceneMode.Single)
|
||||
if (assetInfo.IsInvalid)
|
||||
{
|
||||
UnloadAllScene();
|
||||
YooLogger.Error($"Failed to load scene ! {assetInfo.Error}");
|
||||
CompletedProvider completedProvider = new CompletedProvider(this, assetInfo);
|
||||
completedProvider.SetCompletedWithError(assetInfo.Error);
|
||||
return completedProvider.CreateHandle<SceneHandle>();
|
||||
}
|
||||
|
||||
// 注意:同一个场景的ProviderGUID每次加载都会变化
|
||||
string providerGUID = $"{assetInfo.GUID}-{++_sceneCreateCount}";
|
||||
ProviderBase provider;
|
||||
string providerGUID = $"{assetInfo.GUID}-{++_sceneCreateIndex}";
|
||||
ProviderOperation provider;
|
||||
{
|
||||
if (_simulationOnEditor)
|
||||
provider = new DatabaseSceneProvider(this, providerGUID, assetInfo, sceneMode, suspendLoad);
|
||||
else
|
||||
provider = new BundledSceneProvider(this, providerGUID, assetInfo, sceneMode, suspendLoad);
|
||||
provider.InitSpawnDebugInfo();
|
||||
_providerDic.Add(providerGUID, provider);
|
||||
provider = new SceneProvider(this, providerGUID, assetInfo, loadSceneParams, suspendLoad);
|
||||
provider.InitProviderDebugInfo();
|
||||
ProviderDic.Add(providerGUID, provider);
|
||||
OperationSystem.StartOperation(PackageName, provider);
|
||||
}
|
||||
|
||||
provider.Priority = priority;
|
||||
var handle = provider.CreateHandle<SceneHandle>();
|
||||
handle.PackageName = PackageName;
|
||||
_sceneHandles.Add(providerGUID, handle);
|
||||
SceneHandles.Add(handle);
|
||||
return handle;
|
||||
}
|
||||
|
||||
@@ -221,24 +136,30 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public AssetHandle LoadAssetAsync(AssetInfo assetInfo, uint priority)
|
||||
{
|
||||
if (LockLoadOperation)
|
||||
{
|
||||
string error = $"The load operation locked !";
|
||||
YooLogger.Error(error);
|
||||
CompletedProvider completedProvider = new CompletedProvider(this, assetInfo);
|
||||
completedProvider.SetCompletedWithError(error);
|
||||
return completedProvider.CreateHandle<AssetHandle>();
|
||||
}
|
||||
|
||||
if (assetInfo.IsInvalid)
|
||||
{
|
||||
YooLogger.Error($"Failed to load asset ! {assetInfo.Error}");
|
||||
CompletedProvider completedProvider = new CompletedProvider(assetInfo);
|
||||
completedProvider.SetCompleted(assetInfo.Error);
|
||||
CompletedProvider completedProvider = new CompletedProvider(this, assetInfo);
|
||||
completedProvider.SetCompletedWithError(assetInfo.Error);
|
||||
return completedProvider.CreateHandle<AssetHandle>();
|
||||
}
|
||||
|
||||
string providerGUID = nameof(LoadAssetAsync) + assetInfo.GUID;
|
||||
ProviderBase provider = TryGetProvider(providerGUID);
|
||||
ProviderOperation provider = TryGetAssetProvider(providerGUID);
|
||||
if (provider == null)
|
||||
{
|
||||
if (_simulationOnEditor)
|
||||
provider = new DatabaseAssetProvider(this, providerGUID, assetInfo);
|
||||
else
|
||||
provider = new BundledAssetProvider(this, providerGUID, assetInfo);
|
||||
provider.InitSpawnDebugInfo();
|
||||
_providerDic.Add(providerGUID, provider);
|
||||
provider = new AssetProvider(this, providerGUID, assetInfo);
|
||||
provider.InitProviderDebugInfo();
|
||||
ProviderDic.Add(providerGUID, provider);
|
||||
OperationSystem.StartOperation(PackageName, provider);
|
||||
}
|
||||
|
||||
@@ -251,24 +172,30 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public SubAssetsHandle LoadSubAssetsAsync(AssetInfo assetInfo, uint priority)
|
||||
{
|
||||
if (LockLoadOperation)
|
||||
{
|
||||
string error = $"The load operation locked !";
|
||||
YooLogger.Error(error);
|
||||
CompletedProvider completedProvider = new CompletedProvider(this, assetInfo);
|
||||
completedProvider.SetCompletedWithError(error);
|
||||
return completedProvider.CreateHandle<SubAssetsHandle>();
|
||||
}
|
||||
|
||||
if (assetInfo.IsInvalid)
|
||||
{
|
||||
YooLogger.Error($"Failed to load sub assets ! {assetInfo.Error}");
|
||||
CompletedProvider completedProvider = new CompletedProvider(assetInfo);
|
||||
completedProvider.SetCompleted(assetInfo.Error);
|
||||
CompletedProvider completedProvider = new CompletedProvider(this, assetInfo);
|
||||
completedProvider.SetCompletedWithError(assetInfo.Error);
|
||||
return completedProvider.CreateHandle<SubAssetsHandle>();
|
||||
}
|
||||
|
||||
string providerGUID = nameof(LoadSubAssetsAsync) + assetInfo.GUID;
|
||||
ProviderBase provider = TryGetProvider(providerGUID);
|
||||
ProviderOperation provider = TryGetAssetProvider(providerGUID);
|
||||
if (provider == null)
|
||||
{
|
||||
if (_simulationOnEditor)
|
||||
provider = new DatabaseSubAssetsProvider(this, providerGUID, assetInfo);
|
||||
else
|
||||
provider = new BundledSubAssetsProvider(this, providerGUID, assetInfo);
|
||||
provider.InitSpawnDebugInfo();
|
||||
_providerDic.Add(providerGUID, provider);
|
||||
provider = new SubAssetsProvider(this, providerGUID, assetInfo);
|
||||
provider.InitProviderDebugInfo();
|
||||
ProviderDic.Add(providerGUID, provider);
|
||||
OperationSystem.StartOperation(PackageName, provider);
|
||||
}
|
||||
|
||||
@@ -281,24 +208,30 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public AllAssetsHandle LoadAllAssetsAsync(AssetInfo assetInfo, uint priority)
|
||||
{
|
||||
if (LockLoadOperation)
|
||||
{
|
||||
string error = $"The load operation locked !";
|
||||
YooLogger.Error(error);
|
||||
CompletedProvider completedProvider = new CompletedProvider(this, assetInfo);
|
||||
completedProvider.SetCompletedWithError(error);
|
||||
return completedProvider.CreateHandle<AllAssetsHandle>();
|
||||
}
|
||||
|
||||
if (assetInfo.IsInvalid)
|
||||
{
|
||||
YooLogger.Error($"Failed to load all assets ! {assetInfo.Error}");
|
||||
CompletedProvider completedProvider = new CompletedProvider(assetInfo);
|
||||
completedProvider.SetCompleted(assetInfo.Error);
|
||||
CompletedProvider completedProvider = new CompletedProvider(this, assetInfo);
|
||||
completedProvider.SetCompletedWithError(assetInfo.Error);
|
||||
return completedProvider.CreateHandle<AllAssetsHandle>();
|
||||
}
|
||||
|
||||
string providerGUID = nameof(LoadAllAssetsAsync) + assetInfo.GUID;
|
||||
ProviderBase provider = TryGetProvider(providerGUID);
|
||||
ProviderOperation provider = TryGetAssetProvider(providerGUID);
|
||||
if (provider == null)
|
||||
{
|
||||
if (_simulationOnEditor)
|
||||
provider = new DatabaseAllAssetsProvider(this, providerGUID, assetInfo);
|
||||
else
|
||||
provider = new BundledAllAssetsProvider(this, providerGUID, assetInfo);
|
||||
provider.InitSpawnDebugInfo();
|
||||
_providerDic.Add(providerGUID, provider);
|
||||
provider = new AllAssetsProvider(this, providerGUID, assetInfo);
|
||||
provider.InitProviderDebugInfo();
|
||||
ProviderDic.Add(providerGUID, provider);
|
||||
OperationSystem.StartOperation(PackageName, provider);
|
||||
}
|
||||
|
||||
@@ -311,24 +244,30 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public RawFileHandle LoadRawFileAsync(AssetInfo assetInfo, uint priority)
|
||||
{
|
||||
if (LockLoadOperation)
|
||||
{
|
||||
string error = $"The load operation locked !";
|
||||
YooLogger.Error(error);
|
||||
CompletedProvider completedProvider = new CompletedProvider(this, assetInfo);
|
||||
completedProvider.SetCompletedWithError(error);
|
||||
return completedProvider.CreateHandle<RawFileHandle>();
|
||||
}
|
||||
|
||||
if (assetInfo.IsInvalid)
|
||||
{
|
||||
YooLogger.Error($"Failed to load raw file ! {assetInfo.Error}");
|
||||
CompletedProvider completedProvider = new CompletedProvider(assetInfo);
|
||||
completedProvider.SetCompleted(assetInfo.Error);
|
||||
CompletedProvider completedProvider = new CompletedProvider(this, assetInfo);
|
||||
completedProvider.SetCompletedWithError(assetInfo.Error);
|
||||
return completedProvider.CreateHandle<RawFileHandle>();
|
||||
}
|
||||
|
||||
string providerGUID = nameof(LoadRawFileAsync) + assetInfo.GUID;
|
||||
ProviderBase provider = TryGetProvider(providerGUID);
|
||||
ProviderOperation provider = TryGetAssetProvider(providerGUID);
|
||||
if (provider == null)
|
||||
{
|
||||
if (_simulationOnEditor)
|
||||
provider = new DatabaseRawFileProvider(this, providerGUID, assetInfo);
|
||||
else
|
||||
provider = new BundledRawFileProvider(this, providerGUID, assetInfo);
|
||||
provider.InitSpawnDebugInfo();
|
||||
_providerDic.Add(providerGUID, provider);
|
||||
provider = new RawFileProvider(this, providerGUID, assetInfo);
|
||||
provider.InitProviderDebugInfo();
|
||||
ProviderDic.Add(providerGUID, provider);
|
||||
OperationSystem.StartOperation(PackageName, provider);
|
||||
}
|
||||
|
||||
@@ -336,149 +275,134 @@ namespace YooAsset
|
||||
return provider.CreateHandle<RawFileHandle>();
|
||||
}
|
||||
|
||||
internal void UnloadSubScene(string sceneName)
|
||||
{
|
||||
List<string> removeKeys = new List<string>();
|
||||
foreach (var valuePair in _sceneHandles)
|
||||
{
|
||||
var sceneHandle = valuePair.Value;
|
||||
if (sceneHandle.SceneName == sceneName)
|
||||
{
|
||||
// 释放子场景句柄
|
||||
sceneHandle.ReleaseInternal();
|
||||
removeKeys.Add(valuePair.Key);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (string key in removeKeys)
|
||||
{
|
||||
_sceneHandles.Remove(key);
|
||||
}
|
||||
}
|
||||
private void UnloadAllScene()
|
||||
{
|
||||
// 释放所有场景句柄
|
||||
foreach (var valuePair in _sceneHandles)
|
||||
{
|
||||
valuePair.Value.ReleaseInternal();
|
||||
}
|
||||
_sceneHandles.Clear();
|
||||
}
|
||||
private void ClearSceneHandle()
|
||||
{
|
||||
// 释放资源包下的所有场景
|
||||
if (_bundleQuery.ManifestValid())
|
||||
{
|
||||
string packageName = PackageName;
|
||||
List<string> removeList = new List<string>();
|
||||
foreach (var valuePair in _sceneHandles)
|
||||
{
|
||||
if (valuePair.Value.PackageName == packageName)
|
||||
{
|
||||
removeList.Add(valuePair.Key);
|
||||
}
|
||||
}
|
||||
foreach (var key in removeList)
|
||||
{
|
||||
_sceneHandles.Remove(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal BundleLoaderBase CreateOwnerAssetBundleLoader(AssetInfo assetInfo)
|
||||
internal LoadBundleFileOperation CreateMainBundleFileLoader(AssetInfo assetInfo)
|
||||
{
|
||||
BundleInfo bundleInfo = _bundleQuery.GetMainBundleInfo(assetInfo);
|
||||
return CreateAssetBundleLoaderInternal(bundleInfo);
|
||||
return CreateBundleFileLoaderInternal(bundleInfo);
|
||||
}
|
||||
internal List<BundleLoaderBase> CreateDependAssetBundleLoaders(AssetInfo assetInfo)
|
||||
internal List<LoadBundleFileOperation> CreateDependBundleFileLoaders(AssetInfo assetInfo)
|
||||
{
|
||||
BundleInfo[] depends = _bundleQuery.GetDependBundleInfos(assetInfo);
|
||||
List<BundleLoaderBase> result = new List<BundleLoaderBase>(depends.Length);
|
||||
foreach (var bundleInfo in depends)
|
||||
BundleInfo[] bundleInfos = _bundleQuery.GetDependBundleInfos(assetInfo);
|
||||
List<LoadBundleFileOperation> result = new List<LoadBundleFileOperation>(bundleInfos.Length);
|
||||
foreach (var bundleInfo in bundleInfos)
|
||||
{
|
||||
BundleLoaderBase dependLoader = CreateAssetBundleLoaderInternal(bundleInfo);
|
||||
result.Add(dependLoader);
|
||||
var bundleLoader = CreateBundleFileLoaderInternal(bundleInfo);
|
||||
result.Add(bundleLoader);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
internal void RemoveBundleProviders(List<ProviderBase> removeList)
|
||||
internal void RemoveBundleProviders(List<ProviderOperation> removeList)
|
||||
{
|
||||
foreach (var provider in removeList)
|
||||
{
|
||||
_providerDic.Remove(provider.ProviderGUID);
|
||||
ProviderDic.Remove(provider.ProviderGUID);
|
||||
}
|
||||
}
|
||||
internal bool CheckBundleDestroyed(int bundleID)
|
||||
{
|
||||
string bundleName = _bundleQuery.GetMainBundleName(bundleID);
|
||||
var bundleFileLoader = TryGetBundleFileLoader(bundleName);
|
||||
if (bundleFileLoader == null)
|
||||
return true;
|
||||
return bundleFileLoader.IsDestroyed;
|
||||
}
|
||||
internal bool HasAnyLoader()
|
||||
{
|
||||
return _loaderList.Count > 0;
|
||||
return LoaderDic.Count > 0;
|
||||
}
|
||||
|
||||
private BundleLoaderBase CreateAssetBundleLoaderInternal(BundleInfo bundleInfo)
|
||||
private LoadBundleFileOperation CreateBundleFileLoaderInternal(BundleInfo bundleInfo)
|
||||
{
|
||||
// 如果加载器已经存在
|
||||
string bundleName = bundleInfo.Bundle.BundleName;
|
||||
BundleLoaderBase loader = TryGetAssetBundleLoader(bundleName);
|
||||
if (loader != null)
|
||||
return loader;
|
||||
LoadBundleFileOperation loaderOperation = TryGetBundleFileLoader(bundleName);
|
||||
if (loaderOperation != null)
|
||||
return loaderOperation;
|
||||
|
||||
// 新增下载需求
|
||||
if (_simulationOnEditor)
|
||||
{
|
||||
loader = new VirtualBundleFileLoader(this, bundleInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
#if UNITY_WEBGL
|
||||
if (bundleInfo.Bundle.Buildpipeline== EDefaultBuildPipeline.RawFileBuildPipeline.ToString())
|
||||
loader = new RawBundleWebLoader(this, bundleInfo);
|
||||
else
|
||||
loader = new AssetBundleWebLoader(this, bundleInfo);
|
||||
#else
|
||||
if (bundleInfo.Bundle.Buildpipeline == EDefaultBuildPipeline.RawFileBuildPipeline.ToString())
|
||||
loader = new RawBundleFileLoader(this, bundleInfo);
|
||||
else
|
||||
loader = new AssetBundleFileLoader(this, bundleInfo);
|
||||
#endif
|
||||
}
|
||||
|
||||
_loaderList.Add(loader);
|
||||
_loaderDic.Add(bundleName, loader);
|
||||
return loader;
|
||||
loaderOperation = new LoadBundleFileOperation(this, bundleInfo);
|
||||
LoaderDic.Add(bundleName, loaderOperation);
|
||||
return loaderOperation;
|
||||
}
|
||||
private BundleLoaderBase TryGetAssetBundleLoader(string bundleName)
|
||||
private LoadBundleFileOperation TryGetBundleFileLoader(string bundleName)
|
||||
{
|
||||
if (_loaderDic.TryGetValue(bundleName, out BundleLoaderBase value))
|
||||
if (LoaderDic.TryGetValue(bundleName, out LoadBundleFileOperation value))
|
||||
return value;
|
||||
else
|
||||
return null;
|
||||
}
|
||||
private ProviderBase TryGetProvider(string providerGUID)
|
||||
private ProviderOperation TryGetAssetProvider(string providerGUID)
|
||||
{
|
||||
if (_providerDic.TryGetValue(providerGUID, out ProviderBase value))
|
||||
if (ProviderDic.TryGetValue(providerGUID, out ProviderOperation value))
|
||||
return value;
|
||||
else
|
||||
return null;
|
||||
}
|
||||
private void OnSceneUnloaded(Scene scene)
|
||||
{
|
||||
List<SceneHandle> removeList = new List<SceneHandle>();
|
||||
foreach (var sceneHandle in SceneHandles)
|
||||
{
|
||||
if (sceneHandle.IsValid)
|
||||
{
|
||||
if (sceneHandle.SceneObject == scene)
|
||||
{
|
||||
sceneHandle.Release();
|
||||
removeList.Add(sceneHandle);
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach (var sceneHandle in removeList)
|
||||
{
|
||||
SceneHandles.Remove(sceneHandle);
|
||||
}
|
||||
}
|
||||
|
||||
#region 调试信息
|
||||
internal List<DebugProviderInfo> GetDebugReportInfos()
|
||||
internal List<DebugProviderInfo> GetDebugProviderInfos()
|
||||
{
|
||||
List<DebugProviderInfo> result = new List<DebugProviderInfo>(_providerDic.Count);
|
||||
foreach (var provider in _providerDic.Values)
|
||||
List<DebugProviderInfo> result = new List<DebugProviderInfo>(ProviderDic.Count);
|
||||
foreach (var provider in ProviderDic.Values)
|
||||
{
|
||||
DebugProviderInfo providerInfo = new DebugProviderInfo();
|
||||
providerInfo.AssetPath = provider.MainAssetInfo.AssetPath;
|
||||
providerInfo.SpawnScene = provider.SpawnScene;
|
||||
providerInfo.SpawnTime = provider.SpawnTime;
|
||||
providerInfo.LoadingTime = provider.LoadingTime;
|
||||
providerInfo.BeginTime = provider.BeginTime;
|
||||
providerInfo.LoadingTime = provider.ProcessTime;
|
||||
providerInfo.RefCount = provider.RefCount;
|
||||
providerInfo.Status = provider.Status.ToString();
|
||||
providerInfo.DependBundleInfos = new List<DebugBundleInfo>();
|
||||
provider.GetBundleDebugInfos(providerInfo.DependBundleInfos);
|
||||
providerInfo.DependBundles = provider.GetDebugDependBundles();
|
||||
result.Add(providerInfo);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
internal List<DebugBundleInfo> GetDebugBundleInfos()
|
||||
{
|
||||
List<DebugBundleInfo> result = new List<DebugBundleInfo>(LoaderDic.Values.Count);
|
||||
foreach (var bundleLoader in LoaderDic.Values)
|
||||
{
|
||||
var packageBundle = bundleLoader.LoadBundleInfo.Bundle;
|
||||
var bundleInfo = new DebugBundleInfo();
|
||||
bundleInfo.BundleName = packageBundle.BundleName;
|
||||
bundleInfo.RefCount = bundleLoader.RefCount;
|
||||
bundleInfo.Status = bundleLoader.Status.ToString();
|
||||
bundleInfo.ReferenceBundles = FilterReferenceBundles(packageBundle);
|
||||
result.Add(bundleInfo);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
internal List<string> FilterReferenceBundles(PackageBundle packageBundle)
|
||||
{
|
||||
// 注意:引用的资源包不一定在内存中,所以需要过滤
|
||||
var referenceBundles = packageBundle.GetDebugReferenceBundles();
|
||||
List<string> result = new List<string>(referenceBundles.Count);
|
||||
foreach (var bundleName in referenceBundles)
|
||||
{
|
||||
if (LoaderDic.ContainsKey(bundleName))
|
||||
result.Add(bundleName);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user