存档功能
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using AibisDream.Framework;
|
||||
using AibisDream.Kit;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||
@@ -11,17 +11,21 @@ namespace AibisDream
|
||||
{
|
||||
#region 场景转换参数
|
||||
|
||||
private string currentScene;
|
||||
private BindProperty<string> _currentScene;
|
||||
private AsyncOperationHandle _loadHandle;
|
||||
private string sceneToLoad;
|
||||
private bool isLoading;
|
||||
|
||||
#endregion
|
||||
|
||||
#region 场景切换事件
|
||||
|
||||
public event Action LoadSceneEvent;
|
||||
public event Action UnloadSceneEvent;
|
||||
private string _sceneToLoad;
|
||||
private bool _isLoading;
|
||||
|
||||
public override void OnSingletonInit()
|
||||
{
|
||||
_currentScene = new BindProperty<string>();
|
||||
_currentScene.Register(GameLoopManager.Instance.UpdateCurScene);
|
||||
}
|
||||
|
||||
public override void OnSingletonDestroy()
|
||||
{
|
||||
_currentScene.UnRegister(GameLoopManager.Instance.UpdateCurScene);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -41,50 +45,45 @@ namespace AibisDream
|
||||
/// <returns></returns>
|
||||
public IEnumerator LoadSceneAsync(string targetScene)
|
||||
{
|
||||
if (isLoading)
|
||||
if (_isLoading)
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 场景转换参数
|
||||
isLoading = true;
|
||||
sceneToLoad = targetScene;
|
||||
if (currentScene != null)
|
||||
_isLoading = true;
|
||||
_sceneToLoad = targetScene;
|
||||
if (string.IsNullOrEmpty(_currentScene.Value))
|
||||
{
|
||||
UnloadSceneEvent?.Invoke();
|
||||
yield return Addressables.UnloadSceneAsync(_loadHandle);
|
||||
}
|
||||
|
||||
|
||||
_loadHandle = Addressables.LoadSceneAsync(sceneToLoad, LoadSceneMode.Additive);
|
||||
_loadHandle = Addressables.LoadSceneAsync(_sceneToLoad, LoadSceneMode.Additive);
|
||||
yield return _loadHandle;
|
||||
|
||||
LoadSceneEvent?.Invoke();
|
||||
|
||||
currentScene = sceneToLoad;
|
||||
isLoading = false;
|
||||
_currentScene.Value = _sceneToLoad;
|
||||
_isLoading = false;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerator UnloadSceneAsync(string sceneToUnload)
|
||||
{
|
||||
if (isLoading)
|
||||
if (_isLoading)
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
isLoading = true;
|
||||
_isLoading = true;
|
||||
|
||||
if (currentScene == sceneToUnload)
|
||||
if (_currentScene.Value == sceneToUnload)
|
||||
{
|
||||
UnloadSceneEvent?.Invoke();
|
||||
yield return Addressables.UnloadSceneAsync(_loadHandle, true);
|
||||
currentScene = null;
|
||||
_currentScene.Value = null;
|
||||
}
|
||||
|
||||
isLoading = false;
|
||||
_isLoading = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user