changed xrscroll to inherit baseinteractable

This commit is contained in:
Abraham Blain 2023-11-14 14:53:07 -05:00
parent 21bffe68b7
commit 18b2466551
2 changed files with 21 additions and 24 deletions

View File

@ -1010,7 +1010,6 @@ GameObject:
- component: {fileID: 1093779681373943276}
- component: {fileID: 4409523614097131505}
- component: {fileID: 4925728291234476624}
- component: {fileID: 69090921926065725}
- component: {fileID: 5460423599094637711}
- component: {fileID: 5216593285795032141}
m_Layer: 0
@ -1128,7 +1127,7 @@ MonoBehaviour:
m_EnablePokeAngleThreshold: 1
m_PokeAngleThreshold: 45
m_Variable: {fileID: 0}
--- !u!114 &69090921926065725
--- !u!114 &5460423599094637711
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
@ -1137,7 +1136,7 @@ MonoBehaviour:
m_GameObject: {fileID: 2435604583881702577}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 8a35f6cfbfba9b548aaa00d52cfe8a50, type: 3}
m_Script: {fileID: 11500000, guid: 3647f60f096e78e428aa74212dd78d08, type: 3}
m_Name:
m_EditorClassIdentifier:
m_InteractionManager: {fileID: 0}
@ -1254,18 +1253,6 @@ MonoBehaviour:
m_OnDeactivate:
m_PersistentCalls:
m_Calls: []
--- !u!114 &5460423599094637711
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2435604583881702577}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 3647f60f096e78e428aa74212dd78d08, type: 3}
m_Name:
m_EditorClassIdentifier:
scrollAxis: {x: 0, y: 1, z: 0}
scrollScale: 1000
scrollUpdated:

View File

@ -1,3 +1,4 @@
using System;
using System.Collections;
using TMPro;
using UnityEngine;
@ -6,27 +7,36 @@ using UnityEngine.XR.Interaction.Toolkit;
namespace Interactions
{
public class XRScroll : MonoBehaviour
public class XRScroll : XRBaseInteractable
{
private bool isHovering;
private bool isTracking;
[SerializeField] private Vector3 scrollAxis = Vector3.up;
[SerializeField] private float scrollScale = 1000;
public UnityEvent<float> scrollUpdated;
public void OnSelected(SelectEnterEventArgs args)
protected override void OnDisable()
{
StartCoroutine(Hovering(args.interactorObject.transform));
base.OnDisable();
isTracking = false;
StopAllCoroutines();
}
private IEnumerator Hovering(Transform mover)
public void OnSelected(SelectEnterEventArgs args)
{
if (isHovering) yield break;
isHovering = true;
StartCoroutine(TrackScrolling(args.interactorObject.transform));
}
private IEnumerator TrackScrolling(Transform mover)
{
if (isTracking) yield break;
isTracking = true;
Vector3 previousPos = mover.position;
while (isHovering)
while (isTracking)
{
yield return null;
@ -44,7 +54,7 @@ namespace Interactions
public void OnUnSelected(SelectExitEventArgs args)
{
isHovering = false;
isTracking = false;
}