2025-09-05 19:46:30 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using AlicizaX.Resource.Runtime;
|
|
|
|
|
|
using Cysharp.Threading.Tasks;
|
|
|
|
|
|
using UnityEngine.SceneManagement;
|
|
|
|
|
|
using YooAsset;
|
|
|
|
|
|
|
|
|
|
|
|
namespace AlicizaX.Scene.Runtime
|
|
|
|
|
|
{
|
2026-03-26 16:14:05 +08:00
|
|
|
|
internal class SceneService : ServiceBase, ISceneService
|
2025-09-05 19:46:30 +08:00
|
|
|
|
{
|
2026-03-31 17:25:20 +08:00
|
|
|
|
public string CurrentMainSceneName => EnsureSceneState().CurrentMainSceneName;
|
2025-09-05 19:46:30 +08:00
|
|
|
|
|
2026-03-26 16:14:05 +08:00
|
|
|
|
protected override void OnInitialize()
|
2025-09-05 19:46:30 +08:00
|
|
|
|
{
|
2026-03-31 17:25:20 +08:00
|
|
|
|
var activeScene = SceneManager.GetActiveScene();
|
|
|
|
|
|
EnsureSceneState().SetBootScene(activeScene.name);
|
2025-09-05 19:46:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-26 16:14:05 +08:00
|
|
|
|
protected override void OnDestroyService()
|
2025-09-05 19:46:30 +08:00
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async UniTask<UnityEngine.SceneManagement.Scene> LoadSceneAsync(string location, LoadSceneMode sceneMode = LoadSceneMode.Single, bool suspendLoad = false, uint priority = 100, bool gcCollect = true, Action<float> progressCallBack = null)
|
|
|
|
|
|
{
|
2026-03-31 17:25:20 +08:00
|
|
|
|
var sceneState = EnsureSceneState();
|
|
|
|
|
|
if (!sceneState.TryBeginHandling(location))
|
2025-09-05 19:46:30 +08:00
|
|
|
|
{
|
|
|
|
|
|
Log.Error($"Could not load scene while loading. Scene: {location}");
|
|
|
|
|
|
return default;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (sceneMode == LoadSceneMode.Additive)
|
|
|
|
|
|
{
|
2026-04-07 16:54:59 +08:00
|
|
|
|
if (sceneState.TryGetSubScene(location, out YooAsset.SceneHandle loadedSubScene))
|
2025-09-05 19:46:30 +08:00
|
|
|
|
{
|
|
|
|
|
|
throw new Exception($"Could not load subScene while already loaded. Scene: {location}");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-31 17:25:20 +08:00
|
|
|
|
var subScene = YooAssets.LoadSceneAsync(location, sceneMode, LocalPhysicsMode.None, suspendLoad, priority);
|
|
|
|
|
|
sceneState.AddSubScene(location, subScene);
|
2025-09-05 19:46:30 +08:00
|
|
|
|
|
|
|
|
|
|
if (progressCallBack != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
while (!subScene.IsDone && subScene.IsValid)
|
|
|
|
|
|
{
|
|
|
|
|
|
progressCallBack.Invoke(subScene.Progress);
|
|
|
|
|
|
await UniTask.Yield();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
await subScene.ToUniTask();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-31 17:25:20 +08:00
|
|
|
|
sceneState.EndHandling(location);
|
2025-09-05 19:46:30 +08:00
|
|
|
|
return subScene.SceneObject;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-31 17:25:20 +08:00
|
|
|
|
if (sceneState.CurrentMainSceneHandle is { IsDone: false })
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new Exception($"Could not load MainScene while loading. CurrentMainScene: {sceneState.CurrentMainSceneName}.");
|
|
|
|
|
|
}
|
2025-09-05 19:46:30 +08:00
|
|
|
|
|
2026-03-31 17:25:20 +08:00
|
|
|
|
sceneState = PrepareSceneStateForMainSceneLoad(location);
|
|
|
|
|
|
var mainSceneHandle = YooAssets.LoadSceneAsync(location, sceneMode, LocalPhysicsMode.None, suspendLoad, priority);
|
2025-09-05 19:46:30 +08:00
|
|
|
|
|
2026-03-31 17:25:20 +08:00
|
|
|
|
if (progressCallBack != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
while (!mainSceneHandle.IsDone && mainSceneHandle.IsValid)
|
2025-09-05 19:46:30 +08:00
|
|
|
|
{
|
2026-03-31 17:25:20 +08:00
|
|
|
|
progressCallBack.Invoke(mainSceneHandle.Progress);
|
|
|
|
|
|
await UniTask.Yield();
|
2025-09-05 19:46:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-03-31 17:25:20 +08:00
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
await mainSceneHandle.ToUniTask();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sceneState.SetMainScene(location, mainSceneHandle);
|
|
|
|
|
|
Context.Require<IResourceService>().ForceUnloadUnusedAssets(gcCollect);
|
|
|
|
|
|
sceneState.EndHandling(location);
|
|
|
|
|
|
return mainSceneHandle.SceneObject;
|
2025-09-05 19:46:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void LoadScene(string location, LoadSceneMode sceneMode = LoadSceneMode.Single, bool suspendLoad = false, uint priority = 100,
|
|
|
|
|
|
Action<UnityEngine.SceneManagement.Scene> callBack = null,
|
|
|
|
|
|
bool gcCollect = true, Action<float> progressCallBack = null)
|
|
|
|
|
|
{
|
2026-03-31 17:25:20 +08:00
|
|
|
|
var sceneState = EnsureSceneState();
|
|
|
|
|
|
if (!sceneState.TryBeginHandling(location))
|
2025-09-05 19:46:30 +08:00
|
|
|
|
{
|
|
|
|
|
|
Log.Error($"Could not load scene while loading. Scene: {location}");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (sceneMode == LoadSceneMode.Additive)
|
|
|
|
|
|
{
|
2026-04-07 16:54:59 +08:00
|
|
|
|
if (sceneState.TryGetSubScene(location, out YooAsset.SceneHandle loadedSubScene))
|
2025-09-05 19:46:30 +08:00
|
|
|
|
{
|
|
|
|
|
|
Log.Warning($"Could not load subScene while already loaded. Scene: {location}");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-31 17:25:20 +08:00
|
|
|
|
var subScene = YooAssets.LoadSceneAsync(location, sceneMode, LocalPhysicsMode.None, suspendLoad, priority);
|
|
|
|
|
|
sceneState.AddSubScene(location, subScene);
|
2025-09-05 19:46:30 +08:00
|
|
|
|
subScene.Completed += handle =>
|
|
|
|
|
|
{
|
2026-03-31 17:25:20 +08:00
|
|
|
|
sceneState.EndHandling(location);
|
2025-09-05 19:46:30 +08:00
|
|
|
|
callBack?.Invoke(handle.SceneObject);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
if (progressCallBack != null)
|
|
|
|
|
|
{
|
2026-03-31 17:25:20 +08:00
|
|
|
|
InvokeSceneProgress(subScene, progressCallBack).Forget();
|
2025-09-05 19:46:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-31 17:25:20 +08:00
|
|
|
|
return;
|
2025-09-05 19:46:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-31 17:25:20 +08:00
|
|
|
|
if (sceneState.CurrentMainSceneHandle is { IsDone: false })
|
2025-09-05 19:46:30 +08:00
|
|
|
|
{
|
2026-03-31 17:25:20 +08:00
|
|
|
|
Log.Warning($"Could not load MainScene while loading. CurrentMainScene: {sceneState.CurrentMainSceneName}.");
|
2025-09-05 19:46:30 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-31 17:25:20 +08:00
|
|
|
|
sceneState = PrepareSceneStateForMainSceneLoad(location);
|
|
|
|
|
|
var mainSceneHandle = YooAssets.LoadSceneAsync(location, sceneMode, LocalPhysicsMode.None, suspendLoad, priority);
|
|
|
|
|
|
mainSceneHandle.Completed += handle =>
|
2025-09-05 19:46:30 +08:00
|
|
|
|
{
|
2026-03-31 17:25:20 +08:00
|
|
|
|
sceneState.SetMainScene(location, handle);
|
|
|
|
|
|
sceneState.EndHandling(location);
|
|
|
|
|
|
callBack?.Invoke(handle.SceneObject);
|
|
|
|
|
|
};
|
2025-09-05 19:46:30 +08:00
|
|
|
|
|
2026-03-31 17:25:20 +08:00
|
|
|
|
if (progressCallBack != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
InvokeSceneProgress(mainSceneHandle, progressCallBack).Forget();
|
2025-09-05 19:46:30 +08:00
|
|
|
|
}
|
2026-03-31 17:25:20 +08:00
|
|
|
|
|
|
|
|
|
|
Context.Require<IResourceService>().ForceUnloadUnusedAssets(gcCollect);
|
2025-09-05 19:46:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool ActivateScene(string location)
|
|
|
|
|
|
{
|
2026-03-31 17:25:20 +08:00
|
|
|
|
var sceneState = EnsureSceneState();
|
|
|
|
|
|
if (sceneState.CurrentMainSceneName.Equals(location))
|
2025-09-05 19:46:30 +08:00
|
|
|
|
{
|
2026-03-31 17:25:20 +08:00
|
|
|
|
return sceneState.CurrentMainSceneHandle != null && sceneState.CurrentMainSceneHandle.ActivateScene();
|
2025-09-05 19:46:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-31 17:25:20 +08:00
|
|
|
|
if (sceneState.TryGetSubScene(location, out var subScene) && subScene != null)
|
2025-09-05 19:46:30 +08:00
|
|
|
|
{
|
|
|
|
|
|
return subScene.ActivateScene();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Log.Warning($"IsMainScene invalid location:{location}");
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-31 17:25:20 +08:00
|
|
|
|
|
2025-09-05 19:46:30 +08:00
|
|
|
|
public bool UnSuspend(string location)
|
|
|
|
|
|
{
|
2026-03-31 17:25:20 +08:00
|
|
|
|
var sceneState = EnsureSceneState();
|
|
|
|
|
|
if (sceneState.CurrentMainSceneName.Equals(location))
|
2025-09-05 19:46:30 +08:00
|
|
|
|
{
|
2026-03-31 17:25:20 +08:00
|
|
|
|
return sceneState.CurrentMainSceneHandle != null && sceneState.CurrentMainSceneHandle.UnSuspend();
|
2025-09-05 19:46:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-31 17:25:20 +08:00
|
|
|
|
if (sceneState.TryGetSubScene(location, out var subScene) && subScene != null)
|
2025-09-05 19:46:30 +08:00
|
|
|
|
{
|
|
|
|
|
|
return subScene.UnSuspend();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Log.Warning($"IsMainScene invalid location:{location}");
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool IsMainScene(string location)
|
|
|
|
|
|
{
|
2026-03-31 17:25:20 +08:00
|
|
|
|
var sceneState = EnsureSceneState();
|
|
|
|
|
|
var currentScene = SceneManager.GetActiveScene();
|
2025-09-05 19:46:30 +08:00
|
|
|
|
|
2026-03-31 17:25:20 +08:00
|
|
|
|
if (sceneState.CurrentMainSceneName.Equals(location))
|
2025-09-05 19:46:30 +08:00
|
|
|
|
{
|
2026-03-31 17:25:20 +08:00
|
|
|
|
if (sceneState.CurrentMainSceneHandle == null)
|
2025-09-05 19:46:30 +08:00
|
|
|
|
{
|
2026-03-31 17:25:20 +08:00
|
|
|
|
return currentScene.name == location;
|
2025-09-05 19:46:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-31 17:25:20 +08:00
|
|
|
|
if (currentScene.name == sceneState.CurrentMainSceneHandle.SceneName)
|
2025-09-05 19:46:30 +08:00
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-31 17:25:20 +08:00
|
|
|
|
return sceneState.CurrentMainSceneHandle.SceneName == currentScene.name;
|
2025-09-05 19:46:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-31 17:25:20 +08:00
|
|
|
|
if (currentScene.name == sceneState.CurrentMainSceneHandle?.SceneName)
|
2025-09-05 19:46:30 +08:00
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Log.Warning($"IsMainScene invalid location:{location}");
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async UniTask<bool> UnloadAsync(string location, Action<float> progressCallBack = null)
|
|
|
|
|
|
{
|
2026-03-31 17:25:20 +08:00
|
|
|
|
var sceneState = EnsureSceneState();
|
|
|
|
|
|
if (sceneState.TryGetSubScene(location, out var subScene) && subScene != null)
|
2025-09-05 19:46:30 +08:00
|
|
|
|
{
|
|
|
|
|
|
if (subScene.SceneObject == default)
|
|
|
|
|
|
{
|
|
|
|
|
|
Log.Error($"Could not unload Scene while not loaded. Scene: {location}");
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-31 17:25:20 +08:00
|
|
|
|
if (!sceneState.TryBeginHandling(location))
|
2025-09-05 19:46:30 +08:00
|
|
|
|
{
|
|
|
|
|
|
Log.Warning($"Could not unload Scene while loading. Scene: {location}");
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var unloadOperation = subScene.UnloadAsync();
|
|
|
|
|
|
if (progressCallBack != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
while (!unloadOperation.IsDone && unloadOperation.Status != EOperationStatus.Failed)
|
|
|
|
|
|
{
|
|
|
|
|
|
progressCallBack.Invoke(unloadOperation.Progress);
|
|
|
|
|
|
await UniTask.Yield();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
await unloadOperation.ToUniTask();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-31 17:25:20 +08:00
|
|
|
|
sceneState.RemoveSubScene(location);
|
|
|
|
|
|
sceneState.EndHandling(location);
|
2025-09-05 19:46:30 +08:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Log.Warning($"UnloadAsync invalid location:{location}");
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Unload(string location, Action callBack = null, Action<float> progressCallBack = null)
|
|
|
|
|
|
{
|
2026-03-31 17:25:20 +08:00
|
|
|
|
var sceneState = EnsureSceneState();
|
|
|
|
|
|
if (sceneState.TryGetSubScene(location, out var subScene) && subScene != null)
|
2025-09-05 19:46:30 +08:00
|
|
|
|
{
|
|
|
|
|
|
if (subScene.SceneObject == default)
|
|
|
|
|
|
{
|
|
|
|
|
|
Log.Error($"Could not unload Scene while not loaded. Scene: {location}");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-31 17:25:20 +08:00
|
|
|
|
if (!sceneState.TryBeginHandling(location))
|
2025-09-05 19:46:30 +08:00
|
|
|
|
{
|
|
|
|
|
|
Log.Warning($"Could not unload Scene while loading. Scene: {location}");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-31 17:25:20 +08:00
|
|
|
|
var unloadOperation = subScene.UnloadAsync();
|
|
|
|
|
|
unloadOperation.Completed += @base =>
|
2025-09-05 19:46:30 +08:00
|
|
|
|
{
|
2026-03-31 17:25:20 +08:00
|
|
|
|
sceneState.RemoveSubScene(location);
|
|
|
|
|
|
sceneState.EndHandling(location);
|
2025-09-05 19:46:30 +08:00
|
|
|
|
callBack?.Invoke();
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
if (progressCallBack != null)
|
|
|
|
|
|
{
|
2026-03-31 17:25:20 +08:00
|
|
|
|
InvokeOperationProgress(unloadOperation, progressCallBack).Forget();
|
2025-09-05 19:46:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Log.Warning($"UnloadAsync invalid location:{location}");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool IsContainScene(string location)
|
|
|
|
|
|
{
|
2026-03-31 17:25:20 +08:00
|
|
|
|
return EnsureSceneState().IsContainScene(location);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private SceneDomainStateService EnsureSceneState()
|
|
|
|
|
|
{
|
|
|
|
|
|
var sceneScope = Context.EnsureScene();
|
|
|
|
|
|
if (!sceneScope.TryGet<SceneDomainStateService>(out var sceneState))
|
|
|
|
|
|
{
|
|
|
|
|
|
sceneState = sceneScope.Register(new SceneDomainStateService());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return sceneState;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private SceneDomainStateService PrepareSceneStateForMainSceneLoad(string location)
|
|
|
|
|
|
{
|
|
|
|
|
|
var sceneScope = Context.ResetScene();
|
|
|
|
|
|
var sceneState = sceneScope.Register(new SceneDomainStateService());
|
|
|
|
|
|
sceneState.MarkMainSceneLoading(location);
|
|
|
|
|
|
return sceneState;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-07 16:54:59 +08:00
|
|
|
|
private async UniTaskVoid InvokeSceneProgress(YooAsset.SceneHandle sceneHandle, Action<float> progress)
|
2026-03-31 17:25:20 +08:00
|
|
|
|
{
|
|
|
|
|
|
if (sceneHandle == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
while (!sceneHandle.IsDone && sceneHandle.IsValid)
|
|
|
|
|
|
{
|
|
|
|
|
|
await UniTask.Yield();
|
|
|
|
|
|
progress?.Invoke(sceneHandle.Progress);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async UniTaskVoid InvokeOperationProgress(AsyncOperationBase operation, Action<float> progress)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (operation == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
while (!operation.IsDone && operation.Status != EOperationStatus.Failed)
|
|
|
|
|
|
{
|
|
|
|
|
|
await UniTask.Yield();
|
|
|
|
|
|
progress?.Invoke(operation.Progress);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
internal sealed class SceneDomainStateService : ServiceBase, ISceneStateService
|
|
|
|
|
|
{
|
2026-04-07 16:54:59 +08:00
|
|
|
|
private readonly Dictionary<string,YooAsset.SceneHandle> _subScenes = new ();
|
2026-03-31 17:25:20 +08:00
|
|
|
|
private readonly HashSet<string> _handlingScenes = new HashSet<string>();
|
|
|
|
|
|
|
|
|
|
|
|
public string CurrentMainSceneName { get; private set; } = string.Empty;
|
|
|
|
|
|
|
2026-04-07 16:54:59 +08:00
|
|
|
|
public YooAsset.SceneHandle CurrentMainSceneHandle { get; private set; }
|
2026-03-31 17:25:20 +08:00
|
|
|
|
|
|
|
|
|
|
protected override void OnInitialize()
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override void OnDestroyService()
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var subScene in _subScenes.Values)
|
|
|
|
|
|
{
|
|
|
|
|
|
subScene?.UnloadAsync();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_subScenes.Clear();
|
|
|
|
|
|
_handlingScenes.Clear();
|
|
|
|
|
|
CurrentMainSceneHandle = null;
|
|
|
|
|
|
CurrentMainSceneName = string.Empty;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void SetBootScene(string sceneName)
|
|
|
|
|
|
{
|
|
|
|
|
|
CurrentMainSceneName = sceneName ?? string.Empty;
|
|
|
|
|
|
CurrentMainSceneHandle = null;
|
|
|
|
|
|
_subScenes.Clear();
|
|
|
|
|
|
_handlingScenes.Clear();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void MarkMainSceneLoading(string sceneName)
|
|
|
|
|
|
{
|
|
|
|
|
|
CurrentMainSceneName = sceneName ?? string.Empty;
|
|
|
|
|
|
CurrentMainSceneHandle = null;
|
|
|
|
|
|
_handlingScenes.Clear();
|
|
|
|
|
|
TryBeginHandling(sceneName);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-07 16:54:59 +08:00
|
|
|
|
public void SetMainScene(string sceneName, YooAsset.SceneHandle sceneHandle)
|
2026-03-31 17:25:20 +08:00
|
|
|
|
{
|
|
|
|
|
|
CurrentMainSceneName = sceneName ?? string.Empty;
|
|
|
|
|
|
CurrentMainSceneHandle = sceneHandle;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool TryBeginHandling(string location)
|
|
|
|
|
|
=> !string.IsNullOrEmpty(location) && _handlingScenes.Add(location);
|
|
|
|
|
|
|
|
|
|
|
|
public void EndHandling(string location)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!string.IsNullOrEmpty(location))
|
|
|
|
|
|
{
|
|
|
|
|
|
_handlingScenes.Remove(location);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-07 16:54:59 +08:00
|
|
|
|
public void AddSubScene(string location, YooAsset.SceneHandle sceneHandle)
|
2026-03-31 17:25:20 +08:00
|
|
|
|
{
|
|
|
|
|
|
_subScenes[location] = sceneHandle;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-07 16:54:59 +08:00
|
|
|
|
public bool TryGetSubScene(string location, out YooAsset.SceneHandle sceneHandle)
|
2026-03-31 17:25:20 +08:00
|
|
|
|
=> _subScenes.TryGetValue(location, out sceneHandle);
|
|
|
|
|
|
|
|
|
|
|
|
public bool RemoveSubScene(string location)
|
|
|
|
|
|
=> _subScenes.Remove(location);
|
|
|
|
|
|
|
|
|
|
|
|
public bool IsContainScene(string location)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (CurrentMainSceneName.Equals(location))
|
2025-09-05 19:46:30 +08:00
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-31 17:25:20 +08:00
|
|
|
|
return _subScenes.ContainsKey(location);
|
2025-09-05 19:46:30 +08:00
|
|
|
|
}
|
2026-03-31 17:25:20 +08:00
|
|
|
|
|
|
|
|
|
|
public bool IsMainScene(string location)
|
|
|
|
|
|
=> CurrentMainSceneName.Equals(location);
|
2025-09-05 19:46:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|