diff --git a/Examples~ b/Examples~ index a8ce2ee..3e7049d 160000 --- a/Examples~ +++ b/Examples~ @@ -1 +1 @@ -Subproject commit a8ce2ee705be43c98db82e8307b5b4bf4801387e +Subproject commit 3e7049dfc36383e7e0e4c231c3a84ea50ead98c7 diff --git a/Runtime/Scripts/Controls/UI_Knob.cs b/Runtime/Scripts/Controls/UI_Knob.cs index 639d6a0..d4290ce 100644 --- a/Runtime/Scripts/Controls/UI_Knob.cs +++ b/Runtime/Scripts/Controls/UI_Knob.cs @@ -43,6 +43,10 @@ namespace UnityEngine.UI.Extensions public bool snapToPosition = false; [Tooltip("Number of positions to snap")] public int snapStepsPerLoop = 10; + [Tooltip("Parent touch area to extend the know touch radius")] + public RectTransform ParentTouchMask; + [Tooltip("Default background color of the touch mask. Defaults as transparent")] + public Color MaskBackground = new Color(0, 0, 0, 0); [Space(30)] public KnobFloatValueEvent OnValueChanged; private float _currentLoops = 0; @@ -56,7 +60,48 @@ namespace UnityEngine.UI.Extensions protected override void Awake() { - _screenSpaceOverlay = GetComponentInParent().rootCanvas.renderMode == RenderMode.ScreenSpaceOverlay; + _screenSpaceOverlay = GetComponentInParent().rootCanvas.renderMode == RenderMode.ScreenSpaceOverlay; + } + + protected override void Start() + { + CheckForParentTouchMask(); + } + + private void CheckForParentTouchMask() + { + if (ParentTouchMask) + { + Image maskImage = ParentTouchMask.gameObject.GetOrAddComponent(); + maskImage.color = MaskBackground; + EventTrigger trigger = ParentTouchMask.gameObject.GetOrAddComponent(); + trigger.triggers.Clear(); + //PointerDownEvent + EventTrigger.Entry pointerDownEntry = new EventTrigger.Entry(); + pointerDownEntry.eventID = EventTriggerType.PointerDown; + pointerDownEntry.callback.AddListener((data) => { OnPointerDown((PointerEventData)data); }); + trigger.triggers.Add(pointerDownEntry); + //PointerUpEvent + EventTrigger.Entry pointerUpEntry = new EventTrigger.Entry(); + pointerUpEntry.eventID = EventTriggerType.PointerUp; + pointerUpEntry.callback.AddListener((data) => { OnPointerUp((PointerEventData)data); }); + trigger.triggers.Add(pointerUpEntry); + //PointerEnterEvent + EventTrigger.Entry pointerEnterEntry = new EventTrigger.Entry(); + pointerEnterEntry.eventID = EventTriggerType.PointerEnter; + pointerEnterEntry.callback.AddListener((data) => { OnPointerEnter((PointerEventData)data); }); + trigger.triggers.Add(pointerEnterEntry); + //PointerExitEvent + EventTrigger.Entry pointerExitEntry = new EventTrigger.Entry(); + pointerExitEntry.eventID = EventTriggerType.PointerExit; + pointerExitEntry.callback.AddListener((data) => { OnPointerExit((PointerEventData)data); }); + trigger.triggers.Add(pointerExitEntry); + //DragEvent + EventTrigger.Entry dragEntry = new EventTrigger.Entry(); + dragEntry.eventID = EventTriggerType.Drag; + dragEntry.callback.AddListener((data) => { OnDrag((PointerEventData)data); }); + trigger.triggers.Add(dragEntry); + } } public override void OnPointerUp(PointerEventData eventData) @@ -72,7 +117,6 @@ namespace UnityEngine.UI.Extensions _canDrag = false; } - public override void OnPointerDown(PointerEventData eventData) { _canDrag = true;