public static void Welcome(Packet packet)
        {
            string msg = packet.ReadString();
            int    id  = packet.ReadInt();

            Debug.Log($"服务器消息:{msg}");
            Client.instance.myID = id;

            ClientSend.WelcomeReceived();

            Client.instance.udp.Connect(((IPEndPoint)Client.instance.tcp.socket.Client.LocalEndPoint).Port);
        }
Exemple #2
0
 public static void BeginSceneLoading(string sceneName)
 {
     RefreshBeforeLoad();
     GameManager.instance.RefreshBeforeLoad();
     GameManager.instance.BeginLoadScene(sceneName, (string s) =>
     {
         if (s == sceneName)
         {
             ClientSend.SceneLoaded(s);
             ThreadManager.ExecuteOnMainThread(SendStageSituation);
             InitPostProcess();
         }
     });
 }
        private void Update()
        {
            inputBuffer.Clear();
            float moveValue = Input.GetAxis("Vertical");

            if (moveValue != lastMoveValue)
            {
                inputBuffer.Add(new InputHolder {
                    key = InputType.move, value = moveValue
                });
                lastMoveValue = moveValue;
            }
            float rotateValue = Input.GetAxis("Horizontal");

            if (rotateValue != lastRotateValue)
            {
                inputBuffer.Add(new InputHolder {
                    key = InputType.rotate, value = rotateValue
                });
                lastRotateValue = rotateValue;
            }
            if (Input.GetKeyDown(KeyCode.J) || Input.GetMouseButtonDown(0))
            {
                inputBuffer.Add(new InputHolder {
                    key = InputType.barRotate, value = 1
                });
            }
            else if (Input.GetKeyUp(KeyCode.J) || Input.GetMouseButtonUp(0))
            {
                inputBuffer.Add(new InputHolder {
                    key = InputType.barRotate, value = 0
                });
            }
            if (Input.GetKeyDown(KeyCode.K) || Input.GetKeyDown(KeyCode.Space) || Input.GetMouseButtonDown(1))
            {
                inputBuffer.Add(new InputHolder {
                    key = InputType.charge, value = 1
                });                                                                     //得传状态,按下为1,抬起为-1
            }
            else if (Input.GetKeyUp(KeyCode.K) || Input.GetKeyUp(KeyCode.Space) || Input.GetMouseButtonUp(1))
            {
                inputBuffer.Add(new InputHolder {
                    key = InputType.charge, value = 0
                });                                                                     //得传状态,按下为1,抬起为-1
            }
            if (Input.GetKeyDown(KeyCode.L) || Input.GetMouseButtonDown(2))
            {
                inputBuffer.Add(new InputHolder {
                    key = InputType.ultimate, value = 0
                });                                                                       //value不会提交,服务端那边value会设为1
            }

            //鼠标部分
            Vector3 v3       = Camera.main.WorldToScreenPoint(transform.position);
            Vector3 mousePos = Input.mousePosition;

            if (mousePos != lastMousePos)
            {
                lastMousePos = mousePos;
                mousePos.z   = v3.z;
                Vector3 worldPos = Camera.main.ScreenToWorldPoint(mousePos);
                inputBuffer.Add(new InputHolder {
                    key = InputType.mouseX, value = (worldPos.x - transform.localPosition.x) * 0.1f
                });
                inputBuffer.Add(new InputHolder {
                    key = InputType.mouseY, value = (worldPos.z - transform.localPosition.z) * 0.1f
                });
            }

            //最后发包
            if (inputBuffer.Count > 0)
            {
                ClientSend.InputPacket(inputBuffer);
            }
        }
Exemple #4
0
 public static void SendStageSituation()
 {
     ClientSend.StageSituation(StageManager.instance.GetStageObjectPairs());
 }