Skip to content

Commit

Permalink
adding feature -> custom ExplicitBlock for Click events (when used cu…
Browse files Browse the repository at this point in the history
…stom dragging)
  • Loading branch information
RFedorov committed Jan 10, 2022
1 parent 4c287a3 commit 29a080a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
15 changes: 9 additions & 6 deletions Runtime/SharedResources/Scripts/VRTK3.3.0 UI/VRTK4_UIPointer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Zinnia.Action;
using System;
using Zinnia.Action;

namespace Tilia.VRTKUI
{
Expand Down Expand Up @@ -172,7 +173,8 @@ public enum ClickMethods
protected bool lastPointerPressState = false;
protected bool lastPointerClickState = false;
protected GameObject currentTarget;
public bool isValidStateForClickFromHover = false;
[NonSerialized] public bool IsValidStateForClickFromHover = false;
[NonSerialized] public bool ExplicitBlockClickOnce = false;

// protected VRTK4_EventSystem cachedEventSystem;
protected VRTK4_VRInputModule cachedVRInputModule;
Expand Down Expand Up @@ -201,10 +203,10 @@ public virtual void OnUIPointerElementEnter(VRTK4UIPointerEventArgs e)
}

currentTarget = e.currentTarget;
isValidStateForClickFromHover = true;
IsValidStateForClickFromHover = true;
if (pointerEventData.pointerPress != null && pointerEventData.pointerPress != currentTarget)
{
isValidStateForClickFromHover = false;
IsValidStateForClickFromHover = false;
}

if (UIPointerElementEnter != null)
Expand All @@ -220,7 +222,8 @@ public virtual void OnUIPointerElementExit(VRTK4UIPointerEventArgs e)
ResetHoverTimer();
}

isValidStateForClickFromHover = false;
ExplicitBlockClickOnce = false;
IsValidStateForClickFromHover = false;
if (UIPointerElementExit != null)
{
UIPointerElementExit(this, e);
Expand All @@ -244,7 +247,7 @@ public virtual void OnUIPointerElementClick(VRTK4UIPointerEventArgs e)
ResetHoverTimer();
}

if (isValidStateForClickFromHover)
if (IsValidStateForClickFromHover && !ExplicitBlockClickOnce)
{
if (UIPointerElementClick != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,12 +461,14 @@ protected virtual bool AttemptClick(VRTK4_UIPointer pointer)
{
pointer.OnUIPointerElementClick(pointer.SetUIPointerEvent(
pointer.pointerEventData.pointerPressRaycast, pointer.pointerEventData.pointerPress));
if (pointer.isValidStateForClickFromHover)
if (pointer.IsValidStateForClickFromHover && !pointer.ExplicitBlockClickOnce)
{
ExecuteEvents.ExecuteHierarchy(pointer.pointerEventData.pointerPress, pointer.pointerEventData,
ExecuteEvents.pointerClickHandler);
}

pointer.ExplicitBlockClickOnce = false;

ExecuteEvents.ExecuteHierarchy(pointer.pointerEventData.pointerPress, pointer.pointerEventData,
ExecuteEvents.pointerUpHandler);
pointer.pointerEventData.pointerPress = null;
Expand Down

0 comments on commit 29a080a

Please sign in to comment.