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

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