Exemple #1
0
        /*!
         * @brief Updates GUI components with the initial player data.
         *
         * @details The data here is the actual data that is stored in the
         *          PlayerInitialData class.
         * @param panel The panel on which the data is to be displayed.
         * @param data The data to be displayed.
         */
        public static void SetInitialPlayerData(GameObject panel, PlayerInitialData player)
        {
            // Display data on PlayerEnabeldPanel only.
            if (panel.name.Contains("Enabled"))
            {
                // Nickname.
                InputField nickname = FindChild <InputField>(panel);
                nickname.text = player.Nickname;
                nickname.placeholder.GetComponent <Text>().text = player.Nickname;

                // Color.
                Image color = Find <Image>(FindChild <InputField>(panel).gameObject);
                color.color = player.Color;

                // Left turn key.
                Text leftKey = FindChild <Text>(FindChild <Button>(panel, "Left")
                                                .gameObject);
                leftKey.text = KeyMap[player.LeftKey.ToString()];

                // Right turn key.
                Text rightKey = FindChild <Text>(FindChild <Button>(panel, "Right")
                                                 .gameObject);
                rightKey.text = KeyMap[player.RightKey.ToString()];
            }
        }
Exemple #2
0
        // Reads initial players configuration from 'defaults.cfg' file.
        private static List <PlayerInitialData> InitialPlayerConfiguration()
        {
            string path = "Assets/Resources/Configs/defaults.cfg";

            string[] data;
            using (StreamReader streamReader = new StreamReader(path))
            {
                data = streamReader.ReadToEnd().Split('\n');
            }

            List <PlayerInitialData> initialData = new List <PlayerInitialData>();

            foreach (string row in data)
            {
                string[]          items  = row.Split(',');
                PlayerInitialData player = new PlayerInitialData();
                player.Nickname = items[0];
                player.Color    = new Color(float.Parse(items[1]),
                                            float.Parse(items[2]),
                                            float.Parse(items[3]),
                                            1.0f);
                player.LeftKey  = (KeyCode)Enum.Parse(typeof(KeyCode), items[4]);
                player.RightKey = (KeyCode)Enum.Parse(typeof(KeyCode), items[5]);

                initialData.Add(player);
            }

            return(initialData);
        }
Exemple #3
0
        // Loads PlayerEnabledPanel in place of PlayerDisabledPanel.
        private void EnablePlayer(int id)
        {
            // Increase number of players.
            configurator.AddPlayer(id - 1);

            // Fill player data with the initial values.
            PlayerInitialData player = GUIHelper.PlayerInitialData[id - 1];

            configurator.PlayersData[id - 1].Nickname = player.Nickname;
            configurator.PlayersData[id - 1].Color    = player.Color;
            configurator.PlayersData[id - 1].LeftKey  = KeyCode.None;
            if (GUIHelper.IsKeySupported(player.LeftKey) &&
                !GUIHelper.IsKeyInUsed(player.LeftKey, configurator.PlayersData))
            {
                configurator.PlayersData[id - 1].LeftKey = player.LeftKey;
            }
            configurator.PlayersData[id - 1].RightKey = KeyCode.None;
            if (GUIHelper.IsKeySupported(player.RightKey) &&
                !GUIHelper.IsKeyInUsed(player.RightKey, configurator.PlayersData))
            {
                configurator.PlayersData[id - 1].RightKey = player.RightKey;
            }

            // Display panel on the GUI.
            LoadPanel(enabledPanel, disabledPanel, id);

            UpdateStartButtonStatus();
        }
        /*!
         * @brief Adds a new player to the players list.
         *
         * @details Creates a new Player object and fills it with initial data.
         * @param id Id of the player. The player will be created at the 'id'
         *        position on the list.
         */
        public void AddPlayer(int id)
        {
            ++CurrentNoOfPlayers;

            playersData[id] = new PlayerInitialData();
        }