using UnityEngine;
using System;
using System.Collections.Generic;

namespace mgaia.Utils.Animations
{
    public class GameobjectAlphaAnimation : AbstractCodeAnimation
    {
        private GameObject[] mGameobjects;

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

        protected override void Lerp(ValueType fromValue, ValueType toValue, float normalizedTime)
        {
            mGameobjects.ForEach(obj =>
                obj.renderer.material.color = new Color
                (
                    obj.renderer.material.color.r,
                    obj.renderer.material.color.g,
                    obj.renderer.material.color.b,
                    Mathf.Lerp((float)fromValue, (float)toValue, normalizedTime)
                ));
        }

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