void AddHeart() { int heartIdx = hearts.Count; RectTransform rt = transform as RectTransform; UIHeart heart = Instantiate(heartPrefab); RectTransform heartRT = heart.transform as RectTransform; heartRT.SetParent(rt); PositionHeart(heartRT, heartIdx); hearts.Add(heart); }
UIHeart GetHeart(int heartIndex) { while (heartIndex > hearts.Count - 1) { AddHeart(); } UIHeart heart = hearts[heartIndex]; heart.gameObject.SetActive(true); return(heart); }
private void Awake() { if (!Player.IsAdsEnabled()) { this.gameObject.SetActive(false); return; } UIHeart uiHeart = this.GetComponentInChildren <UIHeart>(); int maxHearts = GameSettings.MAX_HEARTS; for (int i = 0; i < maxHearts - 1; i++) { Instantiate(uiHeart, this.transform, false); } this.uiHearts = this.GetComponentsInChildren <UIHeart>(); EventManager.AddListener <OnHeartsCountWasChanged>(this.OnHeartsCountWasChanged); EventManager.AddListener <OnRemoveAdsBought>(this.OnRemoveAdsBought); }
void UpdateHearts() { for (int idx = 0; idx < maxHealth; idx++) { UIHeart heart = GetHeart(idx); if (idx < lockedHearts) { heart.SetState(UIHeartState.Locked); } else if (idx < health) { heart.SetState(UIHeartState.Active); } else { heart.SetState(UIHeartState.Inactive); } } for (int idx = maxHealth, l = hearts.Count; idx < l; idx++) { hearts[idx].gameObject.SetActive(false); } }