mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 02:36:14 +00:00
提交Unity 联机Pro
This commit is contained in:
35
JNFrame2/Assets/Scripts/Game/Data/DStateBasisData.cs
Normal file
35
JNFrame2/Assets/Scripts/Game/Data/DStateBasisData.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using JNGame.Math;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Game.JNGState.Logic.Data
|
||||
{
|
||||
[Serializable]
|
||||
public class DValuePosition
|
||||
{
|
||||
public long x;
|
||||
public long y;
|
||||
public long z;
|
||||
|
||||
public Vector3 ToVector3()
|
||||
{
|
||||
return new Vector3()
|
||||
{
|
||||
x = new LFloat(true,x).ToFloat(),
|
||||
y = new LFloat(true,y).ToFloat(),
|
||||
z = new LFloat(true,z).ToFloat(),
|
||||
};
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj is not DValuePosition old) return false;
|
||||
return old.x == x && old.y == y && old.z == z;
|
||||
}
|
||||
|
||||
public LVector3 ToLVector3()
|
||||
{
|
||||
return new LVector3(new LFloat(true,x), new LFloat(true,y), new LFloat(true,z));
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e710dfde494c4e8eb582ad2c45b3c12a
|
||||
timeCreated: 1722822666
|
36
JNFrame2/Assets/Scripts/Game/Data/DStateDataSystem.cs
Normal file
36
JNFrame2/Assets/Scripts/Game/Data/DStateDataSystem.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.Collections.Generic;
|
||||
using AppGame;
|
||||
using Google.Protobuf;
|
||||
using JNGame.Sync.Entity;
|
||||
using JNGame.Sync.State.Tile.Entity;
|
||||
using JNGame.Sync.System.Data;
|
||||
using Plugins.JNGame.Network.Action;
|
||||
|
||||
namespace Game.JNGState.Logic.Data
|
||||
{
|
||||
public abstract class DStateDataSystem<T,E> : STileDataSystem<T,E> where T : ISTileData,new() where E : JNTileEntity, new()
|
||||
{
|
||||
protected DStateDataSystem(SStateDataEnum type) : base(type)
|
||||
{
|
||||
}
|
||||
|
||||
public override void OnSendUBytes(Dictionary<long, byte[]> bytes)
|
||||
{
|
||||
|
||||
JNStateItemData data = new JNStateItemData();
|
||||
data.NetID = NetID;
|
||||
|
||||
foreach (var byteItem in bytes)
|
||||
{
|
||||
data.Messages.Add(byteItem.Key,new JNStateData()
|
||||
{
|
||||
Data = ByteString.CopyFrom(byteItem.Value)
|
||||
});
|
||||
}
|
||||
|
||||
App.Server.AllSend((int)NActionEnum.NSyncStateDataUpdate,data);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aadb74e9a104400fa1b865990faf8315
|
||||
timeCreated: 1721997279
|
107
JNFrame2/Assets/Scripts/Game/Data/EDNodeDataSystem.cs
Normal file
107
JNFrame2/Assets/Scripts/Game/Data/EDNodeDataSystem.cs
Normal file
@@ -0,0 +1,107 @@
|
||||
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
|
||||
{
|
||||
|
||||
[Serializable]
|
||||
public class EDNodeValue
|
||||
{
|
||||
public DValuePosition Position = null;
|
||||
}
|
||||
|
||||
public class EDNodeData : ISTileData
|
||||
{
|
||||
|
||||
public readonly EDNodeValue Value = new ();
|
||||
|
||||
private readonly EDNode _data;
|
||||
public override bool IsHost => _data is not null && _data.IsHost;
|
||||
|
||||
public EDNodeData()
|
||||
{
|
||||
}
|
||||
|
||||
public EDNodeData(EDNode node){
|
||||
Id = node.Id;
|
||||
Value.Position = new DValuePosition()
|
||||
{
|
||||
x = node.Position.x.rawValue,
|
||||
y = node.Position.y.rawValue,
|
||||
z = node.Position.z.rawValue,
|
||||
};
|
||||
_data = node;
|
||||
}
|
||||
|
||||
public override bool IsEquals(ISData data)
|
||||
{
|
||||
var node = data as EDNodeData;
|
||||
if (node is null) return false;
|
||||
return Value.Position.Equals(node.Value.Position);
|
||||
}
|
||||
|
||||
public override byte[] GetByte()
|
||||
{
|
||||
return Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(Value));
|
||||
}
|
||||
|
||||
public override byte[] GetByteDifference(ISData diffValue = null)
|
||||
{
|
||||
var diff = diffValue as EDNodeData;
|
||||
if (diff is null || IsEquals(diffValue)) return Array.Empty<byte>();
|
||||
|
||||
var value = new EDNodeValue();
|
||||
|
||||
if (diff.Value.Position is not null) value.Position = diff.Value.Position;
|
||||
|
||||
return Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(value));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生效字节
|
||||
/// </summary>
|
||||
/// <param name="bytes"></param>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public override void UByte(byte[] bytes)
|
||||
{
|
||||
if (bytes.Length == 0) return;
|
||||
var value = JsonConvert.DeserializeObject<EDNodeValue>(Encoding.UTF8.GetString(bytes));
|
||||
if (value.Position is not null) Value.Position = value.Position;
|
||||
|
||||
}
|
||||
}
|
||||
public class EDNodeDataSystem : DStateDataSystem<EDNodeData,EDNode>
|
||||
{
|
||||
|
||||
public EDNodeDataSystem(SStateDataEnum type) : base(type)
|
||||
{
|
||||
}
|
||||
|
||||
public override JNTileContext<EDNode> NodeContext => Contexts.GetContext<EDNodeContext>();
|
||||
|
||||
public override int NetID => (int)NetDataEnum.EDNodeData;
|
||||
|
||||
public override Dictionary<long, EDNodeData> GetLatest()
|
||||
{
|
||||
var nodes = new Dictionary<long, EDNodeData>();
|
||||
NodeContext.GetEntities().ForEach(child =>
|
||||
{
|
||||
nodes.Add(child.Id,new EDNodeData(child));
|
||||
});
|
||||
return nodes;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0f1c12a776364a24a4e8d1b1372bed25
|
||||
timeCreated: 1721101714
|
113
JNFrame2/Assets/Scripts/Game/Data/EDPlayerDataSystem.cs
Normal file
113
JNFrame2/Assets/Scripts/Game/Data/EDPlayerDataSystem.cs
Normal file
@@ -0,0 +1,113 @@
|
||||
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
|
||||
{
|
||||
|
||||
[Serializable]
|
||||
public class EDPlayerValue
|
||||
{
|
||||
public int? Auth = null;
|
||||
public DValuePosition Position = null;
|
||||
}
|
||||
|
||||
public class EDPlayerData : ISTileData
|
||||
{
|
||||
|
||||
public readonly EDPlayerValue Value = new ();
|
||||
private readonly EDPlayer _data;
|
||||
public override bool IsHost => _data is not null && _data.IsHost;
|
||||
|
||||
public EDPlayerData()
|
||||
{
|
||||
}
|
||||
|
||||
public EDPlayerData(EDPlayer node){
|
||||
Id = node.Id;
|
||||
Value.Auth = node.Controller.Auth;
|
||||
Value.Position = new DValuePosition()
|
||||
{
|
||||
x = node.Position.x.rawValue,
|
||||
y = node.Position.y.rawValue,
|
||||
z = node.Position.z.rawValue,
|
||||
};
|
||||
_data = node;
|
||||
}
|
||||
|
||||
public override bool IsEquals(ISData data)
|
||||
{
|
||||
var node = data as EDPlayerData;
|
||||
if (node is null) return false;
|
||||
return Value.Position.Equals(node.Value.Position)
|
||||
&& Value.Auth.Equals(node.Value.Auth);
|
||||
}
|
||||
|
||||
public override byte[] GetByte()
|
||||
{
|
||||
return Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(Value));
|
||||
}
|
||||
|
||||
public override byte[] GetByteDifference(ISData diffValue = null)
|
||||
{
|
||||
var diff = diffValue as EDPlayerData;
|
||||
if (diff is null || IsEquals(diffValue)) return Array.Empty<byte>();
|
||||
|
||||
var value = new EDPlayerValue();
|
||||
|
||||
if (diff.Value.Position is not null) value.Position = diff.Value.Position;
|
||||
if (diff.Value.Auth is not null) value.Auth = diff.Value.Auth;
|
||||
|
||||
return Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(value));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生效字节
|
||||
/// </summary>
|
||||
/// <param name="bytes"></param>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public override void UByte(byte[] bytes)
|
||||
{
|
||||
|
||||
if (bytes.Length == 0) return;
|
||||
var value = JsonConvert.DeserializeObject<EDPlayerValue>(Encoding.UTF8.GetString(bytes));
|
||||
if (value.Position is not null) Value.Position = value.Position;
|
||||
if (value.Auth is not null) Value.Auth = value.Auth;
|
||||
|
||||
}
|
||||
}
|
||||
public class EDPlayerDataSystem : DStateDataSystem<EDPlayerData,EDPlayer>
|
||||
{
|
||||
|
||||
public EDPlayerDataSystem(SStateDataEnum type) : base(type)
|
||||
{
|
||||
}
|
||||
|
||||
public override int NetID => (int)NetDataEnum.EDPlayerData;
|
||||
|
||||
public override JNTileContext<EDPlayer> NodeContext => Contexts.GetContext<EDPlayerContext>();
|
||||
|
||||
|
||||
public override Dictionary<long, EDPlayerData> GetLatest()
|
||||
{
|
||||
var nodes = new Dictionary<long, EDPlayerData>();
|
||||
NodeContext.GetEntities().ForEach(child =>
|
||||
{
|
||||
nodes.Add(child.Id,new EDPlayerData(child));
|
||||
});
|
||||
return nodes;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f7aabf53b2ce4c838b5a5812493a625c
|
||||
timeCreated: 1722256803
|
8
JNFrame2/Assets/Scripts/Game/Data/NetDataEnum.cs
Normal file
8
JNFrame2/Assets/Scripts/Game/Data/NetDataEnum.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace Game.JNGState.Logic.Data
|
||||
{
|
||||
public enum NetDataEnum : int
|
||||
{
|
||||
EDNodeData = 0,
|
||||
EDPlayerData = 1,
|
||||
}
|
||||
}
|
3
JNFrame2/Assets/Scripts/Game/Data/NetDataEnum.cs.meta
Normal file
3
JNFrame2/Assets/Scripts/Game/Data/NetDataEnum.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2e77dac300e7430c8ceebaf85db683c4
|
||||
timeCreated: 1721959245
|
Reference in New Issue
Block a user