2022-10-03 02:04:54 +02:00
|
|
|
using System.Collections;
|
|
|
|
using System;
|
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.UI;
|
|
|
|
using UnityEngine.Events;
|
|
|
|
using TMPro;
|
|
|
|
|
|
|
|
public class ValueManager : MonoBehaviour
|
|
|
|
{
|
|
|
|
TMP_Text tmp;
|
2022-11-05 20:23:31 +01:00
|
|
|
public float value
|
2022-10-07 17:12:42 +02:00
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return _value;
|
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
|
|
|
_value = value;
|
|
|
|
onValueChanged?.Invoke();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private float _value;
|
2022-10-03 02:04:54 +02:00
|
|
|
float tempValue;
|
|
|
|
public bool isPointerDown = false;
|
|
|
|
public UnityEvent onValueChanged = new UnityEvent();
|
|
|
|
void Start()
|
|
|
|
{
|
|
|
|
tmp = GetComponent<TMP_Text>();
|
2022-11-05 01:32:17 +01:00
|
|
|
//ConfigManager.EnsureInitialization();
|
2022-10-03 02:04:54 +02:00
|
|
|
onValueChanged.AddListener(UpdateText);
|
|
|
|
}
|
|
|
|
void Update()
|
|
|
|
{
|
|
|
|
if (isPointerDown)
|
|
|
|
{
|
|
|
|
ChangeValueContinue(tempValue);
|
|
|
|
}
|
|
|
|
}
|
2022-10-07 17:12:42 +02:00
|
|
|
public void ChangeValueContinue(float __value)
|
2022-10-03 02:04:54 +02:00
|
|
|
{
|
2022-10-07 17:12:42 +02:00
|
|
|
tempValue = __value;
|
2022-11-05 20:23:31 +01:00
|
|
|
value += Time.deltaTime * __value;
|
2022-10-03 02:04:54 +02:00
|
|
|
isPointerDown = true;
|
|
|
|
}
|
|
|
|
public void PointerState(bool state)
|
|
|
|
{
|
|
|
|
isPointerDown = state;
|
|
|
|
}
|
|
|
|
public void ResetValue()
|
|
|
|
{
|
2022-11-05 20:23:31 +01:00
|
|
|
value = 0;
|
2022-10-03 02:04:54 +02:00
|
|
|
}
|
|
|
|
public void UpdateText()
|
|
|
|
{
|
2022-10-07 17:12:42 +02:00
|
|
|
tmp.text = String.Format("{0:F2}", _value);
|
2022-10-03 02:04:54 +02:00
|
|
|
}
|
|
|
|
}
|