68 lines
2.1 KiB
C#
68 lines
2.1 KiB
C#
|
using System;
|
||
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Threading;
|
||
|
using Cysharp.Threading.Tasks;
|
||
|
using UnityEngine;
|
||
|
using UnityEngine.SceneManagement;
|
||
|
|
||
|
namespace BITKit.SceneManagement
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// 场景服务,负责场景的加载和卸载
|
||
|
/// </summary>
|
||
|
public interface ISceneService
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// 在场景加载完成后,是否初始化主场景
|
||
|
/// </summary>
|
||
|
bool InitializeMainSceneOnLoad { get; }
|
||
|
public UniTask LoadSceneAsync(string sceneName,CancellationToken cancellationToken, LoadSceneMode loadSceneMode = LoadSceneMode.Additive, bool activateOnLoad = true);
|
||
|
/// <summary>
|
||
|
/// 开始加载场景的回调
|
||
|
/// </summary>
|
||
|
event Action<string> OnLoadScene;
|
||
|
/// <summary>
|
||
|
/// 加载场景进度的回调
|
||
|
/// </summary>
|
||
|
event Action<string,float> OnSceneLoadProgress;
|
||
|
/// <summary>
|
||
|
/// 场景加载完成的回调
|
||
|
/// </summary>
|
||
|
event Action<string> OnSceneLoaded;
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 场景服务代理实现,主要用于快速继承
|
||
|
/// </summary>
|
||
|
public abstract class SceneServiceImplement:ISceneService
|
||
|
{
|
||
|
protected abstract ISceneService _sceneServiceImplementation { get; }
|
||
|
public bool InitializeMainSceneOnLoad => _sceneServiceImplementation.InitializeMainSceneOnLoad;
|
||
|
|
||
|
public UniTask LoadSceneAsync(string sceneName,CancellationToken cancellationToken, LoadSceneMode loadSceneMode = LoadSceneMode.Additive,
|
||
|
bool activateOnLoad = true)
|
||
|
{
|
||
|
return _sceneServiceImplementation.LoadSceneAsync(sceneName,cancellationToken, loadSceneMode, activateOnLoad);
|
||
|
}
|
||
|
|
||
|
public event Action<string> OnLoadScene
|
||
|
{
|
||
|
add => _sceneServiceImplementation.OnLoadScene += value;
|
||
|
remove => _sceneServiceImplementation.OnLoadScene -= value;
|
||
|
}
|
||
|
|
||
|
public event Action<string, float> OnSceneLoadProgress
|
||
|
{
|
||
|
add => _sceneServiceImplementation.OnSceneLoadProgress += value;
|
||
|
remove => _sceneServiceImplementation.OnSceneLoadProgress -= value;
|
||
|
}
|
||
|
|
||
|
public event Action<string> OnSceneLoaded
|
||
|
{
|
||
|
add => _sceneServiceImplementation.OnSceneLoaded += value;
|
||
|
remove => _sceneServiceImplementation.OnSceneLoaded -= value;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|