1
This commit is contained in:
@@ -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();
|
||||
|
11
Src/Core/Extensions/DisplayAttributeExtensions.cs.meta
Normal file
11
Src/Core/Extensions/DisplayAttributeExtensions.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 56c780c378f03f4419272fb5ae8dfb1d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user