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

namespace uTools {
	[AddComponentMenu("uTools/Tween/Tween Scale(uTools)")]
	
	public class uTweenScale : uTweener {

		public Vector3 from = Vector3.zero;
		public Vector3 to = Vector3.one;

		Transform mTransform;

        public Transform cachedTransform { get { if (mTransform == null) mTransform = GetComponent<Transform>(); return mTransform; } }
		public Vector3 value {
            get { return cachedTransform.localScale; }
            set { cachedTransform.localScale = value; }
		}

		protected override void OnUpdate (float factor, bool isFinished)
		{
			value = from + factor * (to - from);
		}

		public static uTweenScale Begin(GameObject go, Vector3 from, Vector3 to, float duration = 1f, float delay = 0f) {
			uTweenScale comp = uTweener.Begin<uTweenScale>(go, duration);
			comp.from = from;
			comp.to = to;
			comp.duration = duration;
			comp.delay = delay;
			if (duration <= 0) {
				comp.Sample(1, true);
				comp.enabled = false;
			}
			return comp;
		}

        public override void SetCurrentValueToStart()
        {
            base.SetCurrentValueToStart();
            value = from;
        }

        public override void SetCurrentValueToEnd()
        {
            base.SetCurrentValueToEnd();
            value = to;
        }
	}
}
