using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using DG.Tweening; public class UILevelGroup : MonoBehaviour { public GameObject[] levels; private Vector3[] levelPositions; private bool isExpanded = false; private int isPlayingCount = 0; // Start is called before the first frame update void Start() { var levelComponents = GetComponentsInChildren(); levels = new GameObject[levelComponents.Length]; levelPositions = new Vector3[levelComponents.Length]; for (int i = 0; i < levelComponents.Length; i++) { levels[i] = levelComponents[i].gameObject; levelPositions[i] = levels[i].transform.position; levels[i].transform.position = transform.position; var background = levels[i].GetComponent().background; background.color = new Color(background.color.r, background.color.g, background.color.b, 0.0f); var number = levels[i].GetComponent().number; number.color = new Color(number.color.r, number.color.g, number.color.b, 0.0f); levels[i].SetActive(false); } } public void ClickLevelGroupButton() { Debug.Log("Clicked!"); Debug.Log(gameObject.name); if (isPlayingCount != 0) return; isPlayingCount = levels.Length; if (isExpanded) { ClickCloseLevels(); } else { ClickExpandLevels(); } } void ClickExpandLevels() { isExpanded = true; for (int i = 0; i < levels.Length; ++i) { levels[i].SetActive(true); var background = levels[i].GetComponent().background; background.DOColor(new Color(background.color.r, background.color.g, background.color.b, 1.0f), 0.5f); var number = levels[i].GetComponent().number; number.DOColor(new Color(number.color.r, number.color.g, number.color.b, 1.0f), 0.5f); levels[i].transform.DOMove(levelPositions[i], 1.0f).onComplete = delegate { isPlayingCount--; }; } } void ClickCloseLevels() { isExpanded = false; foreach (var level in levels) { var background = level.GetComponent().background; background.DOColor(new Color(background.color.r, background.color.g, background.color.b, 0.0f), 0.5f); var number = level.GetComponent().number; number.DOColor(new Color(number.color.r, number.color.g, number.color.b, 0.0f), 0.5f); level.transform.DOMove(transform.position, 1.0f).onComplete = delegate { level.SetActive(false); isPlayingCount--; }; } } }