Hierarchy 개발 중
This commit is contained in:
@@ -141,7 +141,7 @@ namespace UVC.Data.Http
|
||||
}
|
||||
else
|
||||
{
|
||||
infoList[key] = info; // Update existing entry
|
||||
infoList[key] = info; // Update existing ItemPrefab
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
8
Assets/Scripts/UVC/UI/List/Tree.meta
Normal file
8
Assets/Scripts/UVC/UI/List/Tree.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d658ab5aa42417546b742d0696bf028e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
21
Assets/Scripts/UVC/UI/List/Tree/TreeList.cs
Normal file
21
Assets/Scripts/UVC/UI/List/Tree/TreeList.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
#nullable enable
|
||||
using UnityEngine;
|
||||
|
||||
namespace UVC.UI.List.Tree
|
||||
{
|
||||
public class TreeList : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
protected TreeListItem itemPrefab;
|
||||
public TreeListItem ItemPrefab => itemPrefab;
|
||||
|
||||
[SerializeField]
|
||||
protected RectTransform root;
|
||||
|
||||
public void AddItem(TreeListItemData data)
|
||||
{
|
||||
TreeListItem item = GameObject.Instantiate<TreeListItem>(ItemPrefab, root);
|
||||
item.Init(data, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/UVC/UI/List/Tree/TreeList.cs.meta
Normal file
2
Assets/Scripts/UVC/UI/List/Tree/TreeList.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7be08eb56899e2042811c8d1da0924a6
|
||||
121
Assets/Scripts/UVC/UI/List/Tree/TreeListItem.cs
Normal file
121
Assets/Scripts/UVC/UI/List/Tree/TreeListItem.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/UVC/UI/List/Tree/TreeListItem.cs.meta
Normal file
2
Assets/Scripts/UVC/UI/List/Tree/TreeListItem.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 44c14fec77c285b4cb620db0f31c7ad1
|
||||
43
Assets/Scripts/UVC/UI/List/Tree/TreeListItemData.cs
Normal file
43
Assets/Scripts/UVC/UI/List/Tree/TreeListItemData.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
#nullable enable
|
||||
using Gpm.Ui;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace UVC.UI.List.Tree
|
||||
{
|
||||
public class TreeListItemData : InfiniteScrollData
|
||||
{
|
||||
/// <summary>
|
||||
/// 일반 아이템 이름
|
||||
/// </summary>
|
||||
public string generalName = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 일반 아이템 옵션
|
||||
/// </summary>
|
||||
public string generalOption = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 자식 확장 여부
|
||||
/// </summary>
|
||||
internal bool isExpanded = false;
|
||||
|
||||
/// <summary>
|
||||
/// 카테고리 확장/축소 버튼 클릭 시 호출될 액션입니다.
|
||||
/// </summary>
|
||||
public Action<TreeListItemData>? OnClickAction;
|
||||
|
||||
internal List<TreeListItemData> children = new List<TreeListItemData>();
|
||||
|
||||
public TreeListItemData() { }
|
||||
|
||||
public TreeListItemData(string generalName, List<TreeListItemData>? childrenItemData = null)
|
||||
{
|
||||
this.generalName = generalName;
|
||||
if (childrenItemData != null)
|
||||
{
|
||||
this.children = childrenItemData;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/UVC/UI/List/Tree/TreeListItemData.cs.meta
Normal file
2
Assets/Scripts/UVC/UI/List/Tree/TreeListItemData.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8ce1fb5708c2530478603d21c8d9a370
|
||||
21
Assets/Scripts/UVC/UI/Window/HierarchyWindow.cs
Normal file
21
Assets/Scripts/UVC/UI/Window/HierarchyWindow.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UVC.UI.List.Tree;
|
||||
|
||||
namespace UVC.UI.Window
|
||||
{
|
||||
public class HierarchyWindow: MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
protected TreeList treeList;
|
||||
|
||||
public void AddItem(TreeListItemData data)
|
||||
{
|
||||
treeList.AddItem(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/UVC/UI/Window/HierarchyWindow.cs.meta
Normal file
2
Assets/Scripts/UVC/UI/Window/HierarchyWindow.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 73be4d2e3822cba4a85e1cfb52f6b737
|
||||
Reference in New Issue
Block a user