Пример #1
0
        private void ActivateInner(RaceManager manager)
        {
            if (!hasActivatedOnce)
            {
                hasActivatedOnce = true;

                activeScoreboard = Instantiate(scoreboardPrefab);

                for (int i = 0; i < manager.PlayerCount; i++)
                {
                    RacePlayer p = manager[i];
                    if (p.Camera != null)
                    {
                        p.Camera.Remove();
                    }
                }

                foreach (RaceUI ui in FindObjectsOfType <RaceUI>())
                {
                    Destroy(ui.gameObject);
                }

                foreach (PlayerUI ui in FindObjectsOfType <PlayerUI>())
                {
                    Destroy(ui.gameObject);
                }

                cam.gameObject.SetActive(true);
                camRotate.angle = new Vector3(0, 1, 0);
                //cam.enabled = true;
            }
            activeScoreboard.DisplayResults(manager);

            RacePlayer[] movablePlayers = manager.Players.Where(a => a.RaceFinished && !a.FinishReport.Disqualified).OrderBy(a => a.FinishReport.Position).ToArray();
            for (int i = 0; i < movablePlayers.Length; i++)
            {
                Vector3 spawnpoint = lowerPositionsSpawnpoint.position;
                if (i < topPositionSpawnpoints.Length)
                {
                    spawnpoint = topPositionSpawnpoints[i].position;
                }
                RacePlayer playerToMove = movablePlayers[i];
                if (!movedPlayers.Contains(playerToMove))
                {
                    playerToMove.Ball.transform.position = spawnpoint;
                    playerToMove.Ball.transform.rotation = transform.rotation;
                    playerToMove.Ball.GetComponent <Rigidbody>().velocity        = Random.insideUnitSphere * 0.5f;
                    playerToMove.Ball.GetComponent <Rigidbody>().angularVelocity = new Vector3(0, Random.Range(-50f, 50f));
                    playerToMove.Ball.CanMove          = false;
                    playerToMove.Ball.gameObject.layer = LayerMask.NameToLayer("Racer");
                    movedPlayers.Add(playerToMove);
                }
            }
        }
Пример #2
0
        private void CreateBallObjects()
        {
            int nextPos      = 0;
            var matchManager = FindObjectOfType <MatchManager>();

            for (int i = 0; i < matchManager.Players.Count; i++)
            {
                var player = matchManager.Players[i];
                if (NetworkManager.singleton.GetComponent <SanicNetworkManager>().matchManager.isServer)
                {
                    player.BallObject         = FindObjectOfType <RaceBallSpawner>().SpawnBall(nextPos, BallType.Player, player.CtrlType, player.CharacterId, player.Name, player.ConnectionSelf);
                    player.BallObject.CanMove = false;

                    if (!player.BallObject.isLocalPlayer)
                    {
                        player.BallObject.RpcSetCanMove(false);
                        player.BallObject.RpcSetSettings(settings.Laps, settings.StageId);
                    }
                    else
                    {
                    }
                }
                player.BallObject.transform.gameObject.GetComponent <NetworkTransform>().sendInterval = .14f;

                var racePlayer = new RacePlayer(player.BallObject);
                players.Add(racePlayer);

                if (matchManager.Players.Count == 1)
                {
                    racePlayer.LapRecordsEnabled = true;
                }

                racePlayer.FinishLinePassed += RacePlayer_FinishLinePassed;

                if (player.BallObject.isLocalPlayer)
                {
                    var playerUI = Instantiate(playerUIPrefab);
                    playerUI.TargetPlayer  = racePlayer;
                    playerUI.TargetManager = this;


                    int persistentIndex = i;
                    player.BallObject.CameraCreatedEvent += (sender, e) =>
                    {
                        playerUI.TargetCamera = e.CameraCreated2.AttachedCamera;
                        var splitter = e.CameraCreated2.AttachedCamera.GetComponent <CameraSplitter>();
                        if (splitter)
                        {
                            splitter.SplitscreenIndex = persistentIndex;
                        }
                    };
                    //in thispart the init is forced to keyboard...
                    player.BallObject.Init(Sanicball.BallType.Player, Sanicball.ControlType.Keyboard, player.BallObject.CharacterId, player.BallObject.NickName);

                    if (player.BallObject.isServer)
                    {
                        player.BallObject.RpcInit(player.BallObject.Type, player.BallObject.CtrlType, player.BallObject.CharacterId, player.BallObject.NickName);
                    }
                    if (!player.BallObject.isServer && player.BallObject.isClient)
                    {
                        player.BallObject.CmdInit(Sanicball.BallType.Player, Sanicball.ControlType.Keyboard, player.BallObject.CharacterId, player.BallObject.NickName);
                    }

                    player.BallObject.cameraBall.SetDirection(StageReferences.Active.checkpoints[0].transform.rotation);

                    nextPos++;
                }
            }

            if (NetworkManager.singleton.GetComponent <SanicNetworkManager>().matchManager.isServer)
            {
                for (int i = 0; i < settings.AICount; i++)
                {
                    var aiBall = FindObjectOfType <RaceBallSpawner>().SpawnBall(nextPos, BallType.AI, ControlType.None, settings.GetAICharacter(i), "AI #" + i);
                    aiBall.CanMove = false;
                    aiBall.GetComponent <NetworkTransform>().sendInterval = .25f;

                    var racePlayer = new RacePlayer(aiBall);
                    players.Add(racePlayer);
                    racePlayer.FinishLinePassed += RacePlayer_FinishLinePassed;

                    nextPos++;
                }
            }

            // Filling the raceManager of the clients
            if (!NetworkManager.singleton.GetComponent <SanicNetworkManager>().matchManager.isServer)
            {
                Ball[] listaBalls;
                listaBalls = FindObjectsOfType <Ball>();
                for (int j = 0; j < listaBalls.Length; j++)
                {
                    if (!listaBalls[j].isLocalPlayer)
                    {
                        var racePlayer2 = new RacePlayer(listaBalls[j]);
                        racePlayer2.FinishLinePassed += RacePlayer_FinishLinePassed;
                        players.Add(racePlayer2);
                    }
                }
            }
        }