Пример #1
0
    public void UpdateScoreboard(Racecar winner)
    {
        int idx = Array.IndexOf(cars, winner);

        carDisplays[idx].text = winner.carName + ": " + winner.numRacesWon;
        replay.SetActive(true);
    }
Пример #2
0
    private void OnTriggerEnter(Collider other)
    {
        Racecar player = other.attachedRigidbody.GetComponent <Racecar>();

        if (player != null)
        {
            player.HandleFinish(level);
        }
    }
Пример #3
0
    private void OnTriggerEnter(Collider other)
    {
        Racecar car = other.GetComponentInParent <Racecar>();

        if (car != null)
        {
            cars.Add(car);
        }
    }
Пример #4
0
    private void OnTriggerExit(Collider other)
    {
        Racecar car = other.GetComponentInParent <Racecar>();

        if (car != null)
        {
            cars.Remove(car);
        }
    }
Пример #5
0
    private void OnTriggerEnter(Collider other)
    {
        Racecar racecar = other.GetComponentInParent <Racecar>();

        if (racecar != null)
        {
            LevelManager.ResetCar(racecar.Index);
        }
    }
Пример #6
0
    void OnTriggerEnter(Collider winner)
    {
        Racecar car = winner.transform.parent.GetComponent <Racecar>();

        print(car.carName);
        raceInProgress = false;
        car.numRacesWon++;
        scoreboard.UpdateScoreboard(car);
    }
Пример #7
0
    private void OnTriggerEnter(Collider other)
    {
        Racecar player = other.attachedRigidbody.GetComponent <Racecar>();

        if (player != null)
        {
            VariableManager.SetKeyTime(index, Time.time);
        }
    }
    private void OnTriggerEnter(Collider other)
    {
        Racecar racecar = other.GetComponentInParent <Racecar>();

        if (racecar != null)
        {
            AutograderManager.CompleteTask(this);
        }
    }
Пример #9
0
    private void OnCollisionEnter(Collision collision)
    {
        // If the collider is a player, cause the player to fail
        Racecar player = collision.collider.GetComponentInParent <Racecar>();

        if (player != null)
        {
            player.Hud.ShowFailureMessage(FailOnCollide.failureMessage);
        }
    }
Пример #10
0
    private void OnCollisionEnter(Collision collision)
    {
        // If the collider is a player, cause the player to fail
        Racecar player = collision.collider.GetComponentInParent <Racecar>();

        if (player != null)
        {
            LevelManager.HandleFailure(player.Index, FailOnCollide.failureMessage);
        }
    }
    private void OnTriggerEnter(Collider other)
    {
        // If the collider is a player, cause the player to fail
        Racecar player = other.GetComponentInParent <Racecar>();

        if (player != null)
        {
            player.Hud.ShowFailureMessage(isRed ? SlalomCone.redMessage : SlalomCone.blueMessage);
        }
    }
Пример #12
0
    private void Awake()
    {
        // Find components
        this.texts  = GetComponentsInChildren <Text>();
        this.images = this.GetComponentsInChildren <RawImage>();

        this.images[Images.LidarMap.GetHashCode()].texture  = new Texture2D(CameraModule.ColorWidth / Hud.lidarMapScale, CameraModule.ColorHeight / Hud.lidarMapScale);
        this.images[Images.DepthFeed.GetHashCode()].texture = new Texture2D(CameraModule.DepthWidth, CameraModule.DepthHeight);

        this.racecar = this.transform.parent.GetComponentInChildren <Racecar>();
    }
Пример #13
0
    private void OnTriggerEnter(Collider other)
    {
        Racecar player = other.attachedRigidbody.GetComponent <Racecar>();

        if (player != null)
        {
            player.HandleFinish(level);

            VariableManager.SetKeyTime(VariableManager.KeyTime.Finish, Time.time);
        }
    }
    private void OnTriggerEnter(Collider other)
    {
        Racecar player = other.attachedRigidbody.GetComponent <Racecar>();

        if (player != null)
        {
            GameObject raceManager = GameObject.FindGameObjectWithTag("RaceManager");
            if (raceManager != null)
            {
                raceManager.GetComponent <VariableManager>().SetKeyTime(index, Time.time);
            }
        }
    }
Пример #15
0
    private void OnTriggerEnter(Collider other)
    {
        Racecar car = other.attachedRigidbody.GetComponent <Racecar>();

        if (car != null)
        {
            switch (this.Type)
            {
            case KeyPointType.Finish:
                LevelManager.HandleFinish(car.Index);
                break;

            case KeyPointType.Checkpoint:
                LevelManager.HandleCheckpoint(car.Index, this.checkpointIndex);
                break;
            }
        }
    }
    /// <summary>
    /// Creates a Python Interface for a player.
    /// </summary>
    /// <param name="racecar">The car which the python interface will control.</param>
    public PythonInterface(Racecar racecar)
    {
        this.wasExitHandled  = false;
        this.isSyncConnected = false;
        this.racecar         = racecar;

        // Establish and configure a UDP port
        this.udpClient = new UdpClient(new IPEndPoint(PythonInterface.ipAddress, PythonInterface.unityPort));
        this.udpClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
        this.udpClient.Client.ReceiveTimeout = PythonInterface.timeoutTime;

        // Initialize client to handle async calls
        this.asyncClientThread = new Thread(new ThreadStart(this.ProcessAsyncCalls))
        {
            IsBackground = true
        };
        this.asyncClientThread.Start();
    }
Пример #17
0
    static public ICarType getCarTypeObj(string carType)
    {
        ICarType objCarType = null;

        if (carType.ToLower() == "sedan")
        {
            objCarType = new Sedan();
        }
        else if (carType.ToLower() == "racecar")
        {
            objCarType = new Racecar();
        }
        else
        {
            objCarType = new InvalidCarType();
        }
        return(objCarType);
    }
Пример #18
0
    private void OnTriggerEnter(Collider other)
    {
        // If the collider is a player, cause the player to fail
        Racecar player = other.GetComponentInParent <Racecar>();

        if (player != null)
        {
            if (this.isTimePenalty)
            {
                VariableManager.AddPenalty(SlalomCone.timePenalty);
                Destroy(this.gameObject);
            }
            else
            {
                player.Hud.ShowFailureMessage(isRed ? SlalomCone.redMessage : SlalomCone.blueMessage);
            }
        }
    }
    private void OnTriggerStay(Collider other)
    {
        Racecar racecar = other.GetComponentInParent <Racecar>();

        if (racecar != null)
        {
            if (racecar.Physics.LinearVelocity.magnitude < this.maxStopSpeed)
            {
                this.startTime = Mathf.Min(this.startTime, Time.time);
                if (Time.time - this.startTime >= DestinationStop.stopDuration)
                {
                    AutograderManager.CompleteTask(this);
                }
            }
            else
            {
                this.startTime = float.MaxValue;
            }

            this.material.color = new Color(this.material.color.r, this.material.color.g, this.material.color.b, this.Alapha);
        }
    }
Пример #20
0
    private void OnTriggerEnter(Collider other)
    {
        // If the collider is a player, cause the player to fail
        Racecar player = other.GetComponentInParent <Racecar>();

        if (player != null)
        {
            switch (this.penalty)
            {
            case SlalomConePenalty.Disqualify:
                LevelManager.HandleFailure(player.Index, isRed ? SlalomCone.redMessage : SlalomCone.blueMessage);
                break;

            case SlalomConePenalty.Reset:
                LevelManager.ResetCar(player.Index);
                break;

            case SlalomConePenalty.TimePenalty:
                LevelManager.AddTimePenalty(this.timePenalty);
                Destroy(this.gameObject);
                break;
            }
        }
    }
Пример #21
0
 /// <summary>
 /// Set the pointer to the parent Racecar object.
 /// </summary>
 protected virtual void FindParent()
 {
     this.racecar = this.GetComponent <Racecar>();
 }
Пример #22
0
        public void DriveRacecar()
        {
            Racecar raceCar = new Racecar();

            Assert.True(raceCar.Drive());
        }
 private void Awake()
 {
     this.player = GameObject.FindGameObjectWithTag("Player").GetComponent <Racecar>();
 }
    /// <summary>
    /// Calls a Python function on all connected scripts.
    /// </summary>
    /// <param name="function">The Python function to call (start or update)</param>
    private void PythonCall(Header function)
    {
        for (int i = 0; i < this.pythonEndPoints.Count; i++)
        {
            if (this.pythonEndPoints[i] == null)
            {
                continue;
            }

            Racecar    racecar  = LevelManager.GetCar(i);
            IPEndPoint endPoint = this.pythonEndPoints[i];

            // Tell Python what function to call
            this.udpClient.Send(new byte[] { (byte)function }, 1, endPoint);

            // Respond to API calls from Python until we receive a python_finished message
            bool pythonFinished = false;
            while (!pythonFinished)
            {
                // Receive a response from Python
                byte[] data = this.SafeRecieve(endPoint);
                if (data == null)
                {
                    break;
                }
                Header header = (Header)data[0];

                bool shouldSendController = LevelManager.LevelManagerMode != LevelManagerMode.Race || Settings.CheatMode;

                // Send the appropriate response if it was an API call, or break if it was a python_finished message
                byte[] sendData;
                switch (header)
                {
                case Header.error:
                    Error errorCode = (Error)data[1];
                    HandleError($"Error code [{errorCode}] sent from the Python script controlling car {i}.", errorCode);
                    pythonFinished = true;
                    break;

                case Header.python_finished:
                    pythonFinished = true;
                    break;

                case Header.python_exit:
                    this.RemoveSyncClient(endPoint.Port);
                    pythonFinished = true;
                    break;

                case Header.racecar_get_delta_time:
                    sendData = BitConverter.GetBytes(Time.deltaTime);
                    this.udpClient.Send(sendData, sendData.Length, endPoint);
                    break;

                case Header.camera_get_color_image:
                    pythonFinished = !this.SendFragmented(racecar.Camera.ColorImageRaw, 32, endPoint);
                    break;

                case Header.camera_get_depth_image:
                    sendData = racecar.Camera.DepthImageRaw;
                    this.udpClient.Send(sendData, sendData.Length, endPoint);
                    break;

                case Header.camera_get_width:
                    sendData = BitConverter.GetBytes(CameraModule.ColorWidth);
                    this.udpClient.Send(sendData, sendData.Length, endPoint);
                    break;

                case Header.camera_get_height:
                    sendData = BitConverter.GetBytes(CameraModule.ColorHeight);
                    this.udpClient.Send(sendData, sendData.Length, endPoint);
                    break;

                // Always return null controller data when in race mode (except in cheat mode)
                case Header.controller_is_down:
                    Controller.Button buttonDown = (Controller.Button)data[1];
                    sendData = BitConverter.GetBytes(Controller.IsDown(buttonDown) && shouldSendController);
                    this.udpClient.Send(sendData, sendData.Length, endPoint);
                    break;

                case Header.controller_was_pressed:
                    Controller.Button buttonPressed = (Controller.Button)data[1];
                    sendData = BitConverter.GetBytes(Controller.WasPressed(buttonPressed) && shouldSendController);
                    this.udpClient.Send(sendData, sendData.Length, endPoint);
                    break;

                case Header.controller_was_released:
                    Controller.Button buttonReleased = (Controller.Button)data[1];
                    sendData = BitConverter.GetBytes(Controller.WasReleased(buttonReleased) && shouldSendController);
                    this.udpClient.Send(sendData, sendData.Length, endPoint);
                    break;

                case Header.controller_get_trigger:
                    Controller.Trigger trigger = (Controller.Trigger)data[1];
                    float triggerValue         = shouldSendController ? Controller.GetTrigger(trigger) : 0;
                    sendData = BitConverter.GetBytes(triggerValue);
                    this.udpClient.Send(sendData, sendData.Length, endPoint);
                    break;

                case Header.controller_get_joystick:
                    Controller.Joystick joystick       = (Controller.Joystick)data[1];
                    Vector2             joystickValues = shouldSendController ? Controller.GetJoystick(joystick) : Vector2.zero;
                    sendData = new byte[sizeof(float) * 2];
                    Buffer.BlockCopy(new float[] { joystickValues.x, joystickValues.y }, 0, sendData, 0, sendData.Length);
                    this.udpClient.Send(sendData, sendData.Length, endPoint);
                    break;

                case Header.drive_set_speed_angle:
                    racecar.Drive.Speed = BitConverter.ToSingle(data, 4);
                    racecar.Drive.Angle = BitConverter.ToSingle(data, 8);
                    break;

                case Header.drive_stop:
                    racecar.Drive.Stop();
                    break;

                case Header.drive_set_max_speed:
                    racecar.Drive.MaxSpeed = BitConverter.ToSingle(data, 4);
                    break;

                case Header.lidar_get_num_samples:
                    sendData = BitConverter.GetBytes(Lidar.NumSamples);
                    this.udpClient.Send(sendData, sendData.Length, endPoint);
                    break;

                case Header.lidar_get_samples:
                    sendData = new byte[sizeof(float) * Lidar.NumSamples];
                    Buffer.BlockCopy(racecar.Lidar.Samples, 0, sendData, 0, sendData.Length);
                    this.udpClient.Send(sendData, sendData.Length, endPoint);
                    break;

                case Header.physics_get_linear_acceleration:
                    Vector3 linearAcceleration = racecar.Physics.LinearAccceleration;
                    sendData = new byte[sizeof(float) * 3];
                    Buffer.BlockCopy(new float[] { linearAcceleration.x, linearAcceleration.y, linearAcceleration.z }, 0, sendData, 0, sendData.Length);
                    this.udpClient.Send(sendData, sendData.Length, endPoint);
                    break;

                case Header.physics_get_angular_velocity:
                    Vector3 angularVelocity = racecar.Physics.AngularVelocity;
                    sendData = new byte[sizeof(float) * 3];
                    Buffer.BlockCopy(new float[] { angularVelocity.x, angularVelocity.y, angularVelocity.z }, 0, sendData, 0, sendData.Length);
                    this.udpClient.Send(sendData, sendData.Length, endPoint);
                    break;

                default:
                    Debug.LogError($">> Error: The function {header} is not supported by RacecarSim.");
                    pythonFinished = true;
                    break;
                }
            }
        }
    }
    /// <summary>
    /// Creates a UDP client to process asynchronous API calls from Python (for use by Jupyter).
    /// </summary>
    private void ProcessAsyncCalls()
    {
        this.udpClientAsync = new UdpClient(new IPEndPoint(PythonInterface.ipAddress, PythonInterface.unityPortAsync));
        this.udpClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
        while (true)
        {
            IPEndPoint receiveEndPoint = new IPEndPoint(PythonInterface.ipAddress, 0);
            byte[]     data            = this.udpClientAsync.Receive(ref receiveEndPoint);
            Header     header          = (Header)data[0];

            Racecar racecar = LevelManager.GetCar();

            byte[] sendData;
            switch (header)
            {
            case Header.connect:
                int pythonVersion = data.Length > 1 ? data[1] : 0;
                if (PythonInterface.version == pythonVersion)
                {
                    int?index = this.ConnectSyncClient(receiveEndPoint.Port);
                    if (index.HasValue)
                    {
                        sendData = new byte[] { (byte)Header.connect, (byte)index };
                    }
                    else
                    {
                        // TODO: display this message to the screen?
                        Debug.LogError($"Attempted to connect a Python script from port [{receiveEndPoint.Port}], but every racecar already has a connected Python script.");
                        sendData = new byte[] { (byte)Header.error, (byte)Error.no_free_car };
                    }
                }
                else if (PythonInterface.version > pythonVersion)
                {
                    // TODO: display this message to the screen?
                    Debug.LogError("The Python script is using an outdated and incompatible version of racecar_core. Please update you Python racecar libraries to the newest version.");
                    sendData = new byte[] { (byte)Header.error, (byte)Error.python_outdated };
                }
                else
                {
                    // TODO: display this message to the screen?
                    Debug.LogError("The Python script is using a newer and incompatible version of racecar_core. Please download the newest version of RacecarSim.");
                    sendData = new byte[] { (byte)Header.error, (byte)Error.racecarsim_outdated };
                }
                this.udpClientAsync.Send(sendData, sendData.Length, receiveEndPoint);
                break;

            case Header.python_exit:
                this.RemoveSyncClient(receiveEndPoint.Port);
                break;

            case Header.camera_get_color_image:
                this.SendFragmentedAsync(racecar.Camera.GetColorImageRawAsync(), 32, receiveEndPoint);
                break;

            case Header.camera_get_depth_image:
                sendData = racecar.Camera.GetDepthImageRawAsync();
                this.udpClientAsync.Send(sendData, sendData.Length, receiveEndPoint);
                break;

            case Header.lidar_get_samples:
                sendData = new byte[sizeof(float) * Lidar.NumSamples];
                Buffer.BlockCopy(racecar.Lidar.Samples, 0, sendData, 0, sendData.Length);
                this.udpClientAsync.Send(sendData, sendData.Length, receiveEndPoint);
                break;

            default:
                Debug.LogError($">> Error: The function {header} is not supported by RacecarSim for async calls.");
                break;
            }
        }
    }
Пример #26
0
        public void GoFastRacecar()
        {
            Racecar raceCar = new Racecar();

            Assert.True(raceCar.GoFast());
        }
Пример #27
0
        public void HonkRacecar()
        {
            Racecar raceCar = new Racecar();

            Assert.True(raceCar.Honk());
        }
Пример #28
0
 private void Awake()
 {
     this.racecar = this.GetComponentInParent <Racecar>();
 }
Пример #29
0
        public void DraftRacecar()
        {
            Racecar raceCar = new Racecar();

            Assert.True(raceCar.Draft());
        }
Пример #30
0
 public RacecarBuilder()
 {
     Car = new Racecar();
     RandomCarName();
 }