예제 #1
0
        public void UpdateDesiredTargetSpeed(Vector2 input)
        {
            if (Input.GetKeyDown(RunKey))
            {
                isRun = true;
                m_NetSyncController.SyncVariables();
            }
            if (Input.GetKeyUp(RunKey))
            {
                isRun = false;
                m_NetSyncController.SyncVariables();
            }
            CurrentTargetSpeed = Speed * (isRun ? RunMultiplier : 1.0f);

            //if (input == Vector2.zero) return;
            //if (input.x > 0 || input.x < 0)
            //{
            //    //horizontal
            //    CurrentTargetSpeed = /*Horizontal*/Speed * (isRun ? RunMultiplier : 1.0f);
            //}
            //if (input.y > 0 || input.y < 0)
            //{
            //    //vertical
            //    CurrentTargetSpeed = /*Vertical*/Speed * (isRun ? RunMultiplier : 1.0f);
            //}
        }
예제 #2
0
 public void Update()
 {
     if (!GameMgr.instance)//单机状态
     {
         return;
     }
     if (syncPerSecond == 0f)
     {
         return;
     }
     if (is_master_client)//master_client发布信息
     {
         if (Time.time - lastSendInfoTime > 1.0f / syncPerSecond)
         {
             m_NetSyncController.SyncVariables();
             lastSendInfoTime = Time.time;
         }
         // 每秒发送Rpc_syncPerSecond次AI RPC
         if (Time.time - lastSendRpcTime > 1.0f / Rpc_syncPerSecond)
         {
             if (protoCnt != 0)
             {
                 lock (bufferlock)
                 {
                     ProtocolBytes AIRPC_proto = new ProtocolBytes();
                     AIRPC_proto.AddString("AIRPC");
                     AIRPC_proto.AddInt(protoCnt);
                     AIRPC_proto.bytes = AIRPC_proto.bytes.Concat(proto.bytes).ToArray();
                     NetMgr.srvConn.Send(AIRPC_proto);
                     //Debug.LogFormat("Reach Send AIRPC in Update, protoCnt = {0}, bytesLength = {1}", protoCnt, AIRPC_proto.bytes.Length);
                     // 更新缓冲区
                     proto           = new ProtocolBytes();
                     protoCnt        = 0;
                     lastSendRpcTime = Time.time;
                 }
             }
         }
     }
     else //非master_client接受网络同步并预测更新
     {
         NetUpdate();
     }
 }
    private void OnTriggerEnter(Collider other)
    {
        //只有本地玩家才会触发这些事件
        if (transform.GetComponent <NetSyncTransform>().ctrlType == NetSyncTransform.CtrlType.player && !shield.isPlaying)
        {
            if (other.tag == "Hinder")
            {
                AudioSource.PlayClipAtPoint(AC, new Vector3(0f, 0f, 0f));

                this.transform.GetComponentInChildren <CameraShake>().begin();

                ChangeHp(other.gameObject.GetComponent <Hinder>().damage);
                shield.Play();
                //ChangeHp(-40.0f);

                /*Vector3 Force = this.transform.position - other.transform.position;
                 * m_RigidBody.AddForce(Force * 80f);//往反方向推
                 * isPushed = true;*/
                m_NetSyncController.SyncVariables();
            }
            if (Hp == 0f)
            {
                this.GetComponent <Collider>().enabled = false;
                SendDead();
            }
        }

        //只有本地玩家才会触发这些事件
        if (transform.GetComponent <NetSyncTransform>().ctrlType == NetSyncTransform.CtrlType.player)
        {
            if (other.tag == "End")
            {
                //Flyer.GetComponent<UserController>().enabled = false;
                //Flyer.GetComponent<Rigidbody>().velocity = new Vector3(0f, 0f, 0f);
                //Flyer.transform.position = other.transform.position;
                Cursor.lockState = CursorLockMode.None;
                Cursor.visible   = true;
                this.gameObject.SetActive(false);
            }
        }
    }
예제 #4
0
 public void HitRock()
 {
     movementSettings.isPushed = true;
     m_NetSyncController.SyncVariables();
 }