diff --git a/Assets/_PROJECT/Components/NewHandPresence/Prefabs/Scripts/Floor Button Visualizer.cs b/Assets/_PROJECT/Components/NewHandPresence/Prefabs/Scripts/Floor Button Visualizer.cs index 4b32cbc3..7d950e43 100644 --- a/Assets/_PROJECT/Components/NewHandPresence/Prefabs/Scripts/Floor Button Visualizer.cs +++ b/Assets/_PROJECT/Components/NewHandPresence/Prefabs/Scripts/Floor Button Visualizer.cs @@ -7,9 +7,7 @@ public class FloorButtonVisualizer : MonoBehaviour { public Sprite InactiveSprite; public Sprite ActiveSprite; - public float FloorUpperCoordiantes; - public float FloorLowerCoordiantes; - private bool activeState = true; + public bool ActiveState; private Image buttonImage; // Start is called before the first frame update void Start() @@ -17,25 +15,16 @@ public class FloorButtonVisualizer : MonoBehaviour buttonImage = gameObject.GetComponent(); } - // Update is called once per frame - void Update() + public void Activate() { - float height = gameObject.transform.position.y; - if (height < FloorUpperCoordiantes && height > FloorLowerCoordiantes) - { - if (!activeState) { - activeState = true; - buttonImage.sprite = ActiveSprite; - } - - } - else - { - if (activeState) - { - activeState = false; - buttonImage.sprite = InactiveSprite; - } - } + this.ActiveState = true; + buttonImage.sprite = ActiveSprite; + //Debug.Log("Floorbutton of " + gameObject.name + " activated"); + } + public void Deactivate() + { + this.ActiveState = false; + buttonImage.sprite = InactiveSprite; + //Debug.Log("Floorbutton of " + gameObject.name + " deactivated"); } } diff --git a/Assets/_PROJECT/Components/NewHandPresence/Prefabs/Scripts/Menu Teleport Button.cs b/Assets/_PROJECT/Components/NewHandPresence/Prefabs/Scripts/Menu Teleport Button.cs index 094f006c..3fb377de 100644 --- a/Assets/_PROJECT/Components/NewHandPresence/Prefabs/Scripts/Menu Teleport Button.cs +++ b/Assets/_PROJECT/Components/NewHandPresence/Prefabs/Scripts/Menu Teleport Button.cs @@ -3,6 +3,7 @@ using System.Collections; using System.Collections.Generic; using Unity.XR.CoreUtils; using UnityEngine; +using UnityEngine.Rendering; using UnityEngine.UI; using UnityEngine.XR.Interaction.Toolkit; @@ -25,20 +26,38 @@ public class MenuTeleportButton : MonoBehaviour button.onClick.AddListener(TeleportPlayer); TeleportLocation[] locations = FindObjectsOfType(); // Fetches all teleport locations from scene. - Debug.Log("The amount of teleport locations is " + locations.Length); + //Debug.Log("The amount of teleport locations is " + locations.Length); foreach (TeleportLocation location in locations) // Finds the target. { if (location.Name.Equals(TargetName)) { target = location; - Debug.Log("Teleport target of " + target.Name + " found."); + //Debug.Log("Teleport target of " + target.Name + " found."); + } + } + if (target == null) Debug.Log("Teleport target of " + TargetName + " not found."); + } + + public void SetStateSelected() + { + if (button != null) + { + if (HoverSprite != null) + { + button.targetGraphic.GetComponent().sprite = HoverSprite; } } } - - void Update() + public void SetStateDefault() { - + // Refresh the button state. + button.interactable = false; + button.interactable = true; + if (NormalSprite != null) + { + button.targetGraphic.GetComponent().sprite = NormalSprite; + } + } public void SetStateDefault() { @@ -47,16 +66,27 @@ public class MenuTeleportButton : MonoBehaviour } - private void TeleportPlayer() { - Debug.Log("Teleport button clicked"); + //Debug.Log("Teleport button clicked"); + if (target != null && Player != null && Player.Camera != null) { - // Teleport the XR Origin to the specified coordinates. Player.transform.position = target.transform.position; - Player.Camera.transform.rotation = target.transform.rotation; + // 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; } } } diff --git a/Assets/_PROJECT/Components/NewHandPresence/Prefabs/Scripts/Menu.cs b/Assets/_PROJECT/Components/NewHandPresence/Prefabs/Scripts/Menu.cs index 3c286b52..de59612d 100644 --- a/Assets/_PROJECT/Components/NewHandPresence/Prefabs/Scripts/Menu.cs +++ b/Assets/_PROJECT/Components/NewHandPresence/Prefabs/Scripts/Menu.cs @@ -3,6 +3,7 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.InputSystem; +using UnityEngine.InputSystem.LowLevel; using UnityEngine.UI; public class Menu : MonoBehaviour @@ -10,19 +11,29 @@ public class Menu : MonoBehaviour public GameObject MenuRotator; public GameObject Floor1Panel; public GameObject Floor2Panel; - public Button Floor1Button; - public Button Floor2Button; + public FloorButtonVisualizer Floor1Button; + public FloorButtonVisualizer Floor2Button; public Camera Camera; - public Image Playericon; + public Image PlayericonFloor1; + public Image PlayericonFloor2; + public GameObject PlayericonFloor1Parent; + public GameObject PlayericonFloor2Parent; + public InputActionReference openMenuAction; private Canvas canvas; - public Vector2 rotatedPlayerPos = new Vector2(); - public float worldToMapAngle = 130.0f; - public Vector2 VR_P1 = new Vector2(-77.4f, 10.1f); // - 71.2f (alumine punkt) - public Vector2 VR_P2 = new Vector2(95.7f, -82.8f); - public Vector2 IMG_P1 = new Vector2(-387.2f, 193.1f); // - public Vector2 IMG_P2 = new Vector2(389.7f, -221.4f); // + // Values for setting the position of the player marker. Do not touch them without great cause. + private Vector2 rotatedPlayerPos = new Vector2(); + private float worldToMapAngle = 130.0f; + private Vector2 VR_P1 = new Vector2(-77.4f, 10.1f); // - 71.2f (alumine punkt) + private Vector2 VR_P2 = new Vector2(95.7f, -82.8f); + private Vector2 IMG_P1 = new Vector2(-387.2f, 193.1f); // + private Vector2 IMG_P2 = new Vector2(389.7f, -221.4f); // + + protected static float cameraToMapIconRotationOffset = -50; + private float floor2UpperLimit = 9; + private float floorsMidpointLimit = 2.5f; + private float floor1LowerLimit = -5; private void Awake() { @@ -52,8 +63,8 @@ public class Menu : MonoBehaviour // Start is called before the first frame update void Start() { - Floor1Button.onClick.AddListener(DisplayFloor1); - Floor2Button.onClick.AddListener(DisplayFloor2); + Floor1Button.GetComponent