Skip to content

Commit 5ce0982

Browse files
committed
ilrt network test
1 parent f36962f commit 5ce0982

21 files changed

+594
-5
lines changed

Assets/Game/HotFix/HotFix.dll.bytes

8.5 KB
Binary file not shown.

Assets/Game/HotFix/HotFix.pdb.bytes

30 KB
Binary file not shown.

Assets/GameFramework/HotFix/HotFixManager.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,15 @@ void InitializeILRuntime()
103103
//注册CLR绑定
104104
ILRuntime.Runtime.Generated.CLRBindings.Initialize(Appdomain);
105105

106+
//跨域继承的基类
107+
Appdomain.RegisterCrossBindingAdaptor(new Google.Protobuf.IMessageAdaptor());
108+
Appdomain.RegisterCrossBindingAdaptor(new IAsyncStateMachineClassInheritanceAdaptor());
109+
Appdomain.DelegateManager.RegisterFunctionDelegate<Google.Protobuf.IMessageAdaptor.Adaptor>();
110+
Appdomain.DelegateManager.RegisterMethodDelegate<System.Object>();
111+
112+
113+
Appdomain.DelegateManager.RegisterMethodDelegate<System.UInt16, System.Byte[]>();
114+
106115
//这里做一些ILRuntime的注册,HelloWorld示例暂时没有需要注册的
107116
Appdomain.DelegateManager.RegisterMethodDelegate<System.Object, ILRuntime.Runtime.Intepreter.ILTypeInstance>();
108117
Appdomain.DelegateManager.RegisterDelegateConvertor<System.EventHandler<ILRuntime.Runtime.Intepreter.ILTypeInstance>>((act) =>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using GT=GameFramework.Taurus;
2+
3+
namespace HotFix.Taurus
4+
{
5+
[GT.MessageHandler(typeof(C2S_TestInfo))]
6+
public class C2S_TestInfo_Handle:MessageHandlerBase
7+
{
8+
public override void Handle(object message)
9+
{
10+
C2S_TestInfo c2S_TestInfo = message as C2S_TestInfo;
11+
12+
HotFixMode.Network.SendMessage(new S2C_TestInfo(){ Message = "C2S_TestInfo_Handle -- S2C" },new System.Net.IPEndPoint(System.Net.IPAddress.Parse("255.255.255.255"),35120));
13+
}
14+
}
15+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using GT = GameFramework.Taurus;
2+
3+
namespace HotFix.Taurus
4+
{
5+
[GT.MessageHandler(typeof(HotFixProtoTest))]
6+
public class HotFixTestMessageHandle: MessageHandlerBase
7+
{
8+
public override void Handle(object message)
9+
{
10+
HotFixProtoTest test = message as HotFixProtoTest;
11+
}
12+
}
13+
}
Lines changed: 234 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,234 @@
1+
// Generated by the protocol buffer compiler. DO NOT EDIT!
2+
// source: HotFixProto.proto
3+
#pragma warning disable 1591, 0612, 3021
4+
#region Designer generated code
5+
6+
using pb = global::Google.Protobuf;
7+
using pbc = global::Google.Protobuf.Collections;
8+
using scg = global::System.Collections.Generic;
9+
#region Messages
10+
public partial class HotFixProtoTest : pb::IMessage {
11+
private static readonly pb::MessageParser<HotFixProtoTest> _parser = new pb::MessageParser<HotFixProtoTest>(() => new HotFixProtoTest());
12+
public static pb::MessageParser<HotFixProtoTest> Parser { get { return _parser; } }
13+
14+
private int iD_;
15+
public int ID {
16+
get { return iD_; }
17+
set {
18+
iD_ = value;
19+
}
20+
}
21+
22+
private string commit_ = "";
23+
/// <summary>
24+
///提交
25+
/// </summary>
26+
public string Commit {
27+
get { return commit_; }
28+
set {
29+
commit_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
30+
}
31+
}
32+
33+
private string message_ = "";
34+
/// <summary>
35+
///信息
36+
/// </summary>
37+
public string Message {
38+
get { return message_; }
39+
set {
40+
message_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
41+
}
42+
}
43+
44+
public void WriteTo(pb::CodedOutputStream output) {
45+
if (ID != 0) {
46+
output.WriteRawTag(8);
47+
output.WriteInt32(ID);
48+
}
49+
if (Commit.Length != 0) {
50+
output.WriteRawTag(18);
51+
output.WriteString(Commit);
52+
}
53+
if (Message.Length != 0) {
54+
output.WriteRawTag(26);
55+
output.WriteString(Message);
56+
}
57+
}
58+
59+
public int CalculateSize() {
60+
int size = 0;
61+
if (ID != 0) {
62+
size += 1 + pb::CodedOutputStream.ComputeInt32Size(ID);
63+
}
64+
if (Commit.Length != 0) {
65+
size += 1 + pb::CodedOutputStream.ComputeStringSize(Commit);
66+
}
67+
if (Message.Length != 0) {
68+
size += 1 + pb::CodedOutputStream.ComputeStringSize(Message);
69+
}
70+
return size;
71+
}
72+
73+
public void MergeFrom(pb::CodedInputStream input) {
74+
iD_ = 0;
75+
commit_ = "";
76+
message_ = "";
77+
uint tag;
78+
while ((tag = input.ReadTag()) != 0) {
79+
switch(tag) {
80+
default:
81+
input.SkipLastField();
82+
break;
83+
case 8: {
84+
ID = input.ReadInt32();
85+
break;
86+
}
87+
case 18: {
88+
Commit = input.ReadString();
89+
break;
90+
}
91+
case 26: {
92+
Message = input.ReadString();
93+
break;
94+
}
95+
}
96+
}
97+
}
98+
99+
}
100+
101+
public partial class C2S_TestInfo : pb::IMessage {
102+
private static readonly pb::MessageParser<C2S_TestInfo> _parser = new pb::MessageParser<C2S_TestInfo>(() => new C2S_TestInfo());
103+
public static pb::MessageParser<C2S_TestInfo> Parser { get { return _parser; } }
104+
105+
private int rpcId_;
106+
public int RpcId {
107+
get { return rpcId_; }
108+
set {
109+
rpcId_ = value;
110+
}
111+
}
112+
113+
private string message_ = "";
114+
public string Message {
115+
get { return message_; }
116+
set {
117+
message_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
118+
}
119+
}
120+
121+
public void WriteTo(pb::CodedOutputStream output) {
122+
if (RpcId != 0) {
123+
output.WriteRawTag(8);
124+
output.WriteInt32(RpcId);
125+
}
126+
if (Message.Length != 0) {
127+
output.WriteRawTag(18);
128+
output.WriteString(Message);
129+
}
130+
}
131+
132+
public int CalculateSize() {
133+
int size = 0;
134+
if (RpcId != 0) {
135+
size += 1 + pb::CodedOutputStream.ComputeInt32Size(RpcId);
136+
}
137+
if (Message.Length != 0) {
138+
size += 1 + pb::CodedOutputStream.ComputeStringSize(Message);
139+
}
140+
return size;
141+
}
142+
143+
public void MergeFrom(pb::CodedInputStream input) {
144+
rpcId_ = 0;
145+
message_ = "";
146+
uint tag;
147+
while ((tag = input.ReadTag()) != 0) {
148+
switch(tag) {
149+
default:
150+
input.SkipLastField();
151+
break;
152+
case 8: {
153+
RpcId = input.ReadInt32();
154+
break;
155+
}
156+
case 18: {
157+
Message = input.ReadString();
158+
break;
159+
}
160+
}
161+
}
162+
}
163+
164+
}
165+
166+
public partial class S2C_TestInfo : pb::IMessage {
167+
private static readonly pb::MessageParser<S2C_TestInfo> _parser = new pb::MessageParser<S2C_TestInfo>(() => new S2C_TestInfo());
168+
public static pb::MessageParser<S2C_TestInfo> Parser { get { return _parser; } }
169+
170+
private int rpcId_;
171+
public int RpcId {
172+
get { return rpcId_; }
173+
set {
174+
rpcId_ = value;
175+
}
176+
}
177+
178+
private string message_ = "";
179+
public string Message {
180+
get { return message_; }
181+
set {
182+
message_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
183+
}
184+
}
185+
186+
public void WriteTo(pb::CodedOutputStream output) {
187+
if (RpcId != 0) {
188+
output.WriteRawTag(8);
189+
output.WriteInt32(RpcId);
190+
}
191+
if (Message.Length != 0) {
192+
output.WriteRawTag(18);
193+
output.WriteString(Message);
194+
}
195+
}
196+
197+
public int CalculateSize() {
198+
int size = 0;
199+
if (RpcId != 0) {
200+
size += 1 + pb::CodedOutputStream.ComputeInt32Size(RpcId);
201+
}
202+
if (Message.Length != 0) {
203+
size += 1 + pb::CodedOutputStream.ComputeStringSize(Message);
204+
}
205+
return size;
206+
}
207+
208+
public void MergeFrom(pb::CodedInputStream input) {
209+
rpcId_ = 0;
210+
message_ = "";
211+
uint tag;
212+
while ((tag = input.ReadTag()) != 0) {
213+
switch(tag) {
214+
default:
215+
input.SkipLastField();
216+
break;
217+
case 8: {
218+
RpcId = input.ReadInt32();
219+
break;
220+
}
221+
case 18: {
222+
Message = input.ReadString();
223+
break;
224+
}
225+
}
226+
}
227+
}
228+
229+
}
230+
231+
#endregion
232+
233+
234+
#endregion Designer generated code
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using HotFix.Taurus;
2+
using GT=GameFramework.Taurus;
3+
4+
[GT.Message(1000)]
5+
public partial class HotFixProtoTest
6+
{
7+
}
8+
9+
[GT.Message(1001)]
10+
public partial class C2S_TestInfo : IRequest
11+
{
12+
}
13+
14+
[GT.Message(1002)]
15+
public partial class S2C_TestInfo : IResponse
16+
{
17+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using UnityEngine;
2+
3+
namespace HotFix.Taurus
4+
{
5+
[GameState(GameStateType.Start)]
6+
public class HotFixTestState : GameState
7+
{
8+
public override void OnEnter(params object[] parameters)
9+
{
10+
base.OnEnter(parameters);
11+
12+
Debug.Log("HotFixTestState--Start!!");
13+
14+
HotFixMode.Network.SetPort(35120);
15+
}
16+
17+
public override void OnExit()
18+
{
19+
base.OnExit();
20+
}
21+
22+
public override void OnFixedUpdate()
23+
{
24+
base.OnFixedUpdate();
25+
}
26+
27+
public override void OnInit()
28+
{
29+
base.OnInit();
30+
}
31+
32+
public override void OnUpdate()
33+
{
34+
base.OnUpdate();
35+
36+
if (Input.GetKeyDown(KeyCode.T))
37+
{
38+
HotFixMode.Network.SendMessage(new HotFixProtoTest() {ID = 522, Commit = "xxxx", Message = "MMMMMMMM"},
39+
new System.Net.IPEndPoint(System.Net.IPAddress.Parse("255.255.255.255"), 35120));
40+
}
41+
42+
if (Input.GetKeyDown(KeyCode.C))
43+
{
44+
NetworkMessageCallTest();
45+
}
46+
}
47+
48+
49+
private async void NetworkMessageCallTest()
50+
{
51+
S2C_TestInfo s2C_TestInfo = await HotFixMode.Network.Call<S2C_TestInfo>(
52+
new C2S_TestInfo() {Message = "HotFixTestState -- C2S" },
53+
new System.Net.IPEndPoint(System.Net.IPAddress.Parse("255.255.255.255"), 35120));
54+
}
55+
}
56+
}

HotFix/HotFix/GameFramework/Base/HotFixMode.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ public class HotFixMode
66
public static GameStateManager State;
77
public static EventManager Event;
88
public static UIManager UI;
9-
public static DataTableManager DataTable;
9+
public static DataTableManager DataTable;
10+
public static NetworkManager Network;
1011
#endregion
1112

1213
public HotFixMode()
@@ -18,10 +19,11 @@ public HotFixMode()
1819
Event = GameFrameworkMode.GetModule<EventManager>();
1920
UI = GameFrameworkMode.GetModule<UIManager>();
2021
DataTable = GameFrameworkMode.GetModule<DataTableManager>();
21-
#endregion
22+
Network = GameFrameworkMode.GetModule<NetworkManager>();
23+
#endregion
2224

23-
//从主框架中获取热更新模块
24-
GameFramework.Taurus.HotFixManager hotFixManager =
25+
//从主框架中获取热更新模块
26+
GameFramework.Taurus.HotFixManager hotFixManager =
2527
GameFramework.Taurus.GameFrameworkMode.GetModule<GameFramework.Taurus.HotFixManager>();
2628

2729
#region 开启热更新流程

0 commit comments

Comments
 (0)