update operation system
异步操作增加执行优先级
This commit is contained in:
@@ -12,25 +12,29 @@ namespace YooAsset
|
||||
private readonly bool _suspendLoad;
|
||||
private AsyncOperation _asyncOperation;
|
||||
|
||||
public DatabaseSceneProvider(ResourceManager manager, string providerGUID, uint providerPriority, AssetInfo assetInfo, LoadSceneMode sceneMode, bool suspendLoad) : base(manager, providerGUID, providerPriority, assetInfo)
|
||||
public DatabaseSceneProvider(ResourceManager manager, string providerGUID, AssetInfo assetInfo, LoadSceneMode sceneMode, bool suspendLoad) : base(manager, providerGUID, assetInfo)
|
||||
{
|
||||
SceneMode = sceneMode;
|
||||
SceneName = Path.GetFileNameWithoutExtension(assetInfo.AssetPath);
|
||||
_suspendLoad = suspendLoad;
|
||||
}
|
||||
public override void Update()
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
DebugBeginRecording();
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (IsDone)
|
||||
return;
|
||||
|
||||
if (Status == EStatus.None)
|
||||
if (_steps == ESteps.None)
|
||||
{
|
||||
Status = EStatus.CheckBundle;
|
||||
_steps = ESteps.CheckBundle;
|
||||
}
|
||||
|
||||
// 1. 检测资源包
|
||||
if (Status == EStatus.CheckBundle)
|
||||
if (_steps == ESteps.CheckBundle)
|
||||
{
|
||||
if (IsWaitForAsyncComplete)
|
||||
{
|
||||
@@ -42,17 +46,16 @@ namespace YooAsset
|
||||
|
||||
if (OwnerBundle.Status != BundleLoaderBase.EStatus.Succeed)
|
||||
{
|
||||
Status = EStatus.Failed;
|
||||
LastError = OwnerBundle.LastError;
|
||||
InvokeCompletion();
|
||||
string error = OwnerBundle.LastError;
|
||||
InvokeCompletion(error, EOperationStatus.Failed);
|
||||
return;
|
||||
}
|
||||
|
||||
Status = EStatus.Loading;
|
||||
_steps = ESteps.Loading;
|
||||
}
|
||||
|
||||
// 2. 加载资源对象
|
||||
if (Status == EStatus.Loading)
|
||||
if (_steps == ESteps.Loading)
|
||||
{
|
||||
LoadSceneParameters loadSceneParameters = new LoadSceneParameters();
|
||||
loadSceneParameters.loadSceneMode = SceneMode;
|
||||
@@ -60,32 +63,34 @@ namespace YooAsset
|
||||
if (_asyncOperation != null)
|
||||
{
|
||||
_asyncOperation.allowSceneActivation = !_suspendLoad;
|
||||
_asyncOperation.priority = (int)ProviderPriority;
|
||||
_asyncOperation.priority = 100;
|
||||
SceneObject = SceneManager.GetSceneAt(SceneManager.sceneCount - 1);
|
||||
Status = EStatus.Checking;
|
||||
_steps = ESteps.Checking;
|
||||
}
|
||||
else
|
||||
{
|
||||
Status = EStatus.Failed;
|
||||
LastError = $"Failed to load scene : {MainAssetInfo.AssetPath}";
|
||||
YooLogger.Error(LastError);
|
||||
InvokeCompletion();
|
||||
string error = $"Failed to load scene : {MainAssetInfo.AssetPath}";
|
||||
YooLogger.Error(error);
|
||||
InvokeCompletion(error, EOperationStatus.Failed);
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 检测加载结果
|
||||
if (Status == EStatus.Checking)
|
||||
if (_steps == ESteps.Checking)
|
||||
{
|
||||
Progress = _asyncOperation.progress;
|
||||
if (_asyncOperation.isDone)
|
||||
{
|
||||
Status = SceneObject.IsValid() ? EStatus.Succeed : EStatus.Failed;
|
||||
if (Status == EStatus.Failed)
|
||||
if (SceneObject.IsValid())
|
||||
{
|
||||
LastError = $"The loaded scene is invalid : {MainAssetInfo.AssetPath}";
|
||||
YooLogger.Error(LastError);
|
||||
InvokeCompletion(string.Empty, EOperationStatus.Succeed);
|
||||
}
|
||||
else
|
||||
{
|
||||
string error = $"The loaded scene is invalid : {MainAssetInfo.AssetPath}";
|
||||
YooLogger.Error(error);
|
||||
InvokeCompletion(error, EOperationStatus.Failed);
|
||||
}
|
||||
InvokeCompletion();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user