Skip to content

Commit

Permalink
Add IRayPointerDownHandler and IRayPointerUpHandler;
Browse files Browse the repository at this point in the history
Update BaseHandle and users to use PointerDown and PointerUp instead of DragStarted and DragEnded because that is the expected behavior
  • Loading branch information
mtschoen committed Aug 14, 2020
1 parent 3e9e734 commit 8b2f07a
Show file tree
Hide file tree
Showing 30 changed files with 236 additions and 130 deletions.
8 changes: 4 additions & 4 deletions Runtime/Manipulators/BaseManipulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ void Awake()
handle.hovering += OnHandleHovering;
handle.hoverEnded += OnHandleHoverEnded;

handle.dragStarted += OnHandleDragStarted;
handle.pointerDown += OnHandlePointerDown;
handle.dragging += OnHandleDragging;
handle.dragEnded += OnHandleDragEnded;
handle.pointerUp += OnHandlePointerUp;
}
}

Expand Down Expand Up @@ -262,7 +262,7 @@ protected virtual void OnHandleHoverEnded(BaseHandle handle, HandleEventData eve
}
}

protected virtual void OnHandleDragStarted(BaseHandle handle, HandleEventData eventData)
protected virtual void OnHandlePointerDown(BaseHandle handle, HandleEventData eventData)
{
var rayOrigin = eventData.rayOrigin;
if (handle.IndexOfDragSource(rayOrigin) > 0)
Expand Down Expand Up @@ -291,7 +291,7 @@ protected virtual void OnHandleDragging(BaseHandle handle, HandleEventData event
UpdateHandleTip(handle, eventData, true);
}

protected virtual void OnHandleDragEnded(BaseHandle handle, HandleEventData eventData)
protected virtual void OnHandlePointerUp(BaseHandle handle, HandleEventData eventData)
{
var rayOrigin = eventData.rayOrigin;

Expand Down
12 changes: 6 additions & 6 deletions Runtime/Manipulators/DirectManipulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,23 @@ void OnEnable()
{
foreach (var h in m_AllHandles)
{
h.dragStarted += OnHandleDragStarted;
h.pointerDown += OnHandlePointerDown;
h.dragging += OnHandleDragging;
h.dragEnded += OnHandleDragEnded;
h.pointerUp += OnHandlePointerUp;
}
}

void OnDisable()
{
foreach (var h in m_AllHandles)
{
h.dragStarted -= OnHandleDragStarted;
h.pointerDown -= OnHandlePointerDown;
h.dragging -= OnHandleDragging;
h.dragEnded -= OnHandleDragEnded;
h.pointerUp -= OnHandlePointerUp;
}
}

void OnHandleDragStarted(BaseHandle handle, HandleEventData eventData)
void OnHandlePointerDown(BaseHandle handle, HandleEventData eventData)
{
foreach (var h in m_AllHandles)
{
Expand Down Expand Up @@ -78,7 +78,7 @@ void OnHandleDragging(BaseHandle handle, HandleEventData eventData)
rotate(Quaternion.Inverse(target.rotation) * rayOrigin.rotation * m_RotationOffset, rayOrigin);
}

void OnHandleDragEnded(BaseHandle handle, HandleEventData eventData)
void OnHandlePointerUp(BaseHandle handle, HandleEventData eventData)
{
if (gameObject.activeSelf)
{
Expand Down
8 changes: 4 additions & 4 deletions Runtime/Manipulators/StandardManipulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ protected override void ShowHoverState(BaseHandle handle, bool hovering)
handle.GetComponent<MeshFilter>().sharedMesh = hovering ? m_FatRadialHandleMesh : m_RadialHandleMesh;
}

protected override void OnHandleDragStarted(BaseHandle handle, HandleEventData eventData)
protected override void OnHandlePointerDown(BaseHandle handle, HandleEventData eventData)
{
base.OnHandleDragStarted(handle, eventData);
base.OnHandlePointerDown(handle, eventData);

if (handle.IndexOfDragSource(eventData.rayOrigin) > 0)
return;
Expand Down Expand Up @@ -84,9 +84,9 @@ protected override void OnHandleDragging(BaseHandle handle, HandleEventData even
}
}

protected override void OnHandleDragEnded(BaseHandle handle, HandleEventData eventData)
protected override void OnHandlePointerUp(BaseHandle handle, HandleEventData eventData)
{
base.OnHandleDragEnded(handle, eventData);
base.OnHandlePointerUp(handle, eventData);

if (handle.IndexOfDragSource(eventData.rayOrigin) > 0)
return;
Expand Down
4 changes: 2 additions & 2 deletions Runtime/Menus/MainMenu/Scripts/MainMenuFace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public string title
set { m_FaceTitle.text = value; }
}

public bool visible { set { this.RestartCoroutine(ref m_VisibilityCoroutine, AnimateVisibility(value)); } }
public bool visible { set { EditorMonoBehaviour.instance.RestartCoroutine(ref m_VisibilityCoroutine, AnimateVisibility(value)); } }

void Awake()
{
Expand All @@ -95,7 +95,7 @@ public void AddButton(Transform button)

public void Reveal(float delay = 0f)
{
this.RestartCoroutine(ref m_RevealCoroutine, AnimateReveal(delay));
EditorMonoBehaviour.instance.RestartCoroutine(ref m_RevealCoroutine, AnimateReveal(delay));
}

IEnumerator AnimateVisibility(bool show)
Expand Down
62 changes: 48 additions & 14 deletions Runtime/Scripts/Handles/BaseHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ namespace Unity.EditorXR.Handles
/// <summary>
/// Base class for providing draggable handles in 3D (requires PhysicsRaycaster)
/// </summary>
class BaseHandle : MonoBehaviour, ISelectionFlags, IRayBeginDragHandler, IRayDragHandler, IRayEndDragHandler,
IRayEnterHandler, IRayExitHandler, IRayHoverHandler, IPointerClickHandler, IDropReceiver, IDroppable
class BaseHandle : MonoBehaviour, ISelectionFlags, IRayPointerDownHandler, IRayBeginDragHandler, IRayDragHandler,
IRayEndDragHandler, IRayPointerUpHandler, IRayEnterHandler, IRayExitHandler, IRayHoverHandler,
IPointerClickHandler, IDropReceiver, IDroppable
{
protected const int k_DefaultCapacity = 2; // i.e. 2 controllers

Expand Down Expand Up @@ -43,9 +44,11 @@ public SelectionFlags selectionFlags
public event Action<BaseHandle> dropHoverStarted;
public event Action<BaseHandle> dropHoverEnded;

public event Action<BaseHandle, HandleEventData> dragStarted;
public event Action<BaseHandle, HandleEventData> pointerDown;
public event Action<BaseHandle, HandleEventData> beginDrag;
public event Action<BaseHandle, HandleEventData> dragging;
public event Action<BaseHandle, HandleEventData> dragEnded;
public event Action<BaseHandle, HandleEventData> endDrag;
public event Action<BaseHandle, HandleEventData> pointerUp;

public event Action<BaseHandle, PointerEventData> click;
public event Action<BaseHandle, HandleEventData> doubleClick;
Expand Down Expand Up @@ -82,7 +85,8 @@ void OnDisable()
foreach (var rayOrigin in sources)
{
eventData.rayOrigin = rayOrigin;
OnHandleDragEnded(eventData);
OnHandleEndDrag(eventData);
OnHandlePointerUp(eventData);
}
}
}
Expand All @@ -106,7 +110,7 @@ public int IndexOfDragSource(Transform rayOrigin)
return m_DragSources.IndexOf(rayOrigin);
}

public void OnBeginDrag(RayEventData eventData)
public void OnPointerDown(RayEventData eventData)
{
if (!UIUtils.IsValidEvent(eventData, selectionFlags))
return;
Expand All @@ -128,7 +132,13 @@ public void OnBeginDrag(RayEventData eventData)
if (UIUtils.IsDoubleClick(timeSinceLastClick))
OnDoubleClick(handleEventData);

OnHandleDragStarted(handleEventData);
OnHandlePointerDown(handleEventData);
}

public void OnBeginDrag(RayEventData eventData)
{
if (m_DragSources.Count > 0)
OnHandleBeginDrag(GetHandleEventData(eventData));
}

public void OnDrag(RayEventData eventData)
Expand All @@ -138,9 +148,15 @@ public void OnDrag(RayEventData eventData)
}

public void OnEndDrag(RayEventData eventData)
{
if (m_DragSources.Count > 0)
OnHandleEndDrag(GetHandleEventData(eventData));
}

public void OnPointerUp(RayEventData eventData)
{
if (m_DragSources.Remove(eventData.rayOrigin))
OnHandleDragEnded(GetHandleEventData(eventData));
OnHandlePointerUp(GetHandleEventData(eventData));
}

public void OnRayEnter(RayEventData eventData)
Expand Down Expand Up @@ -214,10 +230,19 @@ protected virtual void OnHandleHoverEnded(HandleEventData eventData)
/// <summary>
/// Override to modify event data prior to raising event (requires calling base method at the end)
/// </summary>
protected virtual void OnHandleDragStarted(HandleEventData eventData)
protected virtual void OnHandlePointerDown(HandleEventData eventData)
{
if (pointerDown != null)
pointerDown(this, eventData);
}

/// <summary>
/// Override to modify event data prior to raising event (requires calling base method at the end)
/// </summary>
protected virtual void OnHandleBeginDrag(HandleEventData eventData)
{
if (dragStarted != null)
dragStarted(this, eventData);
if (beginDrag != null)
beginDrag(this, eventData);
}

/// <summary>
Expand All @@ -232,10 +257,19 @@ protected virtual void OnHandleDragging(HandleEventData eventData)
/// <summary>
/// Override to modify event data prior to raising event (requires calling base method at the end)
/// </summary>
protected virtual void OnHandleDragEnded(HandleEventData eventData)
protected virtual void OnHandleEndDrag(HandleEventData eventData)
{
if (endDrag != null)
endDrag(this, eventData);
}

/// <summary>
/// Override to modify event data prior to raising event (requires calling base method at the end)
/// </summary>
protected virtual void OnHandlePointerUp(HandleEventData eventData)
{
if (dragEnded != null)
dragEnded(this, eventData);
if (pointerUp != null)
pointerUp(this, eventData);
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions Runtime/Scripts/Handles/LinearHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,13 @@ protected override void OnHandleHovering(HandleEventData eventData)
base.OnHandleHovering(eventData);
}

protected override void OnHandleDragStarted(HandleEventData eventData)
protected override void OnHandlePointerDown(HandleEventData eventData)
{
var linearEventData = (LinearHandleEventData)eventData;
m_LastPositions[eventData.rayOrigin] = linearEventData.raycastHitWorldPosition;
UpdateEventData(linearEventData);

base.OnHandleDragStarted(eventData);
base.OnHandlePointerDown(eventData);
}

protected override void OnHandleDragging(HandleEventData eventData)
Expand Down
4 changes: 2 additions & 2 deletions Runtime/Scripts/Handles/PlaneHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ protected override HandleEventData GetHandleEventData(RayEventData eventData)
return k_LinearHandleEventData;
}

protected override void OnHandleDragStarted(HandleEventData eventData)
protected override void OnHandlePointerDown(HandleEventData eventData)
{
var planeEventData = eventData as PlaneHandleEventData;
m_LastPositions[eventData.rayOrigin] = planeEventData.raycastHitWorldPosition;

m_Plane.SetNormalAndPosition(transform.forward, transform.position);

base.OnHandleDragStarted(eventData);
base.OnHandlePointerDown(eventData);
}

protected override void OnHandleDragging(HandleEventData eventData)
Expand Down
4 changes: 2 additions & 2 deletions Runtime/Scripts/Handles/RadialHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected override HandleEventData GetHandleEventData(RayEventData eventData)
return k_RadialHandleEventData;
}

protected override void OnHandleDragStarted(HandleEventData eventData)
protected override void OnHandlePointerDown(HandleEventData eventData)
{
var rayOrigin = eventData.rayOrigin;
var radialEventData = (RadialHandleEventData)eventData;
Expand All @@ -47,7 +47,7 @@ protected override void OnHandleDragStarted(HandleEventData eventData)

m_Plane.SetNormalAndPosition(forward, transform.position);

base.OnHandleDragStarted(eventData);
base.OnHandlePointerDown(eventData);
}

protected override void OnHandleDragging(HandleEventData eventData)
Expand Down
8 changes: 4 additions & 4 deletions Runtime/Scripts/Handles/SphereHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected override HandleEventData GetHandleEventData(RayEventData eventData)
return k_SphereHandleEventData;
}

protected override void OnHandleDragStarted(HandleEventData eventData)
protected override void OnHandlePointerDown(HandleEventData eventData)
{
var sphereEventData = (SphereHandleEventData)eventData;

Expand All @@ -56,7 +56,7 @@ protected override void OnHandleDragStarted(HandleEventData eventData)
m_ScrollRate = k_InitialScrollRate;
m_LastPosition = GetRayPoint(eventData);

base.OnHandleDragStarted(eventData);
base.OnHandlePointerDown(eventData);
}
}

Expand All @@ -72,10 +72,10 @@ protected override void OnHandleDragging(HandleEventData eventData)
}
}

protected override void OnHandleDragEnded(HandleEventData eventData)
protected override void OnHandlePointerUp(HandleEventData eventData)
{
if (!hasDragSource)
base.OnHandleDragEnded(eventData);
base.OnHandlePointerUp(eventData);
}

public void ChangeRadius(float delta)
Expand Down
8 changes: 4 additions & 4 deletions Runtime/Scripts/Handles/UI/KeyboardButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ protected override void OnHandleHoverEnded(HandleEventData eventData)
m_WorkspaceButton.highlighted = false;
}

protected override void OnHandleDragStarted(HandleEventData eventData)
protected override void OnHandlePointerDown(HandleEventData eventData)
{
if (eventData == null)
return;
Expand All @@ -254,7 +254,7 @@ protected override void OnHandleDragStarted(HandleEventData eventData)

m_WorkspaceButton.highlighted = true;

base.OnHandleDragStarted(eventData);
base.OnHandlePointerDown(eventData);
}

protected override void OnHandleDragging(HandleEventData eventData)
Expand All @@ -270,7 +270,7 @@ protected override void OnHandleDragging(HandleEventData eventData)
base.OnHandleDragging(eventData);
}

protected override void OnHandleDragEnded(HandleEventData eventData)
protected override void OnHandlePointerUp(HandleEventData eventData)
{
if (eventData == null)
return;
Expand All @@ -280,7 +280,7 @@ protected override void OnHandleDragEnded(HandleEventData eventData)
else if (Time.realtimeSinceStartup - m_PressDownTime < k_ClickTime)
KeyPressed();

base.OnHandleDragEnded(eventData);
base.OnHandlePointerUp(eventData);
}

public void OnTriggerEnter(Collider col)
Expand Down
Loading

0 comments on commit 8b2f07a

Please sign in to comment.