-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding components for visual feedback on HPUI
- Loading branch information
1 parent
4f15885
commit a56ab02
Showing
5 changed files
with
198 additions
and
0 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.
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,87 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using UnityEngine; | ||
using UnityEngine.XR.Interaction.Toolkit; | ||
using UnityEngine.XR.Interaction.Toolkit.Interactors; | ||
using UnityEngine.XR.Interaction.Toolkit.Interactables; | ||
using UnityEngine.XR.Interaction.Toolkit.Utilities; | ||
using UnityEngine.XR.Hands; | ||
using Unity.XR.CoreUtils; | ||
using UnityEngine.Pool; | ||
using ubco.ovilab.HPUI.Interaction; | ||
|
||
namespace ubco.ovilab.HPUI.Components | ||
{ | ||
public class HPUIInteractorLRVisual: MonoBehaviour | ||
{ | ||
[SerializeField, Tooltip("The line renderer object to manage")] | ||
private LineRenderer lineRenderer; | ||
|
||
[SerializeField, Tooltip("The target interactor for event to subscribe to")] | ||
private HPUIInteractor hpuiInteractor; | ||
|
||
/// <inheritdoc /> | ||
private void OnEnable() | ||
{ | ||
if (hpuiInteractor == null) | ||
{ | ||
hpuiInteractor = GetComponent<HPUIInteractor>(); | ||
} | ||
|
||
if (lineRenderer == null) | ||
{ | ||
lineRenderer = gameObject.AddComponent<LineRenderer>(); | ||
} | ||
|
||
if (hpuiInteractor != null) | ||
{ | ||
hpuiInteractor.HoverUpdateEvent.AddListener(OnHoverUpdate); | ||
hpuiInteractor.hoverEntered.AddListener(OnHoverEntered); | ||
hpuiInteractor.hoverExited.AddListener(OnHoverExited); | ||
} | ||
} | ||
|
||
/// <inheritdoc /> | ||
private void OnDisable() | ||
{ | ||
if (hpuiInteractor != null) | ||
{ | ||
hpuiInteractor.HoverUpdateEvent.RemoveListener(OnHoverUpdate); | ||
hpuiInteractor.hoverEntered.RemoveListener(OnHoverEntered); | ||
hpuiInteractor.hoverExited.RemoveListener(OnHoverExited); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Callback for <see cref="HPUIInteractor.HoverUpdateEvent"/> | ||
/// </summary> | ||
private void OnHoverUpdate(HPUIHoverUpdateEventArgs arg) | ||
{ | ||
lineRenderer.SetPosition(0, arg.attachPoint); | ||
lineRenderer.SetPosition(1, arg.hoverPoint); | ||
} | ||
|
||
/// <summary> | ||
/// Callback for <see cref="HPUIInteractor.hoverEntered"/> | ||
/// </summary> | ||
private void OnHoverEntered(HoverEnterEventArgs args) | ||
{ | ||
if (lineRenderer != null) | ||
{ | ||
lineRenderer.enabled = true; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Callback for <see cref="HPUIInteractor.hoverExited"/> | ||
/// </summary> | ||
private void OnHoverExited(HoverExitEventArgs args) | ||
{ | ||
if (lineRenderer != null) | ||
{ | ||
lineRenderer.enabled = false; | ||
} | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using UnityEngine; | ||
using UnityEngine.XR.Interaction.Toolkit; | ||
using UnityEngine.XR.Interaction.Toolkit.Interactors; | ||
using UnityEngine.XR.Interaction.Toolkit.Interactables; | ||
using UnityEngine.XR.Interaction.Toolkit.Utilities; | ||
using UnityEngine.XR.Hands; | ||
using Unity.XR.CoreUtils; | ||
using UnityEngine.Pool; | ||
using ubco.ovilab.HPUI.Interaction; | ||
|
||
namespace ubco.ovilab.HPUI.Components | ||
{ | ||
public class HPUIInteractorTransformVisual: MonoBehaviour | ||
{ | ||
[SerializeField, Tooltip("The line renderer object to manage")] | ||
private Transform visualTransform; | ||
|
||
[SerializeField, Tooltip("The target interactor for event to subscribe to")] | ||
private HPUIInteractor hpuiInteractor; | ||
|
||
/// <inheritdoc /> | ||
private void OnEnable() | ||
{ | ||
if (hpuiInteractor == null) | ||
{ | ||
hpuiInteractor = GetComponent<HPUIInteractor>(); | ||
} | ||
|
||
if (hpuiInteractor != null) | ||
{ | ||
hpuiInteractor.HoverUpdateEvent.AddListener(OnHoverUpdate); | ||
hpuiInteractor.hoverEntered.AddListener(OnHoverEntered); | ||
hpuiInteractor.hoverExited.AddListener(OnHoverExited); | ||
} | ||
} | ||
|
||
/// <inheritdoc /> | ||
private void OnDisable() | ||
{ | ||
if (hpuiInteractor != null) | ||
{ | ||
hpuiInteractor.HoverUpdateEvent.RemoveListener(OnHoverUpdate); | ||
hpuiInteractor.hoverEntered.RemoveListener(OnHoverEntered); | ||
hpuiInteractor.hoverExited.RemoveListener(OnHoverExited); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Callback for <see cref="HPUIInteractor.HoverUpdateEvent"/> | ||
/// </summary> | ||
private void OnHoverUpdate(HPUIHoverUpdateEventArgs arg) | ||
{ | ||
visualTransform.position = arg.hoverPoint; | ||
} | ||
|
||
/// <summary> | ||
/// Callback for <see cref="HPUIInteractor.hoverEntered"/> | ||
/// </summary> | ||
private void OnHoverEntered(HoverEnterEventArgs args) | ||
{ | ||
if (visualTransform != null) | ||
{ | ||
visualTransform.gameObject.SetActive(true); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Callback for <see cref="HPUIInteractor.hoverExited"/> | ||
/// </summary> | ||
private void OnHoverExited(HoverExitEventArgs args) | ||
{ | ||
if (visualTransform != null) | ||
{ | ||
visualTransform.gameObject.SetActive(false); | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.