﻿using UnityEngine;
using System.Collections;

namespace Cafe
{
    public class MkPosition : MkAnimeBase
    {
        [SerializeField]
        MkValue _xVal;

        [SerializeField]
        MkValue _yVal;

        protected override IEnumerator AnimationUpdate()
        {
            while(true)
            {
                float durationDelta = (ElasedTime / Duration);

                // Work With Local Position
                Vector2 position = this.transform.localPosition;

                if (!Smooth)
                {
                    position.x = (Mathf.Lerp(_xVal._beginVal, _xVal._endVal, durationDelta));
                    position.y = (Mathf.Lerp(_yVal._beginVal, _yVal._endVal, durationDelta));
                }
                else
                {
                    position.x = (Mathf.SmoothStep(_xVal._beginVal, _xVal._endVal, durationDelta));
                    position.y = (Mathf.SmoothStep(_yVal._beginVal, _yVal._endVal, durationDelta));
                }

                this.transform.localPosition = position;

                if(durationDelta >= 1.0f && !_isRepeat)
                {
                    StopCoroutine("AnimationUpdate");
                }
                yield return null;
            }
        }

        public MkValue XValue
        {
            set
            {
                _xVal = value;
            }
            get
            {
                return _xVal;
            }
        }

        public MkValue YValue
        {
            set
            {
                _yVal = value;
            }
            get
            {
                return _yVal;
            }
        }
    }
}
