This commit is contained in:
PC-20230316NUNE\Administrator
2024-02-01 19:06:51 +08:00
parent aa4d6c3ce2
commit 877dca3b43
7518 changed files with 653768 additions and 162059 deletions

View File

@@ -0,0 +1,63 @@
using System;
using Game.Plugins.App;
using Google.Protobuf;
using Plugins.JNGame;
using Plugins.JNGame.Network.Action;
using Script.battle;
using UnityEditor;
using UnityEngine;
using UnityEngine.SceneManagement;
//游戏主入口
namespace Script
{
public class Main : MonoBehaviour
{
private void Awake()
{
DontDestroyOnLoad(this.gameObject);
}
async void Start()
{
//创建UI
SceneManager.LoadScene("UIScene", LoadSceneMode.Additive);
//加载框架
await JNGame.Init(App.System());
//初始化模式类
await GBattleModeManager.Instance.Open(GBattleMode.Default);
App.Socket.AddListener(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()
{
Debug.Log("OnNActionDemo");
}
public void OnNSyncFrameBack(JNFrameInfo info)
{
Debug.Log(info.Index);
App.Sync.AddInput(info);
}
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,44 @@
using System;
using Cysharp.Threading.Tasks;
using Game.Plugins.App;
using Script.battle;
using UnityEngine;
using UnityEngine.UI;
namespace Script
{
public class UIMain : MonoBehaviour
{
public Text frameLabel;
private void Awake()
{
DontDestroyOnLoad(this.gameObject);
}
//重置
public void OnClickReset()
{
GBattleModeManager.Instance.Open(GBattleMode.Default).Forget();
}
private void Update()
{
float f = 1.23456789f;
for (int i = 1000 - 1; i >= 0; i--)
{
// 进行一些基本的浮点数运算
f = f + f;
f = f - (f / 2);
f = f * (f / 2);
f = f / (f / 2);
f = (float)Math.Sqrt(f);
f = Math.Abs(f);
f = (float)Math.Log(f);
f = (float)Math.Log10(f);
f = (float)Math.Exp(f);
}
this.frameLabel.text = $"浮点数计算: {f} 服务器帧数: {App.Sync.NServerFrame} 本地运行帧 {App.Sync.NLocalFrame} 本地已执行帧 {App.Sync.NLocalRunFrame} 是否正在请求{App.Sync.IsRequestServerData} FPS:{1f/Time.deltaTime} this.DyTime():{App.Sync.DyTime()}";
}
}
}

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,9 @@
using Game.Plugins.App.Sync;
namespace Script.battle
{
public abstract class GBaseMode<T> : JNGSyncFrame<T>
{
}
}

View File

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

View File

@@ -0,0 +1,103 @@
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 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
// }
// }
}
}
}

View File

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

View File

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

View File

@@ -0,0 +1,39 @@
using Plugins.JNGame.BepuPhysics;
using UnityEngine;
namespace Script.battle.mode
{
public class GWorldSceneModeInput
{
}
public class GWorldSceneMode:GBaseMode<GWorldSceneModeInput>
{
public GameObject[] balls = null;
private JNBepuPhysics Physics;
public override void OnSyncLoad()
{
Physics = new();
// BufferPool pool = new BufferPool();
// Simulation.Create(pool, new DemoNarrowPhaseCallbacks(), new DemoPoseIntegratorCallbacks(new System.Numerics.Vector3(0, -10, 0)), new PositionFirstTimestepper());
}
public override void OnSyncUpdate(int dt, JNFrameInfo frame, GWorldSceneModeInput input)
{
Physics.OnUpdate((float) dt / 1000);
if (frame.Index > 0)
{
var index = GetSync().nRandomInt(0, balls.Length - 1);
Debug.Log(index);
var ballNode = Instantiate(balls[index],this.transform);
var transformPosition = ballNode.transform.position;
ballNode.transform.position = new Vector3(GetSync().nRandomFloat(-6,6),transformPosition.y,GetSync().nRandomFloat(-6,6));
}
}
}
}

View File

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

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 34db681fcdc63ef4888cf7b3a07e2eb7
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,25 @@
using System.Collections;
using System.Collections.Generic;
using BepuPhysics;
using BepuUtilities.Memory;
using Plugins.JNGame.BepuPhysics;
using UnityEngine;
public class DemoMain : MonoBehaviour
{
private JNBepuPhysics Physics;
// Start is called before the first frame update
void Awake()
{
Physics = new JNBepuPhysics();
}
// Update is called once per frame
void Update()
{
Physics.OnUpdate(Time.deltaTime);
}
}

View File

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