94 lines
2.4 KiB
C#
94 lines
2.4 KiB
C#
using System.Collections.Generic;
|
|
using Obvious.Soap;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class UI_ReelMapping : MonoBehaviour
|
|
{
|
|
public FloatVariable DragSetting;
|
|
|
|
public FloatVariable LineLength;
|
|
|
|
public FloatVariable LineOnSpool;
|
|
|
|
[SerializeField]
|
|
private RectTransform _CirclesParent;
|
|
|
|
[SerializeField]
|
|
private float _CirclesMinScale = 23f;
|
|
|
|
[SerializeField]
|
|
private float _CirclesMaxScale = 15f;
|
|
|
|
[SerializeField]
|
|
private RectTransform _RotatorParent;
|
|
|
|
[SerializeField]
|
|
private float _RotatorMinScale = 0.9374835f;
|
|
|
|
[SerializeField]
|
|
private float _RotatorMaxScale = 0.725f;
|
|
|
|
[SerializeField]
|
|
private TextMeshProUGUI _LineLengthText;
|
|
|
|
[SerializeField]
|
|
private Color _DangerMinColor;
|
|
|
|
[SerializeField]
|
|
private Color _DangerMaxColor;
|
|
|
|
[SerializeField]
|
|
private List<Image> _Circles;
|
|
|
|
[SerializeField]
|
|
private float _AnimationSpeed = 1f;
|
|
|
|
private Vector3 _CircleScale;
|
|
|
|
private Vector3 _RotatorScale;
|
|
|
|
private Quaternion _RotatorLocalRotation;
|
|
|
|
private void Start()
|
|
{
|
|
SetScale(DragSetting.Value);
|
|
_CirclesParent.localScale = _CircleScale;
|
|
_RotatorParent.localScale = _RotatorScale;
|
|
_RotatorLocalRotation = _RotatorParent.localRotation;
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
LineLengthOnOnValueChanged(LineLength.Value);
|
|
LineLength.OnValueChanged += LineLengthOnOnValueChanged;
|
|
DragSetting.OnValueChanged += SetScale;
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
LineLength.OnValueChanged -= LineLengthOnOnValueChanged;
|
|
DragSetting.OnValueChanged -= SetScale;
|
|
}
|
|
|
|
private void LineLengthOnOnValueChanged(float obj)
|
|
{
|
|
_LineLengthText.text = obj.ToString((obj >= 10f) ? "F0" : "F1") + "m /\n" + LineOnSpool.Value.ToString("F0") + "m";
|
|
_RotatorLocalRotation = Quaternion.AngleAxis(obj * -60f, Vector3.forward);
|
|
}
|
|
|
|
private void SetScale(float value)
|
|
{
|
|
_CircleScale = Vector3.one * Mathf.Lerp(_CirclesMinScale, _CirclesMaxScale, DragSetting.Value);
|
|
_RotatorScale = Vector3.one * Mathf.Lerp(_RotatorMinScale, _RotatorMaxScale, DragSetting.Value);
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
_CirclesParent.localScale = Vector3.Slerp(_CirclesParent.localScale, _CircleScale, Time.deltaTime * _AnimationSpeed);
|
|
_RotatorParent.localScale = Vector3.Slerp(_RotatorParent.localScale, _RotatorScale, Time.deltaTime * _AnimationSpeed);
|
|
_RotatorParent.localRotation = Quaternion.Slerp(_RotatorParent.localRotation, _RotatorLocalRotation, Time.deltaTime * _AnimationSpeed);
|
|
}
|
|
}
|