예제 #1
0
 public void FinishAnim()
 {
     currentTime = totalTime;
     executeUpdate();
     executeCallBack();
     TweenUtil.GetInstance().animList.Remove(this);
     StackObjectPool <TweenScript> .Push(this);
 }
예제 #2
0
파일: TweenUtil.cs 프로젝트: cnscj/THSTG
        public static void StopAnim(TweenScript tweenData, bool isCallBack = false)
        {
            if (isCallBack)
            {
                tweenData.executeCallBack();
            }

            GetInstance().animList.Remove(tweenData);
            StackObjectPool <TweenScript> .Push(tweenData);
        }
예제 #3
0
        /// <summary>
        /// 动画移动到某位置
        /// </summary>
        /// <returns></returns>
        public static TweenScript TnLocalMove(this Transform trans, Vector3 to, float time = 0.5f,
                                              float delayTime = 0)
        {
            TweenScript tweenTmp = StackObjectPool <TweenScript> .Get();

            tweenTmp.SetValue(trans.localPosition, to);
            tweenTmp.isLocal = true;
            tweenTmp.Init(trans.gameObject, AnimType.Position, time, delayTime);
            TweenUtil.GetInstance().AddTween(tweenTmp);
            return(tweenTmp);
        }
예제 #4
0
        public static TweenScript TnAlphaTo(this Transform trans, float from, float to,
                                            float time      = 0.5f,
                                            float delayTime = 0)
        {
            TweenScript tweenTmp = StackObjectPool <TweenScript> .Get();

            tweenTmp.SetValue(from, to);
            tweenTmp.Init(trans.gameObject, AnimType.Alpha, time, delayTime);
            TweenUtil.GetInstance().AddTween(tweenTmp);
            return(tweenTmp);
        }
예제 #5
0
        /// <summary>
        /// 隐藏/显示
        /// </summary>
        public static TweenScript TnBlink(this Transform trans, float space,
                                          float time      = 0.5f,
                                          float delayTime = 0)
        {
            TweenScript tweenTmp = StackObjectPool <TweenScript> .Get();

            tweenTmp.blinkTime = space;

            tweenTmp.Init(trans.gameObject, AnimType.Blink, time, delayTime);
            TweenUtil.GetInstance().AddTween(tweenTmp);
            return(tweenTmp);
        }
예제 #6
0
        /// <summary>
        /// UGUI RectTransfrom 放大缩小
        /// width/height
        /// </summary>
        public static TweenScript TnUiSize(this RectTransform rectTrans, Vector2 to,
                                           float time      = 0.5f,
                                           float delayTime = 0)
        {
            Vector2     fromTmp  = rectTrans.sizeDelta;
            TweenScript tweenTmp = StackObjectPool <TweenScript> .Get();

            tweenTmp.SetValue(fromTmp, to);
            tweenTmp.Init(rectTrans.gameObject, AnimType.UiSize, time, delayTime);
            TweenUtil.GetInstance().AddTween(tweenTmp);
            return(tweenTmp);
        }
예제 #7
0
        /// <summary>
        /// UGUI Move RectTransform .anchoredPosition3D
        /// </summary>
        public static TweenScript TnAnchoredPosition(this RectTransform rectTrans, Vector3 to,
                                                     float time      = 0.5f,
                                                     float delayTime = 0)
        {
            TweenScript tweenTmp = StackObjectPool <TweenScript> .Get();

            tweenTmp.SetValue(rectTrans.anchoredPosition3D, to);

            tweenTmp.Init(rectTrans.gameObject, AnimType.UiAnchoredPosition, time, delayTime);
            TweenUtil.GetInstance().AddTween(tweenTmp);
            return(tweenTmp);
        }
예제 #8
0
        public static TweenScript TnRotate(this Transform trans, Vector3 to,
                                           float time      = 0.5f,
                                           float delayTime = 0,
                                           bool isLocal    = true)
        {
            TweenScript tweenTmp = StackObjectPool <TweenScript> .Get();

            tweenTmp.SetValue(isLocal ? trans.localEulerAngles : trans.eulerAngles, to);
            tweenTmp.isLocal = isLocal;
            tweenTmp.Init(trans.gameObject, AnimType.Rotate, time, delayTime);
            TweenUtil.GetInstance().AddTween(tweenTmp);
            return(tweenTmp);
        }
예제 #9
0
파일: TweenUtil.cs 프로젝트: cnscj/THSTG
        public void AddTween(TweenScript tweenScript)
        {
            // 避免同一物体同一类型同时存在两次.
            var a = animList.Find(x =>
                                  x.AnimObject == tweenScript.AnimObject && x.AnimType == tweenScript.AnimType);

            if (a != null)
            {
                animList.Remove(a);
                StackObjectPool <TweenScript> .Push(a);
            }

            animList.Add(tweenScript);
        }
예제 #10
0
        public static TweenScript TnPathMove(this Transform trans, Vector3[] path,
                                             float time        = 2,
                                             float delayTime   = 0,
                                             bool isLocal      = false,
                                             PathType pathType = PathType.CatmullRom)
        {
            TweenScript tweenTmp = StackObjectPool <TweenScript> .Get();

            if (pathType == PathType.Line)
            {
                pathType = PathType.CatmullRom;
            }

            Vector3 fromV3;

            if (isLocal)
            {
                fromV3 = trans.transform.localPosition;
            }
            else
            {
                fromV3 = trans.transform.position;
            }

            if (path.Length < 2)
            {
                pathType = PathType.Line; //小于1个点。
                Debug.LogError("Path point it's too short ");
            }
            else
            {
                Vector3[] realPath = new Vector3[path.Length + 1];
                realPath[0] = fromV3;
                for (int i = 0; i < path.Length; i++)
                {
                    realPath[i + 1] = path[i];
                }

                tweenTmp.pathNodes = realPath;
            }

            tweenTmp.isLocal  = isLocal;
            tweenTmp.pathType = pathType;

            tweenTmp.Init(trans.gameObject, AnimType.Position, time, delayTime);
            TweenUtil.GetInstance().AddTween(tweenTmp);
            return(tweenTmp);
        }
예제 #11
0
파일: TweenUtil.cs 프로젝트: cnscj/THSTG
        public static TweenScript CustomTweenFloat(UnityAction <float> method, float from, float to,
                                                   float time          = 0.5f,
                                                   float delayTime     = 0,
                                                   LoopType repeatType = LoopType.Once,
                                                   int repeatCount     = -1)
        {
            TweenScript tweenTmp = StackObjectPool <TweenScript> .Get();

            tweenTmp.SetValue(from, to);
            tweenTmp.customMethodFloat = new AnimCustomMethodFloat();
            tweenTmp.customMethodFloat.AddListener(method);
            tweenTmp.SetLoopType(repeatType, repeatCount);
            tweenTmp.Init(null, AnimType.CustomFloat, time, delayTime);
            GetInstance().animList.Add(tweenTmp);
            return(tweenTmp);
        }
예제 #12
0
        /// <summary>
        /// 停止一个对象身上的所有动画
        /// </summary>
        /// <param name="trans">要停止动画的对象</param>
        /// <param name="isCallBack">是否触发回调</param>
        public static void TnStop(this Transform trans, bool isCallBack = false)
        {
            for (int i = 0; i < TweenUtil.GetInstance().animList.Count; i++)
            {
                if (TweenUtil.GetInstance().animList[i].AnimObject == trans.gameObject)
                {
                    if (isCallBack)
                    {
                        TweenScript dataTmp = TweenUtil.GetInstance().animList[i];
                        dataTmp.executeCallBack();
                    }

                    TweenScript tweenData = TweenUtil.GetInstance().animList[i];
                    TweenUtil.GetInstance().animList.RemoveAt(i);
                    i--;
                    StackObjectPool <TweenScript> .Push(tweenData);
                }
            }
        }
예제 #13
0
파일: TweenUtil.cs 프로젝트: cnscj/THSTG
        public static TweenScript CustomTweenVector3(UnityAction <Vector3> method, Vector3 from, Vector3 to,
                                                     float time          = 0.5f,
                                                     float delayTime     = 0,
                                                     LoopType repeatType = LoopType.Once,
                                                     int repeatCount     = -1)
        {
            TweenScript tweenTmp = StackObjectPool <TweenScript> .Get();

            tweenTmp.SetValue(from, to);
            tweenTmp.customMethodV3 = new AnimCustomMethodVector3();
            if (method != null)
            {
                tweenTmp.customMethodV3.AddListener(method);
            }
            tweenTmp.SetLoopType(repeatType, repeatCount);
            tweenTmp.Init(null, AnimType.CustomVector3, time, delayTime);
            GetInstance().animList.Add(tweenTmp);
            return(tweenTmp);
        }
예제 #14
0
파일: TweenUtil.cs 프로젝트: cnscj/THSTG
        public void Update()
        {
            for (int i = 0; i < animList.Count; i++)
            {
                animList[i].executeUpdate();
                if (animList[i].IsDone)
                {
                    TweenScript tweenTmp = animList[i];
                    if (!tweenTmp.AnimReplayLogic())
                    {
                        animList.Remove(tweenTmp);
                        i--;
                        StackObjectPool <TweenScript> .Push(tweenTmp);
                    }

                    tweenTmp.executeCallBack(); // todo this is bug.
                }
            }
        }