diff --git a/UnityProject/Assets/TEngine/Runtime/Module/SceneModule/ISceneModule.cs b/UnityProject/Assets/TEngine/Runtime/Module/SceneModule/ISceneModule.cs
index 9bc84168..26ab0dff 100644
--- a/UnityProject/Assets/TEngine/Runtime/Module/SceneModule/ISceneModule.cs
+++ b/UnityProject/Assets/TEngine/Runtime/Module/SceneModule/ISceneModule.cs
@@ -1,4 +1,5 @@
using System;
+using Cysharp.Threading.Tasks;
using UnityEngine.SceneManagement;
namespace TEngine
@@ -10,6 +11,18 @@ namespace TEngine
///
public string CurrentMainSceneName { get; }
+ ///
+ /// 加载场景。
+ ///
+ /// 场景的定位地址
+ /// 场景加载模式
+ /// 加载完毕时是否主动挂起
+ /// 优先级
+ /// 加载主场景是否回收垃圾。
+ /// 加载进度回调。
+ public UniTask LoadScene(string location, LoadSceneMode sceneMode = LoadSceneMode.Single, bool suspendLoad = false, uint priority = 100, bool gcCollect = true,
+ Action progressCallBack = null);
+
///
/// 加载场景。
///
@@ -20,7 +33,7 @@ namespace TEngine
/// 加载回调。
/// 加载主场景是否回收垃圾。
/// 加载进度回调。
- public Scene LoadScene(string location,
+ public void LoadScene(string location,
LoadSceneMode sceneMode = LoadSceneMode.Single,
bool suspendLoad = false,
uint priority = 100,
diff --git a/UnityProject/Assets/TEngine/Runtime/Module/SceneModule/SceneModule.cs b/UnityProject/Assets/TEngine/Runtime/Module/SceneModule/SceneModule.cs
index 8e148853..8bd6b93d 100644
--- a/UnityProject/Assets/TEngine/Runtime/Module/SceneModule/SceneModule.cs
+++ b/UnityProject/Assets/TEngine/Runtime/Module/SceneModule/SceneModule.cs
@@ -42,6 +42,74 @@ namespace TEngine
_currentMainSceneName = string.Empty;
}
+ ///
+ /// 加载场景。
+ ///
+ /// 场景的定位地址
+ /// 场景加载模式
+ /// 加载完毕时是否主动挂起
+ /// 优先级
+ /// 加载主场景是否回收垃圾。
+ /// 加载进度回调。
+ public async UniTask LoadScene(string location, LoadSceneMode sceneMode = LoadSceneMode.Single, bool suspendLoad = false, uint priority = 100, bool gcCollect = true, Action progressCallBack = null)
+ {
+ if (sceneMode == LoadSceneMode.Additive)
+ {
+ if (_subScenes.TryGetValue(location, out SceneHandle subScene))
+ {
+ throw new Exception($"Could not load subScene while already loaded. Scene: {location}");
+ }
+
+ subScene = YooAssets.LoadSceneAsync(location, sceneMode, LocalPhysicsMode.None, suspendLoad, priority);
+
+
+ if (progressCallBack != null)
+ {
+ while (!subScene.IsDone && subScene.IsValid)
+ {
+ progressCallBack.Invoke(subScene.Progress);
+ await UniTask.Yield();
+ }
+ }
+ else
+ {
+ await subScene.ToUniTask();
+ }
+
+ _subScenes.Add(location, subScene);
+
+ return subScene.SceneObject;
+ }
+ else
+ {
+ if (_currentMainScene is { IsDone: false })
+ {
+ throw new Exception($"Could not load MainScene while loading. CurrentMainScene: {_currentMainSceneName}.");
+ }
+
+ _currentMainSceneName = location;
+
+ _currentMainScene = YooAssets.LoadSceneAsync(location, sceneMode, LocalPhysicsMode.None, suspendLoad, priority);
+
+ if (progressCallBack != null)
+ {
+ while (!_currentMainScene.IsDone && _currentMainScene.IsValid)
+ {
+ progressCallBack.Invoke(_currentMainScene.Progress);
+ await UniTask.Yield();
+ }
+ }
+ else
+ {
+ await _currentMainScene.ToUniTask();
+ }
+
+ ModuleSystem.GetModule().ForceUnloadUnusedAssets(gcCollect);
+
+ return _currentMainScene.SceneObject;
+ }
+ }
+
///
/// 加载场景。
///
@@ -52,7 +120,7 @@ namespace TEngine
/// 加载回调。
/// 加载主场景是否回收垃圾。
/// 加载进度回调。
- public Scene LoadScene(string location, LoadSceneMode sceneMode = LoadSceneMode.Single, bool suspendLoad = false, uint priority = 100,
+ public void LoadScene(string location, LoadSceneMode sceneMode = LoadSceneMode.Single, bool suspendLoad = false, uint priority = 100,
Action callBack = null,
bool gcCollect = true, Action progressCallBack = null)
{
@@ -61,7 +129,7 @@ namespace TEngine
if (_subScenes.TryGetValue(location, out SceneHandle subScene))
{
Log.Warning($"Could not load subScene while already loaded. Scene: {location}");
- return default;
+ return;
}
subScene = YooAssets.LoadSceneAsync(location, sceneMode, LocalPhysicsMode.None, suspendLoad, priority);
@@ -77,15 +145,13 @@ namespace TEngine
}
_subScenes.Add(location, subScene);
-
- return default;
}
else
{
if (_currentMainScene is { IsDone: false })
{
Log.Warning($"Could not load MainScene while loading. CurrentMainScene: {_currentMainSceneName}.");
- return default;
+ return;
}
_currentMainSceneName = location;
@@ -103,8 +169,6 @@ namespace TEngine
}
ModuleSystem.GetModule().ForceUnloadUnusedAssets(gcCollect);
-
- return _currentMainScene.SceneObject;
}
}