优化场景挂起流程,支持中途取消挂起操作。
pull/274/head
hevinci 2024-04-03 17:11:11 +08:00
parent f06bd83dc3
commit b5ffd5005a
3 changed files with 40 additions and 36 deletions

View File

@ -100,29 +100,21 @@ namespace YooAsset
if (IsValidWithWarning == false)
return false;
// 注意:当场景挂起操作执行之后无法中途取消!
if (SceneObject.IsValid())
if (Provider is DatabaseSceneProvider)
{
if (Provider is DatabaseSceneProvider)
{
var temp = Provider as DatabaseSceneProvider;
return temp.UnSuspendLoad();
}
else if (Provider is BundledSceneProvider)
{
var temp = Provider as BundledSceneProvider;
return temp.UnSuspendLoad();
}
else
{
throw new System.NotImplementedException();
}
var provider = Provider as DatabaseSceneProvider;
provider.UnSuspendLoad();
}
else if (Provider is BundledSceneProvider)
{
var provider = Provider as BundledSceneProvider;
provider.UnSuspendLoad();
}
else
{
YooLogger.Warning($"Scene is invalid : {SceneObject.name}");
return false;
throw new System.NotImplementedException();
}
return true;
}
/// <summary>

View File

@ -9,14 +9,14 @@ namespace YooAsset
internal sealed class BundledSceneProvider : ProviderBase
{
public readonly LoadSceneMode SceneMode;
private readonly bool _suspendLoad;
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);
_suspendLoad = suspendLoad;
_suspendLoadMode = suspendLoad;
}
internal override void InternalOnStart()
{
@ -80,7 +80,7 @@ namespace YooAsset
_asyncOperation = SceneManager.LoadSceneAsync(MainAssetInfo.AssetPath, SceneMode);
if (_asyncOperation != null)
{
_asyncOperation.allowSceneActivation = !_suspendLoad;
_asyncOperation.allowSceneActivation = !_suspendLoadMode;
_asyncOperation.priority = 100;
SceneObject = SceneManager.GetSceneAt(SceneManager.sceneCount - 1);
_steps = ESteps.Checking;
@ -106,6 +106,13 @@ namespace YooAsset
}
else
{
// 注意:在业务层中途可以取消挂起
if (_asyncOperation.allowSceneActivation == false)
{
if (_suspendLoadMode == false)
_asyncOperation.allowSceneActivation = true;
}
Progress = _asyncOperation.progress;
if (_asyncOperation.isDone == false)
return;
@ -128,13 +135,12 @@ namespace YooAsset
/// <summary>
/// 解除场景加载挂起操作
/// </summary>
public bool UnSuspendLoad()
public void UnSuspendLoad()
{
if (_asyncOperation == null)
return false;
_asyncOperation.allowSceneActivation = true;
return true;
if (IsDone == false)
{
_suspendLoadMode = false;
}
}
}
}

View File

@ -9,14 +9,14 @@ namespace YooAsset
internal sealed class DatabaseSceneProvider : ProviderBase
{
public readonly LoadSceneMode SceneMode;
private readonly bool _suspendLoad;
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);
_suspendLoad = suspendLoad;
_suspendLoadMode = suspendLoad;
}
internal override void InternalOnStart()
{
@ -69,7 +69,7 @@ namespace YooAsset
_asyncOperation = UnityEditor.SceneManagement.EditorSceneManager.LoadSceneAsyncInPlayMode(MainAssetInfo.AssetPath, loadSceneParameters);
if (_asyncOperation != null)
{
_asyncOperation.allowSceneActivation = !_suspendLoad;
_asyncOperation.allowSceneActivation = !_suspendLoadMode;
_asyncOperation.priority = 100;
SceneObject = SceneManager.GetSceneAt(SceneManager.sceneCount - 1);
_steps = ESteps.Checking;
@ -95,6 +95,13 @@ namespace YooAsset
}
else
{
// 注意:在业务层中途可以取消挂起
if (_asyncOperation.allowSceneActivation == false)
{
if (_suspendLoadMode == false)
_asyncOperation.allowSceneActivation = true;
}
Progress = _asyncOperation.progress;
if (_asyncOperation.isDone == false)
return;
@ -118,13 +125,12 @@ namespace YooAsset
/// <summary>
/// 解除场景加载挂起操作
/// </summary>
public bool UnSuspendLoad()
public void UnSuspendLoad()
{
if (_asyncOperation == null)
return false;
_asyncOperation.allowSceneActivation = true;
return true;
if (IsDone == false)
{
_suspendLoadMode = false;
}
}
}
}