Updated UI Knob control - enabled dragging outside target area
Added example scenepull/413/head
parent
948d4fe62b
commit
9a0a08da78
|
@ -1 +1 @@
|
||||||
Subproject commit a8ce2ee705be43c98db82e8307b5b4bf4801387e
|
Subproject commit 3e7049dfc36383e7e0e4c231c3a84ea50ead98c7
|
|
@ -43,6 +43,10 @@ namespace UnityEngine.UI.Extensions
|
||||||
public bool snapToPosition = false;
|
public bool snapToPosition = false;
|
||||||
[Tooltip("Number of positions to snap")]
|
[Tooltip("Number of positions to snap")]
|
||||||
public int snapStepsPerLoop = 10;
|
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)]
|
[Space(30)]
|
||||||
public KnobFloatValueEvent OnValueChanged;
|
public KnobFloatValueEvent OnValueChanged;
|
||||||
private float _currentLoops = 0;
|
private float _currentLoops = 0;
|
||||||
|
@ -59,6 +63,47 @@ namespace UnityEngine.UI.Extensions
|
||||||
_screenSpaceOverlay = GetComponentInParent<Canvas>().rootCanvas.renderMode == RenderMode.ScreenSpaceOverlay;
|
_screenSpaceOverlay = GetComponentInParent<Canvas>().rootCanvas.renderMode == RenderMode.ScreenSpaceOverlay;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void Start()
|
||||||
|
{
|
||||||
|
CheckForParentTouchMask();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CheckForParentTouchMask()
|
||||||
|
{
|
||||||
|
if (ParentTouchMask)
|
||||||
|
{
|
||||||
|
Image maskImage = ParentTouchMask.gameObject.GetOrAddComponent<Image>();
|
||||||
|
maskImage.color = MaskBackground;
|
||||||
|
EventTrigger trigger = ParentTouchMask.gameObject.GetOrAddComponent<EventTrigger>();
|
||||||
|
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)
|
public override void OnPointerUp(PointerEventData eventData)
|
||||||
{
|
{
|
||||||
_canDrag = false;
|
_canDrag = false;
|
||||||
|
@ -72,7 +117,6 @@ namespace UnityEngine.UI.Extensions
|
||||||
_canDrag = false;
|
_canDrag = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public override void OnPointerDown(PointerEventData eventData)
|
public override void OnPointerDown(PointerEventData eventData)
|
||||||
{
|
{
|
||||||
_canDrag = true;
|
_canDrag = true;
|
||||||
|
|
Loading…
Reference in New Issue