Exemplo n.º 1
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");
            }
        }
Exemplo n.º 2
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();
        }