mly2023cheat/CheatListView.cs

62 lines
1.4 KiB
C#
Raw Normal View History

2023-08-24 14:33:32 +08:00
using System.Collections.Generic;
using UnityEngine;
namespace Mly.Hotfix
{
public abstract class CheatListView<T> : MonoBehaviour
{
/// <summary>
/// 按钮列表
/// </summary>
protected abstract IList<T> List { get; }
protected virtual GUIStyle ItemStyle => CheatUtil.GetGUIButtonStyle();
private bool collapse;
protected virtual void Awake()
{
CheatUtil.AutoScaling();
}
protected virtual void OnGUI()
{
UpdateView();
}
protected virtual void UpdateView()
{
if (List == null)
return;
CheatUtil.PointToStart();
if (collapse)
UpdateList();
if (GUI.Button(CheatUtil.GetNextRect(), collapse ? "收起" : "展开", ItemStyle))
collapse = !collapse;
}
protected virtual void UpdateList()
{
CheatUtil.DrawCheatList(List, (item, rect) =>
{
if (GUI.Button(rect, GetItemText(item), ItemStyle))
OnClickItem(item);
});
}
/// <summary>
/// 按钮文字
/// </summary>
protected abstract string GetItemText(T item);
/// <summary>
/// 按钮点击
/// </summary>
protected abstract void OnClickItem(T item);
}
}