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

namespace mgaia.tk2d.Animations
{
    public class Tk2dTextColorAnimation : AbstractCodeAnimation
    {
        private tk2dTextMesh[] mTexts;

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

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

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