wangguan
2020-12-17 dcbbe82ceca921e73e1789ae87ea8ac6a59c7bff
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
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Protobuf;
using Google.Protobuf;
 
namespace KTGMGemClient
{
    public class MasterSocket : BaseSocket
    {
        private static MasterSocket _Ins;
        public static MasterSocket Ins{
            get{
                return _Ins;
            }
        }
        /// <summary>
        /// Awake is called when the script instance is being loaded.
        /// </summary>
        void Awake()
        {
            _Ins=this;
        }
        public string MasterIp;
        public int MasterPort;
 
        /// <summary>
        /// 建立tcp链接
        /// </summary>
        public void StartConnect()
        {
            Connect(MasterIp, MasterPort);
            StartCoroutine(StartRecv());
        }
 
        protected override void OnConnected(bool connected)
        {
            Debug.Log("connected master:" + connected);
            EventCenter.Ins.BroadCast((int)KTGMGemClient.EventType.MasterSocketConnectResult, connected);
        }
 
        protected override void OnData(Opcode opcode, IMessage msg)
        {
            Debug.Log("on data: " + opcode + "   msg:" + msg);
            SocketEvent.Ins.BroadCast((int)opcode, msg);
        }
 
        public void SetTestData(Opcode opcode, IMessage msg){
            CommonDebugHelper.Debug("开始使用测试假数据");
            OnData(opcode,msg);
        }
 
        /// <summary>
        /// Callback sent to all game objects before the application is quit.
        /// </summary>
        void OnApplicationQuit()
        {
            Close();
        }
    }
}