Exemple #1
0
    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);
    }
Exemple #2
0
    UIHeart GetHeart(int heartIndex)
    {
        while (heartIndex > hearts.Count - 1)
        {
            AddHeart();
        }
        UIHeart heart = hearts[heartIndex];

        heart.gameObject.SetActive(true);
        return(heart);
    }
Exemple #3
0
    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);
    }
Exemple #4
0
 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);
     }
 }