using System;
using AlicizaX.Runtime;
using UnityEngine;
using UnityEngine.SceneManagement;
using YooAsset;
namespace AlicizaX.Scene.Runtime
{
///
/// 场景管理模块。
///
[DisallowMultipleComponent]
[AddComponentMenu("Game Framework/Scene")]
public sealed class SceneComponent : GameFrameworkComponent
{
private ISceneManager _sceneManager;
protected override void Awake()
{
ImplementationComponentType = Utility.Assembly.GetType(componentType);
InterfaceComponentType = typeof(ISceneManager);
base.Awake();
_sceneManager = SysModuleCenter.GetModule();
}
///
/// 当前主场景名称。
///
public string CurrentMainSceneName => _sceneManager.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 _sceneManager.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 _sceneManager.LoadScene(location, LoadSceneMode.Additive, suspendLoad, priority, callBack, gcCollect, progressCallBack);
}
///
/// 激活场景(当同时存在多个场景时用于切换激活场景)。
///
/// 场景资源定位地址。
/// 是否操作成功。
public bool ActivateScene(string location)
{
return _sceneManager.ActivateScene(location);
}
///
/// 解除场景加载挂起操作。
///
/// 场景资源定位地址。
/// 是否操作成功。
public bool UnSuspend(string location)
{
return _sceneManager.UnSuspend(location);
}
///
/// 异步卸载子场景。
///
/// 场景资源定位地址。
/// 场景卸载异步操作类。
public UnloadSceneOperation UnloadAsync(string location)
{
return _sceneManager.UnloadAsync(location);
}
///
/// 是否包含场景。
///
/// 场景资源定位地址。
/// 是否包含场景。
public bool IsContainScene(string location)
{
return _sceneManager.IsContainScene(location);
}
}
}