1
0
mirror of synced 2024-12-12 14:31:04 +01:00
WACVR/Assets/Script/Configuration/PlayerSettingManager.cs

49 lines
1.9 KiB
C#
Raw Normal View History

2022-10-03 02:04:54 +02:00
using UnityEngine.UI;
using UnityEngine;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
public class PlayerSettingManager : MonoBehaviour
{
private Transform LHandTransform = null;
private Transform RHandTransform = null;
private double height = 0; // meters
[SerializeField]
private double upperLimit = 10; // meters
[SerializeField]
private double lowerLimit = -10; // meters
void Start()
{
2022-10-16 15:42:49 +02:00
LHandTransform = transform.Find("Camera Offset").Find("LeftHand Controller").Find("LHand Virtual");
RHandTransform = transform.Find("Camera Offset").Find("RightHand Controller").Find("RHand Virtual");
2022-10-03 02:04:54 +02:00
ConfigManager.onConfigChanged += ApplyConfig;
ConfigManager.EnsureInitialization();
ApplyConfig();
}
void ApplyConfig()
{
LHandTransform.localPosition = new Vector3(ConfigManager.config.HandPosition[0]/100,
ConfigManager.config.HandPosition[1]/100,
ConfigManager.config.HandPosition[2]/100);
RHandTransform.localPosition = new Vector3(-ConfigManager.config.HandPosition[0]/100,
ConfigManager.config.HandPosition[1]/100,
ConfigManager.config.HandPosition[2]/100);
var value = ConfigManager.config.HandSize;
LHandTransform.localScale = new Vector3(value/100, value/100, value/100);
RHandTransform.localScale = new Vector3(value/100, value/100, value/100);
height = ConfigManager.config.PlayerHeight;
}
void Update()
{
if (height > upperLimit) height = upperLimit;
if (height < lowerLimit) height = lowerLimit;
transform.position = new Vector3(transform.position.x, (float)height, transform.position.z);
}
private void ResetHeight()
{
height = 0;
}
}