using System; using UnityEngine.SceneManagement; using YooAsset; namespace TEngine { /// /// 场景管理模块。 /// public sealed class SceneModule: Module { private ISceneModule _sceneModule; private void Start() { RootModule baseComponent = ModuleSystem.GetModule(); if (baseComponent == null) { Log.Fatal("Root module is invalid."); return; } _sceneModule = ModuleImpSystem.GetModule(); if (_sceneModule == null) { Log.Fatal("SceneModule is invalid."); return; } } /// /// 当前主场景名称。 /// public string CurrentMainSceneName => _sceneModule.CurrentMainSceneName; /// /// 加载场景。 /// /// 场景的定位地址 /// 场景加载模式 /// 加载完毕时是否主动挂起 /// 优先级 /// 加载回调。 /// 加载主场景是否回收垃圾。 /// 加载进度回调。 public SceneHandle LoadScene(string location, LoadSceneMode sceneMode = LoadSceneMode.Single, bool suspendLoad = false, int priority = 100, Action callBack = null, bool gcCollect = true, Action progressCallBack = null) { return _sceneModule.LoadScene(location, sceneMode, suspendLoad, priority, callBack, gcCollect, progressCallBack); } /// /// 加载子场景。 /// /// 场景的定位地址 /// 加载完毕时是否主动挂起 /// 优先级 /// 加载回调。 /// 加载主场景是否回收垃圾。 /// 加载进度回调。 public SceneHandle LoadSubScene(string location, bool suspendLoad = false, int priority = 100, Action callBack = null, bool gcCollect = true, Action progressCallBack = null) { return _sceneModule.LoadScene(location, LoadSceneMode.Additive, suspendLoad, priority, callBack, gcCollect, progressCallBack); } /// /// 激活场景(当同时存在多个场景时用于切换激活场景)。 /// /// 场景资源定位地址。 /// 是否操作成功。 public bool ActivateScene(string location) { return _sceneModule.ActivateScene(location); } /// /// 解除场景加载挂起操作。 /// /// 场景资源定位地址。 /// 是否操作成功。 public bool UnSuspend(string location) { return _sceneModule.UnSuspend(location); } /// /// 是否为主场景。 /// /// 场景资源定位地址。 /// 是否主场景。 public bool IsMainScene(string location) { return _sceneModule.IsMainScene(location); } /// /// 异步卸载子场景。 /// /// 场景资源定位地址。 /// 场景卸载异步操作类。 public UnloadSceneOperation UnloadAsync(string location) { return _sceneModule.UnloadAsync(location); } /// /// 是否包含场景。 /// /// 场景资源定位地址。 /// 是否包含场景。 public bool IsContainScene(string location) { return _sceneModule.IsContainScene(location); } } }