Exemple #1
0
        public static void DeletePlayer(Player player)
        {
            //Store all players
            List <Player> playerList = GameInformation.GetAllPlayers();

            //Remove player to delete of the storage list
            foreach (Player tempPlayer in playerList.ToArray())
            {
                if (tempPlayer.ID == player.ID)
                {
                    playerList.Remove(tempPlayer);
                }
            }

            DeleteAllPlayers();

            //Put all player but the deleted one in the PlayerPrefs
            int playerIndex = 0;

            foreach (Player tempPlayer in playerList)
            {
                tempPlayer.ID = playerIndex;
                Save(Constants.commonPlayerKey + playerIndex, tempPlayer);
                playerIndex++;
            }
        }
Exemple #2
0
        public static void SaveNewPlayer(Player player)
        {
            int newPlayerIndex = GameInformation.GetAllPlayers().Count;

            player.ID = newPlayerIndex;
            Save(Constants.commonPlayerKey + newPlayerIndex, player);
        }
        //Populate avatar UI List with players present in PlayerPrefs
        private void PopulateAvatarUIList()
        {
            DebugLog.DebugMessage("isSelectingPlayer2 : " + isSelectingPlayer2, true);
            //Get all players
            List <Player> playerList = GameInformation.GetAllPlayers();

            //Add player as child
            foreach (Player player in playerList)
            {
                //Hide player if isSelecting player2 and if this player is the current player
                if (isSelectingPlayer2 && player.ID == GameInformation.GetCurrentPlayer().ID)
                {
                    //Do nothing..
                }
                else
                {
                    //Add avatar item in the UI list
                    GameObject avatarItem = Instantiate(avatarPrefab);
                    avatarItem.transform.SetParent(avatarUIList.transform, false);
                    //Set some paramter in the avatar item script
                    avatarItem.GetComponent <AvatarItem>().avatarNameText.text = player.Name;
                    avatarItem.GetComponent <AvatarItem>().avatarImage.sprite  = PPSerialization.Base64ToSprite(player.Base64Image);
                    avatarItem.GetComponent <AvatarItem>().associatedPlayer    = player;
                    avatarItem.GetComponent <AvatarItem>().mainMenu            = mainMenu;
                    avatarItem.GetComponent <AvatarItem>().selectAvatarMenu    = this;
                    if (isSelectingPlayer2)
                    {
                        avatarItem.GetComponent <AvatarItem>().isSelectingPlayer2 = true;
                    }
                    if (isDeleting)
                    {
                        avatarItem.GetComponent <AvatarItem>().isDeleting = true;
                    }
                }
            }
            //Put the + button at the end of the grid
            avatarUIList.transform.Find("CreateNewAvatarPanel").SetAsLastSibling();
        }