This commit is contained in:
CortexCore
2024-12-17 17:51:58 +08:00
parent d502501b27
commit 0fddf0dc2a
10 changed files with 146 additions and 5 deletions

View File

@@ -27,11 +27,12 @@ namespace BITKit
{
return displayNameAttribute.DisplayName;
}
#if NET5_0_OR_GREATER
if (self.GetType().GetCustomAttribute<DisplayAttribute>() is { } displayAttribute)
{
return displayAttribute.Name;
}
#endif
}
{
if (self is Enum)
@@ -42,11 +43,12 @@ namespace BITKit
{
return displayNameAttribute.DisplayName;
}
#if NET5_0_OR_GREATER
if (field.GetCustomAttribute<DisplayAttribute>() is DisplayAttribute displayAttribute)
{
return displayAttribute.Name;
}
#endif
}
}
return self.ToString();

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 56c780c378f03f4419272fb5ae8dfb1d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -2,6 +2,8 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Unity.Mathematics;
using Random = System.Random;
namespace BITKit
{
@@ -198,6 +200,22 @@ namespace BITKit
{
return self[typeof(TKey)];
}
public static TValue[] TakeRandom<TValue>(this TValue[] self, int count)
{
//自动实现
var random = new Random();
var newList = self.ToList();
count = math.min(count, newList.Count);
var result = new TValue[count];
for (var i = 0; i < count; i++)
{
var value = newList[random.Next(0, newList.Count)];
newList.Remove(value);
result[i] = value;
}
return result;
}
public static TValue Get<TKey, TValue>(this IDictionary<TKey, TValue> self, TKey key) where TValue : new()
{
lock (self)