コード例 #1
0
        //change gearbox types
        public override void changeGearBoxToAutomatic()
        {
            GearBox gearbox = GearBox.Create(false, ratios, 0.2f);

            currentMotor = new CarMotor(power, 8, 8f, gearbox);
            resetGears();
        }
コード例 #2
0
        public override void changeGearBoxToManual()
        {
            GearBox gearbox = GearBox.Create(true, ratios, 0.2f);

            currentMotor = new CarMotor(power, 8, 8f, gearbox);
            resetGears();
        }
コード例 #3
0
 private void Awake()
 {
     if (instance == null)
     {
         instance = this;
     }
 }
コード例 #4
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();
    }
コード例 #5
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();
    }
コード例 #6
0
 public void PrintAuto()
 {
     Console.WriteLine("Color: " + Color);
     Console.WriteLine("AmountOfWheels: " + AmountOfWheels);
     Console.WriteLine("Brand: " + Brand);
     Console.WriteLine("AmountOfDoors: " + AmountOfDoors);
     Console.WriteLine("Torque: " + Torque);
     Console.WriteLine("Motor:");
     CarMotor.PrintMotor();
 }
コード例 #7
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
    }
コード例 #8
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);
    }
コード例 #9
0
    public void StopSound()
    {
        // Arrange
        CarMotor car   = new CarMotor();
        var      audio = GetAudioMock();

        car.SetCarAudioInterface(audio);

        //Act
        car.StopSound();

        //Assert
        audio.Received().StopSound();
    }
コード例 #10
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
    }
コード例 #11
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);
    }
コード例 #12
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);
    }
コード例 #13
0
    public void CarAudio()
    {
        // Arrange
        CarMotor car   = new CarMotor();
        var      audio = GetAudioMock();

        car.SetCarAudioInterface(audio);
        car.InitializeCarAudio(0.5f, 0.5f);

        //Act
        car.CarAudio();

        //Assert
        audio.Received().AdjustPitch(Arg.Any <float>());
        audio.Received().AdjustVolumes(Arg.Any <float>(), Arg.Any <float>(), Arg.Any <float>(), Arg.Any <float>());
    }
コード例 #14
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
    }
コード例 #15
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);
    }
コード例 #16
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);
    }
コード例 #17
0
    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.tag == "Player")
        {
            car = other.gameObject.GetComponent <CarMotor>(); // not sure about the syntax here...
            if (car)
            {
                // We speed up the player and then tell to stop after a few seconds
                car.rb.AddTorque(0, 0, car.speedBoost);

                car.speedBoost = 1.5f;
                StartCoroutine(car.StopSpeedUp());
            }
            Destroy(gameObject);
        }
    }
コード例 #18
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
    }
コード例 #19
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);
    }
コード例 #20
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
    }
コード例 #21
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
    }
コード例 #22
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
    }
コード例 #23
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
    }
コード例 #24
0
    // Start is called before the first frame update

    void Awake()
    {
        //storing the lengths of each command in the dict :)
        commandToMaxTime = new Dictionary <Command, float>()
        {
            { Command.SWERVE_LEFT, swervingMaxTime },
            { Command.SWERVE_RIGHT, swervingMaxTime },
            { Command.TURN_LEFT, turningMaxTime },
            { Command.TURN_RIGHT, turningMaxTime },
            { Command.BRAKE, brakingMaxTime },
            { Command.SLOW_DOWN, slowingMaxTime }
        };

        motor = GetComponent <CarMotor>();

        if (!GameObject.Find(AINavigatorTemplate.name))
        {
            GameObject AIObject = Instantiate(AINavigatorTemplate);
            AINavigator = AIObject.GetComponent <NavMeshAgent>();
        }
    }
コード例 #25
0
 /////////////////////////////////////////
 void Start()
 {
     motor    = GetComponent <CarMotor>();
     animator = GetComponent <Animator>();
 }
コード例 #26
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
    }
コード例 #27
0
    public void CarAudio()
    {
        // Arrange
        CarMotor car = new CarMotor();
        var audio = GetAudioMock();
        car.SetCarAudioInterface(audio);
        car.InitializeCarAudio(0.5f, 0.5f);

        //Act
        car.CarAudio();

        //Assert
        audio.Received().AdjustPitch(Arg.Any<float>());
        audio.Received().AdjustVolumes(Arg.Any<float>(), Arg.Any<float>(), Arg.Any<float>(), Arg.Any<float>());
    }
コード例 #28
0
    public void StopSound()
    {
        // Arrange
        CarMotor car = new CarMotor();
        var audio = GetAudioMock();
        car.SetCarAudioInterface(audio);

        //Act
        car.StopSound();

        //Assert
        audio.Received().StopSound();
    }
コード例 #29
0
 // Use this for initialization
 void Start()
 {
     collider = GetComponent <MeshCollider>();
     carMotor = GetComponent <CarMotor>();
 }
コード例 #30
0
 // Use this for initialization
 void Start()
 {
     carMotor = GetComponent <CarMotor>();
 }
コード例 #31
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
    }
コード例 #32
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
    }
コード例 #33
0
 // Start is called before the first frame update
 void Awake()
 {
     motor = GetComponent <CarMotor>();
 }
コード例 #34
0
 // Use this for initialization
 void Start()
 {
     motor = GetComponent <CarMotor>();
     //Disable Dragon Controller. Wait for Player to mount to enable.
     this.enabled = false;
 }
コード例 #35
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
    }