Ejemplo n.º 1
0
 public void UpdateHpUI(bool withAnimation = false)
 {
     for (int i = 0; i < hearts.Count; i++)
     {
         int         currentHp   = pm.champion.currentHp;
         HeartStatus heartStatus = HeartStatus.empty;
         if (i < currentHp / 2)
         {
             heartStatus = HeartStatus.full;
         }
         else if ((i == currentHp / 2) && (currentHp % 2 == 1))
         {
             heartStatus = HeartStatus.half;
         }
         else
         {
             heartStatus = HeartStatus.empty;
         }
         hearts[i].SetHeartSlot(heartStatus);
     }
     if (withAnimation)
     {
         animator_heart.SetTrigger("update");
     }
     // slider_hp.value = pm.player.hp;
     // float percent = (float)slider_hp.value / (float)slider_hp.maxValue;
     // if (percent < 0.5f)
     // { fill_hp.color = Color.Lerp(color_hp_red, color_hp_yellow, percent * 2); }
     // else
     // { fill_hp.color = Color.Lerp(color_hp_yellow, color_hp_green, (percent - 0.5f) * 2); }
 }
Ejemplo n.º 2
0
        public void InitHpUI(int maxHp, int startingHp, bool withAnimation = false)
        {
            hearts.Clear();
            DestroyChildGameObject(container_heart);
            if (maxHp > 14)
            {
                maxHp = 14;
            }
            int heartCount = maxHp % 2 == 1 ? (maxHp + 1) / 2 : maxHp / 2;

            grid.constraintCount = Mathf.Clamp(heartCount, 1, 7);
            // Debug.Log("maxHp: " + maxHp.ToString());
            // Debug.Log("heartCount: " + heartCount.ToString());
            for (int i = 0; i < heartCount; i++)
            {
                Transform heartTransform = Instantiate(heartSlotPrefab) as Transform;
                heartTransform.SetParent(container_heart);
                heartTransform.localScale = Vector3.one;
                heartTransform.position   = Vector2.zero;
                HeartSlot heartSlot = heartTransform.GetComponent <HeartSlot>();
                hearts.Add(heartSlot);
                int         bgColorIndex    = (maxHp - 1) / 8;
                int         heartColorIndex = bgColorIndex + 1;
                HeartStatus heartStatus     = HeartStatus.empty;

                // int remainHp = currentHp % 8;
                // Debug.Log("i: " + i.ToString());
                // Debug.Log("remainHp: " + remainHp.ToString());

                if (i < startingHp / 2)
                {
                    heartStatus = HeartStatus.full;
                }
                else if ((i == startingHp / 2) && (startingHp % 2 == 1))
                {
                    heartStatus = HeartStatus.half;
                }
                else
                {
                    heartStatus = HeartStatus.empty;
                }

                heartSlot.SetHeartSlot(heartStatus);
            }
            LayoutRebuilder.ForceRebuildLayoutImmediate(container_heart.GetComponent <RectTransform>());
            LayoutRebuilder.ForceRebuildLayoutImmediate(layoutgroup_heart.GetComponent <RectTransform>());
            // Canvas.ForceUpdateCanvases();
            // layoutgroup_heart.SetLayoutHorizontal();
            if (withAnimation)
            {
                animator_heart.SetTrigger("update");
            }
        }
Ejemplo n.º 3
0
    public void SetMerry(MerryStatus emotion = MerryStatus.REGULAR, HeartStatus heartStatus = HeartStatus.ONE)
    {
        EraseAll();
        switch (emotion)
        {
        case MerryStatus.REGULAR:
            //
            break;

        case MerryStatus.HAPPY:
            mouthHappy.SetActive(true);
            break;

        case MerryStatus.SAD:
            mouthSad.SetActive(true);
            eyesSad.SetActive(true);
            break;

        case MerryStatus.AWRY:
            mouthHappy.SetActive(true);
            eyesWorried.SetActive(true);
            break;

        case MerryStatus.WORRIED:
            mouthSad.SetActive(true);
            eyesWorried.SetActive(true);
            break;

        case MerryStatus.JOYFUL:
            mouthHappy.SetActive(true);
            eyesClosedHappy.SetActive(true);
            break;
        }

        switch (heartStatus)
        {
        case HeartStatus.ONE:
            heart1.SetActive(true);
            break;

        case HeartStatus.TWO:
            heart2.SetActive(true);
            break;

        case HeartStatus.THREE:
            heart3.SetActive(true);
            break;

        case HeartStatus.FOUR:
            heart4.SetActive(true);
            break;
        }
    }
Ejemplo n.º 4
0
    // Update is called once per frame
    void Update()
    {
        string config = System.IO.File.ReadAllText(Application.dataPath + "/config.json");

        this.config = JsonUtility.FromJson <Config>(config);

        if (time + 1.0f <= Time.time)
        {
            //poll heart rate from node server using ip in config file
            StartCoroutine(WaitForRequest(new WWW(this.config.api)));
            time = Time.time;
        }

        this.currentHeartStatus = calculateHeartStatus();
    }
Ejemplo n.º 5
0
 public void SetHeartSlot(HeartStatus heartStatus)
 {
     image_fill.enabled = true;
     if (heartStatus == HeartStatus.empty)
     {
         image_fill.enabled = false;
     }
     else if (heartStatus == HeartStatus.half)
     {
         image_fill.sprite = sprite_heart_half;
     }
     else if (heartStatus == HeartStatus.full)
     {
         image_fill.sprite = sprite_heart_full;
     }
     else
     {
         Debug.Log("????");
     }
 }
Ejemplo n.º 6
0
        void OnChampionIndexChange(int championIndex)
        {
            // Debug.Log("ChampionPanel.OnChampionIndexChange(" + championIndex.ToString() + ")");
            text_championname.text = champions[championIndex].championId;

            int maxHp   = champions[championIndex].maxHp;
            int startHp = champions[championIndex].startHp;

            if (maxHp > 14)
            {
                maxHp = 14;
            }
            int heartCount = maxHp % 2 == 1 ? (maxHp + 1) / 2 : maxHp / 2;

            DestroyChildGameObject(container_heart);
            for (int i = 0; i < heartCount; i++)
            {
                Transform heartTransform = Instantiate(heartSlotPrefab) as Transform;
                heartTransform.SetParent(container_heart);
                heartTransform.localScale = Vector3.one;
                heartTransform.position   = Vector2.zero;
                HeartSlot heartSlot = heartTransform.GetComponent <HeartSlot>();
                hearts.Add(heartSlot);
                int         bgColorIndex    = (maxHp - 1) / 8;
                int         heartColorIndex = bgColorIndex + 1;
                HeartStatus heartStatus     = HeartStatus.empty;

                if (i < startHp / 2)
                {
                    heartStatus = HeartStatus.full;
                }
                else if ((i == startHp / 2) && (startHp % 2 == 1))
                {
                    heartStatus = HeartStatus.half;
                }
                else
                {
                    heartStatus = HeartStatus.empty;
                }

                heartSlot.SetHeartSlot(heartStatus);
            }


            // for (int i = 0; i < champions.Length; i++)
            // {
            //     if (i == championIndex) continue;
            //     champions[i].transform.SetParent(container_champion);
            //     //위치 원래있던곳으로 애니메이션
            //     champions[i].transform.localPosition = new Vector3(champions[i].championIndex, 0, 0);//애니메이션
            //     champions[i].ScaleDownChampionPreview();
            // }
            if (focusedChampionPreview != null)
            {
                focusedChampionPreview.transform.SetParent(container_champion);
                //위치 원래있던곳으로 애니메이션
                focusedChampionPreview.transform.localPosition = new Vector3(focusedChampionPreview.championIndex, 0, 0);//애니메이션
                focusedChampionPreview.ScaleDownChampionPreview();
            }
            focusedChampionPreview = champions[championIndex];
            focusedChampionPreview.transform.SetParent(container_focus);
            focusedChampionPreview.transform.localPosition = Vector3.zero;//애니메이션
            focusedChampionPreview.SclaeUpChampionPreview();
        }