1
0
mirror of synced 2024-12-12 22:41:06 +01:00
WACVR/Assets/Script/Controller/HandFollowManager.cs

64 lines
1.9 KiB
C#
Raw Normal View History

2022-11-05 01:32:17 +01:00
using TMPro;
2022-10-16 15:42:49 +02:00
using UnityEngine;
2022-11-05 01:32:17 +01:00
using UnityEngine.UI;
2022-10-16 15:42:49 +02:00
public class HandFollowManager : MonoBehaviour
{
public GameObject Target;
public Transform Center;
2022-11-05 01:32:17 +01:00
public CEnum.handStabilization Mode;
2022-10-16 15:42:49 +02:00
public float VelocityThreshold = 0.1f;
private Rigidbody TargetRigidbody;
private Vector3 previousPosition;
private void Start()
{
TargetRigidbody = Target.GetComponent<Rigidbody>();
2022-11-05 01:32:17 +01:00
var modeWidget = ConfigManager.GetConfigPanelWidget("HandStabilization");
var threshWidget = ConfigManager.GetConfigPanelWidget("Threshold");
var modeDropdown = modeWidget.GetComponent<TMP_Dropdown>();
var threshSlider = threshWidget.GetComponent<Slider>();
modeDropdown.onValueChanged.AddListener((int value) => {
VelocityThreshold = ConfigManager.config.HandStabilVelocity;
Mode = (CEnum.handStabilization)value;
});
threshSlider.onValueChanged.AddListener((float value) => {
VelocityThreshold = value;
});
modeDropdown.onValueChanged?.Invoke(modeDropdown.value);
threshSlider.onValueChanged?.Invoke(threshSlider.value);
2022-10-16 15:42:49 +02:00
}
private void VelocityTracking()
{
Vector3 velocity = (Target.transform.position - previousPosition) / Time.deltaTime;
if (velocity.magnitude > VelocityThreshold)
{
transform.position = Target.transform.position;
}
previousPosition = Target.transform.position;
}
private void Update()
{
gameObject.transform.localScale = Target.transform.localScale;
}
private void FixedUpdate()
{
switch (Mode)
{
2022-11-05 01:32:17 +01:00
case CEnum.handStabilization.Velocity:
2022-10-16 15:42:49 +02:00
VelocityTracking();
break;
2022-11-05 01:32:17 +01:00
case CEnum.handStabilization.None:
2022-10-16 15:42:49 +02:00
transform.position = Target.transform.position;
break;
}
}
}