using UnityEngine;
using System;
using System.Collections.Generic;
using mgaia.Utils;

namespace mgaia.tk2d.Animations
{
    public class Tk2dSpriteColorAnimation : AbstractCodeAnimation
    {
        private tk2dBaseSprite[] mSprites;

        public Tk2dSpriteColorAnimation(float[] keyTimes, ValueType[] keyValues, ValueType initialValue, bool loop) : base(keyTimes, keyValues, initialValue, loop) { }

        protected override void Lerp(ValueType fromValue, ValueType toValue, float normalizedTime)
        {
            mSprites.ForEach(sprite => sprite.color = Color.Lerp((Color)fromValue, (Color)toValue, normalizedTime));
        }

        protected override void OnActivateAnimation(object[] objs)
        {
            mSprites = objs.Select(obj => obj as tk2dBaseSprite).ToArray();
        }
    }
}