Ejemplo n.º 1
0
    private CarMotor m_Car; // the car motor we want to use

    private void Awake()
    {
        m_Rigidbody = GetComponent <Rigidbody>();
        m_Car       = new CarMotor();
        m_Car.SetCarMovementInterface(this);
        m_Car.InitializeCarMotor(m_CentreOfMassOffset, m_MaximumSteerAngle, m_SteerHelper, m_TractionControl, m_FullTorqueOverAllWheels, m_ReverseTorque, m_Topspeed, m_RevRangeBoundary, m_SlipLimit, m_BrakeTorque);
        m_Car.SetCarAudioInterface(this);
        m_Car.InitializeCarAudio(lowPitchMin, lowPitchMax);
        m_Car.StartSound();
    }
Ejemplo n.º 2
0
    private CarMotor m_Car; // the car motor we want to use

    private void Awake()
    {
        m_Rigidbody = GetComponent<Rigidbody>();
        m_Car = new CarMotor();
        m_Car.SetCarMovementInterface(this);
        m_Car.InitializeCarMotor(m_CentreOfMassOffset, m_MaximumSteerAngle, m_SteerHelper, m_TractionControl, m_FullTorqueOverAllWheels, m_ReverseTorque, m_Topspeed, m_RevRangeBoundary, m_SlipLimit, m_BrakeTorque);
        m_Car.SetCarAudioInterface(this);
        m_Car.InitializeCarAudio(lowPitchMin, lowPitchMax);
        m_Car.StartSound();
    }
Ejemplo n.º 3
0
    public void InitializeCarMotor()
    {
        //Arrange
        CarMotor car = new CarMotor();
        var movement = GetMovementMock();
        car.SetCarMovementInterface(movement);
        Vector3 CoM = new Vector3(1, 1, 1);

        //Act
        car.InitializeCarMotor(CoM, 25f, 0.7f, 0.5f, 2500f, 500f, 100f, 1f, 0.3f, 20000f);

        //Assert
        movement.Received().SetWheelColliderCenterOfMass(CoM);
    }
Ejemplo n.º 4
0
    public void MoveDidApplyHandbrake()
    {
        //Arrange
        CarMotor car      = new CarMotor();
        var      movement = GetMovementMock();

        car.SetCarMovementInterface(movement);

        //Act
        car.Move(0, 0, 0, 1);

        //Assert
        movement.Received().ApplyHandBrake(Arg.Any <float>()); // we should see the velocity being reset
    }
Ejemplo n.º 5
0
    public void MoveClamping()
    {
        //Arrange
        CarMotor car = new CarMotor();
        var movement = GetMovementMock();
        car.SetCarMovementInterface(movement);
        car.InitializeCarMotor(new Vector3(0, 0, 0), 25f, 0.7f, 0.5f, 2500f, 500f, 100f, 1f, 0.3f, 20000f);

        //Act
        car.Move(0, 25, -25, 0);

        //Assert
        Assert.AreEqual(1f, car.AccelInput);
        Assert.AreEqual(-1f, -car.BrakeInput);
    }
Ejemplo n.º 6
0
    public void InitializeCarMotor()
    {
        //Arrange
        CarMotor car      = new CarMotor();
        var      movement = GetMovementMock();

        car.SetCarMovementInterface(movement);
        Vector3 CoM = new Vector3(1, 1, 1);

        //Act
        car.InitializeCarMotor(CoM, 25f, 0.7f, 0.5f, 2500f, 500f, 100f, 1f, 0.3f, 20000f);

        //Assert
        movement.Received().SetWheelColliderCenterOfMass(CoM);
    }
Ejemplo n.º 7
0
    public void MoveAddDownforce()
    {
        //Arrange
        CarMotor car      = new CarMotor();
        var      movement = GetMovementMock();

        car.SetCarMovementInterface(movement);
        float dF = (float)GetInstanceField(typeof(CarMotor), car, "m_Downforce");

        //Act
        car.Move(0, 0, 0, 1);

        //Assert
        movement.Received().AddDownForce(dF); // we should see the velocity being reset
    }
Ejemplo n.º 8
0
    public void MoveClamping()
    {
        //Arrange
        CarMotor car      = new CarMotor();
        var      movement = GetMovementMock();

        car.SetCarMovementInterface(movement);
        car.InitializeCarMotor(new Vector3(0, 0, 0), 25f, 0.7f, 0.5f, 2500f, 500f, 100f, 1f, 0.3f, 20000f);

        //Act
        car.Move(0, 25, -25, 0);

        //Assert
        Assert.AreEqual(1f, car.AccelInput);
        Assert.AreEqual(-1f, -car.BrakeInput);
    }
Ejemplo n.º 9
0
    public void MoveApplyDrive()
    {
        //Arrange
        CarMotor car = new CarMotor();
        var movement = GetMovementMock();
        car.SetCarMovementInterface(movement);
        car.InitializeCarMotor(new Vector3(0, 0, 0), 25f, 0.7f, 0.5f, 2500f, 500f, 100f, 1f, 0.3f, 20000f);
        float t = (float)GetInstanceField(typeof(CarMotor), car, "m_CurrentTorque");
        float accel = 0.5f;

        //Act
        car.Move(0, accel, 0, 0);

        //Assert
        movement.Received().ApplyMotorTorque(accel * t / 4); // t in this case is the total torque over all 4 wheels so divide by 4
    }
Ejemplo n.º 10
0
    public void MoveRotateTires()
    {
        //Arrange
        CarMotor car = new CarMotor();
        var movement = GetMovementMock();
        car.SetCarMovementInterface(movement);
        car.InitializeCarMotor(new Vector3(0, 0, 0), 25f, 0.7f, 0.5f, 2500f, 500f, 100f, 1f, 0.3f, 20000f);
        float maxSteerAngle = (float)GetInstanceField(typeof(CarMotor), car, "m_MaximumSteerAngle");
        float steering = 0.5f;

        //Act
        car.Move(steering, 0, 0, 0);

        //Assert
        movement.Received().RotateFrontTires(steering * maxSteerAngle);
    }
Ejemplo n.º 11
0
    public void MoveApplyDrive()
    {
        //Arrange
        CarMotor car      = new CarMotor();
        var      movement = GetMovementMock();

        car.SetCarMovementInterface(movement);
        car.InitializeCarMotor(new Vector3(0, 0, 0), 25f, 0.7f, 0.5f, 2500f, 500f, 100f, 1f, 0.3f, 20000f);
        float t     = (float)GetInstanceField(typeof(CarMotor), car, "m_CurrentTorque");
        float accel = 0.5f;

        //Act
        car.Move(0, accel, 0, 0);

        //Assert
        movement.Received().ApplyMotorTorque(accel * t / 4); // t in this case is the total torque over all 4 wheels so divide by 4
    }
Ejemplo n.º 12
0
    public void MoveRotateTires()
    {
        //Arrange
        CarMotor car      = new CarMotor();
        var      movement = GetMovementMock();

        car.SetCarMovementInterface(movement);
        car.InitializeCarMotor(new Vector3(0, 0, 0), 25f, 0.7f, 0.5f, 2500f, 500f, 100f, 1f, 0.3f, 20000f);
        float maxSteerAngle = (float)GetInstanceField(typeof(CarMotor), car, "m_MaximumSteerAngle");
        float steering      = 0.5f;

        //Act
        car.Move(steering, 0, 0, 0);

        //Assert
        movement.Received().RotateFrontTires(steering * maxSteerAngle);
    }
Ejemplo n.º 13
0
    public void MoveCapSpeed()
    {
        //Arrange
        CarMotor car      = new CarMotor();
        var      movement = GetMovementMock();

        movement.GetRigidbodyVelocity().Returns(100f); // this will return a velocity magnitude equal to our top speed variable
        car.SetCarMovementInterface(movement);
        float topSpeed = 100f;

        car.InitializeCarMotor(new Vector3(0, 0, 0), 25f, 0.7f, 0.5f, 2500f, 500f, topSpeed, 1f, 0.3f, 20000f);
        float mphConst = (float)GetInstanceField(typeof(CarMotor), car, "k_MphConst");

        //Act
        car.Move(0, 1, 0, 0);

        //Assert
        movement.Received().SetRigidbodyVelocity(topSpeed / mphConst); // we should see the velocity being reset
    }
Ejemplo n.º 14
0
    public void MoveCheckForWheelSpinEndTrail()
    {
        //Arrange
        CarMotor car      = new CarMotor();
        var      movement = GetMovementMock();

        movement.GetWheelColliderForwardSlip(Arg.Any <int>()).Returns(0);  // less then slip limit
        movement.GetWheelColliderSidewaysSlip(Arg.Any <int>()).Returns(0); // less then slip limit
        car.SetCarMovementInterface(movement);
        float slipLimit = 0.3f;

        car.InitializeCarMotor(new Vector3(0, 0, 0), 25f, 0.7f, 0.5f, 2500f, 500f, 100f, 1f, slipLimit, 20000f);

        //Act
        car.Move(0, 0, 0, 1);

        //Assert
        movement.Received(4).EndSkidTrail(Arg.Any <int>()); // we should the skid trail ending 4 times
    }
Ejemplo n.º 15
0
    public void MoveCheckForWheelSpinTireSmoke()
    {
        //Arrange
        CarMotor car      = new CarMotor();
        var      movement = GetMovementMock();

        movement.GetWheelColliderForwardSlip(Arg.Any <int>()).Returns(1);  // more then slip limit
        movement.GetWheelColliderSidewaysSlip(Arg.Any <int>()).Returns(1); // more then slip limit
        car.SetCarMovementInterface(movement);
        float slipLimit = 0.3f;

        car.InitializeCarMotor(new Vector3(0, 0, 0), 25f, 0.7f, 0.5f, 2500f, 500f, 100f, 1f, slipLimit, 20000f);

        //Act
        car.Move(0, 0, 0, 1);

        //Assert
        movement.Received(4).EmitTireSmoke(Arg.Any <int>()); // we should the tire smoke emitted 4 times
    }
Ejemplo n.º 16
0
    public void MoveCheckForWheelSpinTireSmoke()
    {
        //Arrange
        CarMotor car = new CarMotor();
        var movement = GetMovementMock();
        movement.GetWheelColliderForwardSlip(Arg.Any<int>()).Returns(1); // more then slip limit
        movement.GetWheelColliderSidewaysSlip(Arg.Any<int>()).Returns(1); // more then slip limit
        car.SetCarMovementInterface(movement);
        float slipLimit = 0.3f;
        car.InitializeCarMotor(new Vector3(0, 0, 0), 25f, 0.7f, 0.5f, 2500f, 500f, 100f, 1f, slipLimit, 20000f);

        //Act
        car.Move(0, 0, 0, 1);

        //Assert
        movement.Received(4).EmitTireSmoke(Arg.Any<int>()); // we should the tire smoke emitted 4 times
    }
Ejemplo n.º 17
0
    public void MoveCheckForWheelSpinEndTrail()
    {
        //Arrange
        CarMotor car = new CarMotor();
        var movement = GetMovementMock();
        movement.GetWheelColliderForwardSlip(Arg.Any<int>()).Returns(0); // less then slip limit
        movement.GetWheelColliderSidewaysSlip(Arg.Any<int>()).Returns(0); // less then slip limit
        car.SetCarMovementInterface(movement);
        float slipLimit = 0.3f;
        car.InitializeCarMotor(new Vector3(0, 0, 0), 25f, 0.7f, 0.5f, 2500f, 500f, 100f, 1f, slipLimit, 20000f);

        //Act
        car.Move(0, 0, 0, 1);

        //Assert
        movement.Received(4).EndSkidTrail(Arg.Any<int>()); // we should the skid trail ending 4 times
    }
Ejemplo n.º 18
0
    public void MoveDidApplyHandbrake()
    {
        //Arrange
        CarMotor car = new CarMotor();
        var movement = GetMovementMock();
        car.SetCarMovementInterface(movement);

        //Act
        car.Move(0, 0, 0, 1);

        //Assert
        movement.Received().ApplyHandBrake(Arg.Any<float>()); // we should see the velocity being reset
    }
Ejemplo n.º 19
0
    public void MoveAddDownforce()
    {
        //Arrange
        CarMotor car = new CarMotor();
        var movement = GetMovementMock();
        car.SetCarMovementInterface(movement);
        float dF = (float)GetInstanceField(typeof(CarMotor), car, "m_Downforce");

        //Act
        car.Move(0, 0, 0, 1);

        //Assert
        movement.Received().AddDownForce(dF); // we should see the velocity being reset
    }
Ejemplo n.º 20
0
    public void MoveCapSpeed()
    {
        //Arrange
        CarMotor car = new CarMotor();
        var movement = GetMovementMock();
        movement.GetRigidbodyVelocity().Returns(100f); // this will return a velocity magnitude equal to our top speed variable
        car.SetCarMovementInterface(movement);
        float topSpeed = 100f;
        car.InitializeCarMotor(new Vector3(0, 0, 0), 25f, 0.7f, 0.5f, 2500f, 500f, topSpeed, 1f, 0.3f, 20000f);
        float mphConst = (float)GetInstanceField(typeof(CarMotor), car, "k_MphConst");

        //Act
        car.Move(0, 1, 0, 0);

        //Assert
        movement.Received().SetRigidbodyVelocity(topSpeed/mphConst); // we should see the velocity being reset
    }