Skip to content

Commit

Permalink
Allow button and toggle interaction via grab (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
FejZa authored Jul 16, 2024
1 parent 7278338 commit 94f09f1
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 8 deletions.
26 changes: 22 additions & 4 deletions Runtime/Input/InteractionBehaviours/ButtonBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,36 @@ public class ButtonClickEvent : UnityEvent { }
public ButtonClickEvent Click => click;

/// <inheritdoc/>
protected override void OnSelectEntered(InteractionEventArgs eventArgs)
protected override void OnFirstSelectEntered(InteractionEventArgs eventArgs)
{
if (raiseOnInputDown)
if (raiseOnInputDown && !Interactable.IsGrabbed)
{
Click?.Invoke();
}
}

/// <inheritdoc/>
protected override void OnSelectExited(InteractionExitEventArgs eventArgs)
protected override void OnLastSelectExited(InteractionExitEventArgs eventArgs)
{
if (!raiseOnInputDown)
if (!raiseOnInputDown && !Interactable.IsGrabbed)
{
Click?.Invoke();
}
}

/// <inheritdoc/>
protected override void OnFirstGrabEntered(InteractionEventArgs eventArgs)
{
if (raiseOnInputDown && !Interactable.IsSelected)
{
Click?.Invoke();
}
}

/// <inheritdoc/>
protected override void OnLastGrabExited(InteractionExitEventArgs eventArgs)
{
if (!raiseOnInputDown && !Interactable.IsSelected)
{
Click?.Invoke();
}
Expand Down
26 changes: 22 additions & 4 deletions Runtime/Input/InteractionBehaviours/ToggleBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,36 @@ public bool IsOn
public void SetIsOnWithoutNotify(bool isOn) => this.isOn = isOn;

/// <inheritdoc/>
protected override void OnSelectEntered(InteractionEventArgs eventArgs)
protected override void OnFirstSelectEntered(InteractionEventArgs eventArgs)
{
if (raiseOnInputDown)
if (raiseOnInputDown && !Interactable.IsGrabbed)
{
IsOn = !IsOn;
}
}

/// <inheritdoc/>
protected override void OnSelectExited(InteractionExitEventArgs eventArgs)
protected override void OnLastSelectExited(InteractionExitEventArgs eventArgs)
{
if (!raiseOnInputDown)
if (!raiseOnInputDown && !Interactable.IsGrabbed)
{
IsOn = !IsOn;
}
}

/// <inheritdoc/>
protected override void OnFirstGrabEntered(InteractionEventArgs eventArgs)
{
if (raiseOnInputDown && !Interactable.IsSelected)
{
IsOn = !IsOn;
}
}

/// <inheritdoc/>
protected override void OnLastGrabExited(InteractionExitEventArgs eventArgs)
{
if (!raiseOnInputDown && !Interactable.IsSelected)
{
IsOn = !IsOn;
}
Expand Down

0 comments on commit 94f09f1

Please sign in to comment.