This commit is contained in:
PC-20230316NUNE\Administrator
2024-01-29 19:07:52 +08:00
parent 01293d9c30
commit 09db51f67b
62 changed files with 17325 additions and 1910 deletions

View File

@@ -1,5 +1,7 @@
using System.Collections.Generic;
using Cysharp.Threading.Tasks;
using Plugins.JNGame.Sync.Frame;
using Plugins.JNGame.Util;
using UnityEngine;
using UnityEngine.SceneManagement;
@@ -22,8 +24,8 @@ namespace Script.battle
//全局战斗模式管理器
public class GBattleModeManager : SingletonScene<GBattleModeManager>
{
public static string[] Worlds = { "WorldScene" };
private static readonly string[] Worlds = { "WorldSceneMode" };
//当前模式
private GBattleMode _current = GBattleMode.Not;
@@ -32,6 +34,9 @@ namespace Script.battle
public void Init(GBattleModeInfo info)
{
// App.Event.AddListener(JNSyncFrameEvent.CREATE,LoadScene);
// App.Event.AddListener(JNSyncFrameEvent.CLEAR,UnloadScene);
}
//打开指定模式
@@ -39,22 +44,20 @@ namespace Script.battle
{
//销毁之前模式
await Close();
_current = mode;
await LoadScene(mode);
await OnReset();
//开始同步
App.Sync.onStart();
App.Sync.OnStart();
}
//关闭当前模式
public async UniTask Close()
//重置当前模式
public async UniTask OnReset()
{
await UnloadScene(_current);
App.Sync.onStop();
await this.UnloadScene();
App.Sync.OnReset();
await this.LoadScene();
_current = GBattleMode.Not;
}
//获取场景名称
@@ -64,20 +67,30 @@ namespace Script.battle
}
//加载场景
private async UniTask LoadScene(GBattleMode mode)
private async UniTask LoadScene()
{
GBattleMode mode = this._current;
if (mode == GBattleMode.Not) return;
Debug.Log($"[GBattleModeManager] 打开场景{GetWorldName(mode)}");
await SceneManager.LoadSceneAsync(GetWorldName(mode), LoadSceneMode.Additive);
}
//销毁场景
private async UniTask UnloadScene(GBattleMode mode)
//销毁所有场景
private async UniTask UnloadScene()
{
if (mode == GBattleMode.Not) return;
Debug.Log($"[GBattleModeManager] 关闭场景{GetWorldName(mode)}");
await SceneManager.UnloadSceneAsync(GetWorldName(mode));
Debug.Log($"[GBattleModeManager] 关闭场景");
foreach (var world in Worlds)
{
try
{
await SceneManager.UnloadSceneAsync(world);
}
catch
{
// ignored
}
}
}