Exemple #1
0
        //连接服务器,获取socket
        public static TestClientSocket Connect(string ip = "127.0.0.1", int port = 9527)
        {
            TestClientSocket clientSocket = new TestClientSocket();

            clientSocket.m_serverSocket = TestServer.instance.OnConnect(clientSocket);
            return(clientSocket);
        }
        void Start()
        {
            instance = this;

            TestClientSocket.Add(TestMSG.TMSG_ROLE, TMSG_ROLE.LOGIN, OnLogin);
            TestClientSocket.Add(TestMSG.TMSG_ROLE, TMSG_ROLE.SYNC, OnSync);
            TestClientSocket.Add(TestMSG.TMSG_ROLE, TMSG_ROLE.RENAME, OnRename);
            TestClientSocket.Add(TestMSG.TMSG_LEVEL, TMSG_LEVEL.FIGHT_OVER, OnLevelFight);
            TestClientSocket.Add(TestMSG.TMSG_TASK, TMSG_TASK.GET_REWARD, OnTaskGetReward);
        }
        public TestServerSocket OnConnect(TestClientSocket clientSocket)
        {
            TestServerSocket serverSocket = new TestServerSocket();

            serverSocket.m_clientSocket = clientSocket;
            serverSocket.m_hero.Init();

            //从数据库获取数据初始化玩家
            //未实现

            return(serverSocket);
        }
        void OnGUI()
        {
            if (m_socket == null)
            {
                if (GUILayout.Button("登录"))
                {
                    m_socket = TestClientSocket.Connect();
                    IoBuffer s = m_socket.GetStream();
                    m_socket.Send(TestMSG.TMSG_ROLE, TMSG_ROLE.LOGIN, s);
                }
                return;
            }
            using (new AutoChangeColor(Color.green))
            {
                //绘制玩家信息
                DrawInfo();

                //绘制玩家操作
                DrawHandle();
            }
        }