存档功能

This commit is contained in:
2025-01-08 11:41:20 +08:00
parent c67366664c
commit 43b99f98e7
49 changed files with 2498 additions and 5762 deletions
+27 -28
View File
@@ -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;
}
}
}