SHADE_Y3/Assets/Scripts/UI/SC_MultiplierTextFx.cs

86 lines
2.0 KiB
C#

using SHADE;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace SHADE_Scripting.UI
{
public class MultiplierTextFx : Script
{
[NonSerialized]
private TweenThread sizeThread;
private TweenThread sizeInvertThread;
public float maxSize = 1.0f;
public float minSize = 0.3f;
const float sizeUpDuration = 0.1f;
[NonSerialized]
private Vector3 defaultScale;
private bool tweenUp = false;
protected override void start()
{
sizeThread = TweenManager.CreateTweenThread(0.01f, maxSize, minSize, EASING_METHOD.EASE_IN_SINE);
sizeInvertThread = TweenManager.CreateTweenThread(sizeUpDuration, minSize, maxSize, EASING_METHOD.EASE_IN_SINE);
Transform transform = GetComponent<Transform>();
if (transform != null)
{
defaultScale = transform.LocalScale;
transform.LocalScale = Vector3.Zero;
}
}
protected override void update()
{
if (sizeThread == null || sizeInvertThread == null)
return;
Transform transform = GetComponent<Transform>();
GetComponent<TextRenderable>().Text = $"X {GameManager.Instance.currMultiplierCombo}";
if (transform != null)
{
if (tweenUp == false)
{
transform.LocalScale = defaultScale * sizeThread.GetValue();
}
else
{
if (sizeInvertThread.IsCompleted())
{
tweenUp = false;
sizeThread.Reset();
}
transform.LocalScale = defaultScale * sizeInvertThread.GetValue();
}
}
}
public void ShowMultiplier(int multiplier, float duration)
{
sizeThread.duration = duration + sizeUpDuration;
sizeInvertThread.Reset();
sizeThread.Reset();
tweenUp = true;
}
}
}