Hierarchy 개발 중

This commit is contained in:
logonkhi
2025-10-28 15:36:55 +09:00
parent fdfc6cf727
commit a356c5497a
25 changed files with 4855 additions and 145 deletions

View File

@@ -0,0 +1,121 @@
#nullable enable
using DG.Tweening;
using UnityEngine;
using UnityEngine.UI;
namespace UVC.UI.List.Tree
{
public class TreeListItem : MonoBehaviour
{
[SerializeField]
protected TreeList control;
[SerializeField]
protected TMPro.TextMeshProUGUI valueText;
[SerializeField]
protected Button childExpand;
[SerializeField]
protected GameObject childContainer;
[SerializeField]
protected RectTransform childRoot;
protected TreeListItemData? data;
protected bool isAnimating = false;
public void Init(TreeListItemData data, TreeList control)
{
this.control = control;
this.data = data;
valueText.text = data.generalName;
Debug.Log("Creating children for " + data.generalName+", "+ data.children.Count);
if (data.children.Count == 0)
{
childExpand.gameObject.SetActive(false);
childContainer.SetActive(false);
}
else
{
foreach (var childData in data.children)
{
CreateItem(childData);
}
childExpand.gameObject.SetActive(true);
childContainer.SetActive(true);
SetExpand();
}
}
public void ToggleChild()
{
// 애니메이션이 진행 중이면 중복 호출을 방지합니다.
if (isAnimating)
{
return;
}
isAnimating = true;
data.isExpanded = !data.isExpanded;
childContainer.SetActive(data.isExpanded);
SetExpand(0.3f);
}
private void SetExpand(float duration = 0.0f)
{
childExpand.gameObject.SetActive(childRoot.childCount > 0);
if (childRoot.childCount > 0)
{
if (data != null) data.isExpanded = childContainer.activeSelf == true;
// 애니메이션을 위해 현재 각도에서 목표 각도로 회전시킵니다.
childExpand.transform.DORotate(new Vector3(0, 0, data.isExpanded ? 0 : 90), duration)
.OnComplete(() =>
{
// 애니메이션이 완료되면 플래그를 초기화합니다.
isAnimating = false;
});
}
else
{
if(data != null) data.isExpanded = false;
}
}
public void AddChild()
{
TreeListItemData itemData = new TreeListItemData
{
generalName = data?.generalName + "." + (data?.children.Count + 1),
};
AddChild(itemData);
}
public void AddChild(TreeListItemData data)
{
CreateItem(data);
childContainer.SetActive(true);
SetExpand(0.3f);
}
protected TreeListItem CreateItem(TreeListItemData data)
{
TreeListItem item = GameObject.Instantiate<TreeListItem>(control.ItemPrefab, childRoot);
item.Init(data, control);
return item;
}
public void Delete()
{
GameObject.Destroy(gameObject);
}
}
}