using UnityEngine;
using UnityEngine.UI;
using System;

[RequireComponent (typeof(Image))]
public class ImageColorTo : SomethingTo {

    private Color fromColor;
    private Color targetColor;

    private Image image = null;

    void Awake(){
        image = GetComponent<Image>();
    }

    private void Lerp(float lerp){
        image.color = Color.Lerp(fromColor, targetColor, lerp);
    }

    public void ChangeColor(Color targetColor){
        image.color = targetColor;
    }
    public void ChangeColor(Color targetColor, float interval){
        ChangeColor(targetColor, interval, ActionExtensions.EmptyAction);
    }
    public void ChangeColor(Color targetColor, float interval, Action callback){
        this.targetColor = targetColor;
        this.fromColor = image.color;

        Begin(Lerp, interval, callback);
    }

    public void ChangeColor(Color fromColor, Color targetColor, float interval){
        ChangeColor(fromColor, targetColor, interval, ActionExtensions.EmptyAction);
    }
    public void ChangeColor(Color fromColor, Color targetColor, float interval, Action callback){
        image.color = fromColor;
        ChangeColor(targetColor, interval, callback);
    }
}
