diff --git a/Src/Core/Extensions/IEnumerable.cs b/Src/Core/Extensions/IEnumerable.cs index 67a5c96..b330fa4 100644 --- a/Src/Core/Extensions/IEnumerable.cs +++ b/Src/Core/Extensions/IEnumerable.cs @@ -130,7 +130,7 @@ namespace BITKit } else { - value = new TValue(); + value = new TValue(); self.TryAdd(t, value); } return value; diff --git a/Src/Unity/Configs/Input/BITController.inputactions b/Src/Unity/Configs/Input/BITController.inputactions index bc87ffd..e75e8d1 100644 --- a/Src/Unity/Configs/Input/BITController.inputactions +++ b/Src/Unity/Configs/Input/BITController.inputactions @@ -836,6 +836,24 @@ "processors": "", "interactions": "", "initialStateCheck": true + }, + { + "name": "Chat", + "type": "Button", + "id": "346fc321-a6f0-4d95-81d1-bc531ed3ed28", + "expectedControlType": "", + "processors": "", + "interactions": "", + "initialStateCheck": false + }, + { + "name": "Confirm", + "type": "Button", + "id": "0c71f40f-c39e-4893-b4d7-2c1968a9730d", + "expectedControlType": "", + "processors": "", + "interactions": "", + "initialStateCheck": false } ], "bindings": [ @@ -1146,6 +1164,39 @@ "action": "Delta", "isComposite": false, "isPartOfComposite": false + }, + { + "name": "", + "id": "4f11c618-09f3-4ace-8f9f-efd7821ebe37", + "path": "/enter", + "interactions": "", + "processors": "", + "groups": "", + "action": "Chat", + "isComposite": false, + "isPartOfComposite": false + }, + { + "name": "", + "id": "265f9627-ae29-4f03-80b9-80a64c28a9bf", + "path": "/enter", + "interactions": "", + "processors": "", + "groups": "", + "action": "Confirm", + "isComposite": false, + "isPartOfComposite": false + }, + { + "name": "", + "id": "97306299-e0e4-4e18-805b-51a1674b037d", + "path": "/space", + "interactions": "", + "processors": "", + "groups": "", + "action": "Confirm", + "isComposite": false, + "isPartOfComposite": false } ] }, diff --git a/Src/Unity/Scripts/InputSystem/InputActionGroup.cs b/Src/Unity/Scripts/InputSystem/InputActionGroup.cs index d26bbb3..d5200db 100644 --- a/Src/Unity/Scripts/InputSystem/InputActionGroup.cs +++ b/Src/Unity/Scripts/InputSystem/InputActionGroup.cs @@ -8,20 +8,31 @@ using System.Linq; namespace BITKit { - [System.Serializable] + [Serializable] public class InputActionGroup : IDisposable { - public override string ToString() + private class InputActionProxy { - return $"Source:{Source}\nEnabled:{isEnabled}\nInitialized:{state}\nKeys:{string.Join("\n",actions.Keys)}"; + public event Action Callback; + public void Invoke(InputAction.CallbackContext context) + { + try + { + Callback?.Invoke(context); + } + catch (OperationCanceledException) + { + } + } } - public string Source; - private int lockFile = Guid.NewGuid().GetHashCode(); + + private int _lockFile = Guid.NewGuid().GetHashCode(); public bool allowGlobalActivation = true; [SerializeField, ReadOnly] private bool isEnabled; - private InitializationState state = InitializationState.None; + private InitializationState _state = InitializationState.None; public readonly ValidHandle allowInput = new(); - private readonly ConcurrentDictionary actions = new(); + private readonly ConcurrentDictionary _actions = new(); + private readonly ConcurrentDictionary _callbacks = new(); /// /// 注册所有(started,performed,canceled)回调 @@ -33,20 +44,14 @@ namespace BITKit Action callback) { var action = EnsureCreated(reference); - action.RegisterCallback(callback); + _callbacks[action.GetHashCode()].Callback += callback; return this; } public InputActionGroup RegisterCallback(InputAction inputAction,Action callback) { - EnsureConfiguration(); - - var action = actions.GetOrAdd(inputAction.name, _=>inputAction.Clone()); - - allowInput.Invoke(); - - action.RegisterCallback(callback); - + var action = EnsureCreated(inputAction); + _callbacks[action.GetHashCode()].Callback += callback; return this; } @@ -59,10 +64,16 @@ namespace BITKit } EnsureConfiguration(); - var action = actions.GetOrAdd(reference.name, _ => + var action = _actions.GetOrAdd(reference.name, _ => { var newAction = reference.action.Clone(); newAction.Rename(reference.name); + + var callback = _callbacks[newAction.GetHashCode()] = new(); + newAction.performed += callback.Invoke; + newAction.canceled+=callback.Invoke; + newAction.started+=callback.Invoke; + return newAction; }); @@ -73,10 +84,16 @@ namespace BITKit public InputAction EnsureCreated(InputAction inputAction) { EnsureConfiguration(); - var action = actions.GetOrAdd(inputAction.name, _ => + var action = _actions.GetOrAdd(inputAction.name, _ => { var newAction = inputAction.Clone(); newAction.Rename(inputAction.name); + + var callback = _callbacks[newAction.GetHashCode()] = new(); + newAction.performed += callback.Invoke; + newAction.canceled+=callback.Invoke; + newAction.started+=callback.Invoke; + return newAction; }); @@ -91,34 +108,38 @@ namespace BITKit } public InputAction GetAction(string name) { - if(actions.TryGetValue(name,out var action)) + if(_actions.TryGetValue(name,out var action)) return action; throw new ArgumentException($"未知的引用{name}"); } public InputAction GetAction(InputActionReference reference) { - if(actions.TryGetValue(reference.name,out var action)) + if(_actions.TryGetValue(reference.name,out var action)) return action; throw new ArgumentException($"未知的引用{reference.name}"); } public void UnRegisterCallback(InputActionReference reference, Action callback) { - if(actions.TryGetValue(reference.name,out var action)) - action.UnRegisterCallback(callback); + if (_actions.TryGetValue(reference.name, out var action)) + { + _callbacks[action.GetHashCode()].Callback -= callback; + } } public void UnRegisterCallback(InputAction inputAction, Action callback) { - if(actions.TryGetValue(inputAction.name,out var action)) - action.UnRegisterCallback(callback); + if (_actions.TryGetValue(inputAction.name, out var action)) + { + _callbacks[action.GetHashCode()].Callback -= callback; + } } private void EnsureConfiguration() { - if (state is not InitializationState.Initialized) + if (_state is not InitializationState.Initialized) { Init(); - state = InitializationState.Initialized; + _state = InitializationState.Initialized; } } @@ -131,12 +152,12 @@ namespace BITKit private void ListenGlobalInput(bool allowInput) { - this.allowInput.SetDisableElements(lockFile, !allowInput); + this.allowInput.SetDisableElements(_lockFile, !allowInput); } private void AllowInput(bool allow) { - foreach (var action in actions.Values) + foreach (var action in _actions.Values) { if (allow) { @@ -151,12 +172,12 @@ namespace BITKit } public void Dispose() { - foreach (var action in actions.Values) + foreach (var action in _actions.Values) { action.Disable(); action.Dispose(); } - actions.Clear(); + _actions.Clear(); } } } \ No newline at end of file diff --git a/Src/Unity/Scripts/UX/Service/UI Toolkit/UIToolKitPanel.cs b/Src/Unity/Scripts/UX/Service/UI Toolkit/UIToolKitPanel.cs index 22e33f1..a8281b4 100644 --- a/Src/Unity/Scripts/UX/Service/UI Toolkit/UIToolKitPanel.cs +++ b/Src/Unity/Scripts/UX/Service/UI Toolkit/UIToolKitPanel.cs @@ -124,11 +124,9 @@ namespace BITKit.UX { //WaitUtilTransitionCompleted = new(); } - - protected readonly InputActionGroup InputActionGroup = new() + public readonly InputActionGroup InputActionGroup = new() { allowGlobalActivation = false, - Source = nameof(UIToolKitPanel) }; public virtual bool CloseWhenClickOutside { get;} public virtual bool IsWindow { get; } diff --git a/Src/Unity/Scripts/Utility/Extensions.cs b/Src/Unity/Scripts/Utility/Extensions.cs index 54c6c7d..3d5d5a8 100644 --- a/Src/Unity/Scripts/Utility/Extensions.cs +++ b/Src/Unity/Scripts/Utility/Extensions.cs @@ -679,7 +679,7 @@ namespace BITKit self.schedule.Execute(() => { self.scrollOffset = new Vector2(0, float.MaxValue); - }); + }).ExecuteLater(1);; } public static void ScrollToBottomAutomatic(this ScrollView self, float delay = 0.02f) { @@ -707,7 +707,8 @@ namespace BITKit public static Vector2 GetScreenPosition(this VisualElement self, Vector3 worldPosition) { - var panel = (self.panel ?? self.parent.panel) ?? self.parent.parent.panel; + var panel = self.panel; + if (panel is null) return default; var pos = RuntimePanelUtils .CameraTransformWorldToPanel(panel, worldPosition, Camera); diff --git a/Src/Unity/UX/Common/Common.uss b/Src/Unity/UX/Common/Common.uss index 37392f4..de07377 100644 --- a/Src/Unity/UX/Common/Common.uss +++ b/Src/Unity/UX/Common/Common.uss @@ -7,7 +7,7 @@ ScrollView { --unity-metrics-single_line-height: 500px; } -ScrollView Scroller.unity-scroller{ +ScrollView Scroller.unity-scroller { width: 8; } @@ -653,3 +653,8 @@ OnScreenButton.selected { transform-origin: left top; scale: 0.8 0.8; } + +.text-overflow-warp-normal .unity-text-element { + overflow: hidden; + white-space: normal; +} diff --git a/Src/Unity/UX/MaterialDesign.uss b/Src/Unity/UX/MaterialDesign.uss index b4622b6..7805e18 100644 --- a/Src/Unity/UX/MaterialDesign.uss +++ b/Src/Unity/UX/MaterialDesign.uss @@ -53,6 +53,10 @@ Slider.material { min-width: 128px; } +.material .selected Button { + background-color: rgba(26, 115, 232, 0.25); +} + .material Button:hover { background-color: rgba(26, 115, 232, 0.25); transition-duration: 0.32s;