Create UI manager and Hand Menu

This commit is contained in:
2024-08-31 16:16:46 +02:00
parent c9ee891dc6
commit fb7da37a5a
11 changed files with 4836 additions and 18 deletions

View File

@@ -71,6 +71,7 @@ public class PlayerComponent : NetworkBehaviour
audioListener.enabled = true;
StartCoroutine(DestroySoloComponents());
DontDestroyOnLoad(gameObject);
}
private IEnumerator DestroyMultiplayerComponents()

View File

@@ -1,5 +1,6 @@
using HurricaneVR.Framework.Core;
using HurricaneVR.Framework.Core.Player;
using HurricaneVR.Framework.Core.UI;
using HurricaneVR.Framework.Core.Utils;
using System.Collections;
using Unity.Netcode;
@@ -26,6 +27,9 @@ public class GlobalInstaller : MonoInstaller
[SerializeField]
private GameObject playerPrefab;
[SerializeField]
private GameObject uiManagerPrefab;
public override void Start()
{
base.Start();
@@ -83,5 +87,14 @@ public class GlobalInstaller : MonoInstaller
Container.BindInstance(playerComponent)
.AsSingle();
Container.Bind<HVRInputModule>()
.FromComponentInNewPrefab(uiManagerPrefab)
.AsSingle()
.OnInstantiated<HVRInputModule>((ctx, obj) =>
{
obj.name = uiManagerPrefab.name;
})
.NonLazy();
}
}

View 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;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 889a6708f6f028c4e96df3407816950a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: