-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathTestSkynetClient.cs
80 lines (65 loc) · 1.36 KB
/
TestSkynetClient.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using Skynet.DotNetClient;
using Skynet.DotNetClient.Utils.Signals;
using UnityEngine;
public class TestSkynetClient : MonoBehaviour
{
private TestLoginTcp _login;
private const string Protocol = "tcp"; // "ws"; //"tcp";
private TestGateTcp _gateTcp;
private TestGateWs _gateWs;
private TestGateUdp _gateUdp;
public void Start ()
{
SkynetLogger.Error(Channel.NetDevice, "++++++Skynet Client Start++++");
_login = new TestLoginTcp (Protocol);
_login.Run(ProcessLoginResp);
}
private void ProcessLoginResp(int code, AuthPackageResp resp)
{
_login.DisConnect();
if(code == 200)
{
if (Protocol == "tcp")
{
_gateTcp = new TestGateTcp();
_gateTcp.Run(resp);
}
else
{
_gateWs = new TestGateWs();
_gateWs.Run(resp);
}
Signals.Get<UdpSignal>().AddListener(SignalUdp);
}
_login = null;
}
private void SignalUdp(BattleSession session)
{
_gateUdp = new TestGateUdp();
_gateUdp.Run(session);
}
private void OnDestroy()
{
if (_login != null)
{
_login.DisConnect();
_login = null;
}
if (_gateTcp != null)
{
_gateTcp.DisConnect();
_gateTcp = null;
}
if (_gateWs != null)
{
_gateWs.DisConnect();
_gateWs = null;
}
if (_gateUdp != null)
{
_gateUdp.DisConnect();
_gateUdp = null;
}
SkynetLogger.Error(Channel.NetDevice, "++++++Skynet Client Destroy++++");
}
}