Added options and credits tabs for the in-game UI menu. Credits tab is blank for now. Disabled smooth locomotion to address the player controller confusion issues (see my thesis). Smooth locomotion can be reactivated via the options menu.
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.XR.Interaction.Toolkit;
|
||||
|
||||
public class ContinuoslocomotionConfigurator : MonoBehaviour
|
||||
{
|
||||
public Button turnOffButton;
|
||||
public Button turnOnButton;
|
||||
public ContinuousMoveProviderBase locomotion;
|
||||
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
turnOnButton.onClick.AddListener(enableLocomotion);
|
||||
turnOffButton.onClick.AddListener(disableLocomotion);
|
||||
turnOffButton.gameObject.SetActive(false); // off by default
|
||||
}
|
||||
public void UpdateSpeed(float speed)
|
||||
{
|
||||
locomotion.moveSpeed = speed;
|
||||
}
|
||||
|
||||
private void enableLocomotion()
|
||||
{
|
||||
locomotion.enabled = true;
|
||||
turnOnButton.gameObject.SetActive(false);
|
||||
turnOffButton.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
private void disableLocomotion()
|
||||
{
|
||||
locomotion.enabled = false;
|
||||
turnOnButton.gameObject.SetActive(true);
|
||||
turnOffButton.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 26a0dd79a025e5041a41f576b1aa4968
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,62 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
using System.Collections;
|
||||
|
||||
public class HoverSlideButton : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
|
||||
{
|
||||
public RectTransform buttonTransform;
|
||||
|
||||
public Vector2 offPosition = Vector2.zero;
|
||||
public Vector2 onPosition = new Vector2(30f, 0f); // e.g., slide 30px to the right
|
||||
|
||||
public float slideDuration = 0.2f;
|
||||
|
||||
private Coroutine slideCoroutine;
|
||||
private bool isOn = false;
|
||||
|
||||
private void Reset()
|
||||
{
|
||||
buttonTransform = GetComponent<RectTransform>();
|
||||
}
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
SlideToPosition(onPosition);
|
||||
}
|
||||
|
||||
public void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
if (!isOn) SlideToPosition(offPosition);
|
||||
|
||||
}
|
||||
|
||||
public void SetOnState(bool on)
|
||||
{
|
||||
isOn = on;
|
||||
SlideToPosition(on ? onPosition : offPosition);
|
||||
}
|
||||
|
||||
private void SlideToPosition(Vector2 target)
|
||||
{
|
||||
if (slideCoroutine != null)
|
||||
StopCoroutine(slideCoroutine);
|
||||
|
||||
slideCoroutine = StartCoroutine(SmoothSlide(target));
|
||||
}
|
||||
|
||||
private IEnumerator SmoothSlide(Vector2 target)
|
||||
{
|
||||
Vector2 startPos = buttonTransform.anchoredPosition;
|
||||
float timeElapsed = 0f;
|
||||
|
||||
while (timeElapsed < slideDuration)
|
||||
{
|
||||
buttonTransform.anchoredPosition = Vector2.Lerp(startPos, target, timeElapsed / slideDuration);
|
||||
timeElapsed += Time.deltaTime;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
buttonTransform.anchoredPosition = target;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 926f667f37c3aed4d8c188d64dc8d882
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -24,6 +24,24 @@ public class Menu : MonoBehaviour
|
||||
public InputActionReference openMenuAction;
|
||||
private Canvas canvas;
|
||||
|
||||
public enum MenuTab
|
||||
{
|
||||
Map,
|
||||
Options,
|
||||
Credits
|
||||
}
|
||||
|
||||
public GameObject MapTab;
|
||||
public GameObject OptionsTab;
|
||||
public GameObject CreditsTab;
|
||||
|
||||
private MenuTab currentTab;
|
||||
|
||||
|
||||
public Button mapBookmark;
|
||||
public Button optionsBookmark;
|
||||
public Button creditsBookmark;
|
||||
|
||||
// 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;
|
||||
@@ -38,6 +56,8 @@ public class Menu : MonoBehaviour
|
||||
private float floor1LowerLimit = -5;
|
||||
private bool activated = true;
|
||||
|
||||
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
openMenuAction.action.Enable();
|
||||
@@ -45,6 +65,11 @@ public class Menu : MonoBehaviour
|
||||
InputSystem.onDeviceChange += OnDeviceChange;
|
||||
canvas = GetComponent<Canvas>();
|
||||
setCanvasVisibility(false);
|
||||
|
||||
mapBookmark.onClick.AddListener(activateMapPanel);
|
||||
optionsBookmark.onClick.AddListener(activateOptionsPanel);
|
||||
creditsBookmark.onClick.AddListener(activateCreditsPanel);
|
||||
activateMapPanel();
|
||||
|
||||
}
|
||||
public void DeactivateMenu() // Makes the ToggleMenu inable to toggle.
|
||||
@@ -57,6 +82,36 @@ public class Menu : MonoBehaviour
|
||||
activated = true;
|
||||
}
|
||||
|
||||
private void activateMapPanel()
|
||||
{
|
||||
SetActiveTab(MenuTab.Map);
|
||||
}
|
||||
|
||||
private void activateOptionsPanel()
|
||||
{
|
||||
SetActiveTab(MenuTab.Options);
|
||||
}
|
||||
|
||||
private void activateCreditsPanel()
|
||||
{
|
||||
SetActiveTab(MenuTab.Credits);
|
||||
}
|
||||
|
||||
private void SetActiveTab(MenuTab tab)
|
||||
{
|
||||
currentTab = tab;
|
||||
|
||||
MapTab.SetActive(tab == MenuTab.Map);
|
||||
OptionsTab.SetActive(tab == MenuTab.Options);
|
||||
CreditsTab.SetActive(tab == MenuTab.Credits);
|
||||
|
||||
mapBookmark.GetComponent<HoverSlideButton>().SetOnState(tab == MenuTab.Map);
|
||||
optionsBookmark.GetComponent<HoverSlideButton>().SetOnState(tab == MenuTab.Options);
|
||||
creditsBookmark.GetComponent<HoverSlideButton>().SetOnState(tab == MenuTab.Credits);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void setCanvasVisibility(bool enabled)
|
||||
{
|
||||
canvas.enabled = enabled;
|
||||
@@ -160,10 +215,12 @@ public class Menu : MonoBehaviour
|
||||
ToggleMenu(new InputAction.CallbackContext()); // Activate menu.
|
||||
}
|
||||
}
|
||||
|
||||
UpdatePlayerIconPosition();
|
||||
UpdatePlayerIconRotation();
|
||||
UpdateActveFloor();
|
||||
if (MapTab.activeSelf)
|
||||
{
|
||||
UpdatePlayerIconPosition();
|
||||
UpdatePlayerIconRotation();
|
||||
UpdateActveFloor();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -266,10 +323,12 @@ public class Menu : MonoBehaviour
|
||||
if (PlayericonFloor1Parent.activeSelf)
|
||||
{
|
||||
PlayericonFloor1.GetComponent<RectTransform>().anchoredPosition = IMG_Player;
|
||||
Debug.Log(IMG_Player);
|
||||
}
|
||||
if (PlayericonFloor2Parent.activeSelf)
|
||||
{
|
||||
PlayericonFloor2.GetComponent<RectTransform>().anchoredPosition = IMG_Player;
|
||||
Debug.Log(IMG_Player);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.EventSystems;
|
||||
using TMPro;
|
||||
|
||||
public class SliderDragHandler : MonoBehaviour, IDragHandler, IBeginDragHandler, IEndDragHandler
|
||||
{
|
||||
public RectTransform sliderBackground; // Assign in Inspector
|
||||
public float minValue = 2f;
|
||||
public float maxValue = 5f;
|
||||
public float slideareaOffsetMultiplier = 0.9f;
|
||||
public TMP_Text warningText;
|
||||
public float warningThreshholdValue = 0.65f;
|
||||
public float CurrentValue { get; private set; }
|
||||
|
||||
public ContinuoslocomotionConfigurator configurator;
|
||||
|
||||
private RectTransform handleRect;
|
||||
private Vector2 backgroundStart;
|
||||
private float backgroundWidth;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
handleRect = GetComponent<RectTransform>();
|
||||
|
||||
if (sliderBackground != null)
|
||||
{
|
||||
backgroundStart = sliderBackground.position;
|
||||
backgroundWidth = sliderBackground.rect.width;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void OnBeginDrag(PointerEventData eventData)
|
||||
{
|
||||
UpdateSlider(eventData);
|
||||
}
|
||||
|
||||
public void OnDrag(PointerEventData eventData)
|
||||
{
|
||||
UpdateSlider(eventData);
|
||||
}
|
||||
|
||||
public void OnEndDrag(PointerEventData eventData)
|
||||
{
|
||||
UpdateSlider(eventData);
|
||||
configurator.UpdateSpeed(CurrentValue);
|
||||
}
|
||||
private void UpdateSlider(PointerEventData eventData)
|
||||
{
|
||||
Vector2 localPoint;
|
||||
RectTransformUtility.ScreenPointToLocalPointInRectangle(sliderBackground, eventData.position, eventData.pressEventCamera, out localPoint);
|
||||
|
||||
float halfWidth = sliderBackground.rect.width * 0.5f;
|
||||
|
||||
|
||||
|
||||
// Only allow dragging within 90% of the slider width, centered
|
||||
float limit = halfWidth * slideareaOffsetMultiplier;
|
||||
float clampedX = Mathf.Clamp(localPoint.x, -limit, limit);
|
||||
|
||||
Vector3 newPosition = new Vector3(clampedX, handleRect.localPosition.y, handleRect.localPosition.z);
|
||||
handleRect.localPosition = newPosition;
|
||||
|
||||
// Normalize within the limited 90% range
|
||||
float normalized = (clampedX + limit) / (limit * 2f);
|
||||
//Debug.Log(normalized);
|
||||
CurrentValue = Mathf.Lerp(minValue, maxValue, normalized);
|
||||
|
||||
// Displaying the warning.
|
||||
|
||||
if (CurrentValue > (warningThreshholdValue*(maxValue - minValue) + minValue)) warningText.gameObject.SetActive(true);
|
||||
|
||||
else warningText.gameObject.SetActive(false);
|
||||
|
||||
//Debug.Log(warningThreshholdValue);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a1dff6a2857e62b4d841d7bc2fb986e9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user