SHADE_Y3/Assets/Scripts/UI/SC_MinusTimerText.cs

79 lines
1.8 KiB
C#
Raw Normal View History

2023-03-21 14:40:30 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SHADE;
namespace SHADE_Scripting.UI
{
public class MinusTimerText: Script
{
public float duration = 0.5f;
private Vector3 startPos;
[NonSerialized]
TweenThread thread;
protected override void awake()
{
Transform transform = GetComponent<Transform>();
if(transform)
{
startPos = transform.LocalPosition;
}
}
protected override void start()
{
thread = TweenManager.CreateTweenThread(duration, 1.0f, 0.0f, EASING_METHOD.LINEAR);
thread.SetResetOnInactive(GameObject);
}
protected override void update()
{
if(thread != null)
{
TextRenderable text = GetComponent<TextRenderable>();
if (text)
{
Color temp = text.TextColor;
temp.a = thread.GetValue();
text.TextColor = temp;
}
if(thread.IsCompleted())
{
GameObject.SetActive(false);
}
}
Transform transform = GetComponent<Transform>();
if(transform)
{
Vector3 temp = transform.LocalPosition;
temp.y -= (float)Time.DeltaTime;
transform.LocalPosition = temp;
}
}
public void Reset()
{
GameObject.SetActive(true);
thread.Reset();
Transform transform = GetComponent<Transform>();
if (transform)
{
transform.LocalPosition = startPos;
}
}
}
}