finished portal fundimentals
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.XR.Interaction.Toolkit;
|
||||
|
||||
public class GravityHandler : MonoBehaviour
|
||||
{
|
||||
public InputActionReference teleportAction;
|
||||
public XRInteractorLineVisual TeleportRayLine;
|
||||
public ActionBasedContinuousMoveProvider defaultGravity;
|
||||
public bool isInSpace = false;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
teleportAction.action.Enable();
|
||||
teleportAction.action.performed += OnTeleport;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (isInSpace)
|
||||
{
|
||||
defaultGravity.useGravity = false; // Disable default gravity
|
||||
}
|
||||
else
|
||||
{
|
||||
defaultGravity.useGravity = true; // Enable default gravity
|
||||
Physics.gravity = Vector3.down * 9.81f; // Reset to normal gravity
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTeleport(InputAction.CallbackContext context)
|
||||
{
|
||||
if (isInSpace)
|
||||
{
|
||||
Quaternion newRotation = TeleportRayLine.reticle.transform.rotation;
|
||||
Debug.Log("Teleport detected! Adjusting gravity... New rotation is: " + newRotation.eulerAngles);
|
||||
//AdjustGravity(newRotation);
|
||||
}
|
||||
}
|
||||
|
||||
public void AdjustGravity(Quaternion rotation)
|
||||
{
|
||||
Vector3 newGravityDirection = rotation * Vector3.down; // Rotate gravity based on teleport direction
|
||||
Physics.gravity = newGravityDirection.normalized * Physics.gravity.magnitude;
|
||||
|
||||
Debug.Log("New Gravity: " + Physics.gravity);
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
teleportAction.action.Disable();
|
||||
teleportAction.action.performed -= OnTeleport;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9cdab728e7f1bc945ae623a3e5cc1645
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -15,9 +15,11 @@ public class MenuTeleportButton : MonoBehaviour
|
||||
public XRBaseControllerInteractor LeftXRInteractor; // Reference to XR controller interactor (e.g., Ray Interactor)
|
||||
public XRBaseControllerInteractor RightXRInteractor;
|
||||
public XROrigin Player;
|
||||
public TeleportationProvider teleportationProvider; // Reference to TeleportationProvider
|
||||
|
||||
private Button button;
|
||||
private Button button;
|
||||
private TeleportLocation target; // Target teleport position
|
||||
|
||||
void Start()
|
||||
{
|
||||
button = GetComponent<Button>();
|
||||
@@ -25,65 +27,68 @@ public class MenuTeleportButton : MonoBehaviour
|
||||
// Subscribe to button events
|
||||
button.onClick.AddListener(TeleportPlayer);
|
||||
|
||||
TeleportLocation[] locations = FindObjectsOfType<TeleportLocation>(); // Fetches all teleport locations from scene.
|
||||
//Debug.Log("The amount of teleport locations is " + locations.Length);
|
||||
foreach (TeleportLocation location in locations) // Finds the target.
|
||||
TeleportLocation[] locations = FindObjectsOfType<TeleportLocation>(); // Fetch all teleport locations in the scene.
|
||||
foreach (TeleportLocation location in locations) // Find the target location.
|
||||
{
|
||||
if (location.Name.Equals(TargetName))
|
||||
{
|
||||
target = location;
|
||||
//Debug.Log("Teleport target of " + target.Name + " found.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (target == null) Debug.Log("Teleport target of " + TargetName + " not found.");
|
||||
|
||||
if (target == null)
|
||||
{
|
||||
Debug.LogError("Teleport target of " + TargetName + " not found.");
|
||||
}
|
||||
}
|
||||
|
||||
public void SetStateSelected()
|
||||
{
|
||||
if (button != null)
|
||||
if (button != null && HoverSprite != null)
|
||||
{
|
||||
if (HoverSprite != null)
|
||||
{
|
||||
button.targetGraphic.GetComponent<Image>().sprite = HoverSprite;
|
||||
}
|
||||
button.targetGraphic.GetComponent<Image>().sprite = HoverSprite;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetStateDefault()
|
||||
{
|
||||
// Refresh the button state.
|
||||
button.interactable = false;
|
||||
button.interactable = true;
|
||||
if (NormalSprite != null)
|
||||
{
|
||||
|
||||
if (NormalSprite != null)
|
||||
{
|
||||
button.targetGraphic.GetComponent<Image>().sprite = NormalSprite;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void TeleportPlayer()
|
||||
{
|
||||
//Debug.Log("Teleport button clicked");
|
||||
|
||||
if (target != null && Player != null && Player.Camera != null)
|
||||
if (target == null || Player == null || teleportationProvider == null)
|
||||
{
|
||||
Player.transform.position = target.transform.position;
|
||||
|
||||
// Calculate the rotation offset needed for the player
|
||||
Vector3 targetEulerAngles = target.transform.rotation.eulerAngles;
|
||||
Vector3 currentCameraEulerAngles = Player.Camera.transform.rotation.eulerAngles;
|
||||
|
||||
// Determine the rotation delta around the Y-axis
|
||||
float rotationDeltaY = targetEulerAngles.y - currentCameraEulerAngles.y;
|
||||
|
||||
// Apply the rotation delta to the XR Origin
|
||||
Player.transform.Rotate(0, rotationDeltaY, 0, Space.World);
|
||||
|
||||
// Refresh the button state.
|
||||
button.interactable = false;
|
||||
button.interactable = true;
|
||||
Debug.LogWarning("Teleportation failed: Target, Player, or TeleportationProvider is missing.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Prepare teleport request
|
||||
TeleportRequest request = new TeleportRequest
|
||||
{
|
||||
destinationPosition = target.transform.position,
|
||||
destinationRotation = target.transform.rotation,
|
||||
matchOrientation = MatchOrientation.TargetUpAndForward
|
||||
};
|
||||
|
||||
// Queue teleport request
|
||||
bool success = teleportationProvider.QueueTeleportRequest(request);
|
||||
|
||||
if (!success)
|
||||
{
|
||||
Debug.LogWarning("Teleport request failed to queue.");
|
||||
}
|
||||
|
||||
// Refresh the button state
|
||||
button.interactable = false;
|
||||
button.interactable = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Unity.XR.CoreUtils;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.InputSystem.LowLevel;
|
||||
@@ -19,6 +20,7 @@ public class Menu : MonoBehaviour
|
||||
public GameObject PlayericonFloor1Parent;
|
||||
public GameObject PlayericonFloor2Parent;
|
||||
|
||||
public XROrigin Player;
|
||||
public InputActionReference openMenuAction;
|
||||
private Canvas canvas;
|
||||
|
||||
@@ -44,22 +46,22 @@ public class Menu : MonoBehaviour
|
||||
canvas.enabled = false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void ToggleMenu(InputAction.CallbackContext context)
|
||||
{
|
||||
// Match the Y rotation of the MenuRotator to the Camera
|
||||
Vector3 cameraRotation = Camera.transform.eulerAngles;
|
||||
Vector3 menuRotatorRotation = MenuRotator.transform.eulerAngles;
|
||||
// Get the camera's local Y rotation relative to the parent of MenuRotator
|
||||
float relativeYRotation = Camera.transform.localEulerAngles.y;
|
||||
|
||||
// Update only the Y rotation, keep X and Z unchanged
|
||||
menuRotatorRotation.y = cameraRotation.y;
|
||||
MenuRotator.transform.eulerAngles = menuRotatorRotation;
|
||||
// Apply the relative Y rotation to MenuRotator while keeping X and Z unchanged
|
||||
MenuRotator.transform.localEulerAngles = new Vector3(0, relativeYRotation, 0);
|
||||
|
||||
// Set the menu rotator position to that of the camera
|
||||
// Set the menu position to match the camera's position in local space
|
||||
MenuRotator.transform.position = Camera.transform.position;
|
||||
|
||||
// Toggle the menu visibility
|
||||
canvas.enabled = !canvas.enabled;
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user