示例#1
0
    private void SetPlayers(int humanPlayers, int cpuPlayers)
    {
        bool checkWaypoints = false;

        if (gameMode == GameMode.Race || gameMode == GameMode.Team_Race)
        {
            checkWaypoints = true;
        }

        List <Transform> cameraTargets = new List <Transform>();
        Camera           playerCamera  = Instantiate(followCameraPrefab);

        shipsInPlay = new VehicleController[humanPlayers + cpuPlayers];
        int shipIndex          = 0;
        int vehiclePrefabIndex = 1;

        for (int i = 0; i < humanPlayers; i++)
        {
            VehicleController humanShip = Instantiate(vehiclePrefabs[vehiclePrefabIndex++ % vehiclePrefabs.Length]);
            humanShip.transform.parent = transform;

            cameraTargets.Add(humanShip.transform);
            playerCamera.GetComponent <CameraController>().targets = cameraTargets.ToArray();
            if (splitscreen)
            {
                playerCamera.transform.parent = transform;
                playerCamera.rect             = new Rect(CalculateCamRect(humanPlayers, i));
                cameraTargets = new List <Transform>();
                playerCamera  = Instantiate(followCameraPrefab);
            }

            humanShip.mapController   = mapInPlay;
            humanShip.followingCamera = playerCamera.GetComponent <CameraController>();
            humanShip.driver          = humanShip.gameObject.AddComponent <HumanDriver>();
            ((HumanDriver)humanShip.driver).SetPlayer(i);

            if (checkWaypoints)
            {
                humanShip.driver.waypointCleared += WaypointCleared;
            }

            mapInPlay.AddContestant(humanShip);
            shipsInPlay[shipIndex++] = humanShip;
        }
        for (int i = 0; i < cpuPlayers; i++)
        {
            VehicleController aiShip = Instantiate(vehiclePrefabs[vehiclePrefabIndex++ % vehiclePrefabs.Length]);
            aiShip.transform.parent = transform;

            aiShip.mapController = mapInPlay;
            aiShip.driver        = aiShip.gameObject.AddComponent <AIDriver>();

            if (checkWaypoints)
            {
                aiShip.driver.waypointCleared += WaypointCleared;
            }

            mapInPlay.AddContestant(aiShip);
            shipsInPlay[shipIndex++] = aiShip;
        }
    }