public void IncrementAICharacter(int pos)
        {
            int characterId = tempSettings.GetAICharacter(pos);

            characterId++;
            if (characterId >= ActiveData.Characters.Length)
            {
                characterId = 0;
            }

            tempSettings.SetAICharacter(pos, characterId);
            UpdateUiFields();
        }
예제 #2
0
        private void CreateBallObjects()
        {
            int             nextBallPosition = 0;
            RaceBallSpawner ballSpawner      = StageReferences.Active.spawnPoint;

            //Enable lap records if there is only one local player.
            bool enableLapRecords = matchManager.Players.Count(a => a.ClientGuid == matchManager.LocalClientGuid) == 1;

            //Create all player balls
            for (int i = 0; i < matchManager.Players.Count; i++)
            {
                var matchPlayer = matchManager.Players[i];

                bool local = matchPlayer.ClientGuid == matchManager.LocalClientGuid;

                //Create ball
                string name = matchManager.Clients.FirstOrDefault(a => a.Guid == matchPlayer.ClientGuid).Name;
                matchPlayer.BallObject = ballSpawner.SpawnBall(
                    nextBallPosition,
                    BallType.Player,
                    local ? matchPlayer.CtrlType : ControlType.None,
                    matchPlayer.CharacterId,
                    name + " (" + GameInput.GetControlTypeName(matchPlayer.CtrlType) + ")"
                    );

                //Create race player
                var racePlayer = new RacePlayer(matchPlayer.BallObject, messenger, matchPlayer);
                players.Add(racePlayer);
                racePlayer.LapRecordsEnabled = enableLapRecords && local;
                racePlayer.FinishLinePassed += RacePlayer_FinishLinePassed;

                nextBallPosition++;
            }

            if (!matchManager.OnlineMode)
            {
                //Create all AI balls (In local play only)
                for (int i = 0; i < settings.AICount; i++)
                {
                    //Create ball
                    var aiBall = ballSpawner.SpawnBall(
                        nextBallPosition,
                        BallType.AI,
                        ControlType.None,
                        settings.GetAICharacter(i),
                        "AI #" + i
                        );
                    aiBall.CanMove = false;

                    //Create race player
                    var racePlayer = new RacePlayer(aiBall, messenger, null);
                    players.Add(racePlayer);
                    racePlayer.FinishLinePassed += RacePlayer_FinishLinePassed;

                    nextBallPosition++;
                }
            }

            int nextLocalPlayerIndex = 0;

            foreach (RacePlayer p in players.Where(a => a.CtrlType != ControlType.None))
            {
                //Create player UI
                var playerUI = Instantiate(playerUIPrefab);
                playerUI.TargetManager = this;
                playerUI.TargetPlayer  = p;

                //Connect UI to camera (when the camera has been instanced)
                int persistentIndex = nextLocalPlayerIndex;
                p.AssociatedMatchPlayer.BallObject.CameraCreated += (sender, e) =>
                {
                    playerUI.TargetCamera = e.CameraCreated.AttachedCamera;
                    var splitter = e.CameraCreated.AttachedCamera.GetComponent <CameraSplitter>();
                    if (splitter)
                    {
                        splitter.SplitscreenIndex = persistentIndex;
                    }
                };

                nextLocalPlayerIndex++;
            }
        }