修复场景卸载bug
parent
60c8968bf1
commit
3fb6766520
File diff suppressed because one or more lines are too long
|
|
@ -29,6 +29,8 @@ namespace Gameplay.SubSystems
|
|||
|
||||
private Dictionary<string, AsyncOperationHandle<SceneInstance>> _sceneOpDic = new();
|
||||
|
||||
private string _lastSceneToBeUnload;
|
||||
|
||||
private string GetPostProcessedScenePath(string scenePath) => PostProcessData.Instance[scenePath];
|
||||
|
||||
public async UniTask<SceneHandle> LoadSceneAsync(string scenePath, LoadSceneMode mode = LoadSceneMode.Single)
|
||||
|
|
@ -41,7 +43,10 @@ namespace Gameplay.SubSystems
|
|||
}
|
||||
|
||||
if (mode == LoadSceneMode.Single)
|
||||
{
|
||||
_sceneOpDic.Clear();
|
||||
_lastSceneToBeUnload = null;
|
||||
}
|
||||
|
||||
if (!_sceneOpDic.TryGetValue(scenePath, out var op))
|
||||
{
|
||||
|
|
@ -49,7 +54,13 @@ namespace Gameplay.SubSystems
|
|||
_sceneOpDic.Add(scenePath, op);
|
||||
}
|
||||
|
||||
await op.ToUniTask();
|
||||
await op;
|
||||
if (!string.IsNullOrEmpty(_lastSceneToBeUnload))
|
||||
{
|
||||
UnLoadSceneAsync(_lastSceneToBeUnload);
|
||||
_lastSceneToBeUnload = null;
|
||||
}
|
||||
|
||||
return new(op.Result.Scene);
|
||||
}
|
||||
|
||||
|
|
@ -64,12 +75,20 @@ namespace Gameplay.SubSystems
|
|||
|
||||
if (!_sceneOpDic.TryGetValue(scenePath, out var op))
|
||||
{
|
||||
Debug.LogError($"该场景没有被加载过 scenePath:{scenePath}");
|
||||
DebugUtil.LogError($"该场景没有被加载过 scenePath:{scenePath}");
|
||||
return;
|
||||
}
|
||||
|
||||
_sceneOpDic.Remove(scenePath);
|
||||
await Addressables.UnloadSceneAsync(op).ToUniTask();
|
||||
if (_sceneOpDic.Count == 1)
|
||||
{
|
||||
//如果只剩下一个场景了,那么此次unload必然失败,要等到下一次load新场景后重新unload
|
||||
_lastSceneToBeUnload = scenePath;
|
||||
}
|
||||
else
|
||||
{
|
||||
_sceneOpDic.Remove(scenePath);
|
||||
await Addressables.UnloadSceneAsync(op);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -1761,6 +1761,50 @@ CanvasRenderer:
|
|||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 600099759}
|
||||
m_CullTransparentMesh: 1
|
||||
--- !u!1 &603448208
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 603448210}
|
||||
- component: {fileID: 603448209}
|
||||
m_Layer: 0
|
||||
m_Name: InputManager
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!114 &603448209
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 603448208}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: a12e0c357618e41119174f3503c902dd, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
--- !u!4 &603448210
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 603448208}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0.9085703, y: -2.0125678, z: -1.524627}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!1 &617269941
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
|
@ -8641,3 +8685,4 @@ SceneRoots:
|
|||
- {fileID: 408243506}
|
||||
- {fileID: 2046660689}
|
||||
- {fileID: 14261388}
|
||||
- {fileID: 603448210}
|
||||
|
|
|
|||
Loading…
Reference in New Issue