using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
//Allows us to use the Input System to get values for the thumbstick
|
using UnityEngine.InputSystem;
|
using UnityEngine.XR.Interaction.Toolkit;
|
|
public class TeleportationManager : MonoBehaviour
|
{
|
static private bool _teleportIsActive = false;
|
|
public enum ControllerType
|
{
|
RightHand,
|
LeftHand
|
}
|
|
public ControllerType targetController;
|
|
public InputActionAsset inputAction;
|
|
public XRRayInteractor rayInteractor;
|
|
public TeleportationProvider teleportationProvider;
|
|
private InputAction _thumbstickInputAction;
|
|
private InputAction _teleportActivate;
|
|
private InputAction _teleportCancel;
|
|
void Start()
|
{
|
rayInteractor.enabled = false;
|
|
Debug.Log("XRI " + targetController.ToString());
|
_teleportActivate = inputAction.FindActionMap("XRI " + targetController.ToString() + " Locomotion").FindAction("Teleport Mode Activate");
|
_teleportActivate.Enable();
|
//_teleportActivate.performed += OnTeleportActivate;
|
|
_teleportCancel = inputAction.FindActionMap("XRI " + targetController.ToString() + " Locomotion" ).FindAction("Teleport Mode Cancel");
|
_teleportCancel.Enable();
|
_teleportCancel.performed += OnTeleportCancel;
|
|
_thumbstickInputAction = inputAction.FindActionMap("XRI " + targetController.ToString() + " Locomotion").FindAction("Move");
|
_thumbstickInputAction.Enable();
|
}
|
|
private void OnDestroy()
|
{
|
_teleportActivate.performed -= OnTeleportActivate;
|
_teleportCancel.performed -= OnTeleportCancel;
|
}
|
void Update()
|
{
|
Debug.Log(_teleportIsActive);
|
if (!_teleportIsActive)
|
{
|
return;
|
}
|
if (!rayInteractor.enabled)
|
{
|
return;
|
}
|
|
//if (!rayInteractor.TryGetCurrent3DRaycastHit(out RaycastHit raycastHit))
|
//{
|
// rayInteractor.enabled = false;
|
// _teleportIsActive = false;
|
// return;
|
//}
|
|
//TeleportRequest teleportRequest = new TeleportRequest()
|
//{
|
// destinationPosition = raycastHit.point,
|
//};
|
|
//teleportationProvider.QueueTeleportRequest(teleportRequest);
|
|
//rayInteractor.enabled = false;
|
//_teleportIsActive = false;
|
}
|
|
public void ActivateRayInteractor()
|
{
|
|
rayInteractor.enabled = true;
|
|
|
}
|
|
|
|
private void OnTeleportActivate(InputAction.CallbackContext context)
|
{
|
if (!_teleportIsActive)
|
{
|
rayInteractor.enabled = true;
|
_teleportIsActive = true;
|
}
|
|
}
|
|
|
|
private void OnTeleportCancel(InputAction.CallbackContext context)
|
{
|
if ( rayInteractor.enabled == true)
|
{
|
rayInteractor.enabled = false;
|
_teleportIsActive = false;
|
}
|
|
}
|
}
|