Пример #1
0
        public RacePlayer(Ball ball, MatchMessenger matchMessenger, MatchPlayer associatedMatchPlayer)
        {
            sr = StageReferences.Active;

            this.matchMessenger        = matchMessenger;
            this.associatedMatchPlayer = associatedMatchPlayer;
            matchMessenger.CreateListener <CheckpointPassedMessage>(CheckpointPassedHandler);
            matchMessenger.CreateListener <RaceTimeoutMessage>(RaceTimeoutHandler);

            lap = 1;

            ball.CanMove           = false;
            ball.AutoBrake         = true;
            ball.CheckpointPassed += Ball_CheckpointPassed;
            ball.RespawnRequested += Ball_RespawnRequested;
            currentCheckpointPos   = sr.checkpoints[0].transform.position;
            this.ball              = ball;

            ball.CameraCreated += (sender, e) =>
            {
                ballCamera = e.CameraCreated;
                ballCamera.SetDirection(sr.checkpoints[0].transform.rotation);
            };

            checkpointTimes = new float[StageReferences.Active.checkpoints.Length];

            SetNextCheckpoint();
        }
Пример #2
0
        public void InitLocalMatch()
        {
            currentSettings = ActiveData.MatchSettings;

            messenger = new LocalMatchMessenger();

            showSettingsOnLobbyLoad = true;
            GoToLobby();
        }
Пример #3
0
        public void InitOnlineMatch(Lidgren.Network.NetClient client, MatchState matchState)
        {
            //Create existing clients
            foreach (var clientInfo in matchState.Clients)
            {
                clients.Add(new MatchClient(clientInfo.Guid, clientInfo.Name));
            }

            //Create existing players
            foreach (var playerInfo in matchState.Players)
            {
                MatchPlayer p = new MatchPlayer(playerInfo.ClientGuid, playerInfo.CtrlType, playerInfo.CharacterId);
                p.ReadyToRace = playerInfo.ReadyToRace;
                players.Add(p);

                if (inLobby)
                {
                    SpawnLobbyBall(p);
                }
            }

            //Set settings
            currentSettings = matchState.Settings;

            //Set auto start timer
            //TODO Get and apply travel time
            autoStartTimerOn = matchState.CurAutoStartTime != 0;
            autoStartTimer   = matchState.CurAutoStartTime;

            //Create messenger
            OnlineMatchMessenger messenger = new OnlineMatchMessenger(client);

            this.messenger          = messenger;
            messenger.Disconnected += (sender, e) =>
            {
                QuitMatch(e.Reason);
            };
            messenger.OnPlayerMovement += OnlinePlayerMovement;

            //Create chat
            activeChat              = Instantiate(chatPrefab);
            activeChat.MessageSent += LocalChatMessageSent;

            //Enter the lobby or stage
            if (matchState.InRace)
            {
                joiningRaceInProgress = true;
                GoToStage();
            }
            else
            {
                //showSettingsOnLobbyLoad = true;
                GoToLobby();
            }
        }
Пример #4
0
        public void Init(MatchSettings settings, MatchManager matchManager, MatchMessenger messenger, bool raceIsInProgress)
        {
            this.settings     = settings;
            this.matchManager = matchManager;
            this.messenger    = messenger;

            messenger.CreateListener <StartRaceMessage>(StartRaceCallback);
            messenger.CreateListener <ClientLeftMessage>(ClientLeftCallback);
            messenger.CreateListener <DoneRacingMessage>(DoneRacingCallback);

            if (raceIsInProgress)
            {
                Debug.Log("Starting race in progress");
                joinedWhileRaceInProgress = true;
                CreateBallObjects();
            }
        }