public void DeckChangedNotification(List <CardState> deck, int visibleDeckCount) { //Alphabetize deck, remove champion cards as they crash the game List <CardState> query = deck.OrderBy(card => card.GetTitle()).Where(x => !x.IsChampionCard()).ToList(); //If deck is bigger, increase pool size if (query.Count > SelectionButtonsPool.Count) { for (int i = SelectionButtonsPool.Count; i < query.Count; i++) { DerivedCardStateSelectionButton selectionButton = CreateCardStateSelectionButton(DeckContent.transform); SelectionButtonsPool.Add(selectionButton); } } else { //Hide excessive Selection Buttons for (int i = query.Count; i < SelectionButtonsPool.Count; i++) { SelectionButtonsPool[i].gameObject.SetActive(false); } } //Go through each SelectionButton, updating their text and internal card reference SelectionButton <CardState> sbi; for (int j = 0; j < query.Count; j++) { sbi = SelectionButtonsPool[j]; sbi.gameObject.SetActive(true); sbi.UpdateText(query[j]); } }
/// <summary> /// Creates a Selection Button for CardState /// </summary> /// <param name="parent"></param> /// <returns></returns> public DerivedCardStateSelectionButton CreateCardStateSelectionButton(Transform parent) { GameObject sbp = GameObject.Instantiate(SelectionButtonPrefab); DontDestroyOnLoad(sbp); sbp.transform.SetParent(parent); DerivedCardStateSelectionButton sb = sbp.AddComponent <DerivedCardStateSelectionButton>(); sb.plugin = this; sb.OnClick += OnClickCardState; sb.UpdateTextFunc += GetCardStateName; return(sb); }