67 lines
1.1 KiB
C#
67 lines
1.1 KiB
C#
using BitStrap;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class AnimateButton : MonoBehaviour
|
|
{
|
|
public float delay = 5f;
|
|
|
|
public float animationTime = 0.5f;
|
|
|
|
public Color normalColor = Color.white;
|
|
|
|
public Color targetColor = Color.yellow;
|
|
|
|
public Image target;
|
|
|
|
[ReadOnly]
|
|
public Button button;
|
|
|
|
[ReadOnly]
|
|
public Text text;
|
|
|
|
[ReadOnly]
|
|
public ColorBlock colorBlock = default(ColorBlock);
|
|
|
|
[ReadOnly]
|
|
public float timer;
|
|
|
|
private void Start()
|
|
{
|
|
button = GetComponent<Button>();
|
|
text = GetComponent<Text>();
|
|
if ((bool)button)
|
|
{
|
|
colorBlock = button.colors;
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
timer -= Time.unscaledDeltaTime;
|
|
if (!(timer <= 0f))
|
|
{
|
|
return;
|
|
}
|
|
timer = delay;
|
|
LeanTween.value(base.gameObject, normalColor, targetColor, animationTime).setLoopPingPong(1).setIgnoreTimeScale(true)
|
|
.setEaseInOutQuad()
|
|
.setOnUpdate(delegate(Color val)
|
|
{
|
|
if ((bool)target)
|
|
{
|
|
target.color = val;
|
|
}
|
|
else if ((bool)button)
|
|
{
|
|
colorBlock.normalColor = val;
|
|
button.colors = colorBlock;
|
|
}
|
|
else if ((bool)text)
|
|
{
|
|
text.color = val;
|
|
}
|
|
});
|
|
}
|
|
}
|