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,6 +1,8 @@
namespace Script.battle
using Script.AppImpl.Sync;
namespace Script.battle
{
public class GBaseMode
public abstract class GBaseMode<T> : JNGSyncFrame<T>
{
}

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
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 6b22dd710734444690a739bc582997fa
timeCreated: 1706519323

View File

@@ -0,0 +1,32 @@
using UnityEngine;
namespace Script.battle.mode
{
public class GWorldSceneModeInput
{
}
public class GWorldSceneMode:GBaseMode<GWorldSceneModeInput>
{
public GameObject ball;
// public override void OnSyncLoad()
// {
// base.OnSyncLoad();
// Instantiate(ball,this.transform);
// }
public override void OnSyncUpdate(int dt, JNFrameInfo frame, GWorldSceneModeInput input)
{
if (frame.Index > 0)
{
var ballNode = Instantiate(ball,this.transform);
var transformPosition = ballNode.transform.position;
ballNode.transform.position = new Vector3(transformPosition.x,transformPosition.y,GetSync().nRandomInt(-3,3));
}
Debug.Log("OnSyncUpdate");
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e57d6502487241f9826136613eff59a2
timeCreated: 1706519435