using System.Collections.Generic; using UnityEngine; namespace Mly.Hotfix { public abstract class CheatListView : MonoBehaviour { /// /// 按钮列表 /// protected abstract IList 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); }); } /// /// 按钮文字 /// protected abstract string GetItemText(T item); /// /// 按钮点击 /// protected abstract void OnClickItem(T item); } }