Ejemplo n.º 1
0
        public void OnReplicateMove()
        {
            NCharacterController controller = OwnerController;

            if (controller != null)
            {
                // 发送移动消息
                C2S_Move msg;
                msg.messageId    = C2S_Move.Id;
                msg.Position     = controller.Location;
                msg.Acceleration = controller.Acceleration;
                msg.Yaw          = controller.Rotation.y;
                msg.Flag         = NSavedMove.ControllerToFlags(controller);
                msg.TimeStamp    = NativeEngineHelper.GetTimeSeconds();
                GameFrameManager.SendNetMessage <C2S_Move>(msg);
            }
        }
        internal void OnNetMovement(S2C_Move ret)
        {
            // 位置误差大于一定的阀值之后修正
            Vector3 position = this.Location;

            if ((position - ret.Position).LengthSquared2D() > 300 * 300)
            {
                this.Transport(GameEngine.EngineInstance.GameLevel, ret.Position, true);
            }

            this.Acceleration = ret.Acceleration;
            NSavedMove.FlagsToController(ret.Flag, this);
            Vector3 newRot = this.Rotation;

            newRot.y      = ret.Yaw;
            this.Rotation = newRot;

            //Debug.WriteLine("debug Remote Controller S2C_Move " + "Flag=" + ret.Flag);
        }
        public void OnReplicateMove()
        {
            LocalPlayerController controller = OwnerController;

            if (controller != null &&
                GameFrameManager.Instance.CurrentFrameType == GameFrameType.Gaming)
            {
                // 发送移动消息
                C2S_Move msg;
                msg.messageId    = C2S_Move.Id;
                msg.Position     = controller.Location;
                msg.Acceleration = controller.Acceleration;
                msg.Yaw          = Vector3.CalcYaw(controller.Acceleration);
                msg.Flag         = NSavedMove.ControllerToFlags(controller, controller.PressJump ? (Byte)MovementFlag.PressJump : Byte.MinValue);
                msg.TimeStamp    = NativeEngineHelper.GetTimeSeconds();
                GameFrameManager.SendNetMessage <C2S_Move>(msg);

                // 保存到消息队列以便验证
                controller.NetMovementMessages.Add(msg);

                //Debug.WriteLine("Send C2S_Move " + " Position:" + msg.Position + " Acceleration:" + msg.Acceleration + " Flag:" + msg.Flag);
            }
        }