mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-11-11 00:36:00 +00:00
提交新概念 Tile从服务器
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using AppGame.Systems;
|
||||
using AppGame.Systems.CServer;
|
||||
using Plugins.JNGame.System;
|
||||
using Plugins.JNGame.Util;
|
||||
using Service;
|
||||
@@ -13,6 +14,8 @@ namespace AppGame
|
||||
Client,
|
||||
Server,
|
||||
ServerClient,
|
||||
SlaveServer,
|
||||
SlaveServerClient,
|
||||
}
|
||||
public class App
|
||||
{
|
||||
@@ -35,6 +38,7 @@ namespace AppGame
|
||||
public static readonly JNGSocket Socket = new JNGSocket();
|
||||
public static readonly JAPI API = new(new JAPIConfig(){BaseURL = "http://127.0.0.1:8080"});
|
||||
public static readonly GAPI GAPI = new GAPI();
|
||||
public static readonly EventDispatcher Event = new();
|
||||
public static int ClientID => Client.ClientID;
|
||||
|
||||
public static SystemBase[] AllSystem()
|
||||
@@ -42,8 +46,8 @@ namespace AppGame
|
||||
return new SystemBase[]
|
||||
{
|
||||
Business,
|
||||
IsServer() || IsSlaveServer() ? Server : null,
|
||||
Client,
|
||||
IsServer() ? Server : null,
|
||||
Resource,
|
||||
Game,
|
||||
// Socket,
|
||||
@@ -52,12 +56,17 @@ namespace AppGame
|
||||
|
||||
public static bool IsClient()
|
||||
{
|
||||
return Env is AppEnv.Client or AppEnv.ServerClient;
|
||||
return Env is AppEnv.Client or AppEnv.ServerClient or AppEnv.SlaveServerClient;
|
||||
}
|
||||
public static bool IsServer()
|
||||
{
|
||||
return Env is AppEnv.Server or AppEnv.ServerClient;
|
||||
}
|
||||
|
||||
public static bool IsSlaveServer()
|
||||
{
|
||||
return Env is AppEnv.SlaveServer or AppEnv.SlaveServerClient;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -9,17 +9,18 @@ using UnityEngine;
|
||||
public class DApplication : MonoBehaviour
|
||||
{
|
||||
|
||||
public GameObject Player1;
|
||||
public GameObject Player;
|
||||
public GameObject Boss;
|
||||
public GameObject VWorld;
|
||||
public CinemachineFreeLook FreeLook;
|
||||
|
||||
private async void Awake()
|
||||
{
|
||||
|
||||
|
||||
await JNetGame.Instance.Init(App.AllSystem());
|
||||
|
||||
//绑定资源
|
||||
App.Resource.Register(VWorld,Player1,FreeLook);
|
||||
App.Resource.Register(VWorld,Player,Boss,FreeLook);
|
||||
|
||||
//开始运行同步
|
||||
if (App.IsServer())
|
||||
@@ -27,9 +28,9 @@ public class DApplication : MonoBehaviour
|
||||
var tileServer = App.Game.StartServer<JNGTileServerSystem>();
|
||||
JNTileServerDebuger.Instance.Add(tileServer);
|
||||
}
|
||||
if (App.IsSlaveServer()) App.Game.StartServer<JNGTileSlaveServerSystem>();
|
||||
if (App.IsClient()) App.Game.StartClient<JNGTileClientSystem>();
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void Update()
|
||||
@@ -43,10 +44,17 @@ public class DApplication : MonoBehaviour
|
||||
input.IsPlayerCreate = true;
|
||||
}
|
||||
|
||||
public void OnClickBossCreate()
|
||||
{
|
||||
var input = App.Game.GetInput<IDWorld>();
|
||||
input.IsBossCreate = true;
|
||||
}
|
||||
|
||||
public void OnClickButton()
|
||||
{
|
||||
var input = App.Game.GetInput<IDWorld>();
|
||||
input.IsAdd = true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using Plugins.JNGame.Util;
|
||||
|
||||
@@ -7,9 +8,11 @@ namespace AppGame
|
||||
|
||||
public class TileServerInfo
|
||||
{
|
||||
public int tile;
|
||||
public String server;
|
||||
public String ip;
|
||||
public int port;
|
||||
public bool master;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -23,8 +26,10 @@ namespace AppGame
|
||||
public UniTask<NewsContext<int>> NSyncTileRandomId = App.API.GetNews<int>($"/sync/tile/random/id");
|
||||
//获取端口
|
||||
public UniTask<NewsContext<int>> NSyncTilePort = App.API.GetNews<int>($"/sync/tile/port");
|
||||
//获取默认连接
|
||||
//获取主连接
|
||||
public UniTask<NewsContext<TileServerInfo>> NSyncTileServer(int index) => App.API.GetNews<TileServerInfo>($"/sync/tile/server?index={index}");
|
||||
//获取所有连接
|
||||
public UniTask<NewsContext<List<TileServerInfo>>> NSyncTileListServer(int index) => App.API.GetNews<List<TileServerInfo>>($"/sync/tile/servers?index={index}");
|
||||
//获取玩家Id
|
||||
public UniTask<NewsContext<int>> NSyncTileClientId = App.API.GetNews<int>($"/sync/tile/client/id");
|
||||
|
||||
|
||||
@@ -6,7 +6,10 @@ namespace AppGame
|
||||
{
|
||||
|
||||
//绑定客户端Id
|
||||
BindClientID
|
||||
BindClientID = 10100,
|
||||
|
||||
//绑定客户端角色
|
||||
BindClientRole = 10101,
|
||||
|
||||
}
|
||||
}
|
||||
17
JNFrame2/Assets/Scripts/AppGame/GEvent.cs
Normal file
17
JNFrame2/Assets/Scripts/AppGame/GEvent.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
namespace AppGame
|
||||
{
|
||||
public class GEvent
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 网络 : 有新的Tile服务器
|
||||
/// </summary>
|
||||
public static readonly string NetNewTileServer = "NetNewTileServer";
|
||||
|
||||
/// <summary>
|
||||
/// 游戏 : 切换角色所在的Tile区块
|
||||
/// </summary>
|
||||
public static readonly string GSwPlayerTile = "GSwPlayerTile";
|
||||
|
||||
}
|
||||
}
|
||||
3
JNFrame2/Assets/Scripts/AppGame/GEvent.cs.meta
Normal file
3
JNFrame2/Assets/Scripts/AppGame/GEvent.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fc13d1c3df5342a8a7b6bc3deb29c362
|
||||
timeCreated: 1724924093
|
||||
@@ -24,5 +24,16 @@ namespace AppGame
|
||||
SceneManager.LoadScene(1);
|
||||
}
|
||||
|
||||
public void SetSlaveServerEnv()
|
||||
{
|
||||
App.Env = AppEnv.SlaveServer;
|
||||
SceneManager.LoadScene(1);
|
||||
}
|
||||
public void SetSlaveServerClientEnv()
|
||||
{
|
||||
App.Env = AppEnv.SlaveServerClient;
|
||||
SceneManager.LoadScene(1);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -4,9 +4,10 @@ using DotRecast.Core.Collections;
|
||||
using Game.Input;
|
||||
using Game.JNGFrame.Logic;
|
||||
using Game.JNGFrame.Logic.Entity;
|
||||
using Game.JNGFrame.Logic.System;
|
||||
using Game.JNGFrame.View;
|
||||
using Game.JNGState.Logic.Data;
|
||||
using Game.Logic.System.Logic;
|
||||
using Game.Logic.System.Usual;
|
||||
using JNGame.Sync.Entity;
|
||||
using JNGame.Sync.Frame;
|
||||
using JNGame.Sync.System;
|
||||
|
||||
@@ -2,10 +2,11 @@
|
||||
using Game.Input;
|
||||
using Game.JNGFrame.Logic;
|
||||
using Game.JNGFrame.Logic.Entity;
|
||||
using Game.JNGFrame.Logic.System;
|
||||
using Game.JNGFrame.View;
|
||||
using Game.JNGState.Logic.Data;
|
||||
using Game.Logic.System;
|
||||
using Game.Logic.System.Logic;
|
||||
using Game.Logic.System.Usual;
|
||||
using JNGame.Sync.Entity;
|
||||
using JNGame.Sync.State;
|
||||
using JNGame.Sync.System;
|
||||
@@ -35,6 +36,7 @@ namespace AppGame.Sync
|
||||
new DMapSystem(), //游戏地图
|
||||
new DWorldSystem(), //游戏逻辑
|
||||
new DPlayerSystem(), //玩家逻辑
|
||||
new DBossSystem(), //Boss逻辑
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@@ -23,8 +23,9 @@ namespace AppGame.Sync
|
||||
//区块Socket
|
||||
public Dictionary<int, JNGClient> Sockets = new ();
|
||||
|
||||
//玩家位置
|
||||
//玩家位置 和 区块
|
||||
public LVector3? PlayerPos;
|
||||
public int? PlayerTile;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -64,6 +65,7 @@ namespace AppGame.Sync
|
||||
return new SDataSystemBase[] {
|
||||
new EDNodeDataSystem(SStateDataEnum.Client), //游戏数据
|
||||
new EDPlayerDataSystem(SStateDataEnum.Client), //游戏数据
|
||||
new EDBossDataSystem(SStateDataEnum.Client), //游戏数据
|
||||
};
|
||||
}
|
||||
|
||||
@@ -111,6 +113,12 @@ namespace AppGame.Sync
|
||||
public void SetPlayerPosition(LVector3 pos)
|
||||
{
|
||||
PlayerPos = pos;
|
||||
int index = GetTileIndex(pos);
|
||||
if (PlayerTile != index)
|
||||
{
|
||||
PlayerTile = index;
|
||||
App.Event.Dispatch(GEvent.GSwPlayerTile);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -148,7 +156,7 @@ namespace AppGame.Sync
|
||||
});
|
||||
var keysToRemove = Sockets.Keys.Where(key => !TileShow.Contains(key)).ToList();
|
||||
foreach (var key in keysToRemove)
|
||||
{
|
||||
{
|
||||
RemoveSocket(key);
|
||||
}
|
||||
}
|
||||
@@ -163,7 +171,7 @@ namespace AppGame.Sync
|
||||
return Sockets.ContainsKey(index);
|
||||
}
|
||||
|
||||
protected async Task AddSocket(int index)
|
||||
protected async Task AddSocket(int index,TileServerInfo info = null)
|
||||
{
|
||||
if (IsTileConnect(index)) return;
|
||||
|
||||
@@ -171,8 +179,12 @@ namespace AppGame.Sync
|
||||
Sockets.Add(index,client);
|
||||
|
||||
//获取连接
|
||||
var message = (await App.GAPI.NSyncTileServer(index));
|
||||
TileServerInfo info = message.data;
|
||||
if (info is null)
|
||||
{
|
||||
var message = (await App.GAPI.NSyncTileServer(index));
|
||||
info = message.data;
|
||||
}
|
||||
|
||||
if (info is not null)
|
||||
{
|
||||
client.SetPoint($"{info.ip}:{info.port}");
|
||||
@@ -191,19 +203,25 @@ namespace AppGame.Sync
|
||||
|
||||
}
|
||||
|
||||
public async Task SwSocket(int index,TileServerInfo info)
|
||||
{
|
||||
RemoveSocket(index);
|
||||
await AddSocket(index, info);
|
||||
}
|
||||
|
||||
protected void RemoveSocket(int index)
|
||||
{
|
||||
if (Sockets.TryGetValue(index,out var client))
|
||||
{
|
||||
Debug.Log($"[{index}] 卸载 Socket");
|
||||
App.Client.RemoveClient(client);
|
||||
//并且释放数据
|
||||
GetSystems<ISTileDataSystem>().ForEach(data =>
|
||||
{
|
||||
data.ClearTileData(index);
|
||||
});
|
||||
}
|
||||
Sockets.Remove(index);
|
||||
//并且释放数据
|
||||
GetSystems<ISTileDataSystem>().ForEach(data =>
|
||||
{
|
||||
data.ClearTileData(index);
|
||||
});
|
||||
}
|
||||
public void RemoveSocket(string server)
|
||||
{
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using AppGame.Systems;
|
||||
using AppGame.Systems.CServer;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using DotRecast.Core.Collections;
|
||||
using Game.Input;
|
||||
using Game.JNGFrame.Logic;
|
||||
using Game.JNGFrame.Logic.Entity;
|
||||
using Game.JNGFrame.Logic.System;
|
||||
using Game.JNGFrame.View;
|
||||
using Game.JNGState.Logic.Data;
|
||||
using Game.Logic.System;
|
||||
using Game.Logic.System.Logic;
|
||||
using Game.Logic.System.Usual;
|
||||
using JNGame.Sync.State.Tile;
|
||||
using JNGame.Sync.State.Tile.Entity;
|
||||
using JNGame.Sync.System;
|
||||
@@ -28,11 +28,6 @@ namespace AppGame.Sync
|
||||
/// </summary>
|
||||
public class JNGTileServerSystem : JNSSTileServerService
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 测试标识
|
||||
/// </summary>
|
||||
private static int TileId = 1;
|
||||
|
||||
protected List<JNFrameInput> Inputs = new();
|
||||
|
||||
@@ -41,6 +36,8 @@ namespace AppGame.Sync
|
||||
|
||||
//是否开始前尝试连接周围区块去恢复历史数据
|
||||
public bool isRecover = true;
|
||||
|
||||
public override TileMasterSlaveEnum MSRole => TileMasterSlaveEnum.Master;
|
||||
|
||||
/// <summary>
|
||||
/// 初始化服务器
|
||||
@@ -100,7 +97,8 @@ namespace AppGame.Sync
|
||||
{
|
||||
Tile = TID,
|
||||
Ip = "127.0.0.1",
|
||||
Port = App.Server.Port
|
||||
Port = App.Server.Port,
|
||||
Master = true
|
||||
});
|
||||
|
||||
//定时更新Socket
|
||||
@@ -121,6 +119,7 @@ namespace AppGame.Sync
|
||||
new DMapSystem(), //游戏地图
|
||||
new DWorldSystem(), //游戏逻辑
|
||||
new DPlayerSystem(), //玩家逻辑
|
||||
new DBossSystem(), //Boss逻辑
|
||||
|
||||
};
|
||||
}
|
||||
@@ -128,8 +127,9 @@ namespace AppGame.Sync
|
||||
public override SDataSystemBase[] NewDataSystems()
|
||||
{
|
||||
return new SDataSystemBase[] {
|
||||
new EDNodeDataSystem(SStateDataEnum.Server), //游戏数据
|
||||
new EDPlayerDataSystem(SStateDataEnum.Server), //游戏数据
|
||||
new EDNodeDataSystem(SStateDataEnum.Server), //游戏数据
|
||||
new EDPlayerDataSystem(SStateDataEnum.Server), //游戏数据
|
||||
new EDBossDataSystem(SStateDataEnum.Server), //游戏数据
|
||||
};
|
||||
}
|
||||
|
||||
@@ -253,6 +253,7 @@ namespace AppGame.Sync
|
||||
if (info is not null)
|
||||
{
|
||||
Debug.Log($"[{index}] 连接 Socket");
|
||||
client.SetRole(JNGClientRole.Player);
|
||||
client.SetPoint($"{info.ip}:{info.port}");
|
||||
client.SetTileServer(info.server);
|
||||
await client.OnInit();
|
||||
|
||||
@@ -0,0 +1,202 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using AppGame.Systems;
|
||||
using AppGame.Systems.CServer;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using DotRecast.Core.Collections;
|
||||
using Game.Input;
|
||||
using Game.JNGFrame.Logic;
|
||||
using Game.JNGFrame.Logic.Entity;
|
||||
using Game.JNGFrame.View;
|
||||
using Game.JNGState.Logic.Data;
|
||||
using Game.Logic.System;
|
||||
using Game.Logic.System.Logic;
|
||||
using Game.Logic.System.Usual;
|
||||
using JNGame.Sync.State.Tile;
|
||||
using JNGame.Sync.State.Tile.Entity;
|
||||
using JNGame.Sync.System;
|
||||
using JNGame.Sync.System.Data;
|
||||
using JNGame.Util;
|
||||
using Plugins.JNGame.Network.Action;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AppGame.Sync
|
||||
{
|
||||
/// <summary>
|
||||
/// 瓦片状态同步[从服务器]
|
||||
/// </summary>
|
||||
public class JNGTileSlaveServerSystem : JNSSTileServerService
|
||||
{
|
||||
|
||||
protected List<JNFrameInput> Inputs = new();
|
||||
|
||||
protected override int[][] Tiles => new[]
|
||||
{
|
||||
new[] { 1, 2, 3 },
|
||||
new[] { 4, 5, 6 },
|
||||
new[] { 7, 8, 9 },
|
||||
};
|
||||
|
||||
protected override int TileSize => 100;
|
||||
|
||||
/// <summary>
|
||||
/// 主服务器
|
||||
/// </summary>
|
||||
public JNGTileClient Master { get; private set; }
|
||||
|
||||
public override TileMasterSlaveEnum MSRole => TileMasterSlaveEnum.Slave;
|
||||
|
||||
public override SLogicSystem[] NewLogicSystems()
|
||||
{
|
||||
return new SLogicSystem[]
|
||||
{
|
||||
|
||||
//基础数据
|
||||
new DInputSystem(), //游戏输入
|
||||
new DDataSystem(), //游戏数据
|
||||
|
||||
//逻辑层
|
||||
new DMapSystem(), //游戏地图
|
||||
new DWorldSystem(), //游戏逻辑
|
||||
new DPlayerSystem(), //玩家逻辑
|
||||
new DBossSystem(), //Boss逻辑
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
public override SDataSystemBase[] NewDataSystems()
|
||||
{
|
||||
return new SDataSystemBase[] {
|
||||
new EDNodeDataSystem(SStateDataEnum.Server), //游戏数据
|
||||
new EDPlayerDataSystem(SStateDataEnum.Server), //游戏数据
|
||||
new EDBossDataSystem(SStateDataEnum.Server), //游戏数据
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
// #if UNITY_EDITOR
|
||||
/// <summary>
|
||||
/// 编辑器显示视图层
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public override SViewSystem[] NewViewSystems()
|
||||
{
|
||||
return new SViewSystem[]
|
||||
{
|
||||
//视图层
|
||||
new DViewSystem(), //游戏视图
|
||||
};
|
||||
}
|
||||
// #endif
|
||||
|
||||
protected override JNTileContexts CreateTileContexts()
|
||||
{
|
||||
return new EDContexts();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化服务器
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected override async Task OnInit()
|
||||
{
|
||||
|
||||
RandomSize = (await App.GAPI.NSyncTileRandomId).data;
|
||||
|
||||
await base.OnInit();
|
||||
|
||||
//添加Tile从服务器
|
||||
App.Business.Send((int)NActionEnum.NAddTileServer,new JNAddTileServer()
|
||||
{
|
||||
Tile = TID,
|
||||
Ip = "127.0.0.1",
|
||||
Port = App.Server.Port,
|
||||
Master = false
|
||||
});
|
||||
|
||||
//更新主服务器
|
||||
Timers.Instance.SetInterval(1f, UpdateTileSocket);
|
||||
|
||||
}
|
||||
|
||||
protected override async UniTask<int> FetchTileId()
|
||||
{
|
||||
await UniTask.NextFrame();
|
||||
return 1;
|
||||
}
|
||||
|
||||
protected override void OnRunSimulate()
|
||||
{
|
||||
|
||||
//插入未处理输入
|
||||
lock (Inputs)
|
||||
{
|
||||
foreach (var input in Inputs)
|
||||
{
|
||||
GetSystem<DInputSystem>().Enqueue(input);
|
||||
}
|
||||
Inputs.Clear();
|
||||
}
|
||||
base.OnRunSimulate();
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加输入
|
||||
/// </summary>
|
||||
public void AddInput(JNStateTileInputs info)
|
||||
{
|
||||
lock (Inputs)
|
||||
{
|
||||
info.Message.Inputs.ForEach(child =>
|
||||
{
|
||||
Inputs.Add(child);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 连接主服务器
|
||||
/// </summary>
|
||||
private void UpdateTileSocket()
|
||||
{
|
||||
|
||||
//如果有连接则直接返回
|
||||
if (Master is not null) return;
|
||||
//连接主服务器
|
||||
OnMasterConnect();
|
||||
|
||||
}
|
||||
private async void OnMasterConnect()
|
||||
{
|
||||
|
||||
var message = (await App.GAPI.NSyncTileServer(TID));
|
||||
if (Master is not null) return;
|
||||
|
||||
if (message.data is null) return;
|
||||
|
||||
Master = new JNGTileClient();
|
||||
|
||||
var info = message.data;
|
||||
Debug.Log($"[JNGTileSlaveServerSystem {TID}] 连接 Socket");
|
||||
Master.SetRole(JNGClientRole.SlaveServer);
|
||||
Master.SetPoint($"{info.ip}:{info.port}");
|
||||
Master.SetTileServer(info.server);
|
||||
await Master.OnInit();
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 删除Socket
|
||||
/// </summary>
|
||||
public void RemoveSocket(string server)
|
||||
{
|
||||
if (Master is not null && Master.TileServer == server)
|
||||
{
|
||||
Master.OnClose();
|
||||
Master = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 234cd20f90624e6aa602e3ce4cd5c800
|
||||
timeCreated: 1724639704
|
||||
11
JNFrame2/Assets/Scripts/AppGame/Systems/CServer/CServer.cs
Normal file
11
JNFrame2/Assets/Scripts/AppGame/Systems/CServer/CServer.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace AppGame.Systems.CServer
|
||||
{
|
||||
/// <summary>
|
||||
/// 客户端角色
|
||||
/// </summary>
|
||||
public enum JNGClientRole : int
|
||||
{
|
||||
Player, //玩家
|
||||
SlaveServer //从服务器
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 25def782de754dbfb15c0b04eaa50e66
|
||||
timeCreated: 1724642638
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using AppGame.Systems.CServer;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using DotRecast.Core.Collections;
|
||||
using JNGame.Network;
|
||||
@@ -57,10 +58,15 @@ namespace AppGame.Systems
|
||||
private void OnClientConnect(byte[] obj)
|
||||
{
|
||||
//向服务器发送玩家Id
|
||||
Send((int)GActionEnum.BindClientID,new RClientIDMessage()
|
||||
Send((int)GActionEnum.BindClientID,new GBindClientID()
|
||||
{
|
||||
ClientId = ClientId
|
||||
});
|
||||
//向服务器绑定角色
|
||||
Send((int)GActionEnum.BindClientRole,new GBindClientRole()
|
||||
{
|
||||
Role = (int)JNGClientRole.Player
|
||||
});
|
||||
//向服务器索要全量信息
|
||||
Send((int)NActionEnum.NSyncTileAllUpdate);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using JNGame.Network;
|
||||
using Plugins.JNGame.Network;
|
||||
|
||||
namespace AppGame.Systems.CServer
|
||||
{
|
||||
public partial class JNGServer : JNTCPServer
|
||||
{
|
||||
|
||||
//客户端绑定的Id
|
||||
private Dictionary<string, int> ids = new();
|
||||
|
||||
//客户端角色
|
||||
private Dictionary<string, JNGClientRole> _roles = new();
|
||||
public Dictionary<string, JNGClientRole> Roles => _roles;
|
||||
|
||||
public void OnInit_Game()
|
||||
{
|
||||
|
||||
AddListener((int)GActionEnum.BindClientID,OnBindClientID);
|
||||
AddListener((int)GActionEnum.BindClientRole,OnBindClientRole);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 绑定客户端Id
|
||||
/// </summary>
|
||||
/// <param name="obj"></param>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
private void OnBindClientID(JNServerParam args)
|
||||
{
|
||||
var message = GBindClientID.Parser.ParseFrom(args.Message);
|
||||
ids[args.Client] = message.ClientId;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 绑定客户端角色
|
||||
/// </summary>
|
||||
private void OnBindClientRole(JNServerParam args)
|
||||
{
|
||||
|
||||
var message = GBindClientRole.Parser.ParseFrom(args.Message);
|
||||
_roles[args.Client] = (JNGClientRole)message.Role;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 14c921a786654c3fb9bb74e0d0ba29bd
|
||||
timeCreated: 1724642902
|
||||
@@ -1,28 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Sockets;
|
||||
using System.Threading.Tasks;
|
||||
using AppGame.Sync;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using DotRecast.Core.Collections;
|
||||
using Google.Protobuf;
|
||||
using JNGame.Network;
|
||||
using JNGame.Sync.System;
|
||||
using JNGame.Sync.State.Tile;
|
||||
using JNGame.Sync.System.Data;
|
||||
using Plugins.JNGame.Network;
|
||||
using Plugins.JNGame.Network.Action;
|
||||
|
||||
namespace AppGame.Systems
|
||||
namespace AppGame.Systems.CServer
|
||||
{
|
||||
public class JNGServer : JNTCPServer
|
||||
|
||||
public partial class JNGServer : JNTCPServer
|
||||
{
|
||||
|
||||
private int _index = 1;
|
||||
|
||||
private bool isInit = false;
|
||||
|
||||
//客户端绑定的Id
|
||||
private Dictionary<string, int> ids = new();
|
||||
|
||||
public override async Task OnInit()
|
||||
{
|
||||
@@ -33,7 +31,8 @@ namespace AppGame.Systems
|
||||
AddListener((int)NActionEnum.NSyncTileInput,OnNSyncTileInput);
|
||||
AddListener((int)NActionEnum.NSyncTileAllUpdate,OnNSyncTileAllUpdate);
|
||||
AddListener((int)NActionEnum.NSyncTileGetTileInfo,OnNSyncTileGetTileInfo);
|
||||
AddListener((int)GActionEnum.BindClientID,OnBindClientID);
|
||||
|
||||
OnInit_Game();
|
||||
|
||||
//连接
|
||||
await base.OnInit();
|
||||
@@ -49,18 +48,6 @@ namespace AppGame.Systems
|
||||
{
|
||||
return (await App.GAPI.NSyncTilePort).data;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 绑定客户端Id
|
||||
/// </summary>
|
||||
/// <param name="obj"></param>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
private void OnBindClientID(JNServerParam args)
|
||||
{
|
||||
var message = RClientIDMessage.Parser.ParseFrom(args.Message);
|
||||
ids[args.Client] = message.ClientId;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 接收帧数入
|
||||
@@ -100,13 +87,16 @@ namespace AppGame.Systems
|
||||
private void OnNSyncTileAllUpdate(JNServerParam args)
|
||||
{
|
||||
|
||||
if (App.Game.Server is not JNGTileServerSystem tileServer) return;
|
||||
if (App.Game.Server is not JNSSTileServerService tileServer) return;
|
||||
|
||||
var allData = new JNStateTileAllData();
|
||||
|
||||
allData.TId = tileServer.TID;
|
||||
allData.Data = new JNStateAllData();
|
||||
|
||||
//获取角色 根据角色 返回 全量数据
|
||||
Roles.TryGetValue(args.Client, out var role);
|
||||
|
||||
tileServer.GetSystems<ISTileDataSystem>().ForEach(data =>
|
||||
{
|
||||
|
||||
@@ -114,7 +104,22 @@ namespace AppGame.Systems
|
||||
allData.Data.Data.Add(item);
|
||||
|
||||
item.NetID = ((ISStateDataSystem)data).NetID;
|
||||
data.GetHostDataBytes().ForEach(keyValue =>
|
||||
|
||||
Dictionary<ulong, byte[]> byteData;
|
||||
switch (role)
|
||||
{
|
||||
case JNGClientRole.Player:
|
||||
byteData = data.GetHostDataBytes();
|
||||
break;
|
||||
case JNGClientRole.SlaveServer:
|
||||
byteData = data.GetHostDataBytesFilterSlave();
|
||||
break;
|
||||
default:
|
||||
byteData = new ();
|
||||
break;
|
||||
}
|
||||
|
||||
byteData.ForEach(keyValue =>
|
||||
{
|
||||
item.Messages[keyValue.Key] = new JNStateData() { Data = ByteString.CopyFrom(keyValue.Value) };
|
||||
});
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading.Tasks;
|
||||
using AppGame.Systems.CServer;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using DotRecast.Core.Collections;
|
||||
using JNGame.Network;
|
||||
using Plugins.JNGame.Network;
|
||||
using Plugins.JNGame.Network.Action;
|
||||
|
||||
namespace AppGame.Systems
|
||||
@@ -19,10 +18,24 @@ namespace AppGame.Systems
|
||||
private string _tileServer;
|
||||
public string TileServer => _tileServer;
|
||||
|
||||
private JNGClientRole _role;
|
||||
public JNGClientRole Role => _role;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 设置IP
|
||||
/// </summary>
|
||||
public void SetPoint(string point)
|
||||
{
|
||||
_point = point;
|
||||
}
|
||||
/// <summary>
|
||||
/// 设置角色
|
||||
/// </summary>
|
||||
public void SetRole(JNGClientRole role)
|
||||
{
|
||||
_role = role;
|
||||
}
|
||||
public void SetTileServer(string tileServer)
|
||||
{
|
||||
_tileServer = tileServer;
|
||||
@@ -49,6 +62,11 @@ namespace AppGame.Systems
|
||||
|
||||
private void OnClientConnect(byte[] obj)
|
||||
{
|
||||
//向服务器绑定角色
|
||||
Send((int)GActionEnum.BindClientRole,new GBindClientRole()
|
||||
{
|
||||
Role = (int)Role
|
||||
});
|
||||
//向服务器索要全量信息
|
||||
Send((int)NActionEnum.NSyncTileAllUpdate);
|
||||
}
|
||||
@@ -79,7 +97,7 @@ namespace AppGame.Systems
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 区块全量更新指定区块
|
||||
/// 获取指定区块状态
|
||||
/// </summary>
|
||||
public async Task<JNStateTileAllData> NSyncTileGetTileInfo(int index)
|
||||
{
|
||||
|
||||
@@ -58,20 +58,12 @@ namespace AppGame.Systems
|
||||
/// <returns></returns>
|
||||
public T GetInput<T>() where T : JNInputBase, new()
|
||||
{
|
||||
return GetClient().GetSystem<JNInputSystem>().Input<T>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取第一个客户端
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public JNSyncDefaultService GetClient()
|
||||
{
|
||||
return client;
|
||||
return Client.GetSystem<JNInputSystem>().Input<T>();
|
||||
}
|
||||
public T GetClient<T>() where T : JNSyncDefaultService
|
||||
{
|
||||
return (T)client;
|
||||
if (!IsStartClient) return null;
|
||||
return client as T;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -86,11 +78,18 @@ namespace AppGame.Systems
|
||||
|
||||
public void AddTileInput(JNStateTileInputs frame)
|
||||
{
|
||||
if (server is JNGTileServerSystem system)
|
||||
if (server is JNGTileServerSystem system1)
|
||||
{
|
||||
if (system.TID == frame.TId || frame.TId == 0)
|
||||
if (system1.TID == frame.TId || frame.TId == 0)
|
||||
{
|
||||
system.AddInput(frame);
|
||||
system1.AddInput(frame);
|
||||
}
|
||||
}
|
||||
if (server is JNGTileSlaveServerSystem system2)
|
||||
{
|
||||
if (system2.TID == frame.TId || frame.TId == 0)
|
||||
{
|
||||
system2.AddInput(frame);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ public class JNGSocket : JNSocket
|
||||
{
|
||||
|
||||
AddListener((int)NActionEnum.ServerClientDisconnect,OnServerClientDisconnect);
|
||||
AddListener((int)NActionEnum.NAddTileServer,OnNAddTileServer);
|
||||
|
||||
await base.OnInit();
|
||||
}
|
||||
@@ -34,6 +35,16 @@ public class JNGSocket : JNSocket
|
||||
//断开Tile服务器连接
|
||||
(App.Game.Client as JNGTileClientSystem)?.RemoveSocket(disconnect.ClientId);
|
||||
(App.Game.Server as JNGTileServerSystem)?.RemoveSocket(disconnect.ClientId);
|
||||
(App.Game.Server as JNGTileSlaveServerSystem)?.RemoveSocket(disconnect.ClientId);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 有新的Tile服务器
|
||||
/// </summary>
|
||||
/// <param name="obj"></param>
|
||||
private void OnNAddTileServer(byte[] obj)
|
||||
{
|
||||
App.Event.Dispatch(GEvent.NetNewTileServer);
|
||||
}
|
||||
}
|
||||
28
JNFrame2/Assets/Scripts/Game/Data/EDBossDataSystem.cs
Normal file
28
JNFrame2/Assets/Scripts/Game/Data/EDBossDataSystem.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System.Collections.Generic;
|
||||
using DotRecast.Core.Collections;
|
||||
using Game.JNGFrame.Logic.Entity;
|
||||
using Game.JNGFrame.Logic.Entity.Contexts;
|
||||
using JNGame.Sync.State.Tile.Entity;
|
||||
using JNGame.Sync.System.Data;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Game.JNGState.Logic.Data
|
||||
{
|
||||
|
||||
public class EDBossData : GDataBase<EDBossData,EDNodeValue,EDBoss>
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public class EDBossDataSystem : GDataBaseSystem<EDBossData,EDNodeValue,EDBoss>
|
||||
{
|
||||
public EDBossDataSystem(SStateDataEnum type) : base(type)
|
||||
{
|
||||
}
|
||||
|
||||
public override int NetID => (int)NetDataEnum.EDBossData;
|
||||
public override JNTileContext<EDBoss> NodeContext => Contexts.GetContext<EDBossContext>();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 800b600f0af8416c9f450a329385cfcb
|
||||
timeCreated: 1724675405
|
||||
@@ -25,16 +25,8 @@ namespace Game.JNGState.Logic.Data
|
||||
public class EDNodeData : GDataBase<EDNodeData,EDNodeValue,EDNode>
|
||||
{
|
||||
|
||||
public EDNodeData()
|
||||
{
|
||||
}
|
||||
|
||||
public EDNodeData(EDNode node) : base(node)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
public class EDNodeDataSystem : GDataBaseSystem<EDNodeData,EDNode>
|
||||
public class EDNodeDataSystem : GDataBaseSystem<EDNodeData,EDNodeValue,EDNode>
|
||||
{
|
||||
|
||||
public EDNodeDataSystem(SStateDataEnum type) : base(type)
|
||||
@@ -44,21 +36,6 @@ namespace Game.JNGState.Logic.Data
|
||||
public override JNTileContext<EDNode> NodeContext => Contexts.GetContext<EDNodeContext>();
|
||||
|
||||
public override int NetID => (int)NetDataEnum.EDNodeData;
|
||||
|
||||
public override Dictionary<ulong, EDNodeData> GetLatest()
|
||||
{
|
||||
var nodes = new Dictionary<ulong, EDNodeData>();
|
||||
NodeContext.GetEntities().ForEach(child =>
|
||||
{
|
||||
if (nodes.ContainsKey(child.Id))
|
||||
{
|
||||
Debug.Log($"[EDNodeDataSystem] 出错 发现重复Key");
|
||||
return;
|
||||
}
|
||||
nodes.Add(child.Id,new EDNodeData(child));
|
||||
});
|
||||
return nodes;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,16 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using DotRecast.Core.Collections;
|
||||
using Entitas;
|
||||
using Game.JNGFrame.Logic.Entity;
|
||||
using Game.JNGFrame.Logic.Entity.Contexts;
|
||||
using JNGame.Math;
|
||||
using JNGame.Sync.State.Tile.Entity;
|
||||
using JNGame.Sync.System;
|
||||
using JNGame.Sync.System.Data;
|
||||
using Newtonsoft.Json;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Game.JNGState.Logic.Data
|
||||
{
|
||||
@@ -23,13 +18,10 @@ namespace Game.JNGState.Logic.Data
|
||||
|
||||
public class EDPlayerData : GDataBase<EDPlayerData,EDPlayerValue,EDPlayer>
|
||||
{
|
||||
public EDPlayerData()
|
||||
public override void BindEntity(JNTileEntity entity)
|
||||
{
|
||||
}
|
||||
|
||||
public EDPlayerData(EDPlayer node) : base(node)
|
||||
{
|
||||
Value.Auth = node.Controller.Auth;
|
||||
base.BindEntity(entity);
|
||||
Value.Auth = Node.Controller.Auth;
|
||||
}
|
||||
|
||||
public override bool IsEquals(ISData data)
|
||||
@@ -58,7 +50,7 @@ namespace Game.JNGState.Logic.Data
|
||||
}
|
||||
|
||||
|
||||
public class EDPlayerDataSystem : GDataBaseSystem<EDPlayerData,EDPlayer>
|
||||
public class EDPlayerDataSystem : GDataBaseSystem<EDPlayerData,EDPlayerValue,EDPlayer>
|
||||
{
|
||||
|
||||
public EDPlayerDataSystem(SStateDataEnum type) : base(type)
|
||||
@@ -69,17 +61,6 @@ namespace Game.JNGState.Logic.Data
|
||||
|
||||
public override JNTileContext<EDPlayer> NodeContext => Contexts.GetContext<EDPlayerContext>();
|
||||
|
||||
|
||||
public override Dictionary<ulong, EDPlayerData> GetLatest()
|
||||
{
|
||||
var nodes = new Dictionary<ulong, EDPlayerData>();
|
||||
NodeContext.GetEntities().ForEach(child =>
|
||||
{
|
||||
nodes.Add(child.Id,new EDPlayerData(child));
|
||||
});
|
||||
return nodes;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,7 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using System.Text;
|
||||
using AppGame;
|
||||
using AppGame.Systems.CServer;
|
||||
using DotRecast.Core.Collections;
|
||||
using Google.Protobuf;
|
||||
using JNGame.Math;
|
||||
using JNGame.Sync.Entity;
|
||||
@@ -10,6 +14,7 @@ using JNGame.Sync.System;
|
||||
using JNGame.Sync.System.Data;
|
||||
using Newtonsoft.Json;
|
||||
using Plugins.JNGame.Network.Action;
|
||||
using Plugins.JNGame.Util;
|
||||
|
||||
namespace Game.JNGState.Logic.Data
|
||||
{
|
||||
@@ -27,22 +32,19 @@ namespace Game.JNGState.Logic.Data
|
||||
|
||||
public N Node => Entity as N;
|
||||
|
||||
public override bool IsHost => Node is not null && Node.IsHost;
|
||||
|
||||
public GDataBase()
|
||||
{
|
||||
}
|
||||
|
||||
public GDataBase(N node)
|
||||
public override void BindEntity(JNTileEntity entity)
|
||||
{
|
||||
Id = node.Id;
|
||||
base.BindEntity(entity);
|
||||
Value.Position = new DValuePosition()
|
||||
{
|
||||
x = node.Position.x.rawValue,
|
||||
y = node.Position.y.rawValue,
|
||||
z = node.Position.z.rawValue,
|
||||
x = Node.Position.x.rawValue,
|
||||
y = Node.Position.y.rawValue,
|
||||
z = Node.Position.z.rawValue,
|
||||
};
|
||||
BindEntity(node);
|
||||
}
|
||||
|
||||
public override bool IsEquals(ISData data)
|
||||
@@ -54,7 +56,8 @@ namespace Game.JNGState.Logic.Data
|
||||
|
||||
public sealed override byte[] GetByte()
|
||||
{
|
||||
return Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(Value));
|
||||
// return Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(Value));
|
||||
return ToUtil.ObjectToBytes(Value);
|
||||
}
|
||||
|
||||
public sealed override byte[] GetByteDifference(ISData diffValue = null)
|
||||
@@ -62,7 +65,8 @@ namespace Game.JNGState.Logic.Data
|
||||
var diff = GetDifference(diffValue);
|
||||
if (diff is not null)
|
||||
{
|
||||
return Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(diff));
|
||||
// return Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(diff));
|
||||
return ToUtil.ObjectToBytes(diff);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -85,7 +89,8 @@ namespace Game.JNGState.Logic.Data
|
||||
public sealed override void UByte(byte[] bytes)
|
||||
{
|
||||
if (bytes.Length == 0) return;
|
||||
var value = JsonConvert.DeserializeObject<T>(Encoding.UTF8.GetString(bytes));
|
||||
// var value = JsonConvert.DeserializeObject<T>(Encoding.UTF8.GetString(bytes));
|
||||
var value = ToUtil.BytesToObject<T>(bytes);
|
||||
UData(value);
|
||||
}
|
||||
|
||||
@@ -104,28 +109,54 @@ namespace Game.JNGState.Logic.Data
|
||||
|
||||
}
|
||||
|
||||
public abstract class GDataBaseSystem<T,E> : STileDataSystem<T,E> where T : ISTileData,new() where E : JNTileEntity, new()
|
||||
public abstract class GDataBaseSystem<T,V,E> : STileDataSystem<T,E> where T : GDataBase<T,V,E>,new() where E : JNTileEntity, new() where V : GDataValue,new()
|
||||
{
|
||||
protected GDataBaseSystem(SStateDataEnum type) : base(type)
|
||||
{
|
||||
}
|
||||
|
||||
public override void OnSendUBytes(Dictionary<ulong, byte[]> bytes)
|
||||
public override Dictionary<ulong, T> GetLatest()
|
||||
{
|
||||
var nodes = new Dictionary<ulong, T>();
|
||||
NodeContext.GetHostEntities().ForEach(child =>
|
||||
{
|
||||
var entity = new T();
|
||||
entity.BindEntity(child);
|
||||
nodes.Add(child.Id,entity);
|
||||
});
|
||||
return nodes;
|
||||
}
|
||||
|
||||
JNStateItemData data = new JNStateItemData();
|
||||
data.NetID = NetID;
|
||||
|
||||
public override void OnSendAllData(Dictionary<ulong, byte[]> bytes)
|
||||
{
|
||||
JNStateItemData player = new JNStateItemData(); //玩家状态数据
|
||||
player.NetID = NetID;
|
||||
foreach (var byteItem in bytes)
|
||||
{
|
||||
data.Messages.Add(byteItem.Key,new JNStateData()
|
||||
var data = new JNStateData()
|
||||
{
|
||||
Data = ByteString.CopyFrom(byteItem.Value)
|
||||
});
|
||||
};
|
||||
player.Messages.Add(byteItem.Key,data);
|
||||
}
|
||||
|
||||
App.Server.AllSend((int)NActionEnum.NSyncStateDataUpdate,data);
|
||||
|
||||
//给玩家发送状态信息
|
||||
App.Server.AllSend((int)NActionEnum.NSyncStateDataUpdate,player,client => App.Server.Roles.TryGetValue(client.Id,out var role) && role == JNGClientRole.Player);
|
||||
}
|
||||
|
||||
public override void OnSendSlaveData(Dictionary<ulong, byte[]> bytes)
|
||||
{
|
||||
JNStateItemData slave = new JNStateItemData(); //玩家状态数据
|
||||
slave.NetID = NetID;
|
||||
foreach (var byteItem in bytes)
|
||||
{
|
||||
var data = new JNStateData()
|
||||
{
|
||||
Data = ByteString.CopyFrom(byteItem.Value)
|
||||
};
|
||||
slave.Messages.Add(byteItem.Key,data);
|
||||
}
|
||||
//给从服务器发送状态信息
|
||||
App.Server.AllSend((int)NActionEnum.NSyncStateDataUpdate,slave,client => App.Server.Roles.TryGetValue(client.Id,out var role) && role == JNGClientRole.SlaveServer);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,5 +4,6 @@
|
||||
{
|
||||
EDNodeData = 0,
|
||||
EDPlayerData = 1,
|
||||
EDBossData = 2,
|
||||
}
|
||||
}
|
||||
@@ -20,5 +20,10 @@ namespace Game.Input
|
||||
/// </summary>
|
||||
public bool IsPlayerCreate;
|
||||
|
||||
/// <summary>
|
||||
/// Boss创建
|
||||
/// </summary>
|
||||
public bool IsBossCreate;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
using Entitas;
|
||||
using Game.JNGFrame.Logic.Entity.Contexts;
|
||||
using JNGame.Sync.Entity;
|
||||
using JNGame.Sync.Frame.Entity;
|
||||
using JNGame.Sync.State.Tile.Entity;
|
||||
|
||||
namespace Game.JNGFrame.Logic.Entity
|
||||
@@ -9,7 +7,7 @@ namespace Game.JNGFrame.Logic.Entity
|
||||
public class EDContexts : JNTileContexts
|
||||
{
|
||||
|
||||
public override IContext[] allContexts { get; } = { new EDNodeContext(),new EDPlayerContext() };
|
||||
public override IContext[] allContexts { get; } = { new EDNodeContext(),new EDPlayerContext(),new EDBossContext(), };
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
using DotRecast.Detour.Crowd;
|
||||
using Game.JNGFrame.Logic.System;
|
||||
using Game.Logic.System.Usual;
|
||||
using JNGame.Math;
|
||||
using JNGame.Sync.Entity.Component;
|
||||
using JNGame.Sync.State.Tile.Entity.Component;
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
using Game.Input;
|
||||
using Game.JNGFrame.Logic.Entity.Components;
|
||||
using JNGame.Math;
|
||||
using JNGame.Sync.State.Tile.Entity.Component;
|
||||
|
||||
namespace Game.JNGFrame.Logic.Entity.Controller
|
||||
{
|
||||
/// <summary>
|
||||
/// Boss控制器
|
||||
/// </summary>
|
||||
public class EDBossController : JNTileComponent
|
||||
{
|
||||
public override void OnSyncStart()
|
||||
{
|
||||
base.OnSyncStart();
|
||||
|
||||
//Boss 同步到从服务器
|
||||
TileEntity.IsSyncSlave = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b3e21eba1a90402cbcf1c142b7c6b103
|
||||
timeCreated: 1724723406
|
||||
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using Game.JNGFrame.Logic.Entity.Controller;
|
||||
using JNGame.Sync.Frame.Entity.Components;
|
||||
using JNGame.Util.Types;
|
||||
|
||||
namespace Game.JNGFrame.Logic.Entity.Components
|
||||
{
|
||||
public class EDBoosLookup : JNEntityLookup
|
||||
{
|
||||
|
||||
//移动组件
|
||||
public int Movement { get; set; }
|
||||
public int Controller { get; set; }
|
||||
|
||||
protected override void BindIndex()
|
||||
{
|
||||
base.BindIndex();
|
||||
Movement = Next();
|
||||
Controller = Next();
|
||||
}
|
||||
|
||||
protected override void BindType(KeyValue<int, Type> types)
|
||||
{
|
||||
base.BindType(types);
|
||||
types.Add(Movement,typeof(EDMoveComponent));
|
||||
types.Add(Controller,typeof(EDBossController));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3000f079bc5f4d72aa5d6b4145ac5e0e
|
||||
timeCreated: 1724723017
|
||||
@@ -0,0 +1,18 @@
|
||||
using Game.JNGFrame.Logic.Entity.Components;
|
||||
using Game.JNGFrame.Logic.Entity.Controller;
|
||||
using JNGame.Sync.Frame.Entity;
|
||||
using JNGame.Sync.State.Tile.Entity;
|
||||
|
||||
namespace Game.JNGFrame.Logic.Entity.Contexts
|
||||
{
|
||||
public sealed partial class EDBossContext : JNTileContext<EDBoss>
|
||||
{
|
||||
protected override EDBoss BindComponent(EDBoss entity)
|
||||
{
|
||||
base.BindComponent(entity);
|
||||
entity.AddComponent<EDMoveComponent>();
|
||||
entity.AddComponent<EDBossController>();
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dae9cf4b44914450b1624b40d7646190
|
||||
timeCreated: 1724723007
|
||||
29
JNFrame2/Assets/Scripts/Game/Logic/Entity/Nodes/EDBoss.cs
Normal file
29
JNFrame2/Assets/Scripts/Game/Logic/Entity/Nodes/EDBoss.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using Game.JNGFrame.Logic.Entity.Components;
|
||||
using Game.JNGFrame.Logic.Entity.Controller;
|
||||
using Game.JNGState.Logic.Data;
|
||||
using JNGame.Sync.Frame.Entity.Components;
|
||||
using JNGame.Sync.State.Tile.Entity;
|
||||
using JNGame.Sync.System.Data;
|
||||
using NotImplementedException = System.NotImplementedException;
|
||||
|
||||
namespace Game.JNGFrame.Logic.Entity
|
||||
{
|
||||
public class EDBoss : JNTileEntity
|
||||
{
|
||||
|
||||
public EDMoveComponent Move => CLookup.Query<EDMoveComponent>(this);
|
||||
public EDBossController Controller => CLookup.Query<EDBossController>(this);
|
||||
|
||||
public override void TileSyncData(ISTileData data)
|
||||
{
|
||||
var nodeData = data as EDBossData;
|
||||
Transform.Position = nodeData.Value.Position.ToLVector3();
|
||||
}
|
||||
|
||||
public override JNEntityLookup NewCLookup()
|
||||
{
|
||||
return new EDBoosLookup();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 473e297b1bcf4ff1ad73d3fd1de8c597
|
||||
timeCreated: 1724675433
|
||||
@@ -23,5 +23,6 @@ namespace Game.JNGFrame.Logic.Entity
|
||||
{
|
||||
return new EDNodeLookup();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
3
JNFrame2/Assets/Scripts/Game/Logic/System/Logic.meta
Normal file
3
JNFrame2/Assets/Scripts/Game/Logic/System/Logic.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: babf7d8ac075441b803a0078da31ce8a
|
||||
timeCreated: 1724724193
|
||||
@@ -0,0 +1,40 @@
|
||||
using DotRecast.Core.Collections;
|
||||
using Game.Input;
|
||||
using Game.JNGFrame.Logic.Entity;
|
||||
using Game.JNGFrame.Logic.Entity.Contexts;
|
||||
using JNGame.Math;
|
||||
|
||||
namespace Game.Logic.System.Logic
|
||||
{
|
||||
/// <summary>
|
||||
/// Boss逻辑
|
||||
/// </summary>
|
||||
public class DBossSystem : DGBasisSystem
|
||||
{
|
||||
|
||||
//Node 节点
|
||||
public EDBoss[] Nodes => NodeContext.GetHostEntities();
|
||||
public EDBossContext NodeContext => Contexts.GetContext<EDBossContext>();
|
||||
|
||||
public DInputSystem Input => GetSystem<DInputSystem>();
|
||||
|
||||
public override void OnSyncUpdate()
|
||||
{
|
||||
base.OnSyncUpdate();
|
||||
|
||||
//创建Boss
|
||||
GetSystem<DInputSystem>().SInput<IDWorld>().ForEach(child =>
|
||||
{
|
||||
|
||||
var idWorld = (IDWorld)child.Value;
|
||||
if (idWorld is { IsBossCreate: true })
|
||||
{
|
||||
var entity = NodeContext.CreateEntity();
|
||||
entity.Move.SetPosition(GetTileRandom());
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b48944cb153b4e67809d2cddde1acc6b
|
||||
timeCreated: 1724724224
|
||||
@@ -3,11 +3,8 @@ using Game.Input;
|
||||
using Game.JNGFrame.Logic.Entity;
|
||||
using Game.JNGFrame.Logic.Entity.Contexts;
|
||||
using JNGame.Math;
|
||||
using JNGame.Sync.Frame.Service;
|
||||
using JNGame.Sync.System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Game.Logic.System
|
||||
namespace Game.Logic.System.Logic
|
||||
{
|
||||
/// <summary>
|
||||
/// 玩家逻辑
|
||||
@@ -31,7 +28,7 @@ namespace Game.Logic.System
|
||||
var key = child.Key;
|
||||
var idWorld = (IDWorld)child.Value;
|
||||
|
||||
if (idWorld != null && idWorld.IsPlayerCreate)
|
||||
if (idWorld is { IsPlayerCreate: true })
|
||||
{
|
||||
var entity = NodeContext.CreateEntity();
|
||||
entity.Controller.AuthBind(key);
|
||||
@@ -1,13 +1,10 @@
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using Game.Input;
|
||||
using Game.JNGFrame.Logic.Entity;
|
||||
using Game.JNGFrame.Logic.Entity.Contexts;
|
||||
using Game.Logic.System;
|
||||
using JNGame.Math;
|
||||
using JNGame.Sync.Frame.Service;
|
||||
using JNGame.Sync.System;
|
||||
|
||||
namespace Game.JNGFrame.Logic.System
|
||||
namespace Game.Logic.System.Logic
|
||||
{
|
||||
public class DWorldSystem : DGBasisSystem
|
||||
{
|
||||
@@ -15,7 +12,10 @@ namespace Game.JNGFrame.Logic.System
|
||||
//Node 节点
|
||||
public EDNode[] Nodes => NodeContext.GetHostEntities();
|
||||
public EDNodeContext NodeContext => Contexts.GetContext<EDNodeContext>();
|
||||
|
||||
|
||||
//Node 第一个节点
|
||||
public Queue<EDNode> NodeQueue = new();
|
||||
|
||||
public override void OnSyncUpdate()
|
||||
{
|
||||
|
||||
@@ -25,28 +25,29 @@ namespace Game.JNGFrame.Logic.System
|
||||
//超过500 则 销毁第一个实体
|
||||
if (Nodes.Length >= 100)
|
||||
{
|
||||
var node = Nodes[0];
|
||||
node.Destroy();
|
||||
NodeQueue.Dequeue().Destroy();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
var max = 100;
|
||||
EDNode entity;
|
||||
if (IsTile())
|
||||
{
|
||||
var entity = Contexts.GetContext<EDNodeContext>().CreateEntity();
|
||||
entity = Contexts.GetContext<EDNodeContext>().CreateEntity();
|
||||
entity.Move.SetPosition(GetTileRandom());
|
||||
entity.Move.Go(GetTileRandom());
|
||||
}
|
||||
else
|
||||
{
|
||||
var entity = Contexts.GetContext<EDNodeContext>().CreateEntity();
|
||||
entity = Contexts.GetContext<EDNodeContext>().CreateEntity();
|
||||
var spawn = new LVector3(Random.Float(0, max),Random.Float(0, 100),Random.Float(0, max));
|
||||
entity.Move.SetPosition(spawn);
|
||||
spawn = new LVector3(Random.Float(0, max),Random.Float(0, 100),Random.Float(0, max));
|
||||
entity.Move.Go(spawn);
|
||||
}
|
||||
|
||||
|
||||
NodeQueue.Enqueue(entity);
|
||||
|
||||
}
|
||||
|
||||
3
JNFrame2/Assets/Scripts/Game/Logic/System/Usual.meta
Normal file
3
JNFrame2/Assets/Scripts/Game/Logic/System/Usual.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9c7f6594b809471b929e958068a70d32
|
||||
timeCreated: 1724724127
|
||||
@@ -1,11 +1,8 @@
|
||||
using AppGame;
|
||||
using Game.Logic.System;
|
||||
using JNGame.Map;
|
||||
using JNGame.Map.DotRecast.Util;
|
||||
using JNGame.Sync.System;
|
||||
using Service;
|
||||
|
||||
namespace Game.JNGFrame.Logic
|
||||
namespace Game.Logic.System.Usual
|
||||
{
|
||||
/// <summary>
|
||||
/// 游戏数据
|
||||
@@ -2,13 +2,11 @@
|
||||
using DotRecast.Core.Numerics;
|
||||
using DotRecast.Detour;
|
||||
using DotRecast.Detour.Crowd;
|
||||
using Game.Logic.System;
|
||||
using JNGame.Map.DotRecast;
|
||||
using JNGame.Math;
|
||||
using JNGame.Sync.System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Game.JNGFrame.Logic.System
|
||||
namespace Game.Logic.System.Usual
|
||||
{
|
||||
/// <summary>
|
||||
/// 地图
|
||||
@@ -14,6 +14,7 @@ namespace Game.JNGFrame.View
|
||||
views = new IViewData[] {
|
||||
new VDNodes(this), //显示Demo实体
|
||||
new VDPlayers(this), //显示玩家实体
|
||||
new VDBoss(this), //显示Boss实体
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
50
JNFrame2/Assets/Scripts/Game/View/Entity/VDBoss.cs
Normal file
50
JNFrame2/Assets/Scripts/Game/View/Entity/VDBoss.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using AppGame;
|
||||
using AppGame.Sync;
|
||||
using Cinemachine;
|
||||
using DG.Tweening;
|
||||
using Game.JNGFrame.Logic.Entity;
|
||||
using Game.JNGState.Logic.Data;
|
||||
using JNGame.Math;
|
||||
using JNGame.Sync.System;
|
||||
using JNGame.Sync.View;
|
||||
using Service;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Game.JNGFrame.View.Entity
|
||||
{
|
||||
public class VDBoss : ViewData<EDBossData>
|
||||
{
|
||||
public GameObject VWorld => App.Resource.VWorld;
|
||||
public GameObject Boss => App.Resource.Boss;
|
||||
|
||||
public VDBoss(SViewSystem root) : base(root)
|
||||
{
|
||||
}
|
||||
|
||||
public override void ViewUpdate(EDBossData data, GameObject view)
|
||||
{
|
||||
|
||||
view.name = $"Boss_{data.Id}";
|
||||
if (data.Value.Position != null)
|
||||
{
|
||||
view.transform.DOMove(data.Value.Position.ToVector3(), 0.5f);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public override GameObject NewView(EDBossData data)
|
||||
{
|
||||
return Object.Instantiate(Boss, VWorld.transform);
|
||||
}
|
||||
|
||||
public override EDBossData[] GetData()
|
||||
{
|
||||
return GetService<EDBossDataSystem>().Datas;
|
||||
}
|
||||
|
||||
public override void ViewRemove(GameObject view)
|
||||
{
|
||||
Object.Destroy(view);
|
||||
}
|
||||
}
|
||||
}
|
||||
3
JNFrame2/Assets/Scripts/Game/View/Entity/VDBoss.cs.meta
Normal file
3
JNFrame2/Assets/Scripts/Game/View/Entity/VDBoss.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 211b4062ef0644d583693f4b36358c40
|
||||
timeCreated: 1724724729
|
||||
@@ -1,7 +1,6 @@
|
||||
using AppGame;
|
||||
using DG.Tweening;
|
||||
using Game.JNGFrame.Logic.Entity;
|
||||
using Game.JNGFrame.Logic.System;
|
||||
using Game.JNGState.Logic.Data;
|
||||
using JNGame.Math;
|
||||
using JNGame.Sync.System;
|
||||
@@ -14,7 +13,7 @@ namespace Game.JNGFrame.View.Entity
|
||||
public class VDNodes : ViewData<EDNodeData>
|
||||
{
|
||||
public GameObject VWorld => App.Resource.VWorld;
|
||||
public GameObject Player1 => App.Resource.Player1;
|
||||
public GameObject Player => App.Resource.Player;
|
||||
public VDNodes(SViewSystem root) : base(root)
|
||||
{
|
||||
}
|
||||
@@ -32,7 +31,7 @@ namespace Game.JNGFrame.View.Entity
|
||||
|
||||
public override GameObject NewView(EDNodeData data)
|
||||
{
|
||||
return Object.Instantiate(Player1, VWorld.transform);
|
||||
return Object.Instantiate(Player, VWorld.transform);
|
||||
}
|
||||
|
||||
public override EDNodeData[] GetData()
|
||||
|
||||
@@ -2,13 +2,9 @@
|
||||
using AppGame.Sync;
|
||||
using Cinemachine;
|
||||
using DG.Tweening;
|
||||
using Game.JNGFrame.Logic.Entity;
|
||||
using Game.JNGFrame.Logic.System;
|
||||
using Game.JNGState.Logic.Data;
|
||||
using JNGame.Math;
|
||||
using JNGame.Sync.System;
|
||||
using JNGame.Sync.View;
|
||||
using Service;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Game.JNGFrame.View.Entity
|
||||
@@ -16,13 +12,9 @@ namespace Game.JNGFrame.View.Entity
|
||||
public class VDPlayers : ViewData<EDPlayerData>
|
||||
{
|
||||
public GameObject VWorld => App.Resource.VWorld;
|
||||
public GameObject Player1 => App.Resource.Player1;
|
||||
public GameObject Player => App.Resource.Player;
|
||||
public CinemachineFreeLook FreeLook => App.Resource.FreeLook;
|
||||
|
||||
public Vector3 pos = new Vector3(0, 0, 0);
|
||||
|
||||
public Vector3 target = new Vector3(0, 0, 0);
|
||||
|
||||
public VDPlayers(SViewSystem root) : base(root)
|
||||
{
|
||||
}
|
||||
@@ -36,13 +28,7 @@ namespace Game.JNGFrame.View.Entity
|
||||
{
|
||||
view.transform.DOKill();
|
||||
view.transform.DOMove(data.Value.Position.ToVector3(), 0.5f);
|
||||
// view.transform.position = data.Value.Position.ToVector3();
|
||||
// view.transform.DOKill();
|
||||
// view.transform.DOMove(pos = pos + new Vector3(0,0,10f / 15), 0.07f);
|
||||
}
|
||||
// view.transform.position += new Vector3(0, 0,3f * Time.deltaTime);
|
||||
// view.transform.position += new Vector3(0, 0,30f * Time.deltaTime);
|
||||
// view.transform.position = new Vector3(0, 10, view.transform.position.z);
|
||||
|
||||
//权限操作
|
||||
if (App.IsClient() && data.Value.Auth == App.ClientID)
|
||||
@@ -61,7 +47,7 @@ namespace Game.JNGFrame.View.Entity
|
||||
|
||||
public override GameObject NewView(EDPlayerData data)
|
||||
{
|
||||
var gameObject = Object.Instantiate(Player1, VWorld.transform);
|
||||
var gameObject = Object.Instantiate(Player, VWorld.transform);
|
||||
// gameObject.transform.DOMove(gameObject.transform.position + new Vector3(0,0,1000), 100);
|
||||
return gameObject;
|
||||
}
|
||||
|
||||
@@ -22,13 +22,14 @@ public static partial class GActionMessageReflection {
|
||||
static GActionMessageReflection() {
|
||||
byte[] descriptorData = global::System.Convert.FromBase64String(
|
||||
string.Concat(
|
||||
"ChRHQWN0aW9uTWVzc2FnZS5wcm90byIkChBSQ2xpZW50SURNZXNzYWdlEhAK",
|
||||
"CGNsaWVudElkGAEgASgFQhYKFGNuLmppc29sLm5nYW1lLnByb3RvYgZwcm90",
|
||||
"bzM="));
|
||||
"ChRHQWN0aW9uTWVzc2FnZS5wcm90byIhCg1HQmluZENsaWVudElEEhAKCGNs",
|
||||
"aWVudElkGAEgASgFIh8KD0dCaW5kQ2xpZW50Um9sZRIMCgRyb2xlGAEgASgF",
|
||||
"QhYKFGNuLmppc29sLm5nYW1lLnByb3RvYgZwcm90bzM="));
|
||||
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
|
||||
new pbr::FileDescriptor[] { },
|
||||
new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] {
|
||||
new pbr::GeneratedClrTypeInfo(typeof(global::RClientIDMessage), global::RClientIDMessage.Parser, new[]{ "ClientId" }, null, null, null, null)
|
||||
new pbr::GeneratedClrTypeInfo(typeof(global::GBindClientID), global::GBindClientID.Parser, new[]{ "ClientId" }, null, null, null, null),
|
||||
new pbr::GeneratedClrTypeInfo(typeof(global::GBindClientRole), global::GBindClientRole.Parser, new[]{ "Role" }, null, null, null, null)
|
||||
}));
|
||||
}
|
||||
#endregion
|
||||
@@ -36,18 +37,18 @@ public static partial class GActionMessageReflection {
|
||||
}
|
||||
#region Messages
|
||||
/// <summary>
|
||||
///返回Id
|
||||
///绑定客户端Id
|
||||
/// </summary>
|
||||
public sealed partial class RClientIDMessage : pb::IMessage<RClientIDMessage>
|
||||
public sealed partial class GBindClientID : pb::IMessage<GBindClientID>
|
||||
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
||||
, pb::IBufferMessage
|
||||
#endif
|
||||
{
|
||||
private static readonly pb::MessageParser<RClientIDMessage> _parser = new pb::MessageParser<RClientIDMessage>(() => new RClientIDMessage());
|
||||
private static readonly pb::MessageParser<GBindClientID> _parser = new pb::MessageParser<GBindClientID>(() => new GBindClientID());
|
||||
private pb::UnknownFieldSet _unknownFields;
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public static pb::MessageParser<RClientIDMessage> Parser { get { return _parser; } }
|
||||
public static pb::MessageParser<GBindClientID> Parser { get { return _parser; } }
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
@@ -63,7 +64,7 @@ public sealed partial class RClientIDMessage : pb::IMessage<RClientIDMessage>
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public RClientIDMessage() {
|
||||
public GBindClientID() {
|
||||
OnConstruction();
|
||||
}
|
||||
|
||||
@@ -71,15 +72,15 @@ public sealed partial class RClientIDMessage : pb::IMessage<RClientIDMessage>
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public RClientIDMessage(RClientIDMessage other) : this() {
|
||||
public GBindClientID(GBindClientID other) : this() {
|
||||
clientId_ = other.clientId_;
|
||||
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public RClientIDMessage Clone() {
|
||||
return new RClientIDMessage(this);
|
||||
public GBindClientID Clone() {
|
||||
return new GBindClientID(this);
|
||||
}
|
||||
|
||||
/// <summary>Field number for the "clientId" field.</summary>
|
||||
@@ -100,12 +101,12 @@ public sealed partial class RClientIDMessage : pb::IMessage<RClientIDMessage>
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public override bool Equals(object other) {
|
||||
return Equals(other as RClientIDMessage);
|
||||
return Equals(other as GBindClientID);
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public bool Equals(RClientIDMessage other) {
|
||||
public bool Equals(GBindClientID other) {
|
||||
if (ReferenceEquals(other, null)) {
|
||||
return false;
|
||||
}
|
||||
@@ -178,7 +179,7 @@ public sealed partial class RClientIDMessage : pb::IMessage<RClientIDMessage>
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public void MergeFrom(RClientIDMessage other) {
|
||||
public void MergeFrom(GBindClientID other) {
|
||||
if (other == null) {
|
||||
return;
|
||||
}
|
||||
@@ -230,6 +231,201 @@ public sealed partial class RClientIDMessage : pb::IMessage<RClientIDMessage>
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///绑定客户端角色
|
||||
/// </summary>
|
||||
public sealed partial class GBindClientRole : pb::IMessage<GBindClientRole>
|
||||
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
||||
, pb::IBufferMessage
|
||||
#endif
|
||||
{
|
||||
private static readonly pb::MessageParser<GBindClientRole> _parser = new pb::MessageParser<GBindClientRole>(() => new GBindClientRole());
|
||||
private pb::UnknownFieldSet _unknownFields;
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public static pb::MessageParser<GBindClientRole> Parser { get { return _parser; } }
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public static pbr::MessageDescriptor Descriptor {
|
||||
get { return global::GActionMessageReflection.Descriptor.MessageTypes[1]; }
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
pbr::MessageDescriptor pb::IMessage.Descriptor {
|
||||
get { return Descriptor; }
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public GBindClientRole() {
|
||||
OnConstruction();
|
||||
}
|
||||
|
||||
partial void OnConstruction();
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public GBindClientRole(GBindClientRole other) : this() {
|
||||
role_ = other.role_;
|
||||
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public GBindClientRole Clone() {
|
||||
return new GBindClientRole(this);
|
||||
}
|
||||
|
||||
/// <summary>Field number for the "role" field.</summary>
|
||||
public const int RoleFieldNumber = 1;
|
||||
private int role_;
|
||||
/// <summary>
|
||||
///角色
|
||||
/// </summary>
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public int Role {
|
||||
get { return role_; }
|
||||
set {
|
||||
role_ = value;
|
||||
}
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public override bool Equals(object other) {
|
||||
return Equals(other as GBindClientRole);
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public bool Equals(GBindClientRole other) {
|
||||
if (ReferenceEquals(other, null)) {
|
||||
return false;
|
||||
}
|
||||
if (ReferenceEquals(other, this)) {
|
||||
return true;
|
||||
}
|
||||
if (Role != other.Role) return false;
|
||||
return Equals(_unknownFields, other._unknownFields);
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public override int GetHashCode() {
|
||||
int hash = 1;
|
||||
if (Role != 0) hash ^= Role.GetHashCode();
|
||||
if (_unknownFields != null) {
|
||||
hash ^= _unknownFields.GetHashCode();
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public override string ToString() {
|
||||
return pb::JsonFormatter.ToDiagnosticString(this);
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public void WriteTo(pb::CodedOutputStream output) {
|
||||
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
||||
output.WriteRawMessage(this);
|
||||
#else
|
||||
if (Role != 0) {
|
||||
output.WriteRawTag(8);
|
||||
output.WriteInt32(Role);
|
||||
}
|
||||
if (_unknownFields != null) {
|
||||
_unknownFields.WriteTo(output);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
|
||||
if (Role != 0) {
|
||||
output.WriteRawTag(8);
|
||||
output.WriteInt32(Role);
|
||||
}
|
||||
if (_unknownFields != null) {
|
||||
_unknownFields.WriteTo(ref output);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public int CalculateSize() {
|
||||
int size = 0;
|
||||
if (Role != 0) {
|
||||
size += 1 + pb::CodedOutputStream.ComputeInt32Size(Role);
|
||||
}
|
||||
if (_unknownFields != null) {
|
||||
size += _unknownFields.CalculateSize();
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public void MergeFrom(GBindClientRole other) {
|
||||
if (other == null) {
|
||||
return;
|
||||
}
|
||||
if (other.Role != 0) {
|
||||
Role = other.Role;
|
||||
}
|
||||
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public void MergeFrom(pb::CodedInputStream input) {
|
||||
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
||||
input.ReadRawMessage(this);
|
||||
#else
|
||||
uint tag;
|
||||
while ((tag = input.ReadTag()) != 0) {
|
||||
switch(tag) {
|
||||
default:
|
||||
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
|
||||
break;
|
||||
case 8: {
|
||||
Role = input.ReadInt32();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
|
||||
uint tag;
|
||||
while ((tag = input.ReadTag()) != 0) {
|
||||
switch(tag) {
|
||||
default:
|
||||
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
|
||||
break;
|
||||
case 8: {
|
||||
Role = input.ReadInt32();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
@@ -2,9 +2,16 @@ syntax = "proto3";
|
||||
|
||||
option java_package = "cn.jisol.ngame.proto";
|
||||
|
||||
//返回Id
|
||||
message RClientIDMessage{
|
||||
//绑定客户端Id
|
||||
message GBindClientID{
|
||||
int32 clientId = 1; //输入的Id
|
||||
}
|
||||
|
||||
//绑定客户端角色
|
||||
message GBindClientRole{
|
||||
int32 role = 1; //角色 0.玩家 1.从服务器
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -20,7 +20,9 @@ namespace Service
|
||||
public MeshData MapData2;
|
||||
|
||||
//角色1
|
||||
public GameObject Player1;
|
||||
public GameObject Player;
|
||||
//Boss
|
||||
public GameObject Boss;
|
||||
//世界
|
||||
public GameObject VWorld;
|
||||
|
||||
@@ -37,9 +39,10 @@ namespace Service
|
||||
}
|
||||
|
||||
|
||||
public void Register(GameObject world,GameObject player,CinemachineFreeLook freeLook)
|
||||
public void Register(GameObject world,GameObject player,GameObject boss,CinemachineFreeLook freeLook)
|
||||
{
|
||||
Player1 = player;
|
||||
Player = player;
|
||||
Boss = boss;
|
||||
VWorld = world;
|
||||
FreeLook = freeLook;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using AppGame;
|
||||
using AppGame.Sync;
|
||||
using Game.Input;
|
||||
using JNGame.Math;
|
||||
using JNGame.Util;
|
||||
using Plugins.JNGame.Network;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
@@ -17,6 +22,16 @@ namespace UI
|
||||
|
||||
public Camera MainCamera;
|
||||
|
||||
public Dropdown tileDropdown;
|
||||
|
||||
public List<TileServerInfo> servers;
|
||||
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
AddListener();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
|
||||
@@ -51,5 +66,54 @@ namespace UI
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 监听事件
|
||||
/// </summary>
|
||||
private void AddListener()
|
||||
{
|
||||
App.Event.AddListener(GEvent.GSwPlayerTile,OnGSwPlayerTile);
|
||||
App.Event.AddListener(GEvent.NetNewTileServer,OnGSwPlayerTile);
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
App.Event.RemoveListener(GEvent.GSwPlayerTile,OnGSwPlayerTile);
|
||||
App.Event.RemoveListener(GEvent.NetNewTileServer,OnGSwPlayerTile);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 玩家区块切换了
|
||||
/// </summary>
|
||||
private async void OnGSwPlayerTile()
|
||||
{
|
||||
|
||||
int? tile = App.Game.GetClient<JNGTileClientSystem>()?.PlayerTile;
|
||||
if (tile is null) return;
|
||||
|
||||
async void Action()
|
||||
{
|
||||
servers = (await App.GAPI.NSyncTileListServer(tile.Value)).data;
|
||||
tileDropdown.ClearOptions();
|
||||
tileDropdown.AddOptions(servers.Select(server => $"{(server.master ? "主" : "副")}:{server.port}").ToList());
|
||||
}
|
||||
await UnityMainThreadDispatcher.Instance.EnqueueAsync(Action);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 切换区块
|
||||
/// </summary>
|
||||
public void OnSwitchTile()
|
||||
{
|
||||
|
||||
if (servers.Count <= tileDropdown.value) return;
|
||||
|
||||
App.Game.GetClient<JNGTileClientSystem>()
|
||||
?.SwSocket(servers[tileDropdown.value].tile, servers[tileDropdown.value]);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user