Files
DeltaVR/Assets/_PROJECT/Components/Bolt/Intercation Logic/Passanger Seat.cs
T

94 lines
3.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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 : MonoBehaviour
{
// Start is called before the first frame update
public TeleportLocation 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>();
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;
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;
enablePlayerLocomotion(currentPassanger);
TutorialController cameraChild = currentPassanger.GetComponentInChildren<TutorialController>();
if (cameraChild == null) return;
Transform cameraTransform = cameraChild.transform.parent.transform;
// Set the players parent to null (making it part of the scene hierarchy)
currentPassanger.transform.SetParent(null);
// Put the player outside;
currentPassanger.transform.localPosition = ExitSpot.transform.localPosition;
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()
{
}
}