-
-
Notifications
You must be signed in to change notification settings - Fork 992
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Interaction): add helper for interaction unity events
- Loading branch information
Jonathan Schenker
committed
Aug 25, 2016
1 parent
a713b98
commit 7a9ab9b
Showing
4 changed files
with
118 additions
and
16 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
70 changes: 70 additions & 0 deletions
70
Assets/VRTK/Scripts/Helper/UnityEvents/VRTK_InteractableObject_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,70 @@ | ||
using UnityEngine; | ||
using System.Collections; | ||
using UnityEngine.Events; | ||
using VRTK; | ||
|
||
[RequireComponent (typeof(VRTK_InteractableObject))] | ||
public class VRTK_InteractableObject_UnityEvents : MonoBehaviour | ||
{ | ||
|
||
private VRTK_InteractableObject io; | ||
|
||
[System.Serializable] | ||
public class UnityObjectEvent: UnityEvent<GameObject> {}; | ||
public UnityObjectEvent OnTouch; | ||
public UnityObjectEvent OnUntouch; | ||
public UnityObjectEvent OnGrab; | ||
public UnityObjectEvent OnUngrab; | ||
public UnityObjectEvent OnUse; | ||
public UnityObjectEvent OnUnuse; | ||
|
||
private void OnEnable () | ||
{ | ||
io.InteractableObjectTouched += Touch; | ||
io.InteractableObjectUntouched += UnTouch; | ||
io.InteractableObjectGrabbed += Grab; | ||
io.InteractableObjectUngrabbed += UnGrab; | ||
io.InteractableObjectUsed += Use; | ||
io.InteractableObjectUnused += Unuse; | ||
} | ||
|
||
private void Touch(object o, InteractableObjectEventArgs e) | ||
{ | ||
OnTouch.Invoke(e.interactingObject); | ||
} | ||
|
||
private void UnTouch(object o, InteractableObjectEventArgs e) | ||
{ | ||
OnUntouch.Invoke(e.interactingObject); | ||
} | ||
|
||
private void Grab(object o, InteractableObjectEventArgs e) | ||
{ | ||
OnGrab.Invoke(e.interactingObject); | ||
} | ||
|
||
private void UnGrab(object o, InteractableObjectEventArgs e) | ||
{ | ||
OnUngrab.Invoke(e.interactingObject); | ||
} | ||
|
||
private void Use(object o, InteractableObjectEventArgs e) | ||
{ | ||
OnUse.Invoke(e.interactingObject); | ||
} | ||
|
||
private void Unuse(object o, InteractableObjectEventArgs e) | ||
{ | ||
OnUnuse.Invoke(e.interactingObject); | ||
} | ||
|
||
private void OnDisable () | ||
{ | ||
io.InteractableObjectTouched -= Touch; | ||
io.InteractableObjectUntouched -= UnTouch; | ||
io.InteractableObjectGrabbed -= Grab; | ||
io.InteractableObjectUngrabbed -= UnGrab; | ||
io.InteractableObjectUsed -= Use; | ||
io.InteractableObjectUnused -= Unuse; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
Assets/VRTK/Scripts/Helper/UnityEvents/VRTK_InteractableObject_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