using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class LoaderUI : BaseUI
{
	[SerializeField] Image loaderImage = null; // Set from editor

	const float showTime = 0.4f;

	protected override void Show (OnUIFinishLoading onFinishShowing)
	{
		Timer.Add (showTime, (anim) => {
			if (loaderImage != null)
			{
				loaderImage.color = new Color(0, 0, 0, anim * anim * 1.2f);
			}
		},
		() => {
			if (loaderImage != null)
			{
				loaderImage.color = new Color(0, 0, 0, 1);
			}
			if (onFinishShowing != null)
			{
				onFinishShowing();
			}
		});
	}

	protected override void Hide (OnUIFinishLoading onFinishHiding)
	{
		Timer.Add (showTime, (anim) => {
			if (loaderImage != null)
			{
				loaderImage.color = new Color(0, 0, 0, (1f - anim) * (1f - anim));
			}
		},
		() => {
			if (loaderImage != null)
			{
				loaderImage.color = new Color(0, 0, 0, 0);
			}
			if (onFinishHiding != null)
			{
				onFinishHiding();
			}
		});
	}
}
