mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 02:36:14 +00:00
提交帧同步案例
This commit is contained in:
22
JNFrame/Assets/Script/App.cs
Normal file
22
JNFrame/Assets/Script/App.cs
Normal 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
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
}
|
3
JNFrame/Assets/Script/App.cs.meta
Normal file
3
JNFrame/Assets/Script/App.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 41bc0098f83045f18891ef5190ac6a17
|
||||
timeCreated: 1705981534
|
3
JNFrame/Assets/Script/AppImpl.meta
Normal file
3
JNFrame/Assets/Script/AppImpl.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4d1dd27990674b32820075e52dcbda67
|
||||
timeCreated: 1705993098
|
14
JNFrame/Assets/Script/AppImpl/JNGSocket.cs
Normal file
14
JNFrame/Assets/Script/AppImpl/JNGSocket.cs
Normal 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";
|
||||
}
|
||||
}
|
||||
}
|
3
JNFrame/Assets/Script/AppImpl/JNGSocket.cs.meta
Normal file
3
JNFrame/Assets/Script/AppImpl/JNGSocket.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6018b3436d0447f18eb907f86db6504e
|
||||
timeCreated: 1705993176
|
12
JNFrame/Assets/Script/AppImpl/JNGSyncFrame.cs
Normal file
12
JNFrame/Assets/Script/AppImpl/JNGSyncFrame.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
3
JNFrame/Assets/Script/AppImpl/JNGSyncFrame.cs.meta
Normal file
3
JNFrame/Assets/Script/AppImpl/JNGSyncFrame.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c3b45cb3cc954a99bface55dd2529ce6
|
||||
timeCreated: 1706241635
|
58
JNFrame/Assets/Script/Main.cs
Normal file
58
JNFrame/Assets/Script/Main.cs
Normal 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));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
11
JNFrame/Assets/Script/Main.cs.meta
Normal file
11
JNFrame/Assets/Script/Main.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 00b2d35a0698b224fa03e09bed92aac7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
JNFrame/Assets/Script/UIMain.cs
Normal file
8
JNFrame/Assets/Script/UIMain.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Script
|
||||
{
|
||||
public class UIMain : MonoBehaviour
|
||||
{
|
||||
}
|
||||
}
|
11
JNFrame/Assets/Script/UIMain.cs.meta
Normal file
11
JNFrame/Assets/Script/UIMain.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b87c4476f7ad6954e91fa3172d2b723a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
3
JNFrame/Assets/Script/battle.meta
Normal file
3
JNFrame/Assets/Script/battle.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 93f31f5f8f544a909b295c78ef4dca0b
|
||||
timeCreated: 1706167370
|
7
JNFrame/Assets/Script/battle/GBaseMode.cs
Normal file
7
JNFrame/Assets/Script/battle/GBaseMode.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace Script.battle
|
||||
{
|
||||
public class GBaseMode
|
||||
{
|
||||
|
||||
}
|
||||
}
|
3
JNFrame/Assets/Script/battle/GBaseMode.cs.meta
Normal file
3
JNFrame/Assets/Script/battle/GBaseMode.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 66eaac44e0ad4bf3b54c2806f86280c7
|
||||
timeCreated: 1706252585
|
83
JNFrame/Assets/Script/battle/GBattleModeManager.cs
Normal file
83
JNFrame/Assets/Script/battle/GBattleModeManager.cs
Normal 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));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
3
JNFrame/Assets/Script/battle/GBattleModeManager.cs.meta
Normal file
3
JNFrame/Assets/Script/battle/GBattleModeManager.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 36bc28f3467d4641abb08e83398a8a30
|
||||
timeCreated: 1706167381
|
Reference in New Issue
Block a user