60 lines
1.4 KiB
C#
60 lines
1.4 KiB
C#
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;
|
|
}
|
|
}
|
|
}
|