public void returnToMainMenu()
 {
     Time.timeScale = 1;
     thisGameManager.HardReset();
     ResetController.Reset();
     pauseMenu.SetActive(false);
     SceneManager.LoadScene(0);
 }
    void Awake()
    {
        instance = this;

        originalPositions = new Vector3[objectsToReset.Length];
        originalRotations = new Quaternion[objectsToReset.Length];
        for (int i = 0; i < objectsToReset.Length; i++)
        {
            originalPositions[i] = objectsToReset[i].transform.position;
            originalRotations[i] = objectsToReset[i].transform.rotation;
        }

        VRControllerInput.OnTouchpadPress += ResetScene;
    }
Example #3
0
    public Agent CreateAgent(TrackPath track, float coefficient)
    {
        var container = track.transform.Find("Agents");

        if (!container)
        {
            container = new GameObject("Agents").transform;
            container.SetParent(track.transform);
        }

        var agent = GameObject.Instantiate(AgentPrefab, container);

        agent.name = agent.name + " " + agents.Count;

        var path = agent.gameObject.AddComponent <InterpolatedPath>();

        path.coefficient = coefficient;
        path.Initialise();

        var navigator = agent.GetComponent <PathNavigator>();

        navigator.waypoints        = path;
        navigator.StartingPosition = 0;

        ResetController.ResetPosition(navigator);

        agent.SetActive(true);                          // prefab may be disabled depending on when it was last updated
        SetLayer(agent, TrainingProperties.AgentLayer); // for now car but we may add a training car layer in the future

        return(new Agent()
        {
            navigator = navigator,
            path = path,
            times = new float[path.waypoints.Count]
        });
    }
Example #4
0
 public void Reset()
 {
     ResetController.ResetPosition(navigator);
 }
Example #5
0
 public AstraDevice(IntPtr DeviceHandler, IAstraLibFacade Facade)
 {
     _deviceHandler = DeviceHandler;
     _facade = Facade;
     Reset = new ResetController(this);
 }
Example #6
0
    private IEnumerator ConfigureRaceWorker(RaceConfiguration config)
    {
        stage = RaceStage.Preparation;

        var operation = SceneManager.LoadSceneAsync(config.circuit.sceneName, LoadSceneMode.Additive);

        while (!operation.isDone)
        {
            yield return(null);
        }

        SceneManager.SetActiveScene(SceneManager.GetSceneByName(config.circuit.sceneName));

        var scene    = SceneManager.GetSceneByName(config.circuit.sceneName);
        var track    = scene.GetRootGameObjects().Select(g => g.GetComponentInChildren <Track>()).Where(o => o != null).First();
        var geometry = track.GetComponent <TrackGeometry>();

        var cars = config.cars;

        competitors = new List <Competitor>();
        laps        = config.laps;

        int i = 0;

        for (; i < cars.Count; i++)
        {
            var item = cars[i];
            var car  = GameObject.Instantiate(item.Agent, geometry.transform);
            ResetController.PlacePrefab(car.transform, geometry, GridStartDistance(i), GridStartOffset(i));
            competitors.Add(new Competitor(car));
        }

        if (config.player != null)
        {
            var player = GameObject.Instantiate(config.player.Player, geometry.transform);
            ResetController.PlacePrefab(player.transform, geometry, GridStartDistance(i), GridStartOffset(i));
            this.player = new Competitor(player);
            competitors.Add(this.player);
        }

        foreach (var item in competitors)
        {
            item.navigator.Lap = 0;
        }

        config.leaderboard.Clear();
        foreach (var item in competitors)
        {
            var entry = new LeaderboardEntry();
            entry.car     = item.vehicle.name;
            entry.bestLap = float.PositiveInfinity;
            entry.place   = competitors.IndexOf(item) + 1;

            if (item.vehicle.GetComponent <Agent>())
            {
                entry.driver = item.vehicle.GetComponent <Agent>().DriverName;
            }
            else
            {
                entry.driver = "Player 1";
            }

            config.leaderboard.Add(entry);
            item.entry = entry;
        }

        raceCamera.cameraRigs = competitors.Select(c => c.vehicle.GetComponentInChildren <CamRig>()).ToArray();
        raceCamera.Target     = competitors.Last().vehicle.GetComponent <CamRig>();

        SendMessage("OnRacePrepared", this, SendMessageOptions.DontRequireReceiver);

        StartCoroutine(CountdownWorker());
    }