diff --git a/Assets/Scripts/Studio/Command/CreateConnectedAssetCommand.cs b/Assets/Scripts/Studio/Command/CreateConnectedAssetCommand.cs index 017c7893..1fd89489 100644 --- a/Assets/Scripts/Studio/Command/CreateConnectedAssetCommand.cs +++ b/Assets/Scripts/Studio/Command/CreateConnectedAssetCommand.cs @@ -45,7 +45,7 @@ namespace Studio.Command var renderObjectHandler = ManagerHub.instance.Get(); renderObjectHandler.rtgController.SetGizmoTargetObjects(new List()); - + renderObjectHandler.DeselectAll(); } } diff --git a/Assets/Scripts/Studio/Command/ObjectCommand/CopyObjectCommand.cs b/Assets/Scripts/Studio/Command/ObjectCommand/CopyObjectCommand.cs index 3a99beaa..0c4bb02d 100644 --- a/Assets/Scripts/Studio/Command/ObjectCommand/CopyObjectCommand.cs +++ b/Assets/Scripts/Studio/Command/ObjectCommand/CopyObjectCommand.cs @@ -145,6 +145,8 @@ namespace Studio.Command canvas.panel_dynamicobjectinfo.ResetObjectInfo(); //connector.onRemoveObjects?.Invoke(); connector.componentScrollView.DeselectAll(); + var renderObjectHandler = ManagerHub.instance.Get(); + renderObjectHandler.DeselectAll(); } } diff --git a/Assets/Scripts/Studio/Managers/UserInputManager.cs b/Assets/Scripts/Studio/Managers/UserInputManager.cs index ac5f4d4f..7bc6a984 100644 --- a/Assets/Scripts/Studio/Managers/UserInputManager.cs +++ b/Assets/Scripts/Studio/Managers/UserInputManager.cs @@ -2,6 +2,7 @@ using System; using System.Collections; using System.Collections.Generic; using TMPro; +using UnityEditor.ShortcutManagement; using UnityEngine; using UnityEngine.EventSystems; using XRLib; @@ -13,10 +14,21 @@ namespace Studio.Manage Dictionary getKeyActionTable = new Dictionary(); Dictionary upKeyActionTable = new Dictionary(); Dictionary downKeyActionTable = new Dictionary(); - Dictionary> shortCutActionTable = new (); + Dictionary> shortCutActionTable = new(); + Dictionary shortcutStateTable = new Dictionary(); + + float shortCutInitialDelay = 0.5f; + float shortCutRepeatDelay = 0.1f; + Stack handlerStack = new(); Action updateLoop; + private class ShortcutState + { + public float pressStartTime = -1f; + public float lastActionTime = -1f; + } + public void SetHandler(InputHandler handler) { SetKeyboardPreset(handler); @@ -34,11 +46,11 @@ namespace Studio.Manage RemoveKeyActionPreset(currentHandler); break; } - + tempStack.Push(currentHandler); } - while(tempStack.Count > 0) + while (tempStack.Count > 0) { var tempHandler = tempStack.Pop(); SetKeyboardPreset(tempHandler); @@ -47,24 +59,24 @@ namespace Studio.Manage void RemoveKeyActionPreset(InputHandler handler) { - foreach(var k in handler.getKeyActions) + foreach (var k in handler.getKeyActions) { getKeyActionTable.Remove(k.Key); } - foreach(var k in handler.upKeyActions) + foreach (var k in handler.upKeyActions) { upKeyActionTable.Remove(k.Key); } - foreach(var k in handler.downKeyActions) + foreach (var k in handler.downKeyActions) { downKeyActionTable.Remove(k.Key); } - foreach(var k in handler.shortCutActions) + foreach (var k in handler.shortCutActions) { - foreach(var kk in k.Value) + foreach (var kk in k.Value) { shortCutActionTable[k.Key].Remove(kk.Key); } @@ -79,14 +91,14 @@ namespace Studio.Manage getKeyActionTable[k.Key] = k.Value; } - foreach(var k in handler.upKeyActions) + foreach (var k in handler.upKeyActions) { - upKeyActionTable[k.Key]= k.Value; + upKeyActionTable[k.Key] = k.Value; } - foreach(var k in handler.downKeyActions) + foreach (var k in handler.downKeyActions) { - downKeyActionTable[k.Key]= k.Value; + downKeyActionTable[k.Key] = k.Value; } foreach (var k in handler.shortCutActions) @@ -143,18 +155,53 @@ namespace Studio.Manage { foreach (var k in kk) { - if (Input.GetKeyDown(k.Key)) + string inputKeystring = key + "+" + k.Key; + bool bothKeyPressed = Input.GetKey(k.Key); + + if (!shortcutStateTable.TryGetValue(inputKeystring, out var state)) { - k.Value?.Invoke(); + state = new ShortcutState(); + shortcutStateTable[inputKeystring] = state; + } + + if (bothKeyPressed) + { + float curTime = Time.time; + + if (state.pressStartTime < 0f) + { + state.pressStartTime = curTime; + state.lastActionTime = -1f; + } + + if (state.lastActionTime < 0f) + { + k.Value?.Invoke(); + state.lastActionTime = curTime; + } + else + { + float holdTime = curTime - state.pressStartTime; + float sinceLastAction = curTime - state.lastActionTime; + + if (holdTime >= shortCutInitialDelay && sinceLastAction >= shortCutRepeatDelay) + { + k.Value?.Invoke(); + state.lastActionTime = curTime; + } + } + } + else + { + state.pressStartTime = -1f; + state.lastActionTime = -1f; } } } } } - updateLoop?.Invoke(); } - bool IsEditInputField() { GameObject selectedObj = EventSystem.current.currentSelectedGameObject; @@ -165,4 +212,5 @@ namespace Studio.Manage return selectedObj.GetComponent() != null; } } + }