2017-06-26 01:36:49 +08:00
|
|
|
|
/// Credit SimonDarksideJ
|
|
|
|
|
/// Sourced from my head
|
|
|
|
|
|
2017-08-02 17:21:45 +08:00
|
|
|
|
namespace UnityEngine.UI.Extensions.Examples
|
2017-06-26 01:36:49 +08:00
|
|
|
|
{
|
|
|
|
|
[RequireComponent(typeof(Image))]
|
|
|
|
|
public class CooldownEffect_Image : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
public CooldownButton cooldown;
|
|
|
|
|
public Text displayText;
|
|
|
|
|
private Image target;
|
|
|
|
|
|
|
|
|
|
string originalText;
|
|
|
|
|
|
|
|
|
|
// Use this for initialization
|
|
|
|
|
void Start()
|
|
|
|
|
{
|
|
|
|
|
if (cooldown == null)
|
|
|
|
|
{
|
|
|
|
|
Debug.LogError("Missing Cooldown Button assignment");
|
|
|
|
|
}
|
|
|
|
|
target = GetComponent<Image>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
|
void Update()
|
|
|
|
|
{
|
|
|
|
|
target.fillAmount = Mathf.Lerp(0, 1, cooldown.CooldownTimeRemaining / cooldown.CooldownTimeout);
|
|
|
|
|
if (displayText)
|
|
|
|
|
{
|
|
|
|
|
displayText.text = string.Format("{0}%", cooldown.CooldownPercentComplete);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnDisable()
|
|
|
|
|
{
|
|
|
|
|
if (displayText)
|
|
|
|
|
{
|
|
|
|
|
displayText.text = originalText;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnEnable()
|
|
|
|
|
{
|
|
|
|
|
if (displayText)
|
|
|
|
|
{
|
|
|
|
|
originalText = displayText.text;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|