void Awake() { // init "is any faction enabled" flag bool isAnyFactionEnabled = false; // Create Faction Selection for each faction foreach (Faction faction in Enum.GetValues(typeof(Faction))) { // skip Unknown faction if (faction != Faction.Unknown) { // Create faction selection from template FactionSelection factionSelection = Instantiate(factionSelectionTemplate, transform).GetComponent <FactionSelection>(); // assign it with faction type factionSelection.Faction = faction; // set text to faction name factionSelection.GetComponent <Text>().text = faction.ToString(); // verify we has not enabled already some faction if (!isAnyFactionEnabled) { // enable first faction factionSelection.gameObject.SetActive(true); // reset flag isAnyFactionEnabled = true; } } } }
public void SelectPrevious() { // select previous faction in a list // Get currently selected faction FactionSelection selectedFaction = gameObject.GetComponentInChildren(typeof(FactionSelection), false) as FactionSelection; // get all factions FactionSelection[] factions = GetComponentsInChildren <FactionSelection>(true); // get currently selected element index int selectedFactionIndex = GetSelectedFactionIndex(selectedFaction, factions); Debug.Log("Current Faction index: " + selectedFactionIndex); // select next faction in a list int previousFactionIndex; // verify if we have reached the first (0) element if (selectedFactionIndex == 0) { // select first element previousFactionIndex = factions.Length - 1; } else { // increment index previousFactionIndex = selectedFactionIndex - 1; } Debug.Log("Previous Faction index: " + previousFactionIndex); // deactivate previous selection selectedFaction.gameObject.SetActive(false); // activate next selection factions[previousFactionIndex].gameObject.SetActive(true); // Update Heroes selection GetComponentInParent <ChooseYourFirstHero>().SelectFaction(factions[previousFactionIndex].Faction); }
protected override void SpawnPlayersAndWorlds() { if (GameData.getWorldById(GameData.WorldID) == null) { return; } TextAsset playerSpawnPointsById = GameData.getPlayerSpawnPointsById(GameData.WorldID - 1, GameData.BattleType - 1, GameData.GameType - 1); TextAsset pickupSpawnPointsById = GameData.getPickupSpawnPointsById(GameData.WorldID - 1, GameData.BattleType - 1, GameData.GameType - 1); if (playerSpawnPointsById == null || pickupSpawnPointsById == null) { GameData.LoadSpawnPoints(); return; } GameData.parseAllSpawnPoints(); FactionSelection.DownloadTextureBundles(); int[] atlasDefaultSuits = GameData.AtlasDefaultSuits; foreach (int suitId in atlasDefaultSuits) { AssetLoader.AddSuitToLoad(suitId, AssetLoader.SuitAsset.SuitType.high, 50); } int[] banzaiDefaultSuits = GameData.BanzaiDefaultSuits; foreach (int suitId2 in banzaiDefaultSuits) { AssetLoader.AddSuitToLoad(suitId2, AssetLoader.SuitAsset.SuitType.high, 50); } base.SpawnPlayersAndWorlds(); }
int GetSelectedFactionIndex(FactionSelection selectedFaction, FactionSelection[] factions) { for (int i = 0; i < factions.Length; i++) { if (selectedFaction.Faction == factions[i].Faction) { return(i); } } Debug.LogError("Error: selected faction is not in the list of all possible factions"); return(0); }