62 lines
1.4 KiB
C#
62 lines
1.4 KiB
C#
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);
|
|
}
|
|
}
|
|
|