Ejemplo n.º 1
0
        private void SendCommand(TankNode tankNode, MoveCommand moveCommand)
        {
            TankMovementSenderComponent tankMovementSender = tankNode.tankMovementSender;
            Movement?movement = moveCommand.Movement;

            if (movement != null)
            {
                if (!PhysicsUtil.ValidateMovement(movement.Value))
                {
                    return;
                }
                tankMovementSender.LastSentMovement     = movement;
                tankMovementSender.LastSentMovementTime = PreciseTime.Time;
                base.Log.Debug("SEND MOVEMENT");
            }
            if (moveCommand.WeaponRotation != null)
            {
                if (!PhysicsUtil.IsValidFloat(moveCommand.WeaponRotation.Value))
                {
                    LoggerProvider.GetLogger(typeof(PhysicsUtil)).ErrorFormat("Invalid WeaponRotation. StackTrace:[{0}]", Environment.StackTrace);
                    return;
                }
                tankMovementSender.LastSentWeaponRotationTime = PreciseTime.Time;
                base.Log.Debug("SEND WEAPON_ROTATION");
            }
            base.ScheduleEvent(new MoveCommandEvent(moveCommand), tankNode.Entity);
            base.Log.Debug("SEND DISCRETE");
        }
 private void ApplyMovement(TankNode tank, ref Movement?movement, bool init)
 {
     if (movement != 0)
     {
         Movement m = movement.Value;
         if (PhysicsUtil.ValidateMovement(m))
         {
             bool flag = this.HalveMoveCommandIfNeed(tank, init, ref m);
             base.Log.Debug(!flag ? "APPLY MOVEMENT" : "APPLY HALVED MOVEMENT");
             Transform rigidbodyTransform = tank.rigidbody.RigidbodyTransform;
             Rigidbody rigidbody          = tank.rigidbody.Rigidbody;
             rigidbodyTransform.SetRotationSafe(m.Orientation);
             rigidbodyTransform.SetPositionSafe(TankPositionConverter.ConvertedReceptionFromServer(m.Position, tank.tankCollidersUnity, rigidbodyTransform.position));
             rigidbody.SetVelocitySafe(m.Velocity);
             rigidbody.SetAngularVelocitySafe(m.AngularVelocity);
         }
     }
 }