diff --git a/Src/Core/Extensions/DisplayAttributeExtensions.cs b/Src/Core/Extensions/DisplayAttributeExtensions.cs index 06b63f5..0c70cff 100644 --- a/Src/Core/Extensions/DisplayAttributeExtensions.cs +++ b/Src/Core/Extensions/DisplayAttributeExtensions.cs @@ -27,11 +27,12 @@ namespace BITKit { return displayNameAttribute.DisplayName; } - +#if NET5_0_OR_GREATER if (self.GetType().GetCustomAttribute() 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() is DisplayAttribute displayAttribute) { return displayAttribute.Name; } +#endif } } return self.ToString(); diff --git a/Src/Core/Extensions/DisplayAttributeExtensions.cs.meta b/Src/Core/Extensions/DisplayAttributeExtensions.cs.meta new file mode 100644 index 0000000..d21454f --- /dev/null +++ b/Src/Core/Extensions/DisplayAttributeExtensions.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 56c780c378f03f4419272fb5ae8dfb1d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Src/Core/Extensions/IEnumerable.cs b/Src/Core/Extensions/IEnumerable.cs index 78c679a..670fa6f 100644 --- a/Src/Core/Extensions/IEnumerable.cs +++ b/Src/Core/Extensions/IEnumerable.cs @@ -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(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(this IDictionary self, TKey key) where TValue : new() { lock (self) diff --git a/Src/NetSupport/MathematicsSupport.cs b/Src/NetSupport/MathematicsSupport.cs new file mode 100644 index 0000000..8bd0afb --- /dev/null +++ b/Src/NetSupport/MathematicsSupport.cs @@ -0,0 +1,81 @@ +using System; +using Newtonsoft.Json; +using Unity.Mathematics; + +#if NET5_0_OR_GREATER +namespace BITKit +{ + public class Float2JsonConvertJsonConverter:JsonConverter + { + public override void WriteJson(JsonWriter writer, float2 value, JsonSerializer serializer) + { + writer.WriteStartObject(); + + writer.WritePropertyName(nameof(value.x)); + writer.WriteValue((double)value.x); + + writer.WritePropertyName(nameof(value.y)); + writer.WriteValue((double)value.y); + + writer.WriteEndObject(); + } + + public override float2 ReadJson(JsonReader reader, Type objectType, float2 existingValue, bool hasExistingValue, + JsonSerializer serializer) + { + var result = float2.zero; + + while (reader.TokenType != JsonToken.EndObject) { + reader.Read(); + if (reader.TokenType != JsonToken.PropertyName) continue; + + var property = reader.Value; + if (property is nameof(float2.x)) result.x = (float)reader.ReadAsDouble()!; + if (property is nameof(float2.y)) result.y = (float)reader.ReadAsDouble()!; + } + + return result; + } + } + public class Float4JsonConvertJsonConverter:JsonConverter + { + public override void WriteJson(JsonWriter writer, float4 value, JsonSerializer serializer) + { + writer.WriteStartObject(); + + writer.WritePropertyName(nameof(value.x)); + writer.WriteValue((double)value.x); + + writer.WritePropertyName(nameof(value.y)); + writer.WriteValue((double)value.y); + + writer.WritePropertyName(nameof(value.z)); + writer.WriteValue((double)value.z); + + writer.WritePropertyName(nameof(value.w)); + writer.WriteValue((double)value.w); + + writer.WriteEndObject(); + } + + public override float4 ReadJson(JsonReader reader, Type objectType, float4 existingValue, bool hasExistingValue, + JsonSerializer serializer) + { + var result = float4.zero; + + while (reader.TokenType != JsonToken.EndObject) { + reader.Read(); + if (reader.TokenType != JsonToken.PropertyName) continue; + + var property = reader.Value; + if (property is nameof(float4.x)) result.x = (float)reader.ReadAsDouble()!; + if (property is nameof(float4.y)) result.y = (float)reader.ReadAsDouble()!; + if (property is nameof(float4.z)) result.z = (float)reader.ReadAsDouble()!; + if (property is nameof(float4.w)) result.w = (float)reader.ReadAsDouble()!; + } + + return result; + } + } +} +#endif \ No newline at end of file diff --git a/Src/NetSupport/MathematicsSupport.cs.meta b/Src/NetSupport/MathematicsSupport.cs.meta new file mode 100644 index 0000000..993c322 --- /dev/null +++ b/Src/NetSupport/MathematicsSupport.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 63ffbc9c0b6af6e41b872d6588ac165c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Src/Unity/Scripts/Scenes/SceneService.cs b/Src/Unity/Scripts/Scenes/SceneService.cs index aa1f4c0..aa26df8 100644 --- a/Src/Unity/Scripts/Scenes/SceneService.cs +++ b/Src/Unity/Scripts/Scenes/SceneService.cs @@ -83,6 +83,14 @@ namespace BITKit.SceneManagement public class SceneService : MonoBehaviour,ISceneService { + #if UNITY_EDITOR + [UnityEditor.MenuItem("Tools/Scenes/Toggle Scene Service Once")] + public static void ToggleSceneServiceOnce() + { + AllowInitialize = !AllowInitialize; + Debug.Log("允许初始化场景设置为:"+AllowInitialize); + } + #endif [BITCommand] public static async void Map(string mapName) { diff --git a/Src/Unity/Scripts/UX/Chart/SkiaChart.cs b/Src/Unity/Scripts/UX/Chart/LineChart.cs similarity index 95% rename from Src/Unity/Scripts/UX/Chart/SkiaChart.cs rename to Src/Unity/Scripts/UX/Chart/LineChart.cs index f0f144d..8bbad1a 100644 --- a/Src/Unity/Scripts/UX/Chart/SkiaChart.cs +++ b/Src/Unity/Scripts/UX/Chart/LineChart.cs @@ -174,7 +174,8 @@ namespace BITKit.UX //Debug.Log($"min:{min} max:{max} difference:{difference} max:{max}"); _dataContainer.Clear(); - for (var i = 0; i <= maxLength; i++) + _dataContainer.style.justifyContent = Justify.SpaceAround; + for (var i = 0; i <= 4; i++) { var label = _dataContainer.Create