From c3f0a8e8404659a3013318f92a7ac442bb90a60b Mon Sep 17 00:00:00 2001 From: CortexCore <2630229280@qq.com> Date: Sun, 3 Aug 2025 02:28:50 +0800 Subject: [PATCH] 1 --- Src/Core/ECS/EntitiesService.cs | 2 +- Src/Core/Mathematics/MathE.cs | 13 ++++++ Src/Core/Tween/BITween.cs | 11 ++++- .../Configs/Input/BITController.inputactions | 31 +++++++++++++ .../Extensions/GameObjectExtensions.cs | 13 ++++++ Src/Unity/Scripts/Pool/UnityPoolService.cs | 5 ++- Src/Unity/Scripts/UX/Settings/UXSettings.cs | 43 ++++++++++++++++++- Src/UnityPluginsSupport/Tests/Tests.asmdef | 2 +- 8 files changed, 114 insertions(+), 6 deletions(-) diff --git a/Src/Core/ECS/EntitiesService.cs b/Src/Core/ECS/EntitiesService.cs index ae1cf2e..0eaa5e5 100644 --- a/Src/Core/ECS/EntitiesService.cs +++ b/Src/Core/ECS/EntitiesService.cs @@ -52,7 +52,7 @@ namespace BITKit.Entities { while (_onAddQueue.TryDequeue(out var entity)) { - if(_addingEntities.Remove(entity) is false)continue; + if(_addingEntities.Remove(entity) is false || entity.CancellationToken.IsCancellationRequested)continue; OnAdd?.Invoke(entity); MakeCache(entity); } diff --git a/Src/Core/Mathematics/MathE.cs b/Src/Core/Mathematics/MathE.cs index 070cc62..59791fb 100644 --- a/Src/Core/Mathematics/MathE.cs +++ b/Src/Core/Mathematics/MathE.cs @@ -113,6 +113,19 @@ namespace BITKit } return false; } + + + public static bool Contains(this Span span, T value) + { + foreach (var t in span) + { + if (Equals(t, value)) + return true; + } + + return false; + } + public static bool Contains(IEnumerable a, IEnumerable b) { foreach (var x in b) diff --git a/Src/Core/Tween/BITween.cs b/Src/Core/Tween/BITween.cs index 0c12559..30215d3 100644 --- a/Src/Core/Tween/BITween.cs +++ b/Src/Core/Tween/BITween.cs @@ -5,6 +5,9 @@ using System.Threading; using System.Threading.Tasks; using Cysharp.Threading.Tasks; using Unity.Mathematics; +#if UNITY_5_3_OR_NEWER +using UnityEngine; +#endif namespace BITKit.Tween { @@ -68,7 +71,13 @@ namespace BITKit.Tween //BIT4Log.Log($"已创建Tween,from:[{from}]to:[{to}]duration:[{duration}]delta:[{delta}]"); while (t < 1 && cancellationToken.IsCancellationRequested is false) { - t = math.clamp(t + delta*BITApp.Time.DeltaTime, 0, 1); + var value = t + delta * BITApp.Time.DeltaTime; + +#if UNITY_5_3_OR_NEWER + value = t+ delta * Time.deltaTime; + #endif + + t = math.clamp(value, 0, 1); var next = func(from, to, t); #if UNITY_5_3_OR_NEWER await UniTask.NextFrame(cancellationToken); diff --git a/Src/Unity/Configs/Input/BITController.inputactions b/Src/Unity/Configs/Input/BITController.inputactions index 80390e4..4ba3e9c 100644 --- a/Src/Unity/Configs/Input/BITController.inputactions +++ b/Src/Unity/Configs/Input/BITController.inputactions @@ -854,6 +854,15 @@ "processors": "", "interactions": "", "initialStateCheck": false + }, + { + "name": "Map", + "type": "Button", + "id": "fa290d94-fe08-4c71-823d-0efe096552ff", + "expectedControlType": "", + "processors": "", + "interactions": "", + "initialStateCheck": false } ], "bindings": [ @@ -1197,6 +1206,28 @@ "action": "Cancel", "isComposite": false, "isPartOfComposite": false + }, + { + "name": "", + "id": "e3cd8458-c141-4a70-b841-88fa0711d0f1", + "path": "/capsLock", + "interactions": "", + "processors": "", + "groups": "", + "action": "Map", + "isComposite": false, + "isPartOfComposite": false + }, + { + "name": "", + "id": "a433d70f-d2ca-42a8-ab45-cf68424f6155", + "path": "/m", + "interactions": "", + "processors": "", + "groups": "", + "action": "Map", + "isComposite": false, + "isPartOfComposite": false } ] }, diff --git a/Src/Unity/Scripts/Extensions/GameObjectExtensions.cs b/Src/Unity/Scripts/Extensions/GameObjectExtensions.cs index 7bc0212..4705f46 100644 --- a/Src/Unity/Scripts/Extensions/GameObjectExtensions.cs +++ b/Src/Unity/Scripts/Extensions/GameObjectExtensions.cs @@ -17,5 +17,18 @@ namespace BITKit Object.Destroy(t); return t; } + + public static int RemoveComponentsInChildren(this GameObject gameObject) where T :Component + { + var count = 0; + foreach (var x in gameObject.GetComponentsInChildren()) + { + if (!x) continue; + Object.Destroy(x); + count++; + } + + return count; + } } } diff --git a/Src/Unity/Scripts/Pool/UnityPoolService.cs b/Src/Unity/Scripts/Pool/UnityPoolService.cs index dfbbfc7..fee52cb 100644 --- a/Src/Unity/Scripts/Pool/UnityPoolService.cs +++ b/Src/Unity/Scripts/Pool/UnityPoolService.cs @@ -33,7 +33,7 @@ namespace BITKit.Pool { if (obj is not Component component) continue; if (!hashset.Add(component.gameObject)) continue; - if (component.gameObject) + if (component) Object.Destroy(component.gameObject); } } @@ -87,6 +87,9 @@ namespace BITKit.Pool if (asset is Object o) { var instance = Object.Instantiate(o); + + instance.name = path; + list.Add(instance); UsingPool.GetOrCreate(path).Add(instance); ReadyPool.GetOrCreate(path); diff --git a/Src/Unity/Scripts/UX/Settings/UXSettings.cs b/Src/Unity/Scripts/UX/Settings/UXSettings.cs index 7ed30ae..f452b06 100644 --- a/Src/Unity/Scripts/UX/Settings/UXSettings.cs +++ b/Src/Unity/Scripts/UX/Settings/UXSettings.cs @@ -25,17 +25,42 @@ namespace BITKit.UX.Settings _localizationService = localizationService; _value = _valueWrapper.Value; } - + + + [UXBindPath("settings-container")] private VisualElement _settingsContainer; + [UXBindPath("confirm-button",true)] + private Button _confirmButton; + private void Save() { - _valueWrapper.Value = _value; + if (_confirmButton is null) + { + _valueWrapper.Value = _value; + } } + protected override void OnInitiated() { base.OnInitiated(); + + if (_confirmButton is not null) + { + _confirmButton.clicked += OnConfirmButtonOnclicked; + } + + Rebuild(); + } + + private void OnConfirmButtonOnclicked() + { + _valueWrapper.Value = _value; + } + + private void Rebuild() + { _settingsContainer.Clear(); foreach (var propertyInfo in typeof(TValue).GetProperties()) { @@ -128,12 +153,26 @@ namespace BITKit.UX.Settings return enumField; } break; + case var type when type == typeof(int2): + { + var vector2Field = _settingsContainer.Create(); + vector2Field.label = _localizationService.GetLocalizedString(name); + var int2Value = value.As(); + vector2Field.value = new Vector2(int2Value.x, int2Value.y); + vector2Field.RegisterValueChangedCallback(x => + { + propertyInfo.SetValue(_value, new int2((int)x.newValue.x, (int)x.newValue.y)); + Save(); + }); + return vector2Field; + } } return null; } } } + } } diff --git a/Src/UnityPluginsSupport/Tests/Tests.asmdef b/Src/UnityPluginsSupport/Tests/Tests.asmdef index f9b872c..bbd5ac2 100644 --- a/Src/UnityPluginsSupport/Tests/Tests.asmdef +++ b/Src/UnityPluginsSupport/Tests/Tests.asmdef @@ -1,5 +1,5 @@ { - "name": "Tests", + "name": "BITKit.Tests", "rootNamespace": "", "references": [ "UnityEngine.TestRunner",