using UnityEngine;
using System.Collections;

namespace uTools
{
    [RequireComponent(typeof(CanvasGroup))]
    public class uTweenCanvasGroupAlpha : uTweenValue
    {
        Transform mTransform;

        float mAlpha = 0f;

        public Transform cachedTransform { get { if (mTransform == null) mTransform = transform; return mTransform; } }

        CanvasGroup mCanvasGroup;

        public CanvasGroup canvasGroup
        {
            get
            {
                if (null == mCanvasGroup)
                {
                    mCanvasGroup = GetComponent<CanvasGroup>();
                }
                return mCanvasGroup;
            }
        }

        public float alpha
        {
            get
            {
                return mAlpha;
            }
            set
            {
                SetAlpha(value);
                mAlpha = value;
            }
        }

        protected override void ValueUpdate(float value, bool isFinished)
        {
            alpha = value;
        }

        void SetAlpha(float _alpha)
        {
            canvasGroup.alpha = _alpha;
        }
    }
}