86 lines
2.0 KiB
C#
86 lines
2.0 KiB
C#
using UnityEngine;
|
|
|
|
namespace Superlazy.UI
|
|
{
|
|
public class SLUIScale : SLUIOnOffTransition
|
|
{
|
|
public float onDuration = 0.3f;
|
|
public float offDuration = 0.3f;
|
|
|
|
private float currentTime;
|
|
|
|
protected override void Validate()
|
|
{
|
|
}
|
|
|
|
protected override void Init()
|
|
{
|
|
var newSize = Vector3.zero;
|
|
if (currentState == false)
|
|
{
|
|
currentTime = 0;
|
|
}
|
|
else
|
|
{
|
|
newSize = Vector3.one;
|
|
currentTime = 1;
|
|
}
|
|
|
|
transform.localScale = newSize;
|
|
}
|
|
|
|
protected override bool OnUpdate(bool forceUpdate = false)
|
|
{
|
|
var result = false;
|
|
|
|
if (currentState)
|
|
{
|
|
if (onDuration == 0)
|
|
{
|
|
currentTime = 1;
|
|
}
|
|
else
|
|
{
|
|
currentTime += Time.unscaledDeltaTime / onDuration;
|
|
}
|
|
|
|
if (currentTime >= 1.0f)
|
|
{
|
|
currentTime = 1.0f;
|
|
result = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (offDuration == 0)
|
|
{
|
|
currentTime = 0;
|
|
}
|
|
else
|
|
{
|
|
currentTime -= Time.unscaledDeltaTime / offDuration;
|
|
}
|
|
|
|
if (currentTime <= 0.0f)
|
|
{
|
|
currentTime = 0.0f;
|
|
result = true;
|
|
}
|
|
}
|
|
|
|
var ease = currentTime == 1.0f ? 1 : 1 - Mathf.Pow(2, -10 * currentTime);
|
|
|
|
var newSize = Vector3.one * ease;
|
|
|
|
transform.localScale = newSize;
|
|
|
|
return result;
|
|
}
|
|
|
|
protected override void ForceDisable()
|
|
{
|
|
currentTime = 0.0f;
|
|
transform.localScale = Vector3.zero;
|
|
}
|
|
}
|
|
} |