53 lines
1.2 KiB
C#
53 lines
1.2 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
|
|
public class LeanTimer : MonoBehaviour
|
|
{
|
|
[Header("Start values:")]
|
|
public bool StartOnAwake = false;
|
|
public float StartValue;
|
|
public float EndValue;
|
|
public float Time;
|
|
|
|
|
|
public UnityEvent<float> OnUpdate = new UnityEvent<float>();
|
|
public UnityEvent OnTotalComplete;
|
|
private LTDescr LTDescr;
|
|
|
|
private void Start()
|
|
{
|
|
if (StartOnAwake)
|
|
{
|
|
ManualStart();
|
|
}
|
|
}
|
|
|
|
public void ManualStart()
|
|
{
|
|
StartTimer(StartValue, EndValue, Time);
|
|
}
|
|
|
|
public void StartTimer(float startValue, float endValue, float time, System.Action OnComplete = null)
|
|
{
|
|
LTDescr = LeanTween.value(1, 0, time).setOnUpdate((float x) =>
|
|
{
|
|
OnUpdate?.Invoke(x);
|
|
}).setOnComplete(() =>
|
|
{
|
|
OnComplete?.Invoke();
|
|
OnTotalComplete?.Invoke();
|
|
});
|
|
}
|
|
|
|
public void StopTimer(float value = 0)
|
|
{
|
|
if (LTDescr != null)
|
|
{
|
|
LeanTween.cancel(LTDescr.id);
|
|
OnUpdate?.Invoke(value);
|
|
}
|
|
}
|
|
}
|