仿照NGUI封装 DoTween功能系列(五)-TweenPlay

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yuyingwin/article/details/80074572

using UnityEngine;

namespace UGUITweener
{
    [ExecuteInEditMode]
    public class TweenPlaying : MonoBehaviour
    {
        public Transform transforms;

        private TweenerSetting tweenerSetting;

        public bool incluldeChild;

        public void AutoPlay()
        {
            TweenPlay(true);
        }

        public void PlayForward()
        {
            TweenPlay(true);
        }

        public void PlayReverse()
        {
            TweenPlay(false);
        }

        private void TweenPlay(bool value)
        {
            try
            {
                if (!tweenerSetting && transforms && transforms.GetComponent<TweenerSetting>())
                {
                    tweenerSetting = transforms.GetComponent<TweenerSetting>();
                }

                TweenerSetting[] tweenerSettings = transforms.GetComponentsInChildren<TweenerSetting>(true);

                if (incluldeChild)
                {
                    if (tweenerSetting)
                    {
                        tweenerSetting.TweenPlay(value);
                    }

                    for (int i = 0; i < tweenerSettings.Length; i++)
                    {
                        tweenerSettings[i].TweenPlay(value);
                    }
                }
                else
                {
                    if (tweenerSetting)
                    {
                        tweenerSetting.TweenPlay(value);
                    }
                }
            }
            catch
            {
            }
        }
    }
}

猜你喜欢

转载自blog.csdn.net/yuyingwin/article/details/80074572