提交帧同步案例

This commit is contained in:
PC-20230316NUNE\Administrator
2024-01-26 19:15:07 +08:00
parent 3a345ab966
commit 68c4d5e811
3928 changed files with 463020 additions and 1 deletions

View File

@@ -0,0 +1,22 @@
using Plugins.JNGame.System;
using Script.AppImpl;
namespace Script
{
public static class App
{
public static JNGSocket Socket = new JNGSocket();
public static JNGSyncFrame Sync = new JNGSyncFrame();
public static SystemBase[] System()
{
return new SystemBase[]
{
Socket,
Sync
};
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 41bc0098f83045f18891ef5190ac6a17
timeCreated: 1705981534

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 4d1dd27990674b32820075e52dcbda67
timeCreated: 1705993098

View File

@@ -0,0 +1,14 @@
using System.Threading.Tasks;
using Cysharp.Threading.Tasks;
using Plugins.JNGame.Network;
namespace Script.AppImpl
{
public class JNGSocket : JNSocket
{
protected override async UniTask<string> GetUrl()
{
return "ws://localhost:8080/websocket";
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 6018b3436d0447f18eb907f86db6504e
timeCreated: 1705993176

View File

@@ -0,0 +1,12 @@
using Plugins.JNGame.Sync.Frame;
namespace Script.AppImpl
{
public class JNGSyncFrame : JNSyncFrame
{
protected override void OnSendInput(JNFrameInputs inputs)
{
throw new System.NotImplementedException();
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c3b45cb3cc954a99bface55dd2529ce6
timeCreated: 1706241635

View File

@@ -0,0 +1,58 @@
using System;
using Plugins.JNGame;
using Plugins.JNGame.Network.Action;
using Script.battle;
using UnityEditor;
using UnityEngine;
using UnityEngine.SceneManagement;
//游戏主入口
namespace Script
{
public class Main : MonoBehaviour
{
async void Start()
{
//创建UI
SceneManager.LoadScene("UIScene", LoadSceneMode.Additive);
//加载框架
await JNGame.Init(App.System());
//初始化模式类
await GBattleModeManager.Instance.Open(GBattleMode.Default);
App.Socket.AddListener<NActionDemo>(3,OnNActionDemo);
App.Socket.AddListener<JNFrameInfo>((int)NActionEnum.NSyncFrameBack,OnNSyncFrameBack);
//加载成功向服务器发送帧同步消息
NActionDemo message = new NActionDemo();
message.Message = "HelloWorld Unity NGame";
App.Socket.Send(2,message);
//开启帧同步
App.Socket.Send((int)NActionEnum.NSyncFrameStart);
}
public void OnNActionDemo(NActionDemo demo)
{
Debug.Log(demo.Message);
}
public void OnNSyncFrameBack(JNFrameInfo info)
{
Debug.Log(info.Index);
}
private void Update()
{
App.Sync.Update((int)(Time.deltaTime * 1000));
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 00b2d35a0698b224fa03e09bed92aac7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
using UnityEngine;
namespace Script
{
public class UIMain : MonoBehaviour
{
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b87c4476f7ad6954e91fa3172d2b723a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 93f31f5f8f544a909b295c78ef4dca0b
timeCreated: 1706167370

View File

@@ -0,0 +1,7 @@
namespace Script.battle
{
public class GBaseMode
{
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 66eaac44e0ad4bf3b54c2806f86280c7
timeCreated: 1706252585

View File

@@ -0,0 +1,83 @@
using System.Collections.Generic;
using Cysharp.Threading.Tasks;
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>
{
public static string[] Worlds = { "WorldScene" };
//当前模式
private GBattleMode _current = GBattleMode.Not;
//初始化管理器
public void Init(GBattleModeInfo info)
{
}
//打开指定模式
public async UniTask Open(GBattleMode mode)
{
//销毁之前模式
await Close();
_current = mode;
await LoadScene(mode);
}
//关闭当前模式
public async UniTask Close()
{
await UnloadScene(_current);
_current = GBattleMode.Not;
}
//获取场景名称
public string GetWorldName(GBattleMode mode)
{
return Worlds[(int)mode];
}
//加载场景
private async UniTask LoadScene(GBattleMode mode)
{
if (mode == GBattleMode.Not) return;
Debug.Log($"[GBattleModeManager] 打开场景{GetWorldName(mode)}");
await SceneManager.LoadSceneAsync(GetWorldName(mode), LoadSceneMode.Additive);
}
//销毁场景
private async UniTask UnloadScene(GBattleMode mode)
{
if (mode == GBattleMode.Not) return;
Debug.Log($"[GBattleModeManager] 关闭场景{GetWorldName(mode)}");
await SceneManager.UnloadSceneAsync(GetWorldName(mode));
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 36bc28f3467d4641abb08e83398a8a30
timeCreated: 1706167381