constructed entryway for skywalk

This commit is contained in:
Ranno Samuel Adson
2025-01-15 21:44:46 +02:00
parent 7ba5fe1f30
commit 776c68736d
14 changed files with 1136 additions and 88 deletions

View File

@@ -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<Button>().onClick.AddListener(DisplayFloor1);
Floor2Button.GetComponent<Button>().onClick.AddListener(DisplayFloor2);
DisplayFloor2();
}
private void DisplayFloor1()
@@ -61,13 +72,39 @@ public class Menu : MonoBehaviour
//Debug.Log("Dispaling floor 1");
Floor1Panel.gameObject.SetActive(true);
Floor2Panel.gameObject.SetActive(false);
Button buttonComponent = Floor1Button.GetComponent<Button>();
// Refresh the state of the button.
buttonComponent.interactable = false;
buttonComponent.interactable = true;
}
private void DisplayFloor2()
{
//Debug.Log("Dispaling floor 2");
Floor1Panel.gameObject.SetActive(false);
Floor2Panel.gameObject.SetActive(true);
Button buttonComponent = Floor2Button.GetComponent<Button>();
// Refresh the state of the button.
buttonComponent.interactable = false;
buttonComponent.interactable = true;
}
private int DeterminePlayerCurrentFloor()
{
float yPos = gameObject.transform.position.y;
if (yPos > floorsMidpointLimit && yPos < floor2UpperLimit) // Floor 2
{
return 2;
}
if (yPos > floor1LowerLimit && yPos <= floorsMidpointLimit) // Floor 1
{
return 1;
}
return -1; // If the player should not be on the map
}
private void OnDeviceChange(InputDevice device, InputDeviceChange change) // To avoid bugs with controllers disconnecting.
{
switch (change)
@@ -82,7 +119,7 @@ public class Menu : MonoBehaviour
break;
}
}
// Update is called once per frame
void Update()
{
@@ -93,7 +130,82 @@ public class Menu : MonoBehaviour
ToggleMenu(new InputAction.CallbackContext()); // Activate menu.
}
}
UpdatePlayerIconPosition();
UpdatePlayerIconRotation();
UpdateActveFloor();
}
private void UpdatePlayerIconRotation()
{
float cameraRotationY = -Camera.transform.eulerAngles.y;
float iconRotation = cameraRotationY + cameraToMapIconRotationOffset;
if (PlayericonFloor1Parent.activeSelf)
{
PlayericonFloor1.transform.rotation = Quaternion.Euler(transform.eulerAngles.x, transform.eulerAngles.y, iconRotation);
}
if (PlayericonFloor2Parent.activeSelf)
{
PlayericonFloor2.transform.rotation = Quaternion.Euler(transform.eulerAngles.x, transform.eulerAngles.y, iconRotation);
}
}
private void UpdateActveFloor()
{
int playerCurrentFloor = DeterminePlayerCurrentFloor();
//Debug.Log("Player current floor is " + playerCurrentFloor);
switch (playerCurrentFloor)
{
case 1:
if (!Floor1Button.ActiveState)
{
//Debug.Log("Activating floor 1 Button.");
Floor1Button.Activate();
Floor2Button.Deactivate();
}
if (!PlayericonFloor1Parent.activeSelf)
{
PlayericonFloor1Parent.SetActive(true);
PlayericonFloor2Parent.SetActive(false);
}
break;
case 2:
if (!Floor2Button.ActiveState)
{
//Debug.Log("Activating floor 2 Button.");
Floor1Button.Deactivate();
Floor2Button.Activate();
}
if (!PlayericonFloor2Parent.activeSelf)
{
Debug.Log("PlayericonFloor2Parent is inactive");
PlayericonFloor1Parent.SetActive(false);
PlayericonFloor2Parent.SetActive(true);
Debug.Log(PlayericonFloor2Parent.activeSelf);
}
break;
default:
if (PlayericonFloor1Parent.activeSelf || PlayericonFloor2Parent.activeSelf)
{
//Debug.Log("Deactivating floor Buttons.");
Floor1Button.Deactivate();
Floor2Button.Deactivate();
}
if (PlayericonFloor1.enabled || PlayericonFloor2.enabled)
{
PlayericonFloor1Parent.SetActive(false);
PlayericonFloor2Parent.SetActive(false);
}
break;
}
}
private void UpdatePlayerIconPosition()
{
float worldToMapAngleRad = worldToMapAngle * Mathf.Deg2Rad;
//Vector2 VR_Player = new Vector2(transform.position.x, transform.position.z);
@@ -121,7 +233,14 @@ public class Menu : MonoBehaviour
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;
if (PlayericonFloor1Parent.activeSelf)
{
PlayericonFloor1.GetComponent<RectTransform>().anchoredPosition = IMG_Player;
}
if (PlayericonFloor2Parent.activeSelf)
{
PlayericonFloor2.GetComponent<RectTransform>().anchoredPosition = IMG_Player;
}
/*
float VR_X = transform.position.x;
@@ -142,14 +261,13 @@ public class Menu : MonoBehaviour
//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);
Floor1Button.GetComponent<Button>().onClick.RemoveListener(DisplayFloor1);
Floor2Button.GetComponent<Button>().onClick.RemoveListener(DisplayFloor2);
}
}