设置相关功能脚本呢
This commit is contained in:
34
Assets/Scripts/Utils/Extends/ListExtends.cs
Normal file
34
Assets/Scripts/Utils/Extends/ListExtends.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using NBF.Setting;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public static class ListExtends
|
||||
{
|
||||
public static void SortBySortAttribute(this List<OptionBase> list)
|
||||
{
|
||||
if (list == null)
|
||||
throw new ArgumentNullException(nameof(list));
|
||||
|
||||
list.Sort((a, b) =>
|
||||
{
|
||||
var orderA = GetSortOrder(a);
|
||||
var orderB = GetSortOrder(b);
|
||||
return orderA.CompareTo(orderB);
|
||||
});
|
||||
}
|
||||
|
||||
private static int GetSortOrder(OptionBase option)
|
||||
{
|
||||
if (option == null)
|
||||
return 999;
|
||||
|
||||
var sortAttribute = option.GetType()
|
||||
.GetCustomAttribute<SortAttribute>(inherit: false);
|
||||
|
||||
return sortAttribute?.Sort ?? 999;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Utils/Extends/ListExtends.cs.meta
Normal file
3
Assets/Scripts/Utils/Extends/ListExtends.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 87135425aeb24b8ead2f411dceabb955
|
||||
timeCreated: 1748591603
|
||||
Reference in New Issue
Block a user