mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-06-26 03:14:47 +00:00
110 lines
2.8 KiB
C#
110 lines
2.8 KiB
C#
using System.Collections.Generic;
|
|
using Cysharp.Threading.Tasks;
|
|
using Game.Plugins.App;
|
|
using Plugins.JNGame.Sync.Frame;
|
|
using Plugins.JNGame.Util;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
|
|
namespace Script.battle
|
|
{
|
|
//各种模式场景
|
|
public enum GBattleMode
|
|
{
|
|
Not = -1,
|
|
Default = 0
|
|
}
|
|
|
|
//初始化参数类
|
|
public class GBattleModeInfo
|
|
{
|
|
public List<GameObject> modes;
|
|
public GameObject root;
|
|
}
|
|
|
|
//全局战斗模式管理器
|
|
public class GBattleModeManager : SingletonScene<GBattleModeManager>
|
|
{
|
|
|
|
private static readonly string[] Worlds = { "WorldSync01", };
|
|
|
|
//当前模式
|
|
private GBattleMode _current = GBattleMode.Not;
|
|
|
|
//当前模式实体
|
|
public Object root;
|
|
|
|
//获取当前模式
|
|
public T GetMode<T>() where T : class
|
|
{
|
|
return root as T;
|
|
}
|
|
|
|
//初始化管理器
|
|
public void Init(GBattleModeInfo info)
|
|
{
|
|
// App.Event.AddListener(JNSyncFrameEvent.CREATE,LoadScene);
|
|
// App.Event.AddListener(JNSyncFrameEvent.CLEAR,UnloadScene);
|
|
}
|
|
|
|
//打开指定模式
|
|
public async UniTask Open(GBattleMode mode)
|
|
{
|
|
|
|
//销毁之前模式
|
|
_current = mode;
|
|
await OnReset();
|
|
//开始同步
|
|
App.Sync.OnStart();
|
|
|
|
}
|
|
|
|
//重置当前模式
|
|
public async UniTask OnReset()
|
|
{
|
|
await this.UnloadScene();
|
|
await UniTask.NextFrame();
|
|
App.Sync.OnReset();
|
|
await this.LoadScene();
|
|
_current = GBattleMode.Not;
|
|
}
|
|
|
|
//获取场景名称
|
|
public string GetWorldName(GBattleMode mode)
|
|
{
|
|
return Worlds[(int)mode];
|
|
}
|
|
|
|
//加载场景
|
|
private async UniTask LoadScene()
|
|
{
|
|
GBattleMode mode = this._current;
|
|
if (mode == GBattleMode.Not) return;
|
|
Debug.Log($"[GBattleModeManager] 打开场景{GetWorldName(mode)}");
|
|
await SceneManager.LoadSceneAsync(GetWorldName(mode));
|
|
}
|
|
|
|
//销毁所有场景
|
|
private async UniTask UnloadScene()
|
|
{
|
|
|
|
Debug.Log($"[GBattleModeManager] 关闭场景");
|
|
await UniTask.NextFrame();
|
|
//
|
|
// for (int i = SceneManager.sceneCount - 1; i >= 0; i--)
|
|
// {
|
|
// try
|
|
// {
|
|
// await SceneManager.UnloadSceneAsync(SceneManager.GetSceneAt(i));
|
|
// }
|
|
// catch
|
|
// {
|
|
// // ignored
|
|
// }
|
|
// }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} |