private IEnumerator InitRoutine(List <Pawn> acquiredPawns) { int j = 0; // track the pawnIcons list position for (int i = 0; i < acquiredPawns.Count; i++) // iterate through the master list of pawns (may contain holes) { Pawn pawn = acquiredPawns[i]; if (pawn != null) { if (j >= pawnIcons.Count) // if we need more pawn icons, add new ones to the list { AddNewPawnIcon(pawn); } else { PawnIconStandard pawnIcon = pawnIcons[j].GetComponent <PawnIconStandard>(); pawnIcon.Init(pawn); pawnIcon.onClick = (iconData) => { infoPanel.gameObject.SetActive(true); infoPanel.Init(iconData.pawnData); }; } j++; } } yield return(null); // Wait one frame to avoid any strange glitches StartCoroutine(AnimateIn(acquiredPawns.Count)); }
private void AddNewPawnIcon(Pawn pawn) { GameObject o = Instantiate(pawnIconPrefab); o.transform.SetParent(content, false); o.SetActive(false); PawnIconStandard pawnIcon = o.GetComponent <PawnIconStandard>(); pawnIcon.Init(pawn); pawnIcon.onClick = (iconData) => { infoPanel.gameObject.SetActive(true); infoPanel.Init(iconData.pawnData); }; pawnIcons.Add(o); }
public void Init(Pawn pawn) { pawnIcon.Init(pawn); // Get Hero data HeroData heroData = DataManager.GetHeroData(pawn.type); // Initialize the hero's power up info HeroPowerUpListData powerUpListData = DataManager.GetPowerUpListData(pawn.type); int numPowerUpsUnlocked = HeroPowerUpListData.GetNumPowerUpsUnlocked(pawn.level); for (int i = 0; i < HeroPowerUpListData.powerUpUnlockLevels.Length; i++) { // If the hero has unlocked this powerUp bool locked = i >= numPowerUpsUnlocked; int unlockedLevel = HeroPowerUpListData.powerUpUnlockLevels[i]; HeroPowerUpData data = powerUpListData.powerUps[i].GetComponent <HeroPowerUp>().data; // Get the key for NewFeatureIndicator string newKey = GetViewedPowerKey(i); heroPowerUpInfoIcons[i].GetComponent <HeroPowerUpInfoIcon>().Init(data, locked, newKey, unlockedLevel); heroPowerUpInfoIcons[i].GetComponent <ScrollingTextOption>().scrollingText = infoText; } // Reset MidPanel Menu midPanelTabToggleGroup.SetAllTogglesOff(); // Due to some stupid bug we have to wait one frame before initializing the scroll view StartCoroutine(ForcePosAfter1Frame()); // Initialize the scrolling text to display info about the hero infoText.defaultText = heroData.heroDescription; infoText.SetToDefaultText(); // Initialize NewFeatureIndicator newTextPowers.RegisterKey(HasPlayerViewedPowersTabKey); newTextAbilities.RegisterKey(HasPlayerViewedAbilitiesTabKey); newAbility[0].RegisterKey(GetViewedAbilityKey('0')); newAbility[1].RegisterKey(GetViewedAbilityKey('1')); newSpecial.RegisterKey(GetViewedAbilityKey('S')); // Initialize Abilities Panel abilityIcon1.GetComponent <Image>().sprite = heroData.abilityIcons[0]; abilityIcon2.GetComponent <Image>().sprite = heroData.abilityIcons[1]; specialAbilityIcon.GetComponent <Image>().sprite = heroData.specialAbilityIcon; abilityIcon1.GetComponent <ScrollingTextOption>().text = heroData.ability1Description; abilityIcon2.GetComponent <ScrollingTextOption>().text = heroData.ability2Description; specialAbilityIcon.GetComponent <ScrollingTextOption>().text = heroData.specialDescription; abilityIcon1.GetComponent <Toggle>().isOn = false; abilityIcon2.GetComponent <Toggle>().isOn = false; specialAbilityIcon.GetComponent <Toggle>().isOn = false; }
public void Init() { print("Initializing HeroSelectMenu!"); selectedPawnIcon.onClick = (PawnIconStandard iconData) => { pawnInfoPanel.gameObject.SetActive(true); pawnInfoPanel.Init(iconData.pawnData); }; foreach (PawnIcon pawnIcon in pawnSelectionView.pawnIcons) { PawnIconStandard pawnIconStandard = (PawnIconStandard)pawnIcon; pawnIconStandard.onClick = (PawnIconStandard iconData) => { // If this is not the selected pawnIcon if (selectedPawnIcon.pawnData != iconData.pawnData) { // Select this pawnIcon and deselect previous pawn icon (if it exists) if (highlightedPawnIcon != null) { highlightedPawnIcon.highlight.SetActive(false); } highlightedPawnIcon = iconData; highlightedPawnIcon.highlight.SetActive(true); selectedPawnIcon.Init(iconData.pawnData); // Set gameobject to false then true so animation plays selectedPawnIcon.gameObject.SetActive(false); selectedPawnIcon.gameObject.SetActive(true); GameManager.instance.selectedPawn = pawnIcon.pawnData; } else { // Deselect this pawnIcon highlightedPawnIcon.highlight.SetActive(false); highlightedPawnIcon = null; selectedPawnIcon.pawnData = null; selectedPawnIcon.gameObject.SetActive(false); GameManager.instance.selectedPawn = null; } }; } }
// ========== // Pawn Fusion Logic // ========== public void FusePawns() { GameManager gm = GameManager.instance; PawnWallet pawnWallet = GameManager.instance.saveGame.pawnWallet; if (numSelected != 2) { gm.DisplayAlert("You must select 2 heroes!"); return; } Pawn pawn1 = selectedIcons[0].GetComponent <PawnIcon>().pawnData; Pawn pawn2 = selectedIcons[1].GetComponent <PawnIcon>().pawnData; Debug.Log("Pawn1:" + pawn1 + "\nPawn2:" + pawn2); if (CheckCanFusePawns(pawn1, pawn2)) { // Add the pawns to the save file Pawn pawn = GetFusedPawn(pawn1, pawn2); pawnWallet.RemovePawn(pawn1.id); pawnWallet.RemovePawn(pawn2.id); pawnWallet.AddPawn(pawn, true, 100); gm.AddPawnTimer(pawn.id); // Spend resources bool spentMoney = gm.wallet.TrySpendMoney(GetFusionCost(pawn1, pawn2)); bool spentSouls = gm.wallet.TrySpendSouls(GetFusionSoulsCost(pawn1, pawn2)); UnityEngine.Assertions.Assert.IsTrue(spentMoney && spentSouls); // Save Game SaveLoad.Save(); // Update UI fuseMatIcon1.gameObject.SetActive(false); fuseMatIcon1.pawnData = null; fuseMatIcon2.gameObject.SetActive(false); fuseMatIcon2.pawnData = null; resultIcon.gameObject.SetActive(true); resultIcon.Init(pawn); } UpdateCostText(); }