클래스 생성
This commit is contained in:
68
Assets/Scripts/UVC/UI/Window/AccordionWindow.cs
Normal file
68
Assets/Scripts/UVC/UI/Window/AccordionWindow.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UVC.UI.List.Accordion;
|
||||
|
||||
namespace UVC.UI.Window
|
||||
{
|
||||
public class AccordionWindow : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private RectTransform root = default!;
|
||||
[SerializeField] private AccordionList? accordionListPrefab = null;
|
||||
private AccordionList? _instance;
|
||||
|
||||
private void Reset()
|
||||
{
|
||||
EnsureRoot();
|
||||
EnsureInstance();
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
EnsureRoot();
|
||||
EnsureInstance();
|
||||
}
|
||||
|
||||
private void EnsureRoot()
|
||||
{
|
||||
if (root == null)
|
||||
{
|
||||
var go = new GameObject("AccordionRoot", typeof(RectTransform));
|
||||
go.transform.SetParent(transform, false);
|
||||
root = (RectTransform)go.transform;
|
||||
var v = go.AddComponent<VerticalLayoutGroup>();
|
||||
v.childControlHeight = true;
|
||||
v.childForceExpandHeight = false;
|
||||
v.spacing = 0f;
|
||||
var fitter = go.AddComponent<ContentSizeFitter>();
|
||||
fitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize;
|
||||
}
|
||||
}
|
||||
|
||||
private void EnsureInstance()
|
||||
{
|
||||
if (_instance == null)
|
||||
{
|
||||
if (accordionListPrefab != null)
|
||||
{
|
||||
_instance = Instantiate(accordionListPrefab, root);
|
||||
_instance.gameObject.SetActive(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
var go = new GameObject("AccordionList", typeof(RectTransform), typeof(AccordionList));
|
||||
go.transform.SetParent(root, false);
|
||||
_instance = go.GetComponent<AccordionList>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SetData(AccordionData data)
|
||||
{
|
||||
EnsureRoot();
|
||||
EnsureInstance();
|
||||
_instance!.SetData(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/UVC/UI/Window/AccordionWindow.cs.meta
Normal file
2
Assets/Scripts/UVC/UI/Window/AccordionWindow.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6ad50e65d5080f04c99dd7606a8a4d70
|
||||
@@ -24,9 +24,9 @@ namespace UVC.UI.Window
|
||||
/// <example>
|
||||
/// <![CDATA[
|
||||
/// // 외부에서 창을 참조했다고 가정
|
||||
/// hierarchyWindow.OnItemSelected += item => Debug.Log($"Selected: {item.Name}");
|
||||
/// hierarchyWindow.AddItem(new TreeListItemData("Root A"));
|
||||
/// hierarchyWindow.AddItemAt(new TreeListItemData("Root B"),0);
|
||||
/// accordionWindow.OnItemSelected += item => Debug.Log($"Selected: {item.Name}");
|
||||
/// accordionWindow.AddItem(new TreeListItemData("Root A"));
|
||||
/// accordionWindow.AddItemAt(new TreeListItemData("Root B"),0);
|
||||
/// ]]>
|
||||
/// </example>
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user