Files
DeltaVR/Assets/_PROJECT/Components/NewHandPresence/Prefabs/XROrigin Scripts/Continuos locomotion Conf.cs

74 lines
2.4 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
//using UnityEngine.UIElements;
using UnityEngine.XR.Interaction.Toolkit;
public class ContinuoslocomotionConfigurator : AbstractValueController
{
public Button turnOffButton;
public Button turnOnButton;
public MoveSliderDragHandler moveSpeedSlider;
public ContinuousMoveProviderBase locomotion;
// Events for listeners
public event Action<bool> OnLocomotionToggled; // true = enabled, false = disabled
public event Action<float> OnSpeedChanged; // sends new speed
void Start()
{
turnOnButton.onClick.AddListener(enableLocomotion);
turnOffButton.onClick.AddListener(disableLocomotion);
RestoreFromConfig();
}
override public void RestoreFromConfig()
{
bool isContinuousLocomotion = ConfigManager.instance.GetIsContinuousLocomotion();
turnOffButton.gameObject.SetActive(isContinuousLocomotion);
turnOnButton.gameObject.SetActive(!isContinuousLocomotion);
locomotion.enabled = isContinuousLocomotion;
OnLocomotionToggled?.Invoke(isContinuousLocomotion);
float continuousLocomotionSpeed = ConfigManager.instance.GetContinuousLocomotionSpeed();
moveSpeedSlider.SetHandleValue(continuousLocomotionSpeed);
locomotion.moveSpeed = continuousLocomotionSpeed;
}
public void UpdateSpeed(float speed)
{
locomotion.moveSpeed = speed;
OnSpeedChanged?.Invoke(speed);
WriteToConfig();
}
private void enableLocomotion()
{
AudioManager.Instance.PlayAttachedInstance(FMODEvents.Instance.Click, gameObject);
locomotion.enabled = true;
turnOnButton.gameObject.SetActive(false);
turnOffButton.gameObject.SetActive(true);
OnLocomotionToggled?.Invoke(true);
WriteToConfig();
}
private void disableLocomotion()
{
AudioManager.Instance.PlayAttachedInstance(FMODEvents.Instance.Click, gameObject);
locomotion.enabled = false;
turnOnButton.gameObject.SetActive(true);
turnOffButton.gameObject.SetActive(false);
OnLocomotionToggled?.Invoke(false);
WriteToConfig();
}
protected void WriteToConfig()
{
ConfigManager.instance.SetIsContinuousLocomotion(locomotion.enabled);
ConfigManager.instance.SetContinuousLocomotionSpeed(locomotion.moveSpeed);
}
}