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)

View File

@ -0,0 +1,81 @@
using System;
using Newtonsoft.Json;
using Unity.Mathematics;
#if NET5_0_OR_GREATER
namespace BITKit
{
public class Float2JsonConvertJsonConverter:JsonConverter<float2>
{
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<float4>
{
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

View File

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

View File

@ -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)
{

View File

@ -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<Label>();
@ -183,6 +184,9 @@ namespace BITKit.UX
var t = (float)i / maxLength;
var value = Mathf.Lerp(min, max, t);
label.text = Math.Round(value, 2).ToString();
label.style.marginBottom = label.style.marginLeft = label.style.marginRight = label.style.marginTop = 0;
label.style.paddingBottom = label.style.paddingLeft = label.style.paddingRight = label.style.paddingTop = 0;
}
MarkDirtyRepaint();
}

View File

@ -78,6 +78,10 @@ namespace BITKit.UX
RootVisualElement.SetActive(false);
OnInitiated?.Invoke();
await OnInitiatedAsync.UniTaskFunc();
WaitUtilInitialized.TrySetResult();
}
}
@ -195,6 +199,8 @@ namespace BITKit.UX
public event Action OnExit;
public event Func<UniTask> OnExitAsync;
public event Action OnExitCompleted;
public event Action OnInitiated;
public event Func<UniTask> OnInitiatedAsync;
public virtual void OnTick(float deltaTime)
{

View File

@ -9,8 +9,8 @@ namespace BITKit.GameEditor
{
public class QuickFixBoxCollider
{
[Command(nameof(FixCollider), "快速修复BoxCollider编写", QuickName = "fb"),
MenuItem("Tools/Scenes/Fix Float Model Position")]
[Command(nameof(FixCollider), "快速修复BoxCollider便捷", QuickName = "qkc"),
MenuItem("Tools/Scenes/Quick Fix Box Collider Bounds")]
public static void FixCollider()
{
foreach (var transform in UnityEditor.Selection.transforms)