121 lines
2.8 KiB
C#
121 lines
2.8 KiB
C#
using SHADE;
|
|
using SHADE_Scripting.Audio;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading;
|
|
|
|
|
|
namespace SHADE_Scripting.UI
|
|
{
|
|
|
|
public class TweenThread
|
|
{
|
|
private float timer = 0.0f;
|
|
public float duration = 1.0f;
|
|
public EASING_METHOD method;
|
|
private float value = 0.0f;
|
|
public float startValue = 0.0f;
|
|
public float endValue = 1.0f;
|
|
|
|
|
|
public TweenThread(float duration, float startValue, float endValue, EASING_METHOD method)
|
|
{
|
|
this.duration = duration;
|
|
this.method = method;
|
|
this.startValue = startValue;
|
|
this.endValue = endValue;
|
|
}
|
|
|
|
public void Update(float deltaTime)
|
|
{
|
|
if (timer >= duration)
|
|
return;
|
|
|
|
timer += deltaTime;
|
|
if (timer >= duration)
|
|
timer = duration;
|
|
|
|
value = EasingHelper.EaseHelp(timer/duration, method) * (endValue - startValue) + startValue ;
|
|
}
|
|
|
|
public bool IsCompleted()
|
|
{
|
|
return timer >= duration;
|
|
}
|
|
|
|
public void Reset()
|
|
{
|
|
timer = 0.0f;
|
|
value = startValue;
|
|
}
|
|
public void Reset(float startValue, float endValue)
|
|
{
|
|
Reset();
|
|
this.startValue = startValue;
|
|
this.endValue = endValue;
|
|
}
|
|
public void ResetInvert()
|
|
{
|
|
Reset();
|
|
float temp = startValue;
|
|
startValue = endValue;
|
|
endValue = temp;
|
|
}
|
|
|
|
|
|
public float GetValue()
|
|
{
|
|
return value;
|
|
}
|
|
|
|
}
|
|
|
|
public class TweenManager : Script
|
|
{
|
|
public static TweenManager Instance { get; private set; }
|
|
|
|
[NonSerialized]
|
|
private List<TweenThread> threadList;
|
|
|
|
protected override void awake()
|
|
{
|
|
if (Instance != null && Instance != this)
|
|
RemoveScript<TweenManager>();
|
|
else
|
|
Instance = this;
|
|
|
|
threadList = new List<TweenThread>();
|
|
|
|
}
|
|
|
|
protected override void onDestroy()
|
|
{
|
|
if (Instance == this)
|
|
Instance = null;
|
|
|
|
}
|
|
|
|
protected override void update()
|
|
{
|
|
foreach (TweenThread thread in threadList)
|
|
{
|
|
thread.Update(Time.DeltaTimeF);
|
|
}
|
|
}
|
|
|
|
|
|
public static TweenThread CreateTweenThread(float duration, float startValue, float endValue, EASING_METHOD method)
|
|
{
|
|
if (Instance == null)
|
|
return null;
|
|
|
|
|
|
TweenThread thread = new TweenThread(duration, startValue, endValue, method);
|
|
Instance.threadList.Add(thread);
|
|
thread.Reset();
|
|
return thread;
|
|
}
|
|
|
|
}
|
|
}
|