Unity 自动在关闭程序时Kill已启动的DoTween动画

自动在关闭程序时Kill已启动的DoTween动画

食用方法

把脚本放到文件夹内即可,会在运行时自动加入到场景中

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using ZYFLongLive;

namespace ZYF
{
    
    
    public class KillAllTweenOnApplicationStop : MonoBehaviour
    {
    
    
        private void OnDestroy()
        {
    
    
            DG.Tweening.DOTween.KillAll();
            Debug.Log($"Kill All Tween");
        }
        [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)]
        public static void AutoAddGo()
        {
    
    
            var go = new GameObject($"{
      
      nameof(KillAllTweenOnApplicationStop)}");
            var comp = go.AddComponent<KillAllTweenOnApplicationStop>();
            DontDestroyOnLoad( go );
            go.hideFlags = HideFlags.HideInHierarchy;
        }
    }

}

猜你喜欢

转载自blog.csdn.net/qq_26318597/article/details/131935040