Implimented the card

This commit is contained in:
Ranno Samuel Adson
2025-01-07 02:40:37 +02:00
parent 98094a9f5f
commit 7ba5fe1f30
53 changed files with 5686 additions and 6 deletions

View File

@@ -0,0 +1,41 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class FloorButtonVisualizer : MonoBehaviour
{
public Sprite InactiveSprite;
public Sprite ActiveSprite;
public float FloorUpperCoordiantes;
public float FloorLowerCoordiantes;
private bool activeState = true;
private Image buttonImage;
// Start is called before the first frame update
void Start()
{
buttonImage = gameObject.GetComponent<Image>();
}
// Update is called once per frame
void Update()
{
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;
}
}
}
}

View File

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

View File

@@ -0,0 +1,59 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Unity.XR.CoreUtils;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.XR.Interaction.Toolkit;
public class MenuTeleportButton : MonoBehaviour
{
public Sprite NormalSprite;
public Sprite HoverSprite;
public String TargetName;
public XRBaseControllerInteractor LeftXRInteractor; // Reference to XR controller interactor (e.g., Ray Interactor)
public XRBaseControllerInteractor RightXRInteractor;
public XROrigin Player;
private Button button;
private TeleportLocation target; // Target teleport position
void Start()
{
button = GetComponent<Button>();
// 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.
{
if (location.Name.Equals(TargetName))
{
target = location;
Debug.Log("Teleport target of " + target.Name + " found.");
}
}
}
void Update()
{
}
private void TeleportPlayer()
{
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;
}
}
}

View File

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

View File

@@ -0,0 +1,155 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.UI;
public class Menu : MonoBehaviour
{
public GameObject MenuRotator;
public GameObject Floor1Panel;
public GameObject Floor2Panel;
public Button Floor1Button;
public Button Floor2Button;
public Camera Camera;
public Image Playericon;
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); //
private void Awake()
{
openMenuAction.action.Enable();
openMenuAction.action.performed += ToggleMenu;
InputSystem.onDeviceChange += OnDeviceChange;
canvas = GetComponent<Canvas>();
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;
// Update only the Y rotation, keep X and Z unchanged
menuRotatorRotation.y = cameraRotation.y;
MenuRotator.transform.eulerAngles = menuRotatorRotation;
// Set the menu rotator position to that of the camera
MenuRotator.transform.position = Camera.transform.position;
canvas.enabled = !canvas.enabled;
}
// Start is called before the first frame update
void Start()
{
Floor1Button.onClick.AddListener(DisplayFloor1);
Floor2Button.onClick.AddListener(DisplayFloor2);
DisplayFloor2();
}
private void DisplayFloor1()
{
//Debug.Log("Dispaling floor 1");
Floor1Panel.gameObject.SetActive(true);
Floor2Panel.gameObject.SetActive(false);
}
private void DisplayFloor2()
{
//Debug.Log("Dispaling floor 2");
Floor1Panel.gameObject.SetActive(false);
Floor2Panel.gameObject.SetActive(true);
}
private void OnDeviceChange(InputDevice device, InputDeviceChange change) // To avoid bugs with controllers disconnecting.
{
switch (change)
{
case InputDeviceChange.Disconnected:
openMenuAction.action.Disable();
openMenuAction.action.performed -= ToggleMenu;
break;
case InputDeviceChange.Reconnected:
openMenuAction.action.Enable();
openMenuAction.action.performed += ToggleMenu;
break;
}
}
// Update is called once per frame
void Update()
{
if (transform.position.y < -50) // If the player has fallen off the platform.
{
if (!canvas.enabled) // If has menu not activated.
{
ToggleMenu(new InputAction.CallbackContext()); // Activate menu.
}
}
float worldToMapAngleRad = worldToMapAngle * Mathf.Deg2Rad;
//Vector2 VR_Player = new Vector2(transform.position.x, transform.position.z);
Vector2 VR_Player = new Vector2(
Mathf.Cos(worldToMapAngleRad) * transform.position.x - Mathf.Sin(worldToMapAngleRad) * transform.position.z,
Mathf.Sin(worldToMapAngleRad) * transform.position.x + Mathf.Cos(worldToMapAngleRad) * transform.position.z
);
VR_Player = VR_Player * new Vector2(1.0f, 1.0f);
rotatedPlayerPos = VR_Player;
//Debug.Log(VR_Player);
//Vector2 VR_P1 = new Vector2(-10, 102);
//Vector2 VR_P2 = new Vector2(-123, -19);
/*Vector2 VR_P1 = new Vector2(-102.0f, 73.0f);
Vector2 VR_P2 = new Vector2(71.1f, 76.6f);
Vector2 IMG_P1 = new Vector2(-364.0f, -180.0f);
Vector2 IMG_P2 = new Vector2(394.0f, -225.0f);*/
Vector2 VR_L = VR_P2 - VR_P1;
Vector2 IMG_L = IMG_P2 - IMG_P1;
Vector2 IMG_Player = (VR_Player - VR_P1) / VR_L * IMG_L + IMG_P1;
Playericon.GetComponent<RectTransform>().anchoredPosition = IMG_Player;
/*
float VR_X = transform.position.x;
float VR_Y = transform.position.y;
float VR_X1 = -10;
float VR_X2 = -123;
float IMG_X1 = -364;
float IMG_X2 = 394;
float Lvr = VR_X2 - VR_X1;//(-138 - -10)
float Limg = IMG_X2 - IMG_X1;
IMG_X = (VR_X - VR_X1) / Lvr * Limg + IMG_X1;
*/
//IMG_Y = (VR_Y - VR_Y1) / Lvr * Limg + IMG_Y1;
//Playericon.transform.position.Set(IMG_X,0,0);
//Playericon.GetComponent<RectTransform>().anchoredPosition = new Vector2(IMG_X, IMG_Y);
//Debug.Log(IMG_X + " vs " + Playericon.GetComponent<RectTransform>().anchoredPosition.x);
}
private void OnDestroy()
{
openMenuAction.action.Disable();
openMenuAction.action.performed -= ToggleMenu;
InputSystem.onDeviceChange -= OnDeviceChange;
Floor1Button.onClick.RemoveListener(DisplayFloor1);
Floor2Button.onClick.RemoveListener(DisplayFloor2);
}
}

View File

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

View File

@@ -0,0 +1,19 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TeleportLocation : MonoBehaviour
{
public string Name;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}

View File

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