< Summary

Class:DG.Tweening.DOTweenModuleUtils
Assembly:DOTween.Modules
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Plugins/DOTween/Modules/DOTweenModuleUtils.cs
Covered lines:5
Uncovered lines:21
Coverable lines:26
Total lines:167
Line coverage:19.2% (5 of 26)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Init()0%220100%
Preserver()0%2100%
PlaymodeStateChanged(...)0%6200%
SetOrientationOnPath(...)0%6200%
HasRigidbody2D(...)0%2100%
HasRigidbody(...)0%2100%
CreateDOTweenPathTween(...)0%42600%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Plugins/DOTween/Modules/DOTweenModuleUtils.cs

#LineLine coverage
 1// Author: Daniele Giardini - http://www.demigiant.com
 2// Created: 2018/07/13
 3
 4using System;
 5using System.Reflection;
 6using UnityEngine;
 7using DG.Tweening.Core;
 8using DG.Tweening.Plugins.Core.PathCore;
 9using DG.Tweening.Plugins.Options;
 10
 11#pragma warning disable 1591
 12namespace DG.Tweening
 13{
 14    /// <summary>
 15    /// Utility functions that deal with available Modules.
 16    /// Modules defines:
 17    /// - DOTAUDIO
 18    /// - DOTPHYSICS
 19    /// - DOTPHYSICS2D
 20    /// - DOTSPRITE
 21    /// - DOTUI
 22    /// Extra defines set and used for implementation of external assets:
 23    /// - DOTWEEN_TMP ► TextMesh Pro
 24    /// - DOTWEEN_TK2D ► 2D Toolkit
 25    /// </summary>
 26  public static class DOTweenModuleUtils
 27    {
 28        static bool _initialized;
 29
 30        #region Reflection
 31
 32        /// <summary>
 33        /// Called via Reflection by DOTweenComponent on Awake
 34        /// </summary>
 35#if UNITY_2018_1_OR_NEWER
 36        [UnityEngine.Scripting.Preserve]
 37#endif
 38        public static void Init()
 39        {
 77340            if (_initialized) return;
 41
 142            _initialized = true;
 143            DOTweenExternalCommand.SetOrientationOnPath += Physics.SetOrientationOnPath;
 44
 45#if UNITY_EDITOR
 46#if UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_5 || UNITY_2017_1
 47            UnityEditor.EditorApplication.playmodeStateChanged += PlaymodeStateChanged;
 48#else
 149            UnityEditor.EditorApplication.playModeStateChanged += PlaymodeStateChanged;
 50#endif
 51#endif
 152        }
 53
 54#if UNITY_2018_1_OR_NEWER
 55#pragma warning disable
 56        [UnityEngine.Scripting.Preserve]
 57        // Just used to preserve methods when building, never called
 58        static void Preserver()
 59        {
 060            Assembly[] loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies();
 061            MethodInfo mi = typeof(MonoBehaviour).GetMethod("Stub");
 062        }
 63#pragma warning restore
 64#endif
 65
 66        #endregion
 67
 68#if UNITY_EDITOR
 69        // Fires OnApplicationPause in DOTweenComponent even when Editor is paused (otherwise it's only fired at runtime
 70#if UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_5 || UNITY_2017_1
 71        static void PlaymodeStateChanged()
 72        #else
 73        static void PlaymodeStateChanged(UnityEditor.PlayModeStateChange state)
 74#endif
 75        {
 076            if (DOTween.instance == null) return;
 077            DOTween.instance.OnApplicationPause(UnityEditor.EditorApplication.isPaused);
 078        }
 79#endif
 80
 81        // █████████████████████████████████████████████████████████████████████████████████████████████████████████████
 82        // ███ INTERNAL CLASSES ████████████████████████████████████████████████████████████████████████████████████████
 83        // █████████████████████████████████████████████████████████████████████████████████████████████████████████████
 84
 85        public static class Physics
 86        {
 87            // Called via DOTweenExternalCommand callback
 88            public static void SetOrientationOnPath(PathOptions options, Tween t, Quaternion newRot, Transform trans)
 89            {
 90#if true // PHYSICS_MARKER
 091                if (options.isRigidbody) ((Rigidbody)t.target).rotation = newRot;
 092                else trans.rotation = newRot;
 93#else
 94                trans.rotation = newRot;
 95#endif
 096            }
 97
 98            // Returns FALSE if the DOTween's Physics2D Module is disabled, or if there's no Rigidbody2D attached
 99            public static bool HasRigidbody2D(Component target)
 100            {
 101#if false // PHYSICS2D_MARKER
 102                return target.GetComponent<Rigidbody2D>() != null;
 103#else
 0104                return false;
 105#endif
 106            }
 107
 108            #region Called via Reflection
 109
 110
 111            // Called via Reflection by DOTweenPathInspector
 112            // Returns FALSE if the DOTween's Physics Module is disabled, or if there's no rigidbody attached
 113#if UNITY_2018_1_OR_NEWER
 114            [UnityEngine.Scripting.Preserve]
 115#endif
 116            public static bool HasRigidbody(Component target)
 117            {
 118#if true // PHYSICS_MARKER
 0119                return target.GetComponent<Rigidbody>() != null;
 120#else
 121                return false;
 122#endif
 123            }
 124
 125            // Called via Reflection by DOTweenPath
 126#if UNITY_2018_1_OR_NEWER
 127            [UnityEngine.Scripting.Preserve]
 128#endif
 129            public static TweenerCore<Vector3, Path, PathOptions> CreateDOTweenPathTween(
 130                MonoBehaviour target, bool tweenRigidbody, bool isLocal, Path path, float duration, PathMode pathMode
 131            ){
 0132                TweenerCore<Vector3, Path, PathOptions> t = null;
 0133                bool rBodyFoundAndTweened = false;
 134#if true // PHYSICS_MARKER
 0135                if (tweenRigidbody) {
 0136                    Rigidbody rBody = target.GetComponent<Rigidbody>();
 0137                    if (rBody != null) {
 0138                        rBodyFoundAndTweened = true;
 0139                        t = isLocal
 140                            ? rBody.DOLocalPath(path, duration, pathMode)
 141                            : rBody.DOPath(path, duration, pathMode);
 142                    }
 143                }
 144#endif
 145#if false // PHYSICS2D_MARKER
 146                if (!rBodyFoundAndTweened && tweenRigidbody) {
 147                    Rigidbody2D rBody2D = target.GetComponent<Rigidbody2D>();
 148                    if (rBody2D != null) {
 149                        rBodyFoundAndTweened = true;
 150                        t = isLocal
 151                            ? rBody2D.DOLocalPath(path, duration, pathMode)
 152                            : rBody2D.DOPath(path, duration, pathMode);
 153                    }
 154                }
 155#endif
 0156                if (!rBodyFoundAndTweened) {
 0157                    t = isLocal
 158                        ? target.transform.DOLocalPath(path, duration, pathMode)
 159                        : target.transform.DOPath(path, duration, pathMode);
 160                }
 0161                return t;
 162            }
 163
 164            #endregion
 165        }
 166    }
 167}