BS 0.2.0 Visual
This commit is contained in:
49
Convention/[Visual]/UIComponent/CustomMenu.cs
Normal file
49
Convention/[Visual]/UIComponent/CustomMenu.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using System.Collections.Generic;
|
||||
using Convention.WindowsUI;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Convention
|
||||
{
|
||||
public class CustomMenu : WindowsComponent
|
||||
{
|
||||
[Setting, SerializeField] private bool IsDestroy = true;
|
||||
[Resources, SerializeField, OnlyNotNullMode] private Button ButtonPrefab;
|
||||
[Resources, SerializeField, OnlyNotNullMode] private RectTransform Plane;
|
||||
[Content] public List<GameObject> childs = new();
|
||||
|
||||
[Content, OnlyPlayMode]
|
||||
[return: IsInstantiated(true)]
|
||||
public virtual Button CreateItem()
|
||||
{
|
||||
var item = GameObject.Instantiate(ButtonPrefab, Plane).GetComponent<Button>();
|
||||
item.gameObject.SetActive(true);
|
||||
childs.Add(item.gameObject);
|
||||
return item;
|
||||
}
|
||||
[return: IsInstantiated(true)]
|
||||
public virtual Button CreateItem(UnityAction callback, string title)
|
||||
{
|
||||
var item = CreateItem();
|
||||
item.onClick.AddListener(callback);
|
||||
item.GetComponents<IText>()[0].text = title;
|
||||
return item;
|
||||
}
|
||||
public virtual void ClearAllItem()
|
||||
{
|
||||
foreach (var child in childs)
|
||||
{
|
||||
GameObject.Destroy(child);
|
||||
}
|
||||
childs.Clear();
|
||||
}
|
||||
public virtual void ReleaseMenu()
|
||||
{
|
||||
if (IsDestroy)
|
||||
Destroy(this.gameObject);
|
||||
else
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user