Beispiel #1
0
        // Initializes the game for each level.
        internal void InitGame(GameManager.GameStateData data)
        {
            if (data != null)
            {
                Debug.Log("Initializing using " + data.CurrentPhase + ": " +
                          data.SerialNumber);

                // if we are moving to the next level of the game, reload!
                if (owner.Level != data.Level)
                {
                    Debug.Log("Going from level " + owner.Level + " to " +
                              data.Level);
                    owner.GameState = data;
                    owner.LevelManager.DestroyBoard();
                    SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
                    return;
                }

                // Call the SetupScene function of the BoardManager script,
                // pass it current level number.
                owner.LevelManager.SetupScene(data.Level, data.LevelData);

                // associate each player with the player state received.
                foreach (PlayerInfo.PlayerData p in data.Players)
                {
                    PlayerInfo player = PlayerInfo.GetPlayer(p.DeviceId);
                    if (player != null)
                    {
                        player.DataState.AvatarIndex = p.AvatarIndex;
                        player.DataState.Name        = p.Name;
                        player.Score = p.score;
                    }
                    else
                    {
                        // the endpoint is not known for players that are not local
                        // so make one up that is unique.
                        player = PlayerInfo.AddPendingPlayer(
                            new NearbyPlayer(
                                p.DeviceId,
                                "unknown" + p.DeviceId,
                                p.Name),
                            p.AvatarIndex);
                    }

                    owner.CreatePlayerScorePanel(player);
                }
            }
        }
        public void OnNewGameState(GameManager.GameStateData newState, List <ItemState> changes)
        {
            if (newState != null)
            {
                // we don't do anything with game state we receive since we
                // are the local game manager which is the source of truth for
                // the game state.
                Debug.Log("Got new game state: " + newState);
            }

            if (changes != null && changes.Count > 0)
            {
                Debug.Log("Got New changes from Remote! with " + changes.Count);

                // Only change the players and scores
                foreach (ItemState item in changes)
                {
                    Debug.Log("Processing  ----> " + item.Name);
                    GameObject obj = owner.LevelManager.Find(item.Name);
                    if (obj != null)
                    {
                        PlayerController ctl = obj.GetComponent <PlayerController>();

                        // only move players - enemies are managed locally.
                        if (ctl != null && !ctl.Player.IsLocal)
                        {
                            ctl.MoveTo(item.Position);
                        }
                    }
                    else if (item.Name.StartsWith(GameManager.ScoreChangedItemName))
                    {
                        PlayerInfo p = PlayerInfo.GetPlayer(item.TileSetName);
                        if (p != null)
                        {
                            p.Score = (p.Score > item.PrefabIndex) ? p.Score : item.PrefabIndex;
                        }
                    }
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Raises the new game state event.
        /// </summary>
        /// <param name="newState">New state of the game.</param>
        /// <param name="changes">Changes received from the room</param>
        public void OnNewGameState(
            GameManager.GameStateData newState,
            List <ItemState> changes)
        {
            if (newState != null)
            {
                InitGame(newState);

                // record the game state if we are starting out or on a new
                // level.
                if (newState.CurrentPhase == GameManager.GameStateData.Phase.Connecting ||
                    newState.CurrentPhase == GameManager.GameStateData.Phase.Initializing)
                {
                    owner.GameState = newState;
                }
            }

            if (changes != null)
            {
                ProcessChanges(changes);
            }
        }