using UnityEngine;
using System.Collections;

namespace uTools
{
    public class uTweenWorldPosition_Axis : uTweenValue
    {
        public enum Axis
        {
            x,
            y,
            z,
        }

        public Axis axis;
        
        Transform mTransform;

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

        protected override void ValueUpdate(float value, bool isFinished)
        {
            base.ValueUpdate(value, isFinished);
            switch (axis)
            {
                case Axis.x:
                    this.value = new Vector3(value, this.value.y, this.value.z);
                    break;
                case Axis.y:
                    this.value = new Vector3(this.value.x, value, this.value.z);
                    break;
                case Axis.z:
                    this.value = new Vector3(this.value.x, this.value.y, value);
                    break;
                default:
                    break;
            }
        }
    }
}
