Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Controller): add event for action of toggling visibility
The Controller Actions script now emits events when the visibility of the controller is toggled. When the visibility is toggled on then the: `ControllerModelVisible` event is emitted. When the visibility is toggled off then the: `ControllerModelInvisible` event is emitted.
- Loading branch information
1 parent
e89f780
commit 574f2a4
Showing
4 changed files
with
151 additions
and
1 deletion.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
Assets/VRTK/Scripts/Helper/UnityEvents/VRTK_ControllerActions_UnityEvents.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
namespace VRTK.UnityEventHelper | ||
{ | ||
using UnityEngine; | ||
using UnityEngine.Events; | ||
|
||
[RequireComponent(typeof(VRTK_ControllerActions))] | ||
public class VRTK_ControllerActions_UnityEvents : MonoBehaviour | ||
{ | ||
private VRTK_ControllerActions ca; | ||
|
||
[System.Serializable] | ||
public class UnityObjectEvent : UnityEvent<ControllerActionsEventArgs> { }; | ||
|
||
/// <summary> | ||
/// Emits the ControllerModelVisible class event. | ||
/// </summary> | ||
public UnityObjectEvent OnControllerModelVisible; | ||
/// <summary> | ||
/// Emits the ControllerModelInvisible class event. | ||
/// </summary> | ||
public UnityObjectEvent OnControllerModelInvisible; | ||
|
||
private void SetControllerAction() | ||
{ | ||
if (ca == null) | ||
{ | ||
ca = GetComponent<VRTK_ControllerActions>(); | ||
} | ||
} | ||
|
||
private void OnEnable() | ||
{ | ||
SetControllerAction(); | ||
if (ca == null) | ||
{ | ||
Debug.LogError("The VRTK_ControllerActions_UnityEvents script requires to be attached to a GameObject that contains a VRTK_ControllerActions script"); | ||
return; | ||
} | ||
|
||
ca.ControllerModelVisible += ControllerModelVisible; | ||
ca.ControllerModelInvisible += ControllerModelInvisible; | ||
} | ||
|
||
private void ControllerModelVisible(object o, ControllerActionsEventArgs e) | ||
{ | ||
OnControllerModelVisible.Invoke(e); | ||
} | ||
|
||
private void ControllerModelInvisible(object o, ControllerActionsEventArgs e) | ||
{ | ||
OnControllerModelInvisible.Invoke(e); | ||
} | ||
|
||
private void OnDisable() | ||
{ | ||
if (ca == null) | ||
{ | ||
return; | ||
} | ||
|
||
ca.ControllerModelVisible -= ControllerModelVisible; | ||
ca.ControllerModelInvisible -= ControllerModelInvisible; | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
Assets/VRTK/Scripts/Helper/UnityEvents/VRTK_ControllerActions_UnityEvents.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters