98 lines
3.3 KiB
C#
Raw Blame History

using _PROJECT.NewHandPresence;
using System.Collections;
using System.Collections.Generic;
using Unity.XR.CoreUtils;
using UnityEngine;
using UnityEngine.XR.Content.Interaction;
using UnityEngine.XR.Interaction.Toolkit;
public class PassangerSeat : LocomotionProvider
{
// Start is called before the first frame update
public GameObject ExitSpot;
public CarTeleportButton ExitButton;
private XROrigin currentPassanger;
private LocomotionSystem currentPlayerLocomotion;
void Start()
{
}
public void activateButtonPush(XROrigin player, CarTeleportButton button)
{
if (button == ExitButton) ExitCar();
else EnterCar(player);
}
public void EnterCar(XROrigin player)
{
if (player == null || currentPassanger != null) return;
TutorialController cameraChild = player.GetComponentInChildren<TutorialController>();
//TunnelingVignetteController vignetteController = player.GetComponentInChildren<TunnelingVignetteController>();
//LocomotionVignetteProvider vignetteProvider = player.GetComponentInChildren<LocomotionVignetteProvider>();
if (cameraChild == null) return;
Transform cameraTransform = cameraChild.transform.parent.transform;
Vector3 cameraShift = cameraTransform.localPosition;
currentPassanger = player;
player.transform.SetParent(this.transform);
player.transform.localPosition = -cameraShift;
player.transform.localRotation = Quaternion.identity;
cameraTransform.localRotation = this.transform.rotation;
BeginLocomotion();
disablePlayerLocomotion(player);
}
private void disablePlayerLocomotion(XROrigin player)
{
Menu menu = player.GetComponentInChildren<Menu>();
if (menu == null) return;
menu.DeactivateMenu();
LocomotionSystem locomotion = player.GetComponentInChildren<LocomotionSystem>();
currentPlayerLocomotion = locomotion;
//if (locomotion == null) return;
Debug.Log("LocomotionSystem of: " + locomotion + " disabled");
locomotion.gameObject.SetActive(false);
}
public void ExitCar()
{
if (currentPassanger == null) return;
EndLocomotion();
enablePlayerLocomotion(currentPassanger);
TutorialController cameraChild = currentPassanger.GetComponentInChildren<TutorialController>();
if (cameraChild == null) return;
Transform cameraTransform = cameraChild.transform.parent.transform;
// Set the player<65>s parent to null (making it part of the scene hierarchy)
currentPassanger.transform.SetParent(null);
// Put the player outside;
currentPassanger.transform.localPosition = ExitSpot.transform.position;
cameraTransform.rotation = ExitSpot.transform.rotation;
currentPassanger = null;
}
private void enablePlayerLocomotion(XROrigin player)
{
Menu menu = player.GetComponentInChildren<Menu>();
//if (menu == null) return;
menu.ReactivateMenu();
//LocomotionSystem locomotion = player.GetComponentInChildren<LocomotionSystem>();
//if (locomotion == null) return;
currentPlayerLocomotion.gameObject.SetActive(true);
}
// Update is called once per frame
void Update()
{
}
}