finished portal fundimentals

This commit is contained in:
2025-03-09 20:43:38 +02:00
parent 960991b17d
commit b62e851c0e
1229 changed files with 46770 additions and 7301 deletions

View File

@@ -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;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9cdab728e7f1bc945ae623a3e5cc1645
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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;
}
}

View File

@@ -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()
{

View File

@@ -225,6 +225,7 @@ MonoBehaviour:
PlayericonFloor2: {fileID: 7554133574101087666}
PlayericonFloor1Parent: {fileID: 8144600077522330704}
PlayericonFloor2Parent: {fileID: 3922359959326010239}
Player: {fileID: 0}
openMenuAction: {fileID: 2462937694456473221, guid: c348712bda248c246b8c49b3db54643f,
type: 3}
--- !u!1 &916340287994646858
@@ -240,6 +241,7 @@ GameObject:
- component: {fileID: 4126484334133781733}
- component: {fileID: 7229210520247497862}
- component: {fileID: 4682670891357688467}
- component: {fileID: 2457808414162356797}
m_Layer: 0
m_Name: XR Origin
m_TagString: Player
@@ -340,6 +342,23 @@ MonoBehaviour:
- {fileID: 5861557227681292572}
- {fileID: 8032053745934150659}
- {fileID: 1557304905219974776}
--- !u!114 &2457808414162356797
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 916340287994646858}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 9cdab728e7f1bc945ae623a3e5cc1645, type: 3}
m_Name:
m_EditorClassIdentifier:
teleportAction: {fileID: -8061240218431744966, guid: c348712bda248c246b8c49b3db54643f,
type: 3}
TeleportRayLine: {fileID: 4167169049726400930}
defaultGravity: {fileID: 5354856814699964556}
isInSpace: 0
--- !u!1 &1266300925333121652
GameObject:
m_ObjectHideFlags: 0
@@ -2106,6 +2125,7 @@ MonoBehaviour:
m_EnableStrafe: 1
m_EnableFly: 0
m_UseGravity: 1
inGravityDisableArea: 0
m_GravityApplicationMode: 0
m_ForwardSource: {fileID: 0}
m_LeftHandMoveAction:
@@ -3357,6 +3377,11 @@ PrefabInstance:
propertyPath: RightXRInteractor
value:
objectReference: {fileID: 140507709088905439}
- target: {fileID: 5406280067121556080, guid: f2ade1e8dce12be43ab14956a6244406,
type: 3}
propertyPath: teleportationProvider
value:
objectReference: {fileID: 320882828650175455}
- target: {fileID: 8452192790917719765, guid: f2ade1e8dce12be43ab14956a6244406,
type: 3}
propertyPath: m_Sprite
@@ -3607,6 +3632,11 @@ PrefabInstance:
propertyPath: RightXRInteractor
value:
objectReference: {fileID: 140507709088905439}
- target: {fileID: 5406280067121556080, guid: f2ade1e8dce12be43ab14956a6244406,
type: 3}
propertyPath: teleportationProvider
value:
objectReference: {fileID: 320882828650175455}
- target: {fileID: 8452192790917719765, guid: f2ade1e8dce12be43ab14956a6244406,
type: 3}
propertyPath: m_Sprite
@@ -3857,6 +3887,11 @@ PrefabInstance:
propertyPath: RightXRInteractor
value:
objectReference: {fileID: 140507709088905439}
- target: {fileID: 5406280067121556080, guid: f2ade1e8dce12be43ab14956a6244406,
type: 3}
propertyPath: teleportationProvider
value:
objectReference: {fileID: 320882828650175455}
- target: {fileID: 8452192790917719765, guid: f2ade1e8dce12be43ab14956a6244406,
type: 3}
propertyPath: m_Sprite
@@ -4211,6 +4246,11 @@ PrefabInstance:
propertyPath: RightXRInteractor
value:
objectReference: {fileID: 140507709088905439}
- target: {fileID: 5406280067121556080, guid: f2ade1e8dce12be43ab14956a6244406,
type: 3}
propertyPath: teleportationProvider
value:
objectReference: {fileID: 320882828650175455}
- target: {fileID: 8452192790917719765, guid: f2ade1e8dce12be43ab14956a6244406,
type: 3}
propertyPath: m_Sprite
@@ -4363,7 +4403,7 @@ PrefabInstance:
- target: {fileID: 8429981633443581383, guid: 1670dca8ee98f864eb412b51a24c08e1,
type: 3}
propertyPath: m_LocomotionVignetteProviders.Array.data[2].m_Enabled
value: 1
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8429981633443581383, guid: 1670dca8ee98f864eb412b51a24c08e1,
type: 3}
@@ -4480,6 +4520,21 @@ PrefabInstance:
propertyPath: m_LocomotionVignetteProviders.Array.data[0].m_OverrideParameters.m_VignetteColor.a
value: 1
objectReference: {fileID: 0}
- target: {fileID: 8429981633443581383, guid: 1670dca8ee98f864eb412b51a24c08e1,
type: 3}
propertyPath: m_LocomotionVignetteProviders.Array.data[0].m_OverrideParameters.m_VignetteColor.b
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8429981633443581383, guid: 1670dca8ee98f864eb412b51a24c08e1,
type: 3}
propertyPath: m_LocomotionVignetteProviders.Array.data[0].m_OverrideParameters.m_VignetteColor.g
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8429981633443581383, guid: 1670dca8ee98f864eb412b51a24c08e1,
type: 3}
propertyPath: m_LocomotionVignetteProviders.Array.data[0].m_OverrideParameters.m_VignetteColor.r
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8429981633443581383, guid: 1670dca8ee98f864eb412b51a24c08e1,
type: 3}
propertyPath: m_LocomotionVignetteProviders.Array.data[1].m_OverrideParameters.m_VignetteColor.a
@@ -4490,6 +4545,21 @@ PrefabInstance:
propertyPath: m_LocomotionVignetteProviders.Array.data[2].m_OverrideParameters.m_VignetteColor.a
value: 1
objectReference: {fileID: 0}
- target: {fileID: 8429981633443581383, guid: 1670dca8ee98f864eb412b51a24c08e1,
type: 3}
propertyPath: m_LocomotionVignetteProviders.Array.data[2].m_OverrideParameters.m_VignetteColor.b
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8429981633443581383, guid: 1670dca8ee98f864eb412b51a24c08e1,
type: 3}
propertyPath: m_LocomotionVignetteProviders.Array.data[2].m_OverrideParameters.m_VignetteColor.g
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8429981633443581383, guid: 1670dca8ee98f864eb412b51a24c08e1,
type: 3}
propertyPath: m_LocomotionVignetteProviders.Array.data[2].m_OverrideParameters.m_VignetteColor.r
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8429981633443581383, guid: 1670dca8ee98f864eb412b51a24c08e1,
type: 3}
propertyPath: m_LocomotionVignetteProviders.Array.data[3].m_OverrideParameters.m_VignetteColor.a
@@ -4508,7 +4578,7 @@ PrefabInstance:
- target: {fileID: 8429981633443581383, guid: 1670dca8ee98f864eb412b51a24c08e1,
type: 3}
propertyPath: m_LocomotionVignetteProviders.Array.data[2].m_OverrideParameters.m_FeatheringEffect
value: 0.3
value: 0.289
objectReference: {fileID: 0}
- target: {fileID: 8429981633443581383, guid: 1670dca8ee98f864eb412b51a24c08e1,
type: 3}
@@ -4520,6 +4590,21 @@ PrefabInstance:
propertyPath: m_LocomotionVignetteProviders.Array.data[0].m_OverrideParameters.m_VignetteColorBlend.a
value: 1
objectReference: {fileID: 0}
- target: {fileID: 8429981633443581383, guid: 1670dca8ee98f864eb412b51a24c08e1,
type: 3}
propertyPath: m_LocomotionVignetteProviders.Array.data[0].m_OverrideParameters.m_VignetteColorBlend.b
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8429981633443581383, guid: 1670dca8ee98f864eb412b51a24c08e1,
type: 3}
propertyPath: m_LocomotionVignetteProviders.Array.data[0].m_OverrideParameters.m_VignetteColorBlend.g
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8429981633443581383, guid: 1670dca8ee98f864eb412b51a24c08e1,
type: 3}
propertyPath: m_LocomotionVignetteProviders.Array.data[0].m_OverrideParameters.m_VignetteColorBlend.r
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8429981633443581383, guid: 1670dca8ee98f864eb412b51a24c08e1,
type: 3}
propertyPath: m_LocomotionVignetteProviders.Array.data[1].m_OverrideParameters.m_VignetteColorBlend.a
@@ -4530,6 +4615,21 @@ PrefabInstance:
propertyPath: m_LocomotionVignetteProviders.Array.data[2].m_OverrideParameters.m_VignetteColorBlend.a
value: 1
objectReference: {fileID: 0}
- target: {fileID: 8429981633443581383, guid: 1670dca8ee98f864eb412b51a24c08e1,
type: 3}
propertyPath: m_LocomotionVignetteProviders.Array.data[2].m_OverrideParameters.m_VignetteColorBlend.b
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8429981633443581383, guid: 1670dca8ee98f864eb412b51a24c08e1,
type: 3}
propertyPath: m_LocomotionVignetteProviders.Array.data[2].m_OverrideParameters.m_VignetteColorBlend.g
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8429981633443581383, guid: 1670dca8ee98f864eb412b51a24c08e1,
type: 3}
propertyPath: m_LocomotionVignetteProviders.Array.data[2].m_OverrideParameters.m_VignetteColorBlend.r
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8429981633443581383, guid: 1670dca8ee98f864eb412b51a24c08e1,
type: 3}
propertyPath: m_LocomotionVignetteProviders.Array.data[3].m_OverrideParameters.m_VignetteColorBlend.a
@@ -4634,6 +4734,18 @@ PrefabInstance:
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: b0b2b7e0bfc3c6347b6aa4f25e1f4901, type: 3}
--- !u!114 &4167169049726400930 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 5908283647240594644, guid: b0b2b7e0bfc3c6347b6aa4f25e1f4901,
type: 3}
m_PrefabInstance: {fileID: 7506007993771089270}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7827849396487446313}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: e988983f96fe1dd48800bcdfc82f23e9, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!4 &6912108174874316264 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 4018916498608410782, guid: b0b2b7e0bfc3c6347b6aa4f25e1f4901,