Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        public int CompareTo(object obj)
        {
            if (obj == null)
            {
                return(1);
            }

            ScoreUiElementManager otherManager = obj as ScoreUiElementManager;

            if (otherManager != null)
            {
                return(this.score.CompareTo(otherManager.score));
            }
            else
            {
                throw new ArgumentException("Object is not a ScoreUiElementManager");
            }
        }
Exemplo n.º 3
0
        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
        }