Implement hand menu features
This commit is contained in:
@@ -5,6 +5,7 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using Zenject;
|
||||
|
||||
public class HandMenuUI : MonoBehaviour
|
||||
@@ -13,47 +14,147 @@ public class HandMenuUI : MonoBehaviour
|
||||
[ReadOnly]
|
||||
private HVRInputModule uiInput;
|
||||
|
||||
[Inject]
|
||||
[ReadOnly]
|
||||
private SceneManager sceneManager;
|
||||
|
||||
[SerializeField]
|
||||
private GameObject anchor;
|
||||
|
||||
[SerializeField]
|
||||
[ReadOnly]
|
||||
private float forwardOffset = 0.1f;
|
||||
private Transform lookAt;
|
||||
|
||||
[SerializeField]
|
||||
[ReadOnly]
|
||||
private Canvas canvas;
|
||||
|
||||
private float smoothTime = 0.3F;
|
||||
|
||||
private Vector3 velocity = Vector3.zero;
|
||||
private float forwardOffset = 0.5f;
|
||||
|
||||
[SerializeField]
|
||||
private TextMeshProUGUI titleText;
|
||||
|
||||
[SerializeField]
|
||||
private TextMeshProUGUI roomCodeText;
|
||||
|
||||
[SerializeField]
|
||||
private Button restartButton;
|
||||
|
||||
[SerializeField]
|
||||
private Button quitButton;
|
||||
|
||||
[SerializeField]
|
||||
[ReadOnly]
|
||||
private TextMeshProUGUI quitButtonText;
|
||||
|
||||
[SerializeField]
|
||||
private Button closeButton;
|
||||
|
||||
[SerializeField]
|
||||
private Button settingsButton;
|
||||
|
||||
[SerializeField]
|
||||
private Button startButton;
|
||||
|
||||
[SerializeField]
|
||||
private Button backButton;
|
||||
|
||||
[SerializeField]
|
||||
[ReadOnly]
|
||||
private bool isSettingsVisible = false;
|
||||
|
||||
[SerializeField]
|
||||
private GameObject mainMenu;
|
||||
|
||||
[SerializeField]
|
||||
private GameObject settings;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
canvas = GetComponent<Canvas>();
|
||||
if (uiInput == null) return;
|
||||
|
||||
canvas = GetComponent<Canvas>();
|
||||
uiInput?.AddCanvas(canvas);
|
||||
|
||||
canvas.enabled = false;
|
||||
|
||||
quitButtonText = quitButton.GetComponentInChildren<TextMeshProUGUI>();
|
||||
|
||||
UpdateTextsAndButtons();
|
||||
|
||||
sceneManager.SceneLoaded.AddListener(() => UpdateTextsAndButtons());
|
||||
closeButton.onClick.AddListener(() => ToggleVisibility());
|
||||
quitButton.onClick.AddListener(() => QuitClicked());
|
||||
backButton.onClick.AddListener(() => BackClicked());
|
||||
settingsButton.onClick.AddListener(() => SettingsClicked());
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
UpdatePosition();
|
||||
//UpdatePosition();
|
||||
CheckInput();
|
||||
}
|
||||
|
||||
private void UpdatePosition()
|
||||
{
|
||||
var rotation = Quaternion.Euler(0, anchor.transform.eulerAngles.y - 180, 0);
|
||||
var targetPosition = anchor.transform.position - anchor.transform.forward * forwardOffset;
|
||||
var smoothPosition = Vector3.SmoothDamp(transform.position, targetPosition, ref velocity, smoothTime);
|
||||
transform.SetPositionAndRotation(smoothPosition, rotation);
|
||||
var targetPosition = lookAt.position + (lookAt.forward * forwardOffset);
|
||||
transform.position = new Vector3(targetPosition.x, lookAt.position.y, targetPosition.z);
|
||||
|
||||
var lookAtPositon = new Vector3(lookAt.position.x, transform.position.y, lookAt.position.z);
|
||||
transform.rotation = Quaternion.LookRotation(transform.position - lookAtPositon);
|
||||
}
|
||||
|
||||
private void CheckInput()
|
||||
{
|
||||
if (HVRInputManager.Instance.LeftController.PrimaryButtonState.JustActivated)
|
||||
{
|
||||
canvas.enabled = !canvas.enabled;
|
||||
ToggleVisibility();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateTextsAndButtons()
|
||||
{
|
||||
titleText.text = sceneManager.LoadedScene.name;
|
||||
quitButtonText.text = sceneManager.IsInLobby ? "Quit" : "Give Up";
|
||||
backButton.gameObject.SetActive(isSettingsVisible);
|
||||
mainMenu.SetActive(!isSettingsVisible);
|
||||
settings.SetActive(isSettingsVisible);
|
||||
restartButton.gameObject.SetActive(!sceneManager.IsInLobby);
|
||||
startButton.gameObject.SetActive(!sceneManager.IsInLobby);
|
||||
}
|
||||
|
||||
private void ToggleVisibility()
|
||||
{
|
||||
canvas.enabled = !canvas.enabled;
|
||||
|
||||
if (canvas.enabled)
|
||||
{
|
||||
UpdatePosition();
|
||||
}
|
||||
}
|
||||
|
||||
private void BackClicked()
|
||||
{
|
||||
isSettingsVisible = false;
|
||||
UpdateTextsAndButtons();
|
||||
}
|
||||
|
||||
private void SettingsClicked()
|
||||
{
|
||||
isSettingsVisible = true;
|
||||
UpdateTextsAndButtons();
|
||||
}
|
||||
|
||||
private void QuitClicked()
|
||||
{
|
||||
if (sceneManager.IsInLobby)
|
||||
{
|
||||
Application.Quit();
|
||||
}
|
||||
else
|
||||
{
|
||||
sceneManager.SwitchToLobbyLevel();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user