Create UI manager and Hand Menu
This commit is contained in:
59
Assets/Scripts/UI/HandMenuUI.cs
Normal file
59
Assets/Scripts/UI/HandMenuUI.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using HurricaneVR.Framework.ControllerInput;
|
||||
using HurricaneVR.Framework.Core.UI;
|
||||
using Sirenix.OdinInspector;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using Zenject;
|
||||
|
||||
public class HandMenuUI : MonoBehaviour
|
||||
{
|
||||
[Inject]
|
||||
[ReadOnly]
|
||||
private HVRInputModule uiInput;
|
||||
|
||||
[SerializeField]
|
||||
private GameObject anchor;
|
||||
|
||||
[SerializeField]
|
||||
[ReadOnly]
|
||||
private float forwardOffset = 0.1f;
|
||||
|
||||
[SerializeField]
|
||||
[ReadOnly]
|
||||
private Canvas canvas;
|
||||
|
||||
private float smoothTime = 0.3F;
|
||||
|
||||
private Vector3 velocity = Vector3.zero;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
canvas = GetComponent<Canvas>();
|
||||
|
||||
uiInput.AddCanvas(canvas);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
private void CheckInput()
|
||||
{
|
||||
if (HVRInputManager.Instance.LeftController.PrimaryButtonState.JustActivated)
|
||||
{
|
||||
canvas.enabled = !canvas.enabled;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user