Skip to content

Commit

Permalink
feat(ControllerEvents): provide alternative events for obsolete aliases
Browse files Browse the repository at this point in the history
The Controller Events button alias events were deprecated but there
were no alternatives for these events.

The relevant scripts now emit a controller event which will replace
these obsolete alias events.

Any public bool that was used for an alias state has also been
replicated in the relevant script.

All obsolete messages now provide a message which denotes what the
alternative method or parameter should be used.
  • Loading branch information
thestonefox committed Apr 1, 2017
1 parent c70df31 commit ea7ba80
Show file tree
Hide file tree
Showing 13 changed files with 456 additions and 52 deletions.
16 changes: 8 additions & 8 deletions Assets/VRTK/Examples/ExampleResources/Scripts/Controller_Hand.cs
Expand Up @@ -22,10 +22,10 @@ public enum Hands

private void Start()
{
GetComponentInParent<VRTK_InteractGrab>().ControllerGrabInteractableObject += DoGrabOn;
GetComponentInParent<VRTK_InteractGrab>().ControllerUngrabInteractableObject += DoGrabOff;
GetComponentInParent<VRTK_InteractUse>().ControllerUseInteractableObject += DoUseOn;
GetComponentInParent<VRTK_InteractUse>().ControllerUnuseInteractableObject += DoUseOff;
GetComponentInParent<VRTK_InteractGrab>().GrabButtonPressed += DoGrabOn;
GetComponentInParent<VRTK_InteractGrab>().GrabButtonReleased += DoGrabOff;
GetComponentInParent<VRTK_InteractUse>().UseButtonPressed += DoUseOn;
GetComponentInParent<VRTK_InteractUse>().UseButtonReleased += DoUseOff;

var handContainer = "ModelPieces";
pointerFinger = transform.Find(handContainer + "/PointerFingerContainer");
Expand All @@ -52,22 +52,22 @@ private void InversePosition(Transform givenTransform)
givenTransform.localEulerAngles = new Vector3(givenTransform.localEulerAngles.x, givenTransform.localEulerAngles.y * -1, givenTransform.localEulerAngles.z);
}

private void DoGrabOn(object sender, ObjectInteractEventArgs e)
private void DoGrabOn(object sender, ControllerInteractionEventArgs e)
{
targetGripRotation = maxRotation;
}

private void DoGrabOff(object sender, ObjectInteractEventArgs e)
private void DoGrabOff(object sender, ControllerInteractionEventArgs e)
{
targetGripRotation = originalGripRotation;
}

private void DoUseOn(object sender, ObjectInteractEventArgs e)
private void DoUseOn(object sender, ControllerInteractionEventArgs e)
{
targetPointerRotation = maxRotation;
}

private void DoUseOff(object sender, ObjectInteractEventArgs e)
private void DoUseOff(object sender, ControllerInteractionEventArgs e)
{
targetPointerRotation = originalPointerRotation;
}
Expand Down
42 changes: 27 additions & 15 deletions Assets/VRTK/Scripts/Interactions/VRTK_ControllerEvents.cs
Expand Up @@ -218,30 +218,31 @@ public enum ButtonAlias
/// This will be true if the button aliased to the pointer is held down.
/// </summary>
[HideInInspector]
[Obsolete("`VRTK_ControllerEvents.pointerPressed` is no longer used. This parameter will be removed in a future version of VRTK.")]
[Obsolete("`VRTK_ControllerEvents.pointerPressed` is no longer used, use `VRTK_Pointer.IsActivationButtonPressed()` instead. This parameter will be removed in a future version of VRTK.")]
public bool pointerPressed = false;
/// <summary>
/// This will be true if the button aliased to the grab is held down.
/// </summary>
[HideInInspector]
[Obsolete("`VRTK_ControllerEvents.grabPressed` is no longer used. This parameter will be removed in a future version of VRTK.")]
[Obsolete("`VRTK_ControllerEvents.grabPressed` is no longer used, use `VRTK_InteractGrab.IsGrabButtonPressed()` instead. This parameter will be removed in a future version of VRTK.")]
public bool grabPressed = false;
/// <summary>
/// This will be true if the button aliased to the use is held down.
/// </summary>
[HideInInspector]
[Obsolete("`VRTK_ControllerEvents.usePressed` is no longer used. This parameter will be removed in a future version of VRTK.")]
[Obsolete("`VRTK_ControllerEvents.usePressed` is no longer used, use `VRTK_InteractUse.IsUseButtonPressed()` instead. This parameter will be removed in a future version of VRTK.")]
public bool usePressed = false;
/// <summary>
/// This will be true if the button aliased to the UI click is held down.
/// </summary>
[HideInInspector]
[Obsolete("`VRTK_ControllerEvents.uiClickPressed` is no longer used. This parameter will be removed in a future version of VRTK.")]
[Obsolete("`VRTK_ControllerEvents.uiClickPressed` is no longer used, use `VRTK_UIPointer.IsSelectionButtonPressed()` instead. This parameter will be removed in a future version of VRTK.")]
public bool uiClickPressed = false;
/// <summary>
/// This will be true if the button aliased to the menu is held down.
/// </summary>
[HideInInspector]
[Obsolete("`VRTK_ControllerEvents.menuPressed` is no longer used, use `VRTK_ControllerEvents.buttonTwoPressed` instead. This parameter will be removed in a future version of VRTK.")]
public bool menuPressed = false;

/// <summary>
Expand Down Expand Up @@ -401,61 +402,61 @@ public enum ButtonAlias
/// <summary>
/// Emitted when the pointer toggle alias button is pressed.
/// </summary>
[Obsolete("`VRTK_ControllerEvents.AliasPointerOn` is no longer used. This parameter will be removed in a future version of VRTK.")]
[Obsolete("`VRTK_ControllerEvents.AliasPointerOn` has been replaced with `VRTK_Pointer.ActivationButtonPressed`. This parameter will be removed in a future version of VRTK.")]
public event ControllerInteractionEventHandler AliasPointerOn;
/// <summary>
/// Emitted when the pointer toggle alias button is released.
/// </summary>
[Obsolete("`VRTK_ControllerEvents.AliasPointerOff` is no longer used. This parameter will be removed in a future version of VRTK.")]
[Obsolete("`VRTK_ControllerEvents.AliasPointerOff` has been replaced with `VRTK_Pointer.ActivationButtonReleased`. This parameter will be removed in a future version of VRTK.")]
public event ControllerInteractionEventHandler AliasPointerOff;
/// <summary>
/// Emitted when the pointer set alias button is released.
/// </summary>
[Obsolete("`VRTK_ControllerEvents.AliasPointerSet` is no longer used. This parameter will be removed in a future version of VRTK.")]
[Obsolete("`VRTK_ControllerEvents.AliasPointerSet` has been replaced with `VRTK_Pointer.SelectionButtonReleased`. This parameter will be removed in a future version of VRTK.")]
public event ControllerInteractionEventHandler AliasPointerSet;

/// <summary>
/// Emitted when the grab toggle alias button is pressed.
/// </summary>
[Obsolete("`VRTK_ControllerEvents.AliasGrabOn` is no longer used. This parameter will be removed in a future version of VRTK.")]
[Obsolete("`VRTK_ControllerEvents.AliasGrabOn` has been replaced with `VRTK_InteractGrab.GrabButtonPressed`. This parameter will be removed in a future version of VRTK.")]
public event ControllerInteractionEventHandler AliasGrabOn;
/// <summary>
/// Emitted when the grab toggle alias button is released.
/// </summary>
[Obsolete("`VRTK_ControllerEvents.AliasGrabOff` is no longer used. This parameter will be removed in a future version of VRTK.")]
[Obsolete("`VRTK_ControllerEvents.AliasGrabOff` has been replaced with `VRTK_InteractGrab.GrabButtonReleased`. This parameter will be removed in a future version of VRTK.")]
public event ControllerInteractionEventHandler AliasGrabOff;

/// <summary>
/// Emitted when the use toggle alias button is pressed.
/// </summary>
[Obsolete("`VRTK_ControllerEvents.AliasUseOn` is no longer used. This parameter will be removed in a future version of VRTK.")]
[Obsolete("`VRTK_ControllerEvents.AliasUseOn` has been replaced with `VRTK_InteractUse.UseButtonPressed`. This parameter will be removed in a future version of VRTK.")]
public event ControllerInteractionEventHandler AliasUseOn;
/// <summary>
/// Emitted when the use toggle alias button is released.
/// </summary>
[Obsolete("`VRTK_ControllerEvents.AliasUseOff` is no longer used. This parameter will be removed in a future version of VRTK.")]
[Obsolete("`VRTK_ControllerEvents.AliasUseOff` has been replaced with `VRTK_InteractUse.UseButtonReleased`. This parameter will be removed in a future version of VRTK.")]
public event ControllerInteractionEventHandler AliasUseOff;

/// <summary>
/// Emitted when the menu toggle alias button is pressed.
/// </summary>
[Obsolete("`VRTK_ControllerEvents.AliasMenuOn` is no longer used. This parameter will be removed in a future version of VRTK.")]
[Obsolete("`VRTK_ControllerEvents.AliasMenuOn` is no longer used, use `VRTK_ControllerEvents.ButtonTwoPressed` instead. This parameter will be removed in a future version of VRTK.")]
public event ControllerInteractionEventHandler AliasMenuOn;
/// <summary>
/// Emitted when the menu toggle alias button is released.
/// </summary>
[Obsolete("`VRTK_ControllerEvents.AliasMenuOff` is no longer used. This parameter will be removed in a future version of VRTK.")]
[Obsolete("`VRTK_ControllerEvents.AliasMenuOff` is no longer used, use `VRTK_ControllerEvents.ButtonTwoReleased` instead. This parameter will be removed in a future version of VRTK.")]
public event ControllerInteractionEventHandler AliasMenuOff;

/// <summary>
/// Emitted when the UI click alias button is pressed.
/// </summary>
[Obsolete("`VRTK_ControllerEvents.AliasUIClickOn` is no longer used. This parameter will be removed in a future version of VRTK.")]
[Obsolete("`VRTK_ControllerEvents.AliasUIClickOn` has been replaced with `VRTK_UIPointer.SelectionButtonPressed`. This parameter will be removed in a future version of VRTK.")]
public event ControllerInteractionEventHandler AliasUIClickOn;
/// <summary>
/// Emitted when the UI click alias button is released.
/// </summary>
[Obsolete("`VRTK_ControllerEvents.AliasUIClickOff` is no longer used. This parameter will be removed in a future version of VRTK.")]
[Obsolete("`VRTK_ControllerEvents.AliasUIClickOff` has been replaced with `VRTK_UIPointer.SelectionButtonReleased`. This parameter will be removed in a future version of VRTK.")]
public event ControllerInteractionEventHandler AliasUIClickOff;

/// <summary>
Expand Down Expand Up @@ -750,6 +751,7 @@ public virtual void OnStartMenuReleased(ControllerInteractionEventArgs e)
}
}

[Obsolete("`VRTK_ControllerEvents.OnAliasPointerOn` has been replaced with `VRTK_Pointer.OnActivationButtonPressed`. This method will be removed in a future version of VRTK.")]
public virtual void OnAliasPointerOn(ControllerInteractionEventArgs e)
{
if (AliasPointerOn != null)
Expand All @@ -758,6 +760,7 @@ public virtual void OnAliasPointerOn(ControllerInteractionEventArgs e)
}
}

[Obsolete("`VRTK_ControllerEvents.OnAliasPointerOff` has been replaced with `VRTK_Pointer.OnActivationButtonReleased`. This method will be removed in a future version of VRTK.")]
public virtual void OnAliasPointerOff(ControllerInteractionEventArgs e)
{
if (AliasPointerOff != null)
Expand All @@ -766,6 +769,7 @@ public virtual void OnAliasPointerOff(ControllerInteractionEventArgs e)
}
}

[Obsolete("`VRTK_ControllerEvents.OnAliasPointerSet` has been replaced with `VRTK_Pointer.OnSelectionButtonReleased`. This method will be removed in a future version of VRTK.")]
public virtual void OnAliasPointerSet(ControllerInteractionEventArgs e)
{
if (AliasPointerSet != null)
Expand All @@ -774,6 +778,7 @@ public virtual void OnAliasPointerSet(ControllerInteractionEventArgs e)
}
}

[Obsolete("`VRTK_ControllerEvents.OnAliasGrabOn` has been replaced with `VRTK_InteractGrab.OnGrabButtonPressed`. This method will be removed in a future version of VRTK.")]
public virtual void OnAliasGrabOn(ControllerInteractionEventArgs e)
{
if (AliasGrabOn != null)
Expand All @@ -782,6 +787,7 @@ public virtual void OnAliasGrabOn(ControllerInteractionEventArgs e)
}
}

[Obsolete("`VRTK_ControllerEvents.OnAliasGrabOff` has been replaced with `VRTK_InteractGrab.OnGrabButtonReleased`. This method will be removed in a future version of VRTK.")]
public virtual void OnAliasGrabOff(ControllerInteractionEventArgs e)
{
if (AliasGrabOff != null)
Expand All @@ -790,6 +796,7 @@ public virtual void OnAliasGrabOff(ControllerInteractionEventArgs e)
}
}

[Obsolete("`VRTK_ControllerEvents.OnAliasUseOn` has been replaced with `VRTK_InteractUse.OnUseButtonPressed`. This method will be removed in a future version of VRTK.")]
public virtual void OnAliasUseOn(ControllerInteractionEventArgs e)
{
if (AliasUseOn != null)
Expand All @@ -798,6 +805,7 @@ public virtual void OnAliasUseOn(ControllerInteractionEventArgs e)
}
}

[Obsolete("`VRTK_ControllerEvents.OnAliasUseOff` has been replaced with `VRTK_InteractUse.OnUseButtonReleased`. This method will be removed in a future version of VRTK.")]
public virtual void OnAliasUseOff(ControllerInteractionEventArgs e)
{
if (AliasUseOff != null)
Expand All @@ -806,6 +814,7 @@ public virtual void OnAliasUseOff(ControllerInteractionEventArgs e)
}
}

[Obsolete("`VRTK_ControllerEvents.OnAliasUIClickOn` has been replaced with `VRTK_UIPointer.OnSelectionButtonPressed`. This method will be removed in a future version of VRTK.")]
public virtual void OnAliasUIClickOn(ControllerInteractionEventArgs e)
{
if (AliasUIClickOn != null)
Expand All @@ -814,6 +823,7 @@ public virtual void OnAliasUIClickOn(ControllerInteractionEventArgs e)
}
}

[Obsolete("`VRTK_ControllerEvents.OnAliasUIClickOff` has been replaced with `VRTK_UIPointer.OnSelectionButtonReleased`. This method will be removed in a future version of VRTK.")]
public virtual void OnAliasUIClickOff(ControllerInteractionEventArgs e)
{
if (AliasUIClickOff != null)
Expand All @@ -822,6 +832,7 @@ public virtual void OnAliasUIClickOff(ControllerInteractionEventArgs e)
}
}

[Obsolete("`VRTK_ControllerEvents.OnAliasMenuOn` has been replaced with `VRTK_ControllerEvents.OnButtonTwoPressed`. This method will be removed in a future version of VRTK.")]
public virtual void OnAliasMenuOn(ControllerInteractionEventArgs e)
{
if (AliasMenuOn != null)
Expand All @@ -830,6 +841,7 @@ public virtual void OnAliasMenuOn(ControllerInteractionEventArgs e)
}
}

[Obsolete("`VRTK_ControllerEvents.OnAliasMenuOff` has been replaced with `VRTK_ControllerEvents.OnButtonTwoReleased`. This method will be removed in a future version of VRTK.")]
public virtual void OnAliasMenuOff(ControllerInteractionEventArgs e)
{
if (AliasMenuOff != null)
Expand Down
29 changes: 27 additions & 2 deletions Assets/VRTK/Scripts/Interactions/VRTK_InteractGrab.cs
Expand Up @@ -48,6 +48,15 @@ public class VRTK_InteractGrab : MonoBehaviour
[Tooltip("The Interact Touch to listen for touches on. If the script is being applied onto a controller then this parameter can be left blank as it will be auto populated by the controller the script is on at runtime.")]
public VRTK_InteractTouch interactTouch;

/// <summary>
/// Emitted when the grab button is pressed.
/// </summary>
public event ControllerInteractionEventHandler GrabButtonPressed;
/// <summary>
/// Emitted when the grab button is released.
/// </summary>
public event ControllerInteractionEventHandler GrabButtonReleased;

/// <summary>
/// Emitted when a valid object is grabbed.
/// </summary>
Expand Down Expand Up @@ -83,6 +92,22 @@ public virtual void OnControllerUngrabInteractableObject(ObjectInteractEventArgs
}
}

public virtual void OnGrabButtonPressed(ControllerInteractionEventArgs e)
{
if (GrabButtonPressed != null)
{
GrabButtonPressed(this, e);
}
}

public virtual void OnGrabButtonReleased(ControllerInteractionEventArgs e)
{
if (GrabButtonReleased != null)
{
GrabButtonReleased(this, e);
}
}

/// <summary>
/// The IsGrabButtonPressed method determines whether the current grab alias button is being pressed down.
/// </summary>
Expand Down Expand Up @@ -479,14 +504,14 @@ protected virtual void AttemptReleaseObject()

protected virtual void DoGrabObject(object sender, ControllerInteractionEventArgs e)
{
grabPressed = true;
OnGrabButtonPressed(controllerEvents.SetControllerEvent(ref grabPressed, true));
AttemptGrabObject();
}

protected virtual void DoReleaseObject(object sender, ControllerInteractionEventArgs e)
{
AttemptReleaseObject();
grabPressed = false;
OnGrabButtonReleased(controllerEvents.SetControllerEvent(ref grabPressed, false));
}

protected virtual void CheckControllerAttachPointSet()
Expand Down
29 changes: 27 additions & 2 deletions Assets/VRTK/Scripts/Interactions/VRTK_InteractUse.cs
Expand Up @@ -36,6 +36,15 @@ public class VRTK_InteractUse : MonoBehaviour
[Tooltip("The Interact Grab to listen for grab actions on. If the script is being applied onto a controller then this parameter can be left blank as it will be auto populated by the controller the script is on at runtime.")]
public VRTK_InteractGrab interactGrab;

/// <summary>
/// Emitted when the use toggle alias button is pressed.
/// </summary>
public event ControllerInteractionEventHandler UseButtonPressed;
/// <summary>
/// Emitted when the use toggle alias button is released.
/// </summary>
public event ControllerInteractionEventHandler UseButtonReleased;

/// <summary>
/// Emitted when a valid object starts being used.
/// </summary>
Expand Down Expand Up @@ -67,6 +76,22 @@ public virtual void OnControllerUnuseInteractableObject(ObjectInteractEventArgs
}
}

public virtual void OnUseButtonPressed(ControllerInteractionEventArgs e)
{
if (UseButtonPressed != null)
{
UseButtonPressed(this, e);
}
}

public virtual void OnUseButtonReleased(ControllerInteractionEventArgs e)
{
if (UseButtonReleased != null)
{
UseButtonReleased(this, e);
}
}

/// <summary>
/// The IsUsebuttonPressed method determines whether the current use alias button is being pressed down.
/// </summary>
Expand Down Expand Up @@ -340,7 +365,7 @@ protected virtual void AttemptUseObject()

protected virtual void DoStartUseObject(object sender, ControllerInteractionEventArgs e)
{
usePressed = true;
OnUseButtonPressed(controllerEvents.SetControllerEvent(ref usePressed, true));
AttemptUseObject();
}

Expand All @@ -350,7 +375,7 @@ protected virtual void DoStopUseObject(object sender, ControllerInteractionEvent
{
StopUsing();
}
usePressed = false;
OnUseButtonReleased(controllerEvents.SetControllerEvent(ref usePressed, false));
}
}
}
2 changes: 1 addition & 1 deletion Assets/VRTK/Scripts/Internal/VRTK_VRInputModule.cs
Expand Up @@ -260,7 +260,7 @@ protected virtual bool AttemptClick(VRTK_UIPointer pointer)

protected virtual void Drag(VRTK_UIPointer pointer, List<RaycastResult> results)
{
pointer.pointerEventData.dragging = pointer.SelectionButtonActive() && pointer.pointerEventData.delta != Vector2.zero;
pointer.pointerEventData.dragging = pointer.IsSelectionButtonPressed() && pointer.pointerEventData.delta != Vector2.zero;

if (pointer.pointerEventData.pointerDrag)
{
Expand Down

0 comments on commit ea7ba80

Please sign in to comment.