using System.Collections; using System.Collections.Generic; using System.Linq; using UnityEngine; using UnityEngine.UI; public class HeroHandControls { public delegate void CardClickedAction(HeroCard card); public event CardClickedAction OnCardClicked; private MonoBehaviour root; private GameObject uiCanvas; private GameObject cardPrefab; private List cardsInHandUIs; public HeroHandControls(MonoBehaviour root, GameObject uiCanvas, GameObject cardPrefab) { this.root = root; this.uiCanvas = uiCanvas; this.cardPrefab = cardPrefab; } public void SetHeroHand(List hand) { if (this.cardsInHandUIs != null) { foreach (GameObject cardInHandUI in this.cardsInHandUIs) { GameObject.Destroy(cardInHandUI); } } this.cardsInHandUIs = new List(); for (int i = 0; i < hand.Count; i++) { HeroCard card = hand[i]; GameObject cardUI = GameObject.Instantiate(this.cardPrefab, this.uiCanvas.transform); this.cardsInHandUIs.Add(cardUI); cardUI.transform.position = CalculateHandCardPosition(i, hand.Count); cardUI.GetComponent().Init(card); int cardIndex = i; cardUI.GetComponent