写一个类,重写Sort方法,用自定义的比较器来 自定义 排序规则(例如:武将的排序,可以按国家、星级、等级排序)
UITable 第123行
/// <summary>
/// Want your own custom sorting logic? Override this function.
/// </summary>
protected virtual void Sort (List<Transform> list) { list.Sort(UIGrid.SortByName); }
class UIMyTable:UITable { protected override void Sort(List<UnityEngine.Transform> list) { if (sorting== Sorting.Country) { Debug.Log("sorted by country"); list.Sort(this.SortByCountry); } } int SortByCountry(Transform g1, Transform g2) { return g1.GetComponent<General>().Country.CompareTo(g2.GetComponent<General>().Country); } int SortByLevel(Transform t1, Transform t2) { return t1.GetComponent<General>().Level.CompareTo(t2.GetComponent<General>().Level); } int SortByStarLevel(Transform t1,Transform t2) { return t1.GetComponent<General>().GeneralStarLevel.CompareTo(t2.GetComponent<General>().GeneralStarLevel); } 接着写比较器 }
时间: 2024-10-08 20:50:29