Advertisement
Demigiant

DOTweenTimeline custom plugin example

Aug 6th, 2020
970
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.97 KB | None | 0 0
  1. using System;
  2. using DG.Tweening.Timeline.Core;
  3. using DG.Tweening.Timeline.Core.Plugins;
  4. using UnityEngine;
  5.  
  6. namespace Demigiant.DOTweenExtended
  7. {
  8. #if UNITY_EDITOR
  9.     [UnityEditor.InitializeOnLoad]
  10. #endif
  11.     public static class Test_ExtraVisualTweenPlugins
  12.     {
  13. #if UNITY_EDITOR
  14.         static Test_ExtraVisualTweenPlugins()
  15.         {
  16.             // Used only to register plugins to be displayed in editor's timeline (runtime uses Register method directly)
  17.             if (!UnityEditor.EditorApplication.isPlayingOrWillChangePlaymode) Register();
  18.         }
  19. #endif
  20.  
  21.         [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
  22.         static void Register()
  23.         {
  24.             DOVisualPluginsManager.RegisterGlobalTweenPlugins(GetGlobalTweenPlugin, "Custom Global");
  25.             DOVisualPluginsManager.RegisterTweenPlugins(GetTweenPlugin);
  26.         }
  27.  
  28.         static DOVisualTweenPlugin GetGlobalTweenPlugin(string id)
  29.         {
  30.             switch (id) {
  31.             case "Custom Global":
  32.                 return DOVisualPluginsManager.CacheAndReturnGlobal(id,
  33.                     new PlugDataGlobalTween("Custom Time/Time Scale", ()=> Time.timeScale, x => Time.timeScale = x)
  34.                 );
  35.             }
  36.  
  37.             return null;
  38.         }
  39.  
  40.         static DOVisualTweenPlugin GetTweenPlugin(Type targetType, string targetTypeFullName)
  41.         {
  42.             if (targetType == typeof(Test_CustomComponent)) {
  43.                 return DOVisualPluginsManager.CacheAndReturn(targetType,
  44.                     new PlugDataTween("A Float", (c,s,i) => ()=> ((Test_CustomComponent)c).aFloat, (c,s,i) => x => ((Test_CustomComponent)c).aFloat = x),
  45.                     new PlugDataTween("An Int", (c,s,i) => ()=> ((Test_CustomComponent)c).aInt, (c,s,i) => x => ((Test_CustomComponent)c).aInt = x),
  46.                     new PlugDataTween("A Uint", (c,s,i) => ()=> ((Test_CustomComponent)c).aUint, (c,s,i) => x => ((Test_CustomComponent)c).aUint = x),
  47.                     new PlugDataTween("A String", (c,s,i) => ()=> ((Test_CustomComponent)c).aString, (c,s,i) => x => ((Test_CustomComponent)c).aString = x),
  48.                     new PlugDataTween("A Vector2", (c,s,i) => ()=> ((Test_CustomComponent)c).aVector2, (c,s,i) => x => ((Test_CustomComponent)c).aVector2 = x),
  49.                     new PlugDataTween("A Vector3", (c,s,i) => ()=> ((Test_CustomComponent)c).aVector3, (c,s,i) => x => ((Test_CustomComponent)c).aVector3 = x),
  50.                     new PlugDataTween("A Vector4", (c,s,i) => ()=> ((Test_CustomComponent)c).aVector4, (c,s,i) => x => ((Test_CustomComponent)c).aVector4 = x),
  51.                     new PlugDataTween("A Color", (c,s,i) => ()=> ((Test_CustomComponent)c).aColor, (c,s,i) => x => ((Test_CustomComponent)c).aColor = x),
  52.                     new PlugDataTween("A Rect", (c,s,i) => ()=> ((Test_CustomComponent)c).aRect, (c,s,i) => x => ((Test_CustomComponent)c).aRect = x)
  53.                 );
  54.             }
  55.  
  56.             return null;
  57.         }
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement