public void AddNewPlayer(PlayerIdentifier player, int score)
        {
            MyContract.RequireArgumentNotNull(player, "player");
            MyContract.RequireField(
                !ScoreElement.ContainsKey(player.PlayerID),
                "does not already contain an entry for player "
                + player.ToString(),
                "ScoreElement"
                );

            Debug.Log(
                "ScoreboardUIManager: Adding new element ["
                + player.ToString()
                + " -> "
                + score + "]"
                );

            GameObject NewScoreUiElement;
            string     DisplayName = "[Uninitialised]";

            if (player.PlayerID == LocalPlayerId)
            {
                NewScoreUiElement
                            = Instantiate(LocalPlayerScoreUiElementPrefab);
                DisplayName = player.ToString() + " (Me)";
            }
            else
            {
                NewScoreUiElement
                            = Instantiate(ScoreUiElementPrefab);
                DisplayName = player.ToString();
            }

            NewScoreUiElement.transform.SetParent(UiElementListParent, false);

            ScoreUiElementManager ElementManager
                = NewScoreUiElement.GetComponent <ScoreUiElementManager>();

            // This is programmer/compile-time error if it occurs
            // as in, this shouldn't be needed in production code
            MyContract.RequireFieldNotNull(ElementManager, "ScoreUiElementManager");
            ElementManager.Initialise(DisplayName, score);
            NewScoreUiElement.SetActive(true);

            ScoreUiElements.Add(ElementManager);
            SortScoreElements();
            ScoreElement.Add(player.PlayerID, ElementManager);
        }
示例#2
0
        CreateNew
            (NetworkedPlayerController controller)
        {
            MyContract.RequireArgumentNotNull(
                controller,
                "NetworkedPlayerController"
                );

            PlayerIdentifier ExtantId
                = controller
                  .gameObject
                  .GetComponent <PlayerIdentifier>();
            PlayerIdentifier NewId = ExtantId;

            if (ExtantId == null)
            {
                NewId = controller
                        .gameObject
                        .AddComponent <PlayerIdentifier>();
                NewId.SetBackingController(controller);
                Debug.Log(
                    "No existing PlayerIdentifier for "
                    + NewId.ToString()
                    + "\nCreating new PlayerIdentifier with net id "
                    + NewId.netId
                    );
            }
            return(NewId);
        }
示例#3
0
 public void RemovePlayer(PlayerIdentifier playerId)
 {
     MyContract.RequireArgumentNotNull(playerId, "newPlayerId");
     MyContract.RequireField(
         PlayerScore.ContainsKey(playerId.PlayerID),
         "PlayerScore contains the player ID "
         + playerId.ToString(),
         "playerId " + playerId.ToString()
         );
     PlayerScore.Remove(playerId.PlayerID);
     Debug.Log("Scoreboard: Removed player id "
               + playerId.ToString()
               + " from the scoreboard.");
     Debug.Log(PrintPlayerScore());
     if (oem.shouldTriggerEvent(PlayerRemoved))
     {
         PlayerRemoved(playerId);
     }
 }
示例#4
0
 public void RegisterNewPlayer(PlayerIdentifier newPlayerId)
 {
     MyContract.RequireArgumentNotNull(newPlayerId, "newPlayerId");
     MyContract.RequireField(
         !PlayerScore.ContainsKey(newPlayerId.PlayerID),
         "PlayerScore does not contain the new player ID "
         + newPlayerId.ToString(),
         "newPlayerId " + newPlayerId.ToString()
         );
     PlayerScore.Add(newPlayerId.PlayerID, InitialScore);
     Debug.Log("Scoreboard: Added player id "
               + newPlayerId.ToString()
               + " to the scoreboard.");
     Debug.Log(PrintPlayerScore());
     if (oem.shouldTriggerEvent(ScoreUpdate))
     {
         ScoreUpdate(newPlayerId, InitialScore);
     }
 }
示例#5
0
 OnKillEvent
     (PlayerIdentifier hunter,
     PlayerIdentifier hunted)
 {
     Debug.Log(PrintPlayerScore());
     MyContract.RequireField(PlayerScore.ContainsKey(hunter.PlayerID),
                             "contains an entry for netid " + hunter.ToString(),
                             "PlayerScore");
     PlayerScore[hunter.PlayerID] += 1;
     ScoreUpdate(hunter, PlayerScore[hunter.PlayerID]);
 }
 public void ChangePlayerScore(PlayerIdentifier player, int score)
 {
     MyContract.RequireArgumentNotNull(player, "player");
     if (ScoreElement.ContainsKey(player.PlayerID))
     {
         ScoreElement[player.PlayerID].UpdateScore(score);
         SortScoreElements();
     }
     else
     {
         Debug.Log(
             "ScoreboardUIManager: Received a ChangePlayerScore "
             + "request for an unregistered player ("
             + player.ToString()
             + ")"
             );
         AddNewPlayer(player, score);
     }
 }
        public void RemovePlayer(PlayerIdentifier player)
        {
            MyContract.RequireArgumentNotNull(player, "player");
            MyContract.RequireField(
                ScoreElement.ContainsKey(player.PlayerID),
                "Contains an entry for player "
                + player.ToString(),
                "ScoreElement"
                );

            ScoreUiElementManager ElementManager = ScoreElement[player.PlayerID];

            ScoreElement.Remove(player.PlayerID);
            ScoreUiElements.Remove(ElementManager);
            // If needed this can be optimised by pooling the
            // score ui elements,
            // so when a player is removed they are deactivated,
            // then when a new player is added they try to reactivate
            // an old slot before instantiating a new one.
            Destroy(ElementManager.gameObject);
            //SortScoreElements(); should remain sorted
        }
示例#8
0
 public void SetKiller(PlayerIdentifier killer)
 {
     KillerIdentifierDisplay.text = killer.ToString();
 }