mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 02:36:14 +00:00
提交帧同步案例
This commit is contained in:
3
JNFrame/Assets/Plugins/JNGame/Network/Action.meta
Normal file
3
JNFrame/Assets/Plugins/JNGame/Network/Action.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dd0b2e123a2647faa14dc3c101cb9924
|
||||
timeCreated: 1706264437
|
15
JNFrame/Assets/Plugins/JNGame/Network/Action/NActionEnum.cs
Normal file
15
JNFrame/Assets/Plugins/JNGame/Network/Action/NActionEnum.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
namespace Plugins.JNGame.Network.Action
|
||||
{
|
||||
public enum NActionEnum
|
||||
{
|
||||
Ping = 1, //PING
|
||||
NActionDemo = 2, //Demo 消息
|
||||
NActionDemo2 = 3, //Demo 消息
|
||||
|
||||
NSyncFrameStart = 100, //帧同步开始
|
||||
NSyncFrameEnd = 101, //帧同步结束
|
||||
NSyncFrameBack = 102, //帧同步回调
|
||||
NSyncFrameInput = 103, //帧同步输入
|
||||
NSyncFrameReset = 104, //重置帧同步
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 07d3dc0f03a24e18b4bee8832eef7a47
|
||||
timeCreated: 1706264441
|
8
JNFrame/Assets/Plugins/JNGame/Network/Entity.meta
Normal file
8
JNFrame/Assets/Plugins/JNGame/Network/Entity.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7d3cabfc01539db4dbf0d4961f07368c
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
50
JNFrame/Assets/Plugins/JNGame/Network/Entity/JNetParam.cs
Normal file
50
JNFrame/Assets/Plugins/JNGame/Network/Entity/JNetParam.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using Google.Protobuf;
|
||||
using UnityEditor;
|
||||
|
||||
namespace Plugins.JNGame.Network.Entity
|
||||
{
|
||||
public class JNetParam
|
||||
{
|
||||
|
||||
//请求处理 Id (用来找到处理方法)
|
||||
private int _hId;
|
||||
public int HId => _hId;
|
||||
|
||||
//请求Id (请求标识)
|
||||
private int _id;
|
||||
public int ID => _id;
|
||||
|
||||
|
||||
//请求参数
|
||||
private IMessage _data;
|
||||
public IMessage Data => _data;
|
||||
|
||||
|
||||
private byte[] _bytes;
|
||||
|
||||
public byte[] Bytes => _bytes;
|
||||
|
||||
public JNetParam(int id,int hId)
|
||||
{
|
||||
_hId = hId;
|
||||
_id = id;
|
||||
}
|
||||
|
||||
//构造器
|
||||
public static JNetParam Build(int id,int hId){
|
||||
return new JNetParam(id,hId);
|
||||
}
|
||||
|
||||
|
||||
public JNetParam SetData(IMessage data){
|
||||
this._data = data;
|
||||
return this;
|
||||
}
|
||||
public JNetParam SetByte(byte[] bytes){
|
||||
this._bytes = bytes;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f311c8c368584fab839dd72819fc55da
|
||||
timeCreated: 1706004134
|
135
JNFrame/Assets/Plugins/JNGame/Network/JNSocket.cs
Normal file
135
JNFrame/Assets/Plugins/JNGame/Network/JNSocket.cs
Normal file
@@ -0,0 +1,135 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using BestHTTP.WebSocket;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using Google.Protobuf;
|
||||
using Plugins.JNGame.Network.Entity;
|
||||
using Plugins.JNGame.Network.Util;
|
||||
using Plugins.JNGame.System;
|
||||
using Plugins.JNGame.Util;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Plugins.JNGame.Network
|
||||
{
|
||||
public abstract class JNSocket : SystemBase
|
||||
{
|
||||
private WebSocket _socket;
|
||||
|
||||
//消息Id
|
||||
int _id = 0;
|
||||
|
||||
private UniTaskCompletionSource _onOpen;
|
||||
|
||||
//创建通知
|
||||
private EventDispatcher _event = new();
|
||||
|
||||
public override async Task OnInit()
|
||||
{
|
||||
await this.OnConnect();
|
||||
}
|
||||
|
||||
private async UniTask OnConnect()
|
||||
{
|
||||
|
||||
var url = $"{await this.GetUrl()}";
|
||||
this._socket = new WebSocket(new Uri(url));
|
||||
|
||||
this._socket.OnOpen += OnOpen;
|
||||
this._socket.OnMessage += OnMessageReceived;
|
||||
this._socket.OnError += OnError;
|
||||
this._socket.OnClosed += OnClosed;
|
||||
this._socket.OnBinary += Onbinary;
|
||||
|
||||
NSystem.Log($"[JNSocket]初始化WebSocket成功,URL:{url}");
|
||||
this._socket.Open();
|
||||
|
||||
//等待连接成功
|
||||
await (this._onOpen = new UniTaskCompletionSource()).Task;
|
||||
|
||||
}
|
||||
|
||||
private void OnOpen(WebSocket websocket)
|
||||
{
|
||||
NSystem.Log($"[JNSocket] OnOpen");
|
||||
this._onOpen.TrySetResult();
|
||||
}
|
||||
|
||||
private void OnMessageReceived(WebSocket websocket, string message)
|
||||
{
|
||||
NSystem.Log($"[JNSocket] OnMessageReceived");
|
||||
}
|
||||
|
||||
private void OnError(WebSocket websocket, Exception ex)
|
||||
{
|
||||
NSystem.Log($"[JNSocket] OnError");
|
||||
}
|
||||
|
||||
private void OnClosed(WebSocket websocket, ushort code, string message)
|
||||
{
|
||||
NSystem.Log($"[JNSocket] OnClosed");
|
||||
}
|
||||
|
||||
private void Onbinary(WebSocket websocket, byte[] data)
|
||||
{
|
||||
|
||||
NSystem.Log($"[JNSocket] Onbinary");
|
||||
Dispatch(NDataUtil.Parse(data));
|
||||
|
||||
}
|
||||
|
||||
//通知消息
|
||||
private void Dispatch(JNetParam data)
|
||||
{
|
||||
|
||||
//发送消息
|
||||
List<Delegate> funs = _event.EventHandlers[$"{data.HId}"];
|
||||
funs.ForEach(fun =>
|
||||
{
|
||||
if (data.Bytes.Length <= 0)
|
||||
{
|
||||
((Action<IMessage>)fun)(null);
|
||||
return;
|
||||
}
|
||||
if(fun.Method.GetParameters().Length == 1 && typeof(IMessage).IsAssignableFrom(fun.Method.GetParameters()[0].ParameterType))
|
||||
{
|
||||
var type = fun.Method.GetParameters()[0].ParameterType;
|
||||
var cType = type.GetProperty("Parser", BindingFlags.Static | BindingFlags.Public);
|
||||
if (cType != null)
|
||||
{
|
||||
var methodInfo = cType.PropertyType.GetMethod("ParseFrom",new[]{ typeof(byte[]) });
|
||||
if (methodInfo != null)
|
||||
{
|
||||
var message = methodInfo.Invoke(cType.GetValue(null), new object[] { data.Bytes });
|
||||
fun.Method.Invoke(fun.Target,new object[]{ message });
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
//外部监听消息
|
||||
public void AddListener<T>(int hId,Action<T> listener) where T : IMessage
|
||||
{
|
||||
_event.AddListener($"{hId}",listener);
|
||||
}
|
||||
|
||||
//删除外部监听
|
||||
public void RemoveListener<T>(int hId,Action<T> listener) where T : IMessage
|
||||
{
|
||||
_event.RemoveListener($"{hId}",listener);
|
||||
}
|
||||
|
||||
protected abstract UniTask<string> GetUrl();
|
||||
|
||||
|
||||
//向服务器发送消息
|
||||
public void Send(int hId,IMessage data = null)
|
||||
{
|
||||
_socket.Send(NDataUtil.Encrypt(JNetParam.Build(this._id++,hId).SetData(data)));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
11
JNFrame/Assets/Plugins/JNGame/Network/JNSocket.cs.meta
Normal file
11
JNFrame/Assets/Plugins/JNGame/Network/JNSocket.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 85daeb9010873c6408e58fd210d7ec47
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
JNFrame/Assets/Plugins/JNGame/Network/Proto.meta
Normal file
8
JNFrame/Assets/Plugins/JNGame/Network/Proto.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 48ddea52cea7e1145b20a9674aeeca02
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
1092
JNFrame/Assets/Plugins/JNGame/Network/Proto/JNSyncMessage.cs
Normal file
1092
JNFrame/Assets/Plugins/JNGame/Network/Proto/JNSyncMessage.cs
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 417922a615a577540b5a5f446a197bdc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,27 @@
|
||||
syntax = "proto3";
|
||||
|
||||
option java_package = "cn.jisol.ngame.proto";
|
||||
|
||||
//帧同步输入
|
||||
message JNFrameInput{
|
||||
int32 nId = 1; //输入的Id
|
||||
optional bytes input = 2; //输入内容
|
||||
}
|
||||
//帧输入列表
|
||||
message JNFrameInputs {
|
||||
repeated JNFrameInput inputs = 1; //输入列表
|
||||
}
|
||||
//帧同步消息
|
||||
message JNFrameInfo {
|
||||
int32 index = 1; //帧数
|
||||
repeated JNFrameInput messages = 2; //消息bytes
|
||||
}
|
||||
//帧同步集合
|
||||
message JNFrameInfos{
|
||||
repeated JNFrameInfo frames = 1; //帧数集
|
||||
}
|
||||
|
||||
//帧同步输入
|
||||
message JNInput {
|
||||
optional string message = 1;
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f5033772dc466fc46a8ac64d8dbc5d00
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
445
JNFrame/Assets/Plugins/JNGame/Network/Proto/NActionMessage.cs
Normal file
445
JNFrame/Assets/Plugins/JNGame/Network/Proto/NActionMessage.cs
Normal file
@@ -0,0 +1,445 @@
|
||||
// <auto-generated>
|
||||
// Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
// source: NActionMessage.proto
|
||||
// </auto-generated>
|
||||
#pragma warning disable 1591, 0612, 3021, 8981
|
||||
#region Designer generated code
|
||||
|
||||
using pb = global::Google.Protobuf;
|
||||
using pbc = global::Google.Protobuf.Collections;
|
||||
using pbr = global::Google.Protobuf.Reflection;
|
||||
using scg = global::System.Collections.Generic;
|
||||
/// <summary>Holder for reflection information generated from NActionMessage.proto</summary>
|
||||
public static partial class NActionMessageReflection {
|
||||
|
||||
#region Descriptor
|
||||
/// <summary>File descriptor for NActionMessage.proto</summary>
|
||||
public static pbr::FileDescriptor Descriptor {
|
||||
get { return descriptor; }
|
||||
}
|
||||
private static pbr::FileDescriptor descriptor;
|
||||
|
||||
static NActionMessageReflection() {
|
||||
byte[] descriptorData = global::System.Convert.FromBase64String(
|
||||
string.Concat(
|
||||
"ChROQWN0aW9uTWVzc2FnZS5wcm90byIvCgtOQWN0aW9uRGVtbxIUCgdtZXNz",
|
||||
"YWdlGAEgASgJSACIAQFCCgoIX21lc3NhZ2UiMAoMTkFjdGlvbkRlbW8yEhQK",
|
||||
"B21lc3NhZ2UYASABKAlIAIgBAUIKCghfbWVzc2FnZUIWChRjbi5qaXNvbC5u",
|
||||
"Z2FtZS5wcm90b2IGcHJvdG8z"));
|
||||
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
|
||||
new pbr::FileDescriptor[] { },
|
||||
new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] {
|
||||
new pbr::GeneratedClrTypeInfo(typeof(global::NActionDemo), global::NActionDemo.Parser, new[]{ "Message" }, new[]{ "Message" }, null, null, null),
|
||||
new pbr::GeneratedClrTypeInfo(typeof(global::NActionDemo2), global::NActionDemo2.Parser, new[]{ "Message" }, new[]{ "Message" }, null, null, null)
|
||||
}));
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
#region Messages
|
||||
public sealed partial class NActionDemo : pb::IMessage<NActionDemo>
|
||||
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
||||
, pb::IBufferMessage
|
||||
#endif
|
||||
{
|
||||
private static readonly pb::MessageParser<NActionDemo> _parser = new pb::MessageParser<NActionDemo>(() => new NActionDemo());
|
||||
private pb::UnknownFieldSet _unknownFields;
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public static pb::MessageParser<NActionDemo> Parser { get { return _parser; } }
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public static pbr::MessageDescriptor Descriptor {
|
||||
get { return global::NActionMessageReflection.Descriptor.MessageTypes[0]; }
|
||||
}
|
||||
|
||||
[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 NActionDemo() {
|
||||
OnConstruction();
|
||||
}
|
||||
|
||||
partial void OnConstruction();
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public NActionDemo(NActionDemo other) : this() {
|
||||
message_ = other.message_;
|
||||
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public NActionDemo Clone() {
|
||||
return new NActionDemo(this);
|
||||
}
|
||||
|
||||
/// <summary>Field number for the "message" field.</summary>
|
||||
public const int MessageFieldNumber = 1;
|
||||
private string message_;
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public string Message {
|
||||
get { return message_ ?? ""; }
|
||||
set {
|
||||
message_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
|
||||
}
|
||||
}
|
||||
/// <summary>Gets whether the "message" field is set</summary>
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public bool HasMessage {
|
||||
get { return message_ != null; }
|
||||
}
|
||||
/// <summary>Clears the value of the "message" field</summary>
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public void ClearMessage() {
|
||||
message_ = null;
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public override bool Equals(object other) {
|
||||
return Equals(other as NActionDemo);
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public bool Equals(NActionDemo other) {
|
||||
if (ReferenceEquals(other, null)) {
|
||||
return false;
|
||||
}
|
||||
if (ReferenceEquals(other, this)) {
|
||||
return true;
|
||||
}
|
||||
if (Message != other.Message) 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 (HasMessage) hash ^= Message.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 (HasMessage) {
|
||||
output.WriteRawTag(10);
|
||||
output.WriteString(Message);
|
||||
}
|
||||
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 (HasMessage) {
|
||||
output.WriteRawTag(10);
|
||||
output.WriteString(Message);
|
||||
}
|
||||
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 (HasMessage) {
|
||||
size += 1 + pb::CodedOutputStream.ComputeStringSize(Message);
|
||||
}
|
||||
if (_unknownFields != null) {
|
||||
size += _unknownFields.CalculateSize();
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public void MergeFrom(NActionDemo other) {
|
||||
if (other == null) {
|
||||
return;
|
||||
}
|
||||
if (other.HasMessage) {
|
||||
Message = other.Message;
|
||||
}
|
||||
_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 10: {
|
||||
Message = input.ReadString();
|
||||
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 10: {
|
||||
Message = input.ReadString();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
public sealed partial class NActionDemo2 : pb::IMessage<NActionDemo2>
|
||||
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
||||
, pb::IBufferMessage
|
||||
#endif
|
||||
{
|
||||
private static readonly pb::MessageParser<NActionDemo2> _parser = new pb::MessageParser<NActionDemo2>(() => new NActionDemo2());
|
||||
private pb::UnknownFieldSet _unknownFields;
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public static pb::MessageParser<NActionDemo2> Parser { get { return _parser; } }
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public static pbr::MessageDescriptor Descriptor {
|
||||
get { return global::NActionMessageReflection.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 NActionDemo2() {
|
||||
OnConstruction();
|
||||
}
|
||||
|
||||
partial void OnConstruction();
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public NActionDemo2(NActionDemo2 other) : this() {
|
||||
message_ = other.message_;
|
||||
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public NActionDemo2 Clone() {
|
||||
return new NActionDemo2(this);
|
||||
}
|
||||
|
||||
/// <summary>Field number for the "message" field.</summary>
|
||||
public const int MessageFieldNumber = 1;
|
||||
private string message_;
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public string Message {
|
||||
get { return message_ ?? ""; }
|
||||
set {
|
||||
message_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
|
||||
}
|
||||
}
|
||||
/// <summary>Gets whether the "message" field is set</summary>
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public bool HasMessage {
|
||||
get { return message_ != null; }
|
||||
}
|
||||
/// <summary>Clears the value of the "message" field</summary>
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public void ClearMessage() {
|
||||
message_ = null;
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public override bool Equals(object other) {
|
||||
return Equals(other as NActionDemo2);
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public bool Equals(NActionDemo2 other) {
|
||||
if (ReferenceEquals(other, null)) {
|
||||
return false;
|
||||
}
|
||||
if (ReferenceEquals(other, this)) {
|
||||
return true;
|
||||
}
|
||||
if (Message != other.Message) 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 (HasMessage) hash ^= Message.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 (HasMessage) {
|
||||
output.WriteRawTag(10);
|
||||
output.WriteString(Message);
|
||||
}
|
||||
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 (HasMessage) {
|
||||
output.WriteRawTag(10);
|
||||
output.WriteString(Message);
|
||||
}
|
||||
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 (HasMessage) {
|
||||
size += 1 + pb::CodedOutputStream.ComputeStringSize(Message);
|
||||
}
|
||||
if (_unknownFields != null) {
|
||||
size += _unknownFields.CalculateSize();
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
|
||||
public void MergeFrom(NActionDemo2 other) {
|
||||
if (other == null) {
|
||||
return;
|
||||
}
|
||||
if (other.HasMessage) {
|
||||
Message = other.Message;
|
||||
}
|
||||
_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 10: {
|
||||
Message = input.ReadString();
|
||||
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 10: {
|
||||
Message = input.ReadString();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#endregion Designer generated code
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7a64c8e0d9371ec4a8dc561dbfe81026
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,12 @@
|
||||
syntax = "proto3";
|
||||
|
||||
option java_package = "cn.jisol.ngame.proto";
|
||||
|
||||
message NActionDemo {
|
||||
optional string message = 1;
|
||||
}
|
||||
|
||||
message NActionDemo2 {
|
||||
optional string message = 1;
|
||||
}
|
||||
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e48e0afd082b466081556cb81d66935f
|
||||
timeCreated: 1705996154
|
3
JNFrame/Assets/Plugins/JNGame/Network/Util.meta
Normal file
3
JNFrame/Assets/Plugins/JNGame/Network/Util.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f297d4999ae14dd7a046a1faebd6845a
|
||||
timeCreated: 1706004786
|
41
JNFrame/Assets/Plugins/JNGame/Network/Util/NDataUtil.cs
Normal file
41
JNFrame/Assets/Plugins/JNGame/Network/Util/NDataUtil.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Google.Protobuf;
|
||||
using Plugins.JNGame.Network.Entity;
|
||||
using Plugins.JNGame.Util;
|
||||
|
||||
namespace Plugins.JNGame.Network.Util
|
||||
{
|
||||
// 网络数据工具类 [请求Id*4,处理Id*4,...参数数据*N]
|
||||
public static class NDataUtil
|
||||
{
|
||||
|
||||
// 解析
|
||||
public static JNetParam Parse(byte[] data)
|
||||
{
|
||||
|
||||
return JNetParam.Build(
|
||||
ToUtil.Byte4ToInt(data.Skip(0).Take(4).ToArray()),
|
||||
ToUtil.Byte4ToInt(data.Skip(4).Take(4).ToArray()))
|
||||
.SetByte(data.Skip(8).Take(data.Length - 8).ToArray());
|
||||
|
||||
}
|
||||
|
||||
// 编码
|
||||
public static byte[] Encrypt(JNetParam param)
|
||||
{
|
||||
|
||||
byte[] hId = ToUtil.IntToByte4(param.HId);
|
||||
byte[] id = ToUtil.IntToByte4(param.ID);
|
||||
byte[] data = Array.Empty<byte>();
|
||||
if(param.Data != null)
|
||||
data = param.Data.ToByteArray();
|
||||
|
||||
return id.Concat(hId).Concat(data).ToArray();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8b05544adb2f44b4af8f86b2bc66a035
|
||||
timeCreated: 1706004790
|
Reference in New Issue
Block a user