动画缩放和移动

using DG.Tweening;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace XGUI
{
    public class XScaleTween : MonoBehaviour
    {
        public Ease m_ease = Ease.InOutBack;
        public Vector3 startValue = new Vector3(0.8f, 0.8f, 0.8f);
        public Vector3 endValue = new Vector3(1f, 1f, 1f);
        public float duration = 1.0f;
        public float delay = 0.0f;
        public int loops = 0;
        public LoopType loopType;
        private RectTransform rm_transform;
        public bool playAutomatically = false;
        private void Awake()
        {
            rm_transform = gameObject.GetComponent<RectTransform>();
        }

        public void SetPivot(float fx, float fy)
        {
            Vector2 sizeD = rm_transform.sizeDelta;

            rm_transform.pivot = new Vector2(sizeD.x / fx, sizeD.y / fy);
        }

        private void OnEnable()
        {
            if (playAutomatically) Play();
        }
        private void OnDisable()
        {
            Stop();
        }

        public void Play()
        {
            if (rm_transform == null) return;
            ResetEx();

            if (delay > 0)
                Invoke("DoPlay", this.delay);
            else
                DoPlay();

        }

        private void DoPlay()
        {

            rm_transform.localScale = startValue;
            rm_transform.DOScale(endValue, duration).SetLoops(loops, loopType);
        }

        public void ResetEx()
        {
            CancelInvoke();
            rm_transform.localScale = startValue;
            rm_transform.DOKill();
        }

        public void Stop()
        {
            rm_transform.localScale = endValue;
            rm_transform.DOKill();
        }
        private void OnDestroy()
        {
            rm_transform.DOKill();
        }
    }
}
using DG.Tweening;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
namespace XGUI
{
    public class XSimpleMove : MonoBehaviour
    {

        public enum EaseType
        {
            dotweenEase = 1,
            animCurve = 2,
        }

        [SerializeField]
        private AnimationCurve animCurve = new AnimationCurve(new Keyframe[] { new Keyframe(0f, 0f), new Keyframe(3f, 40f) });

        public EaseType m_easeType = EaseType.dotweenEase;
        public Ease m_ease = Ease.InOutBack;
        public RectTransform startPos;
        public RectTransform endPos;
        public float duration = 1.0f;
        public float delay = 0.0f;
        private RectTransform m_transform;
        public bool playAutomatically = false;

        void Awake()
        {
            m_transform = gameObject.GetComponent<RectTransform>();
         
        }

        private void OnEnable()
        {
            if (playAutomatically) Play(null);
        }
        private void OnDisable()
        {
            Stop();
        }

        public void Play(TweenCallback onCompleFun)
        {
            if (m_transform == null || startPos == null) return;
            ResetEx();
            m_transform.anchoredPosition = startPos.anchoredPosition;

            if (delay > 0)
                StartCoroutine(DoWait(onCompleFun));
            else
                DoPlay(onCompleFun);
        }

        private IEnumerator DoWait(TweenCallback onCompleFun)
        {
            yield return new WaitForSeconds(delay);

            DoPlay(onCompleFun);
        }

        private void DoPlay(TweenCallback onCompleFun)
        {
            Tweener tweener = m_transform.DOAnchorPos(endPos.anchoredPosition, duration);
            if (m_easeType == EaseType.animCurve)
                tweener.SetEase(animCurve);
            else
                tweener.SetEase(m_ease);

            if (onCompleFun != null)
            {
                tweener.OnComplete(delegate () {
                    onCompleFun();
                });
            }
        }

        public void ResetEx()
        {
            if (startPos == null) return;
            m_transform.anchoredPosition = startPos.anchoredPosition;
            m_transform.DOKill();
        }

        public void Stop()
        {
            if(m_transform != null && endPos != null)
            {
                m_transform.anchoredPosition = endPos.anchoredPosition;
                m_transform.DOKill();
            }
        }

        private void OnDestroy()
        {
            m_transform.DOKill();
        }
    }

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值