/// <summary> /// Update the Upgrades based on CardState /// </summary> public void UpdateUpgrades() { if (currentSave != null && selectedCardState != null) { List <CardUpgradeState> query = selectedCardState.GetCardStateModifiers().GetCardUpgrades().OrderBy(x => x.GetUpgradeTitle()).ToList(); if (query.Count > UpgradeStateSelectionButtonsPool.Count) { for (int i = UpgradeStateSelectionButtonsPool.Count; i < query.Count; i++) { DerivedUpgradeStateSelectionButton selectionButton = CreateUpgradeStateSelectionButton(UpgradeContent.transform); UpgradeStateSelectionButtonsPool.Add(selectionButton); } } else { //Hide excessive Selection Buttons for (int i = query.Count; i < UpgradeStateSelectionButtonsPool.Count; i++) { UpgradeStateSelectionButtonsPool[i].gameObject.SetActive(false); } } //Go through each SelectionButton, updating their text and internal card reference SelectionButton <CardUpgradeState> sbi; for (int j = 0; j < query.Count; j++) { sbi = UpgradeStateSelectionButtonsPool[j]; sbi.gameObject.SetActive(true); sbi.UpdateText(query[j]); } } }
/// <summary> /// Creates a Selection Button for CardData /// </summary> /// <param name="parent"></param> /// <returns></returns> public DerivedUpgradeStateSelectionButton CreateUpgradeStateSelectionButton(Transform parent) { GameObject sbp = GameObject.Instantiate(SelectionButtonPrefab); DontDestroyOnLoad(sbp); sbp.transform.SetParent(parent); DerivedUpgradeStateSelectionButton sb = sbp.AddComponent <DerivedUpgradeStateSelectionButton>(); sb.plugin = this; sb.OnClick += OnClickUpgradeState; sb.UpdateTextFunc += GetUpgradeStateName; return(sb); }