From 3da538a1a0db6f4a6286ca78ca3c65c22febcdf4 Mon Sep 17 00:00:00 2001 From: Demigiant Date: Sun, 15 Jul 2018 11:02:59 +0200 Subject: [PATCH] Modules working (upgrade features to complete) --- .gitignore | 6 +- _DOTween.Assembly/DOTween.sln | 41 +- _DOTween.Assembly/DOTween.sln.DotSettings | 2 - .../DOTween/Core/DOTweenComponent.cs | 7 + .../DOTween/Core/DOTweenExternalCommand.cs | 22 + .../DOTween/Core/Enums/SpecialStartupMode.cs | 3 +- _DOTween.Assembly/DOTween/Core/Extensions.cs | 30 +- _DOTween.Assembly/DOTween/DOTween.cs | 2 +- _DOTween.Assembly/DOTween/DOTween.csproj | 45 +- .../Plugins/Options/QuaternionOptions.cs | 6 +- .../DOTween/Plugins/PathPlugin.cs | 13 +- .../DOTween/ShortcutExtensions.cs | 266 +------- _DOTween.Assembly/DOTween/Tween.cs | 12 +- .../DOTween46/ShortcutExtensions46.cs | 60 +- .../DOTweenEditor/Core/EditorUtils.cs | 98 +++ .../DOTweenEditor/DOTweenEditor.csproj | 47 +- .../DOTweenEditor/DOTweenModulesSetupGUI.cs | 94 +++ .../DOTweenEditor/DOTweenSetupMenuItem.cs | 54 +- .../DOTweenEditor/DOTweenUtilityWindow.cs | 87 +-- .../DOTween_LooseScripts.csproj | 121 ++++ .../Properties/AssemblyInfo.cs | 36 ++ _DOTween.Assembly/PostBuild_DOTween.bat | 81 +++ .../bin/Modules/DOTweenModuleAudio.cs | 193 ++++++ .../bin/Modules/DOTweenModulePhysics.cs | 212 +++++++ .../bin/Modules/DOTweenModulePhysics2D.cs | 101 ++++ .../bin/Modules/DOTweenModuleSprite.cs | 88 +++ .../bin/Modules/DOTweenModuleUI.cs | 570 ++++++++++++++++++ .../bin/Modules/DOTweenModuleUnityVersion.cs | 252 ++++++++ .../bin/Modules/DOTweenModuleUtils.cs | 108 ++++ 29 files changed, 2175 insertions(+), 482 deletions(-) delete mode 100644 _DOTween.Assembly/DOTween.sln.DotSettings create mode 100644 _DOTween.Assembly/DOTween/Core/DOTweenExternalCommand.cs create mode 100644 _DOTween.Assembly/DOTweenEditor/DOTweenModulesSetupGUI.cs create mode 100644 _DOTween.Assembly/DOTween_LooseScripts/DOTween_LooseScripts.csproj create mode 100644 _DOTween.Assembly/DOTween_LooseScripts/Properties/AssemblyInfo.cs create mode 100644 _DOTween.Assembly/PostBuild_DOTween.bat create mode 100644 _DOTween.Assembly/bin/Modules/DOTweenModuleAudio.cs create mode 100644 _DOTween.Assembly/bin/Modules/DOTweenModulePhysics.cs create mode 100644 _DOTween.Assembly/bin/Modules/DOTweenModulePhysics2D.cs create mode 100644 _DOTween.Assembly/bin/Modules/DOTweenModuleSprite.cs create mode 100644 _DOTween.Assembly/bin/Modules/DOTweenModuleUI.cs create mode 100644 _DOTween.Assembly/bin/Modules/DOTweenModuleUnityVersion.cs create mode 100644 _DOTween.Assembly/bin/Modules/DOTweenModuleUtils.cs diff --git a/.gitignore b/.gitignore index 703753c..033680a 100644 --- a/.gitignore +++ b/.gitignore @@ -34,6 +34,10 @@ zz UnityTests* zzTestBuilds *.tmp *.pdb +*.DotSettings UnityTests.Unity5BETA -biz \ No newline at end of file +UnityTests.Unity5 - LastVersionBeforeModules +ModulesTest.Unity2018 +biz +zzTemp \ No newline at end of file diff --git a/_DOTween.Assembly/DOTween.sln b/_DOTween.Assembly/DOTween.sln index 9a5fab8..07d5337 100644 --- a/_DOTween.Assembly/DOTween.sln +++ b/_DOTween.Assembly/DOTween.sln @@ -17,10 +17,18 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DOTween46", "DOTween46\DOTw EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DOTween50", "DOTween50\DOTween50.csproj", "{930C3B07-B00A-44B8-A8E5-452A8FD125C7}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DOTween_LooseScripts", "DOTween_LooseScripts\DOTween_LooseScripts.csproj", "{0B529A90-0B97-4840-BEB6-4A6700B46655}" + ProjectSection(ProjectDependencies) = postProject + {DE17C145-3E8D-45D6-BBB6-D06BD7D80A55} = {DE17C145-3E8D-45D6-BBB6-D06BD7D80A55} + EndProjectSection +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Legacy_NoModules", "Legacy_NoModules", "{3945F2EC-EA44-45DF-82B5-33E978AE8345}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution CompatibilityMode|Any CPU = CompatibilityMode|Any CPU Debug|Any CPU = Debug|Any CPU + Release_IncludeRigidbody|Any CPU = Release_IncludeRigidbody|Any CPU Release_NoRigidbody|Any CPU = Release_NoRigidbody|Any CPU Release|Any CPU = Release|Any CPU EndGlobalSection @@ -29,6 +37,8 @@ Global {DE17C145-3E8D-45D6-BBB6-D06BD7D80A55}.CompatibilityMode|Any CPU.Build.0 = CompatibilityMode|Any CPU {DE17C145-3E8D-45D6-BBB6-D06BD7D80A55}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {DE17C145-3E8D-45D6-BBB6-D06BD7D80A55}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DE17C145-3E8D-45D6-BBB6-D06BD7D80A55}.Release_IncludeRigidbody|Any CPU.ActiveCfg = Release_IncludeRigidbody|Any CPU + {DE17C145-3E8D-45D6-BBB6-D06BD7D80A55}.Release_IncludeRigidbody|Any CPU.Build.0 = Release_IncludeRigidbody|Any CPU {DE17C145-3E8D-45D6-BBB6-D06BD7D80A55}.Release_NoRigidbody|Any CPU.ActiveCfg = Release_IncludeRigidbody|Any CPU {DE17C145-3E8D-45D6-BBB6-D06BD7D80A55}.Release_NoRigidbody|Any CPU.Build.0 = Release_IncludeRigidbody|Any CPU {DE17C145-3E8D-45D6-BBB6-D06BD7D80A55}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -37,6 +47,8 @@ Global {421ACC19-8922-4E98-8921-B52240CE172A}.CompatibilityMode|Any CPU.Build.0 = CompatibilityMode|Any CPU {421ACC19-8922-4E98-8921-B52240CE172A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {421ACC19-8922-4E98-8921-B52240CE172A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {421ACC19-8922-4E98-8921-B52240CE172A}.Release_IncludeRigidbody|Any CPU.ActiveCfg = Release_IncludeRigidbody|Any CPU + {421ACC19-8922-4E98-8921-B52240CE172A}.Release_IncludeRigidbody|Any CPU.Build.0 = Release_IncludeRigidbody|Any CPU {421ACC19-8922-4E98-8921-B52240CE172A}.Release_NoRigidbody|Any CPU.ActiveCfg = Release_IncludeRigidbody|Any CPU {421ACC19-8922-4E98-8921-B52240CE172A}.Release_NoRigidbody|Any CPU.Build.0 = Release_IncludeRigidbody|Any CPU {421ACC19-8922-4E98-8921-B52240CE172A}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -45,44 +57,49 @@ Global {20D2E542-D14F-4678-9C38-F3C0ECF6A2F6}.CompatibilityMode|Any CPU.Build.0 = CompatibilityMode|Any CPU {20D2E542-D14F-4678-9C38-F3C0ECF6A2F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {20D2E542-D14F-4678-9C38-F3C0ECF6A2F6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {20D2E542-D14F-4678-9C38-F3C0ECF6A2F6}.Release_IncludeRigidbody|Any CPU.ActiveCfg = Release_IncludeRigidbody|Any CPU + {20D2E542-D14F-4678-9C38-F3C0ECF6A2F6}.Release_IncludeRigidbody|Any CPU.Build.0 = Release_IncludeRigidbody|Any CPU {20D2E542-D14F-4678-9C38-F3C0ECF6A2F6}.Release_NoRigidbody|Any CPU.ActiveCfg = Release_IncludeRigidbody|Any CPU {20D2E542-D14F-4678-9C38-F3C0ECF6A2F6}.Release_NoRigidbody|Any CPU.Build.0 = Release_IncludeRigidbody|Any CPU {20D2E542-D14F-4678-9C38-F3C0ECF6A2F6}.Release|Any CPU.ActiveCfg = Release|Any CPU {20D2E542-D14F-4678-9C38-F3C0ECF6A2F6}.Release|Any CPU.Build.0 = Release|Any CPU {978C0952-38D0-4C22-B96C-823EAFEDF0FA}.CompatibilityMode|Any CPU.ActiveCfg = CompatibilityMode|Any CPU - {978C0952-38D0-4C22-B96C-823EAFEDF0FA}.CompatibilityMode|Any CPU.Build.0 = CompatibilityMode|Any CPU {978C0952-38D0-4C22-B96C-823EAFEDF0FA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {978C0952-38D0-4C22-B96C-823EAFEDF0FA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {978C0952-38D0-4C22-B96C-823EAFEDF0FA}.Release_IncludeRigidbody|Any CPU.ActiveCfg = Release_IncludeRigidbody|Any CPU {978C0952-38D0-4C22-B96C-823EAFEDF0FA}.Release_NoRigidbody|Any CPU.ActiveCfg = Release_IncludeRigidbody|Any CPU - {978C0952-38D0-4C22-B96C-823EAFEDF0FA}.Release_NoRigidbody|Any CPU.Build.0 = Release_IncludeRigidbody|Any CPU {978C0952-38D0-4C22-B96C-823EAFEDF0FA}.Release|Any CPU.ActiveCfg = Release|Any CPU - {978C0952-38D0-4C22-B96C-823EAFEDF0FA}.Release|Any CPU.Build.0 = Release|Any CPU {279545AE-D268-42F0-A4C6-AA5BA15FB9BE}.CompatibilityMode|Any CPU.ActiveCfg = CompatibilityMode|Any CPU {279545AE-D268-42F0-A4C6-AA5BA15FB9BE}.CompatibilityMode|Any CPU.Build.0 = CompatibilityMode|Any CPU {279545AE-D268-42F0-A4C6-AA5BA15FB9BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {279545AE-D268-42F0-A4C6-AA5BA15FB9BE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {279545AE-D268-42F0-A4C6-AA5BA15FB9BE}.Release_IncludeRigidbody|Any CPU.ActiveCfg = Release_IncludeRigidbody|Any CPU + {279545AE-D268-42F0-A4C6-AA5BA15FB9BE}.Release_IncludeRigidbody|Any CPU.Build.0 = Release_IncludeRigidbody|Any CPU {279545AE-D268-42F0-A4C6-AA5BA15FB9BE}.Release_NoRigidbody|Any CPU.ActiveCfg = Release_IncludeRigidbody|Any CPU {279545AE-D268-42F0-A4C6-AA5BA15FB9BE}.Release_NoRigidbody|Any CPU.Build.0 = Release_IncludeRigidbody|Any CPU {279545AE-D268-42F0-A4C6-AA5BA15FB9BE}.Release|Any CPU.ActiveCfg = Release|Any CPU {279545AE-D268-42F0-A4C6-AA5BA15FB9BE}.Release|Any CPU.Build.0 = Release|Any CPU {AC1E5A23-CE58-419C-B165-EB1CD39AB433}.CompatibilityMode|Any CPU.ActiveCfg = CompatibilityMode|Any CPU - {AC1E5A23-CE58-419C-B165-EB1CD39AB433}.CompatibilityMode|Any CPU.Build.0 = CompatibilityMode|Any CPU {AC1E5A23-CE58-419C-B165-EB1CD39AB433}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {AC1E5A23-CE58-419C-B165-EB1CD39AB433}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AC1E5A23-CE58-419C-B165-EB1CD39AB433}.Release_IncludeRigidbody|Any CPU.ActiveCfg = Release_IncludeRigidbody|Any CPU {AC1E5A23-CE58-419C-B165-EB1CD39AB433}.Release_NoRigidbody|Any CPU.ActiveCfg = Release_IncludeRigidbody|Any CPU - {AC1E5A23-CE58-419C-B165-EB1CD39AB433}.Release_NoRigidbody|Any CPU.Build.0 = Release_IncludeRigidbody|Any CPU {AC1E5A23-CE58-419C-B165-EB1CD39AB433}.Release|Any CPU.ActiveCfg = Release|Any CPU - {AC1E5A23-CE58-419C-B165-EB1CD39AB433}.Release|Any CPU.Build.0 = Release|Any CPU {930C3B07-B00A-44B8-A8E5-452A8FD125C7}.CompatibilityMode|Any CPU.ActiveCfg = CompatibilityMode|Any CPU - {930C3B07-B00A-44B8-A8E5-452A8FD125C7}.CompatibilityMode|Any CPU.Build.0 = CompatibilityMode|Any CPU {930C3B07-B00A-44B8-A8E5-452A8FD125C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {930C3B07-B00A-44B8-A8E5-452A8FD125C7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {930C3B07-B00A-44B8-A8E5-452A8FD125C7}.Release_IncludeRigidbody|Any CPU.ActiveCfg = Release_IncludeRigidbody|Any CPU {930C3B07-B00A-44B8-A8E5-452A8FD125C7}.Release_NoRigidbody|Any CPU.ActiveCfg = Release_IncludeRigidbody|Any CPU - {930C3B07-B00A-44B8-A8E5-452A8FD125C7}.Release_NoRigidbody|Any CPU.Build.0 = Release_IncludeRigidbody|Any CPU {930C3B07-B00A-44B8-A8E5-452A8FD125C7}.Release|Any CPU.ActiveCfg = Release|Any CPU - {930C3B07-B00A-44B8-A8E5-452A8FD125C7}.Release|Any CPU.Build.0 = Release|Any CPU + {0B529A90-0B97-4840-BEB6-4A6700B46655}.CompatibilityMode|Any CPU.ActiveCfg = Release|Any CPU + {0B529A90-0B97-4840-BEB6-4A6700B46655}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0B529A90-0B97-4840-BEB6-4A6700B46655}.Release_IncludeRigidbody|Any CPU.ActiveCfg = Release|Any CPU + {0B529A90-0B97-4840-BEB6-4A6700B46655}.Release_NoRigidbody|Any CPU.ActiveCfg = Release|Any CPU + {0B529A90-0B97-4840-BEB6-4A6700B46655}.Release|Any CPU.ActiveCfg = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {978C0952-38D0-4C22-B96C-823EAFEDF0FA} = {3945F2EC-EA44-45DF-82B5-33E978AE8345} + {AC1E5A23-CE58-419C-B165-EB1CD39AB433} = {3945F2EC-EA44-45DF-82B5-33E978AE8345} + {930C3B07-B00A-44B8-A8E5-452A8FD125C7} = {3945F2EC-EA44-45DF-82B5-33E978AE8345} + EndGlobalSection EndGlobal diff --git a/_DOTween.Assembly/DOTween.sln.DotSettings b/_DOTween.Assembly/DOTween.sln.DotSettings deleted file mode 100644 index 0f129db..0000000 --- a/_DOTween.Assembly/DOTween.sln.DotSettings +++ /dev/null @@ -1,2 +0,0 @@ - - CY \ No newline at end of file diff --git a/_DOTween.Assembly/DOTween/Core/DOTweenComponent.cs b/_DOTween.Assembly/DOTween/Core/DOTweenComponent.cs index 65d2d6f..9665a2e 100644 --- a/_DOTween.Assembly/DOTween/Core/DOTweenComponent.cs +++ b/_DOTween.Assembly/DOTween/Core/DOTweenComponent.cs @@ -4,7 +4,9 @@ // License Copyright (c) Daniele Giardini. // This work is subject to the terms at http://dotween.demigiant.com/license.php +using System; using System.Collections; +using System.Reflection; using UnityEngine; #pragma warning disable 1591 @@ -31,6 +33,11 @@ namespace DG.Tweening.Core { inspectorUpdater = 0; _unscaledTime = Time.realtimeSinceStartup; + + // Initialize DOTweenModuleUtils via Reflection + // TODO DOTweenModuleUtils.Init > verify that this works + MethodInfo mi = Type.GetType("DG.Tweening.DOTweenModuleUtils").GetMethod("Init", BindingFlags.Static | BindingFlags.Public); + mi.Invoke(null, null); } void Start() diff --git a/_DOTween.Assembly/DOTween/Core/DOTweenExternalCommand.cs b/_DOTween.Assembly/DOTween/Core/DOTweenExternalCommand.cs new file mode 100644 index 0000000..88aefb1 --- /dev/null +++ b/_DOTween.Assembly/DOTween/Core/DOTweenExternalCommand.cs @@ -0,0 +1,22 @@ +// Author: Daniele Giardini - http://www.demigiant.com +// Created: 2018/07/13 19:21 +// License Copyright (c) Daniele Giardini +// This work is subject to the terms at http://dotween.demigiant.com/license.php + +using System; +using DG.Tweening.Plugins.Options; +using UnityEngine; + +#pragma warning disable 1591 +namespace DG.Tweening.Core +{ + /// + /// Used to dispatch commands that need to be captured externally, usually by Modules + /// + public static class DOTweenExternalCommand + { + public static event Action SetOrientationOnPath; + internal static void Dispatch_SetOrientationOnPath(PathOptions options, Tween t, Quaternion newRot, Transform trans) + { if (SetOrientationOnPath != null) SetOrientationOnPath(options, t, newRot, trans); } + } +} \ No newline at end of file diff --git a/_DOTween.Assembly/DOTween/Core/Enums/SpecialStartupMode.cs b/_DOTween.Assembly/DOTween/Core/Enums/SpecialStartupMode.cs index b72ff64..6b2c12e 100644 --- a/_DOTween.Assembly/DOTween/Core/Enums/SpecialStartupMode.cs +++ b/_DOTween.Assembly/DOTween/Core/Enums/SpecialStartupMode.cs @@ -4,9 +4,10 @@ // License Copyright (c) Daniele Giardini. // This work is subject to the terms at http://dotween.demigiant.com/license.php +#pragma warning disable 1591 namespace DG.Tweening.Core.Enums { - internal enum SpecialStartupMode + public enum SpecialStartupMode { None, SetLookAt, diff --git a/_DOTween.Assembly/DOTween/Core/Extensions.cs b/_DOTween.Assembly/DOTween/Core/Extensions.cs index 651cd27..aa7c2ae 100644 --- a/_DOTween.Assembly/DOTween/Core/Extensions.cs +++ b/_DOTween.Assembly/DOTween/Core/Extensions.cs @@ -14,27 +14,33 @@ namespace DG.Tweening.Core /// public static class Extensions { - // Used internally by DO shortcuts to set special startup mode - internal static T SetSpecialStartupMode(this T t, SpecialStartupMode mode) where T : Tween + /// + /// INTERNAL: used by DO shortcuts and Modules to set special startup mode + /// + public static T SetSpecialStartupMode(this T t, SpecialStartupMode mode) where T : Tween { t.specialStartupMode = mode; return t; } - // Prevents a tween to use a From setup even if passed - internal static TweenerCore NoFrom(this TweenerCore t) - where TPlugOptions : struct, IPlugOptions - { - t.isFromAllowed = false; - return t; - } - - // Sets the tween as blendable - internal static TweenerCore Blendable(this TweenerCore t) + /// + /// INTERNAL: used by DO shortcuts and Modules to set the tween as blendable + /// + public static TweenerCore Blendable(this TweenerCore t) where TPlugOptions : struct, IPlugOptions { t.isBlendable = true; return t; } + + /// + /// INTERNAL: used by DO shortcuts and Modules to prevent a tween from using a From setup even if passed + /// + public static TweenerCore NoFrom(this TweenerCore t) + where TPlugOptions : struct, IPlugOptions + { + t.isFromAllowed = false; + return t; + } } } \ No newline at end of file diff --git a/_DOTween.Assembly/DOTween/DOTween.cs b/_DOTween.Assembly/DOTween/DOTween.cs index b3560b8..0f1272f 100644 --- a/_DOTween.Assembly/DOTween/DOTween.cs +++ b/_DOTween.Assembly/DOTween/DOTween.cs @@ -32,7 +32,7 @@ namespace DG.Tweening public class DOTween { /// DOTween's version - public static readonly string Version = "1.1.755"; + public static readonly string Version = "1.2.000"; // Last version before modules: 1.1.755 /////////////////////////////////////////////// // Options //////////////////////////////////// diff --git a/_DOTween.Assembly/DOTween/DOTween.csproj b/_DOTween.Assembly/DOTween/DOTween.csproj index 907fd0e..3e46965 100644 --- a/_DOTween.Assembly/DOTween/DOTween.csproj +++ b/_DOTween.Assembly/DOTween/DOTween.csproj @@ -64,7 +64,7 @@ - C:\Program Files (x86)\Unity 3\Editor\Data\Managed\UnityEngine.dll + C:\Program Files (x86)\Unity 46\Editor\Data\Managed\UnityEngine.dll False @@ -87,6 +87,7 @@ + @@ -166,47 +167,7 @@ - set BinDir=bin.Global\DOTween -set DestinationDir=$(SolutionDir)..\..\%25BinDir%25 -set BinDirNoMeta=bin.Global_no_meta\DOTween -set DestinationDirNoMeta=$(SolutionDir)..\..\%25BinDirNoMeta%25 -set BinDirUnityTests=UnityTests.Unity4\Assets\Demigiant\DOTween -set DestinationDirUnityTests=$(SolutionDir)..\%25BinDirUnityTests%25 -set BinDirUnity5Tests=UnityTests.Unity5\Assets\Demigiant\DOTween -set DestinationDirUnity5Tests=$(SolutionDir)..\%25BinDirUnity5Tests%25 -set BinDirCompatibilityTests=UnityCompatibilityTests.Unity35\Assets\Demigiant\DOTween -set DestinationDirCompatibilityTests=$(SolutionDir)..\%25BinDirCompatibilityTests%25 -set BinDirExtPluginsTests=ExternalPluginsTestsAndExamples.Unity5\Assets\Demigiant\DOTween -set DestinationDirExtPluginsTests=$(SolutionDir)..\%25BinDirExtPluginsTests%25 - -echo %25DestinationDir%25 - -echo Deleting TMPs... -DEL $(TargetDir)\*.tmp - -CD $(TargetDir) -echo Converting PDB to MDB and deleting PDB... -"c:\Program Files\pdb2mdb\pdb2mdb.exe" $(TargetFileName) -DEL $(TargetName).pdb - -echo Exporting Assembly to %25DestinationDir%25 -echo Copying files to Destination... -echo f | xcopy "$(SolutionDir)\bin" %25DestinationDir%25 /Y /I /E - -echo Exporting Assembly to %25DestinationDirNoMeta%25 -echo f | xcopy "$(SolutionDir)\bin" %25DestinationDirNoMeta%25 /Y /I /E - -echo Exporting Assembly to %25DestinationDirUnityTests%25 -echo f | xcopy "$(SolutionDir)\bin" %25DestinationDirUnityTests%25 /Y /I /E - -echo Exporting Assembly to %25DestinationDirUnity5Tests%25 -echo f | xcopy "$(SolutionDir)\bin" %25DestinationDirUnity5Tests%25 /Y /I /E - -echo Exporting Assembly to %25DestinationDirCompatibilityTests%25 -echo f | xcopy "$(SolutionDir)\bin" %25DestinationDirCompatibilityTests%25 /Y /I /E - -echo Exporting Assembly to %25DestinationDirExtPluginsTests%25 -echo f | xcopy "$(SolutionDir)\bin" %25DestinationDirExtPluginsTests%25 /Y /I /E + call $(SolutionDir)PostBuild_DOTween.bat $(SolutionDir) $(TargetDir) $(TargetFileName) $(TargetName) DOTween bin + \ No newline at end of file diff --git a/_DOTween.Assembly/DOTween_LooseScripts/Properties/AssemblyInfo.cs b/_DOTween.Assembly/DOTween_LooseScripts/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..977fd30 --- /dev/null +++ b/_DOTween.Assembly/DOTween_LooseScripts/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("DOTween_LooseScripts")] +[assembly: AssemblyDescription("Deals with lose scripts inside bin and bin_pro folders")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Demigiant")] +[assembly: AssemblyProduct("DOTween_LooseScripts")] +[assembly: AssemblyCopyright("Copyright © Daniele Giardini, Demigiant 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("807e068c-2a0e-4c81-a303-4b4fd3924511")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/_DOTween.Assembly/PostBuild_DOTween.bat b/_DOTween.Assembly/PostBuild_DOTween.bat new file mode 100644 index 0000000..275d745 --- /dev/null +++ b/_DOTween.Assembly/PostBuild_DOTween.bat @@ -0,0 +1,81 @@ +:: %1 = $(SolutionDir) ► Solution dir path - with final slash +:: %2 = $(TargetDir) ► Bin folder dir path - with final slash +:: %3 = $(TargetFileName) ► DLL filename with extension +:: %4 = $(TargetName) ► DLL filename without extension +:: %5 = Main export dir ► Main folder inside bin.Global/etc where to copy the files (ex: "DOTween", "DOTweenPro") +:: %6 = Bin dir name ► (ex: "bin", "bin_pro") +:: %7 = Eventual export subdir (can be NULL) ► Eventual subdirectory inside the main export dir (ex: "Editor") + +echo : +echo : +echo : +echo : +echo ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +echo :::::::::::::::::: EXECUTING BATCH FILE ::::::::::::::::::::::: +echo ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +echo : +echo : +echo : +echo : +echo :::::: TARGET: %5 %7 + +echo :::::: Deleting TMPs... +DEL %2*.tmp + +echo :::::: Converting PDB to MDB and deleting PDB... +CD %2 +"c:\Program Files\pdb2mdb\pdb2mdb.exe" %3 +echo ::: Deleting PDB files: %4.pdb +DEL %4.pdb +echo ::: PDB files deleted, PAUSE for 0.5 second +waitfor pdbsToBeDeletedHopefully /t 0.5 2>NUL || type nul>nul + +echo :::::: Starting export... + +set SubDir=%7 +if not "%SubDir%"=="" ( set SubDir=\%7 ) +set CopyFromDir=%1%6%SubDir% + +set CopyToDir=%1..\..\bin.Global\%5%SubDir% +set CopyToDirNoMeta=%1..\..\bin.Global_no_meta\%5%SubDir% +set CopyToDirUnityTests=%1..\UnityTests.Unity4\Assets\Demigiant\%5%SubDir% +set CopyToDirUnity5Tests=%1..\UnityTests.Unity5\Assets\Demigiant\%5%SubDir% +set CopyToDirCompatibilityTests=%1..\UnityCompatibilityTests.Unity35\Assets\Demigiant\%5%SubDir% +set CopyToDirExtPluginsTests=%1..\ExternalPluginsTestsAndExamples.Unity5\Assets\Demigiant\%5%SubDir% +set CopyToDirModulesTest=%1..\ModulesTest.Unity2018\Assets\Demigiant\%5%SubDir% + +:: For now build only to Modules test project +echo ::: Exporting from %CopyFromDir% to %CopyToDirModulesTest% +echo ::: f | xcopy %CopyFromDir% %CopyToDirModulesTest% /Y /I /E + +exit /B + +echo ::: Exporting from %CopyFromDir% to %CopyToDir% +echo ::: f | xcopy %CopyFromDir% %CopyToDir% /Y /I /E + +echo ::: Exporting from %CopyFromDir% to %CopyToDirNoMeta% +echo ::: f | xcopy %CopyFromDir% %CopyToDirNoMeta% /Y /I /E + +echo ::: Exporting from %CopyFromDir% to %CopyToDirUnityTests% +echo ::: f | xcopy %CopyFromDir% %CopyToDirUnityTests% /Y /I /E + +echo ::: Exporting from %CopyFromDir% to %CopyToDirUnity5Tests% +echo ::: f | xcopy %CopyFromDir% %CopyToDirUnity5Tests% /Y /I /E + +echo ::: Exporting from %CopyFromDir% to %CopyToDirCompatibilityTests% +echo ::: f | xcopy %CopyFromDir% %CopyToDirCompatibilityTests% /Y /I /E + +echo ::: Exporting from %CopyFromDir% to %CopyToDirExtPluginsTests% +echo ::: f | xcopy %CopyFromDir% %CopyToDirExtPluginsTests% /Y /I /E + +echo : +echo : +echo : +echo : +echo ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +echo ::::::::::::::::::::: BATCH FILE END :::::::::::::::::::::::::: +echo ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +echo : +echo : +echo : +echo : \ No newline at end of file diff --git a/_DOTween.Assembly/bin/Modules/DOTweenModuleAudio.cs b/_DOTween.Assembly/bin/Modules/DOTweenModuleAudio.cs new file mode 100644 index 0000000..ec2be84 --- /dev/null +++ b/_DOTween.Assembly/bin/Modules/DOTweenModuleAudio.cs @@ -0,0 +1,193 @@ +// Author: Daniele Giardini - http://www.demigiant.com +// Created: 2018/07/13 + +#if DOTAUDIO +using System; +using UnityEngine; +using UnityEngine.Audio; + +#pragma warning disable 1591 +namespace DG.Tweening +{ + public static class DOTweenModuleAudio + { + #region Shortcuts + + #region Audio + + /// Tweens an AudioSource's volume to the given value. + /// Also stores the AudioSource as the tween's target so it can be used for filtered operations + /// The end value to reach (0 to 1)The duration of the tween + public static Tweener DOFade(this AudioSource target, float endValue, float duration) + { + if (endValue < 0) endValue = 0; + else if (endValue > 1) endValue = 1; + return DOTween.To(() => target.volume, x => target.volume = x, endValue, duration).SetTarget(target); + } + + /// Tweens an AudioSource's pitch to the given value. + /// Also stores the AudioSource as the tween's target so it can be used for filtered operations + /// The end value to reachThe duration of the tween + public static Tweener DOPitch(this AudioSource target, float endValue, float duration) + { + return DOTween.To(() => target.pitch, x => target.pitch = x, endValue, duration).SetTarget(target); + } + + #endregion + +#if UNITY_5 || UNITY_2017_0_OR_NEWER + #region AudioMixer (Unity 5 or Newer) + + /// Tweens an AudioMixer's exposed float to the given value. + /// Also stores the AudioMixer as the tween's target so it can be used for filtered operations. + /// Note that you need to manually expose a float in an AudioMixerGroup in order to be able to tween it from an AudioMixer. + /// Name given to the exposed float to set + /// The end value to reachThe duration of the tween + public static Tweener DOSetFloat(this AudioMixer target, string floatName, float endValue, float duration) + { + return DOTween.To(()=> { + float currVal; + target.GetFloat(floatName, out currVal); + return currVal; + }, x=> target.SetFloat(floatName, x), endValue, duration) + .SetTarget(target); + } + + #region Operation Shortcuts + + /// + /// Completes all tweens that have this target as a reference + /// (meaning tweens that were started from this target, or that had this target added as an Id) + /// and returns the total number of tweens completed + /// (meaning the tweens that don't have infinite loops and were not already complete) + /// + /// For Sequences only: if TRUE also internal Sequence callbacks will be fired, + /// otherwise they will be ignored + public static int DOComplete(this AudioMixer target, bool withCallbacks = false) + { + return DOTween.Complete(target, withCallbacks); + } + + /// + /// Kills all tweens that have this target as a reference + /// (meaning tweens that were started from this target, or that had this target added as an Id) + /// and returns the total number of tweens killed. + /// + /// If TRUE completes the tween before killing it + public static int DOKill(this AudioMixer target, bool complete = false) + { + return DOTween.Kill(target, complete); + } + + /// + /// Flips the direction (backwards if it was going forward or viceversa) of all tweens that have this target as a reference + /// (meaning tweens that were started from this target, or that had this target added as an Id) + /// and returns the total number of tweens flipped. + /// + public static int DOFlip(this AudioMixer target) + { + return DOTween.Flip(target); + } + + /// + /// Sends to the given position all tweens that have this target as a reference + /// (meaning tweens that were started from this target, or that had this target added as an Id) + /// and returns the total number of tweens involved. + /// + /// Time position to reach + /// (if higher than the whole tween duration the tween will simply reach its end) + /// If TRUE will play the tween after reaching the given position, otherwise it will pause it + public static int DOGoto(this AudioMixer target, float to, bool andPlay = false) + { + return DOTween.Goto(target, to, andPlay); + } + + /// + /// Pauses all tweens that have this target as a reference + /// (meaning tweens that were started from this target, or that had this target added as an Id) + /// and returns the total number of tweens paused. + /// + public static int DOPause(this AudioMixer target) + { + return DOTween.Pause(target); + } + + /// + /// Plays all tweens that have this target as a reference + /// (meaning tweens that were started from this target, or that had this target added as an Id) + /// and returns the total number of tweens played. + /// + public static int DOPlay(this AudioMixer target) + { + return DOTween.Play(target); + } + + /// + /// Plays backwards all tweens that have this target as a reference + /// (meaning tweens that were started from this target, or that had this target added as an Id) + /// and returns the total number of tweens played. + /// + public static int DOPlayBackwards(this AudioMixer target) + { + return DOTween.PlayBackwards(target); + } + + /// + /// Plays forward all tweens that have this target as a reference + /// (meaning tweens that were started from this target, or that had this target added as an Id) + /// and returns the total number of tweens played. + /// + public static int DOPlayForward(this AudioMixer target) + { + return DOTween.PlayForward(target); + } + + /// + /// Restarts all tweens that have this target as a reference + /// (meaning tweens that were started from this target, or that had this target added as an Id) + /// and returns the total number of tweens restarted. + /// + public static int DORestart(this AudioMixer target) + { + return DOTween.Restart(target); + } + + /// + /// Rewinds all tweens that have this target as a reference + /// (meaning tweens that were started from this target, or that had this target added as an Id) + /// and returns the total number of tweens rewinded. + /// + public static int DORewind(this AudioMixer target) + { + return DOTween.Rewind(target); + } + + /// + /// Smoothly rewinds all tweens that have this target as a reference + /// (meaning tweens that were started from this target, or that had this target added as an Id) + /// and returns the total number of tweens rewinded. + /// + public static int DOSmoothRewind(this AudioMixer target) + { + return DOTween.SmoothRewind(target); + } + + /// + /// Toggles the paused state (plays if it was paused, pauses if it was playing) of all tweens that have this target as a reference + /// (meaning tweens that were started from this target, or that had this target added as an Id) + /// and returns the total number of tweens involved. + /// + public static int DOTogglePause(this AudioMixer target) + { + return DOTween.TogglePause(target); + } + + #endregion + + #endregion +#endif + + #endregion + } +} +#endif diff --git a/_DOTween.Assembly/bin/Modules/DOTweenModulePhysics.cs b/_DOTween.Assembly/bin/Modules/DOTweenModulePhysics.cs new file mode 100644 index 0000000..dca71a0 --- /dev/null +++ b/_DOTween.Assembly/bin/Modules/DOTweenModulePhysics.cs @@ -0,0 +1,212 @@ +// Author: Daniele Giardini - http://www.demigiant.com +// Created: 2018/07/13 + +#if DOTPHYSICS +using System; +using DG.Tweening.Core; +using DG.Tweening.Core.Enums; +using DG.Tweening.Plugins; +using DG.Tweening.Plugins.Core.PathCore; +using DG.Tweening.Plugins.Options; +using UnityEngine; + +#pragma warning disable 1591 +namespace DG.Tweening +{ + public static class DOTweenModulePhysics + { + #region Shortcuts + + #region Rigidbody + + /// Tweens a Rigidbody's position to the given value. + /// Also stores the rigidbody as the tween's target so it can be used for filtered operations + /// The end value to reachThe duration of the tween + /// If TRUE the tween will smoothly snap all values to integers + public static Tweener DOMove(this Rigidbody target, Vector3 endValue, float duration, bool snapping = false) + { + return DOTween.To(() => target.position, target.MovePosition, endValue, duration) + .SetOptions(snapping).SetTarget(target); + } + + /// Tweens a Rigidbody's X position to the given value. + /// Also stores the rigidbody as the tween's target so it can be used for filtered operations + /// The end value to reachThe duration of the tween + /// If TRUE the tween will smoothly snap all values to integers + public static Tweener DOMoveX(this Rigidbody target, float endValue, float duration, bool snapping = false) + { + return DOTween.To(() => target.position, target.MovePosition, new Vector3(endValue, 0, 0), duration) + .SetOptions(AxisConstraint.X, snapping).SetTarget(target); + } + + /// Tweens a Rigidbody's Y position to the given value. + /// Also stores the rigidbody as the tween's target so it can be used for filtered operations + /// The end value to reachThe duration of the tween + /// If TRUE the tween will smoothly snap all values to integers + public static Tweener DOMoveY(this Rigidbody target, float endValue, float duration, bool snapping = false) + { + return DOTween.To(() => target.position, target.MovePosition, new Vector3(0, endValue, 0), duration) + .SetOptions(AxisConstraint.Y, snapping).SetTarget(target); + } + + /// Tweens a Rigidbody's Z position to the given value. + /// Also stores the rigidbody as the tween's target so it can be used for filtered operations + /// The end value to reachThe duration of the tween + /// If TRUE the tween will smoothly snap all values to integers + public static Tweener DOMoveZ(this Rigidbody target, float endValue, float duration, bool snapping = false) + { + return DOTween.To(() => target.position, target.MovePosition, new Vector3(0, 0, endValue), duration) + .SetOptions(AxisConstraint.Z, snapping).SetTarget(target); + } + + /// Tweens a Rigidbody's rotation to the given value. + /// Also stores the rigidbody as the tween's target so it can be used for filtered operations + /// The end value to reachThe duration of the tween + /// Rotation mode + public static Tweener DORotate(this Rigidbody target, Vector3 endValue, float duration, RotateMode mode = RotateMode.Fast) + { + TweenerCore t = DOTween.To(() => target.rotation, target.MoveRotation, endValue, duration); + t.SetTarget(target); + t.plugOptions.rotateMode = mode; + return t; + } + + /// Tweens a Rigidbody's rotation so that it will look towards the given position. + /// Also stores the rigidbody as the tween's target so it can be used for filtered operations + /// The position to look atThe duration of the tween + /// Eventual axis constraint for the rotation + /// The vector that defines in which direction up is (default: Vector3.up) + public static Tweener DOLookAt(this Rigidbody target, Vector3 towards, float duration, AxisConstraint axisConstraint = AxisConstraint.None, Vector3? up = null) + { + TweenerCore t = DOTween.To(() => target.rotation, target.MoveRotation, towards, duration) + .SetTarget(target).SetSpecialStartupMode(SpecialStartupMode.SetLookAt); + t.plugOptions.axisConstraint = axisConstraint; + t.plugOptions.up = (up == null) ? Vector3.up : (Vector3)up; + return t; + } + + #region Special + + /// Tweens a Rigidbody's position to the given value, while also applying a jump effect along the Y axis. + /// Returns a Sequence instead of a Tweener. + /// Also stores the Rigidbody as the tween's target so it can be used for filtered operations + /// The end value to reach + /// Power of the jump (the max height of the jump is represented by this plus the final Y offset) + /// Total number of jumps + /// The duration of the tween + /// If TRUE the tween will smoothly snap all values to integers + public static Sequence DOJump(this Rigidbody target, Vector3 endValue, float jumpPower, int numJumps, float duration, bool snapping = false) + { + if (numJumps < 1) numJumps = 1; + float startPosY = 0; + float offsetY = -1; + bool offsetYSet = false; + Sequence s = DOTween.Sequence(); + Tween yTween = DOTween.To(() => target.position, target.MovePosition, new Vector3(0, jumpPower, 0), duration / (numJumps * 2)) + .SetOptions(AxisConstraint.Y, snapping).SetEase(Ease.OutQuad).SetRelative() + .SetLoops(numJumps * 2, LoopType.Yoyo) + .OnStart(() => startPosY = target.position.y); + s.Append(DOTween.To(() => target.position, target.MovePosition, new Vector3(endValue.x, 0, 0), duration) + .SetOptions(AxisConstraint.X, snapping).SetEase(Ease.Linear) + ).Join(DOTween.To(() => target.position, target.MovePosition, new Vector3(0, 0, endValue.z), duration) + .SetOptions(AxisConstraint.Z, snapping).SetEase(Ease.Linear) + ).Join(yTween) + .SetTarget(target).SetEase(DOTween.defaultEaseType); + yTween.OnUpdate(() => { + if (!offsetYSet) { + offsetYSet = true; + offsetY = s.isRelative ? endValue.y : endValue.y - startPosY; + } + Vector3 pos = target.position; + pos.y += DOVirtual.EasedValue(0, offsetY, yTween.ElapsedPercentage(), Ease.OutQuad); + target.MovePosition(pos); + }); + return s; + } + + /// Tweens a Rigidbody's position through the given path waypoints, using the chosen path algorithm. + /// Also stores the Rigidbody as the tween's target so it can be used for filtered operations. + /// NOTE: to tween a rigidbody correctly it should be set to kinematic at least while being tweened. + /// BEWARE: doesn't work on Windows Phone store (waiting for Unity to fix their own bug). + /// If you plan to publish there you should use a regular transform.DOPath. + /// The waypoints to go through + /// The duration of the tween + /// The type of path: Linear (straight path) or CatmullRom (curved CatmullRom path) + /// The path mode: 3D, side-scroller 2D, top-down 2D + /// The resolution of the path (useless in case of Linear paths): higher resolutions make for more detailed curved paths but are more expensive. + /// Defaults to 10, but a value of 5 is usually enough if you don't have dramatic long curves between waypoints + /// The color of the path (shown when gizmos are active in the Play panel and the tween is running) + public static TweenerCore DOPath( + this Rigidbody target, Vector3[] path, float duration, PathType pathType = PathType.Linear, + PathMode pathMode = PathMode.Full3D, int resolution = 10, Color? gizmoColor = null + ) + { + if (resolution < 1) resolution = 1; + TweenerCore t = DOTween.To(PathPlugin.Get(), () => target.position, target.MovePosition, new Path(pathType, path, resolution, gizmoColor), duration) + .SetTarget(target).SetUpdate(UpdateType.Fixed); + + t.plugOptions.isRigidbody = true; + t.plugOptions.mode = pathMode; + return t; + } + /// Tweens a Rigidbody's localPosition through the given path waypoints, using the chosen path algorithm. + /// Also stores the Rigidbody as the tween's target so it can be used for filtered operations + /// NOTE: to tween a rigidbody correctly it should be set to kinematic at least while being tweened. + /// BEWARE: doesn't work on Windows Phone store (waiting for Unity to fix their own bug). + /// If you plan to publish there you should use a regular transform.DOLocalPath. + /// The waypoint to go through + /// The duration of the tween + /// The type of path: Linear (straight path) or CatmullRom (curved CatmullRom path) + /// The path mode: 3D, side-scroller 2D, top-down 2D + /// The resolution of the path: higher resolutions make for more detailed curved paths but are more expensive. + /// Defaults to 10, but a value of 5 is usually enough if you don't have dramatic long curves between waypoints + /// The color of the path (shown when gizmos are active in the Play panel and the tween is running) + public static TweenerCore DOLocalPath( + this Rigidbody target, Vector3[] path, float duration, PathType pathType = PathType.Linear, + PathMode pathMode = PathMode.Full3D, int resolution = 10, Color? gizmoColor = null + ) + { + if (resolution < 1) resolution = 1; + Transform trans = target.transform; + TweenerCore t = DOTween.To(PathPlugin.Get(), () => trans.localPosition, x => target.MovePosition(trans.parent == null ? x : trans.parent.TransformPoint(x)), new Path(pathType, path, resolution, gizmoColor), duration) + .SetTarget(target).SetUpdate(UpdateType.Fixed); + + t.plugOptions.isRigidbody = true; + t.plugOptions.mode = pathMode; + t.plugOptions.useLocalPosition = true; + return t; + } + // Used by path editor when creating the actual tween, so it can pass a pre-compiled path + internal static TweenerCore DOPath( + this Rigidbody target, Path path, float duration, PathMode pathMode = PathMode.Full3D + ) + { + TweenerCore t = DOTween.To(PathPlugin.Get(), () => target.position, target.MovePosition, path, duration) + .SetTarget(target); + + t.plugOptions.isRigidbody = true; + t.plugOptions.mode = pathMode; + return t; + } + internal static TweenerCore DOLocalPath( + this Rigidbody target, Path path, float duration, PathMode pathMode = PathMode.Full3D + ) + { + Transform trans = target.transform; + TweenerCore t = DOTween.To(PathPlugin.Get(), () => trans.localPosition, x => target.MovePosition(trans.parent == null ? x : trans.parent.TransformPoint(x)), path, duration) + .SetTarget(target); + + t.plugOptions.isRigidbody = true; + t.plugOptions.mode = pathMode; + t.plugOptions.useLocalPosition = true; + return t; + } + + #endregion + + #endregion + + #endregion + } +} +#endif diff --git a/_DOTween.Assembly/bin/Modules/DOTweenModulePhysics2D.cs b/_DOTween.Assembly/bin/Modules/DOTweenModulePhysics2D.cs new file mode 100644 index 0000000..b99b8ab --- /dev/null +++ b/_DOTween.Assembly/bin/Modules/DOTweenModulePhysics2D.cs @@ -0,0 +1,101 @@ +// Author: Daniele Giardini - http://www.demigiant.com +// Created: 2018/07/13 + +#if DOTPHYSICS2D && (UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_5 || UNITY_2017_0_OR_NEWER) +using System; +using UnityEngine; + +#pragma warning disable 1591 +namespace DG.Tweening +{ + public static class DOTweenModulePhysics2D + { + #region Shortcuts + + #region Rigidbody2D Shortcuts + + /// Tweens a Rigidbody2D's position to the given value. + /// Also stores the Rigidbody2D as the tween's target so it can be used for filtered operations + /// The end value to reachThe duration of the tween + /// If TRUE the tween will smoothly snap all values to integers + public static Tweener DOMove(this Rigidbody2D target, Vector2 endValue, float duration, bool snapping = false) + { + return DOTween.To(() => target.position, target.MovePosition, endValue, duration) + .SetOptions(snapping).SetTarget(target); + } + + /// Tweens a Rigidbody2D's X position to the given value. + /// Also stores the Rigidbody2D as the tween's target so it can be used for filtered operations + /// The end value to reachThe duration of the tween + /// If TRUE the tween will smoothly snap all values to integers + public static Tweener DOMoveX(this Rigidbody2D target, float endValue, float duration, bool snapping = false) + { + return DOTween.To(() => target.position, target.MovePosition, new Vector2(endValue, 0), duration) + .SetOptions(AxisConstraint.X, snapping).SetTarget(target); + } + + /// Tweens a Rigidbody2D's Y position to the given value. + /// Also stores the Rigidbody2D as the tween's target so it can be used for filtered operations + /// The end value to reachThe duration of the tween + /// If TRUE the tween will smoothly snap all values to integers + public static Tweener DOMoveY(this Rigidbody2D target, float endValue, float duration, bool snapping = false) + { + return DOTween.To(() => target.position, target.MovePosition, new Vector2(0, endValue), duration) + .SetOptions(AxisConstraint.Y, snapping).SetTarget(target); + } + + /// Tweens a Rigidbody2D's rotation to the given value. + /// Also stores the Rigidbody2D as the tween's target so it can be used for filtered operations + /// The end value to reachThe duration of the tween + public static Tweener DORotate(this Rigidbody2D target, float endValue, float duration) + { + return DOTween.To(() => target.rotation, target.MoveRotation, endValue, duration) + .SetTarget(target); + } + + #region Special + + /// Tweens a Rigidbody2D's position to the given value, while also applying a jump effect along the Y axis. + /// Returns a Sequence instead of a Tweener. + /// Also stores the Rigidbody2D as the tween's target so it can be used for filtered operations. + /// IMPORTANT: a rigidbody2D can't be animated in a jump arc using MovePosition, so the tween will directly set the position + /// The end value to reach + /// Power of the jump (the max height of the jump is represented by this plus the final Y offset) + /// Total number of jumps + /// The duration of the tween + /// If TRUE the tween will smoothly snap all values to integers + public static Sequence DOJump(this Rigidbody2D target, Vector2 endValue, float jumpPower, int numJumps, float duration, bool snapping = false) + { + if (numJumps < 1) numJumps = 1; + float startPosY = 0; + float offsetY = -1; + bool offsetYSet = false; + Sequence s = DOTween.Sequence(); + Tween yTween = DOTween.To(() => target.position, x => target.position = x, new Vector2(0, jumpPower), duration / (numJumps * 2)) + .SetOptions(AxisConstraint.Y, snapping).SetEase(Ease.OutQuad).SetRelative() + .SetLoops(numJumps * 2, LoopType.Yoyo) + .OnStart(() => startPosY = target.position.y); + s.Append(DOTween.To(() => target.position, x => target.position = x, new Vector2(endValue.x, 0), duration) + .SetOptions(AxisConstraint.X, snapping).SetEase(Ease.Linear) + ).Join(yTween) + .SetTarget(target).SetEase(DOTween.defaultEaseType); + yTween.OnUpdate(() => { + if (!offsetYSet) { + offsetYSet = true; + offsetY = s.isRelative ? endValue.y : endValue.y - startPosY; + } + Vector3 pos = target.position; + pos.y += DOVirtual.EasedValue(0, offsetY, yTween.ElapsedPercentage(), Ease.OutQuad); + target.MovePosition(pos); + }); + return s; + } + + #endregion + + #endregion + + #endregion + } +} +#endif diff --git a/_DOTween.Assembly/bin/Modules/DOTweenModuleSprite.cs b/_DOTween.Assembly/bin/Modules/DOTweenModuleSprite.cs new file mode 100644 index 0000000..91505c9 --- /dev/null +++ b/_DOTween.Assembly/bin/Modules/DOTweenModuleSprite.cs @@ -0,0 +1,88 @@ +// Author: Daniele Giardini - http://www.demigiant.com +// Created: 2018/07/13 + +#if DOTSPRITE && (UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_5 || UNITY_2017_0_OR_NEWER) +using System; +using UnityEngine; +using DG.Tweening.Core; + +#pragma warning disable 1591 +namespace DG.Tweening +{ + public static class DOTweenModuleSprite + { + #region Shortcuts + + #region SpriteRenderer + + /// Tweens a SpriteRenderer's color to the given value. + /// Also stores the spriteRenderer as the tween's target so it can be used for filtered operations + /// The end value to reachThe duration of the tween + public static Tweener DOColor(this SpriteRenderer target, Color endValue, float duration) + { + return DOTween.To(() => target.color, x => target.color = x, endValue, duration).SetTarget(target); + } + + /// Tweens a Material's alpha color to the given value. + /// Also stores the spriteRenderer as the tween's target so it can be used for filtered operations + /// The end value to reachThe duration of the tween + public static Tweener DOFade(this SpriteRenderer target, float endValue, float duration) + { + return DOTween.ToAlpha(() => target.color, x => target.color = x, endValue, duration) + .SetTarget(target); + } + + /// Tweens a SpriteRenderer's color using the given gradient + /// (NOTE 1: only uses the colors of the gradient, not the alphas - NOTE 2: creates a Sequence, not a Tweener). + /// Also stores the image as the tween's target so it can be used for filtered operations + /// The gradient to useThe duration of the tween + public static Sequence DOGradientColor(this SpriteRenderer target, Gradient gradient, float duration) + { + Sequence s = DOTween.Sequence(); + GradientColorKey[] colors = gradient.colorKeys; + int len = colors.Length; + for (int i = 0; i < len; ++i) { + GradientColorKey c = colors[i]; + if (i == 0 && c.time <= 0) { + target.color = c.color; + continue; + } + float colorDuration = i == len - 1 + ? duration - s.Duration(false) // Verifies that total duration is correct + : duration * (i == 0 ? c.time : c.time - colors[i - 1].time); + s.Append(target.DOColor(c.color, colorDuration).SetEase(Ease.Linear)); + } + return s; + } + + #endregion + + #region Blendables + + #region SpriteRenderer + + /// Tweens a SpriteRenderer's color to the given value, + /// in a way that allows other DOBlendableColor tweens to work together on the same target, + /// instead than fight each other as multiple DOColor would do. + /// Also stores the SpriteRenderer as the tween's target so it can be used for filtered operations + /// The value to tween toThe duration of the tween + public static Tweener DOBlendableColor(this SpriteRenderer target, Color endValue, float duration) + { + endValue = endValue - target.color; + Color to = new Color(0, 0, 0, 0); + return DOTween.To(() => to, x => { + Color diff = x - to; + to = x; + target.color += diff; + }, endValue, duration) + .Blendable().SetTarget(target); + } + + #endregion + + #endregion + + #endregion + } +} +#endif diff --git a/_DOTween.Assembly/bin/Modules/DOTweenModuleUI.cs b/_DOTween.Assembly/bin/Modules/DOTweenModuleUI.cs new file mode 100644 index 0000000..1eaca57 --- /dev/null +++ b/_DOTween.Assembly/bin/Modules/DOTweenModuleUI.cs @@ -0,0 +1,570 @@ +// Author: Daniele Giardini - http://www.demigiant.com +// Created: 2018/07/13 + +#if DOTUI && (UNITY_4_6 || UNITY_5 || UNITY_2017_0_OR_NEWER) +using System; +using UnityEngine; +using UnityEngine.UI; +using DG.Tweening.Core; +using DG.Tweening.Core.Enums; + +#pragma warning disable 1591 +namespace DG.Tweening +{ + public static class DOTweenModuleUI + { + #region Shortcuts + + #region CanvasGroup + + /// Tweens a CanvasGroup's alpha color to the given value. + /// Also stores the canvasGroup as the tween's target so it can be used for filtered operations + /// The end value to reachThe duration of the tween + public static Tweener DOFade(this CanvasGroup target, float endValue, float duration) + { + return DOTween.To(() => target.alpha, x => target.alpha = x, endValue, duration) + .SetTarget(target); + } + + #endregion + + #region Graphic + + /// Tweens an Graphic's color to the given value. + /// Also stores the image as the tween's target so it can be used for filtered operations + /// The end value to reachThe duration of the tween + public static Tweener DOColor(this Graphic target, Color endValue, float duration) + { + return DOTween.To(() => target.color, x => target.color = x, endValue, duration).SetTarget(target); + } + + /// Tweens an Graphic's alpha color to the given value. + /// Also stores the image as the tween's target so it can be used for filtered operations + /// The end value to reachThe duration of the tween + public static Tweener DOFade(this Graphic target, float endValue, float duration) + { + return DOTween.ToAlpha(() => target.color, x => target.color = x, endValue, duration) + .SetTarget(target); + } + + #endregion + + #region Image + + /// Tweens an Image's color to the given value. + /// Also stores the image as the tween's target so it can be used for filtered operations + /// The end value to reachThe duration of the tween + public static Tweener DOColor(this Image target, Color endValue, float duration) + { + return DOTween.To(() => target.color, x => target.color = x, endValue, duration).SetTarget(target); + } + + /// Tweens an Image's alpha color to the given value. + /// Also stores the image as the tween's target so it can be used for filtered operations + /// The end value to reachThe duration of the tween + public static Tweener DOFade(this Image target, float endValue, float duration) + { + return DOTween.ToAlpha(() => target.color, x => target.color = x, endValue, duration) + .SetTarget(target); + } + + /// Tweens an Image's fillAmount to the given value. + /// Also stores the image as the tween's target so it can be used for filtered operations + /// The end value to reach (0 to 1)The duration of the tween + public static Tweener DOFillAmount(this Image target, float endValue, float duration) + { + if (endValue > 1) endValue = 1; + else if (endValue < 0) endValue = 0; + return DOTween.To(() => target.fillAmount, x => target.fillAmount = x, endValue, duration) + .SetTarget(target); + } + + /// Tweens an Image's colors using the given gradient + /// (NOTE 1: only uses the colors of the gradient, not the alphas - NOTE 2: creates a Sequence, not a Tweener). + /// Also stores the image as the tween's target so it can be used for filtered operations + /// The gradient to useThe duration of the tween + public static Sequence DOGradientColor(this Image target, Gradient gradient, float duration) + { + Sequence s = DOTween.Sequence(); + GradientColorKey[] colors = gradient.colorKeys; + int len = colors.Length; + for (int i = 0; i < len; ++i) { + GradientColorKey c = colors[i]; + if (i == 0 && c.time <= 0) { + target.color = c.color; + continue; + } + float colorDuration = i == len - 1 + ? duration - s.Duration(false) // Verifies that total duration is correct + : duration * (i == 0 ? c.time : c.time - colors[i - 1].time); + s.Append(target.DOColor(c.color, colorDuration).SetEase(Ease.Linear)); + } + return s; + } + + #endregion + + #region LayoutElement + + /// Tweens an LayoutElement's flexibleWidth/Height to the given value. + /// Also stores the LayoutElement as the tween's target so it can be used for filtered operations + /// The end value to reachThe duration of the tween + /// If TRUE the tween will smoothly snap all values to integers + public static Tweener DOFlexibleSize(this LayoutElement target, Vector2 endValue, float duration, bool snapping = false) + { + return DOTween.To(() => new Vector2(target.flexibleWidth, target.flexibleHeight), x => { + target.flexibleWidth = x.x; + target.flexibleHeight = x.y; + }, endValue, duration) + .SetOptions(snapping).SetTarget(target); + } + + /// Tweens an LayoutElement's minWidth/Height to the given value. + /// Also stores the LayoutElement as the tween's target so it can be used for filtered operations + /// The end value to reachThe duration of the tween + /// If TRUE the tween will smoothly snap all values to integers + public static Tweener DOMinSize(this LayoutElement target, Vector2 endValue, float duration, bool snapping = false) + { + return DOTween.To(() => new Vector2(target.minWidth, target.minHeight), x => { + target.minWidth = x.x; + target.minHeight = x.y; + }, endValue, duration) + .SetOptions(snapping).SetTarget(target); + } + + /// Tweens an LayoutElement's preferredWidth/Height to the given value. + /// Also stores the LayoutElement as the tween's target so it can be used for filtered operations + /// The end value to reachThe duration of the tween + /// If TRUE the tween will smoothly snap all values to integers + public static Tweener DOPreferredSize(this LayoutElement target, Vector2 endValue, float duration, bool snapping = false) + { + return DOTween.To(() => new Vector2(target.preferredWidth, target.preferredHeight), x => { + target.preferredWidth = x.x; + target.preferredHeight = x.y; + }, endValue, duration) + .SetOptions(snapping).SetTarget(target); + } + + #endregion + + #region Outline + + /// Tweens a Outline's effectColor to the given value. + /// Also stores the Outline as the tween's target so it can be used for filtered operations + /// The end value to reachThe duration of the tween + public static Tweener DOColor(this Outline target, Color endValue, float duration) + { + return DOTween.To(() => target.effectColor, x => target.effectColor = x, endValue, duration).SetTarget(target); + } + + /// Tweens a Outline's effectColor alpha to the given value. + /// Also stores the Outline as the tween's target so it can be used for filtered operations + /// The end value to reachThe duration of the tween + public static Tweener DOFade(this Outline target, float endValue, float duration) + { + return DOTween.ToAlpha(() => target.effectColor, x => target.effectColor = x, endValue, duration) + .SetTarget(target); + } + + /// Tweens a Outline's effectDistance to the given value. + /// Also stores the Outline as the tween's target so it can be used for filtered operations + /// The end value to reachThe duration of the tween + public static Tweener DOScale(this Outline target, Vector2 endValue, float duration) + { + return DOTween.To(() => target.effectDistance, x => target.effectDistance = x, endValue, duration) + .SetTarget(target); + } + + #endregion + + #region RectTransform + + /// Tweens a RectTransform's anchoredPosition to the given value. + /// Also stores the RectTransform as the tween's target so it can be used for filtered operations + /// The end value to reachThe duration of the tween + /// If TRUE the tween will smoothly snap all values to integers + public static Tweener DOAnchorPos(this RectTransform target, Vector2 endValue, float duration, bool snapping = false) + { + return DOTween.To(() => target.anchoredPosition, x => target.anchoredPosition = x, endValue, duration) + .SetOptions(snapping).SetTarget(target); + } + /// Tweens a RectTransform's anchoredPosition X to the given value. + /// Also stores the RectTransform as the tween's target so it can be used for filtered operations + /// The end value to reachThe duration of the tween + /// If TRUE the tween will smoothly snap all values to integers + public static Tweener DOAnchorPosX(this RectTransform target, float endValue, float duration, bool snapping = false) + { + return DOTween.To(() => target.anchoredPosition, x => target.anchoredPosition = x, new Vector2(endValue, 0), duration) + .SetOptions(AxisConstraint.X, snapping).SetTarget(target); + } + /// Tweens a RectTransform's anchoredPosition Y to the given value. + /// Also stores the RectTransform as the tween's target so it can be used for filtered operations + /// The end value to reachThe duration of the tween + /// If TRUE the tween will smoothly snap all values to integers + public static Tweener DOAnchorPosY(this RectTransform target, float endValue, float duration, bool snapping = false) + { + return DOTween.To(() => target.anchoredPosition, x => target.anchoredPosition = x, new Vector2(0, endValue), duration) + .SetOptions(AxisConstraint.Y, snapping).SetTarget(target); + } + + /// Tweens a RectTransform's anchoredPosition3D to the given value. + /// Also stores the RectTransform as the tween's target so it can be used for filtered operations + /// The end value to reachThe duration of the tween + /// If TRUE the tween will smoothly snap all values to integers + public static Tweener DOAnchorPos3D(this RectTransform target, Vector3 endValue, float duration, bool snapping = false) + { + return DOTween.To(() => target.anchoredPosition3D, x => target.anchoredPosition3D = x, endValue, duration) + .SetOptions(snapping).SetTarget(target); + } + /// Tweens a RectTransform's anchoredPosition3D X to the given value. + /// Also stores the RectTransform as the tween's target so it can be used for filtered operations + /// The end value to reachThe duration of the tween + /// If TRUE the tween will smoothly snap all values to integers + public static Tweener DOAnchorPos3DX(this RectTransform target, float endValue, float duration, bool snapping = false) + { + return DOTween.To(() => target.anchoredPosition3D, x => target.anchoredPosition3D = x, new Vector3(endValue, 0, 0), duration) + .SetOptions(AxisConstraint.X, snapping).SetTarget(target); + } + /// Tweens a RectTransform's anchoredPosition3D Y to the given value. + /// Also stores the RectTransform as the tween's target so it can be used for filtered operations + /// The end value to reachThe duration of the tween + /// If TRUE the tween will smoothly snap all values to integers + public static Tweener DOAnchorPos3DY(this RectTransform target, float endValue, float duration, bool snapping = false) + { + return DOTween.To(() => target.anchoredPosition3D, x => target.anchoredPosition3D = x, new Vector3(0, endValue, 0), duration) + .SetOptions(AxisConstraint.Y, snapping).SetTarget(target); + } + /// Tweens a RectTransform's anchoredPosition3D Z to the given value. + /// Also stores the RectTransform as the tween's target so it can be used for filtered operations + /// The end value to reachThe duration of the tween + /// If TRUE the tween will smoothly snap all values to integers + public static Tweener DOAnchorPos3DZ(this RectTransform target, float endValue, float duration, bool snapping = false) + { + return DOTween.To(() => target.anchoredPosition3D, x => target.anchoredPosition3D = x, new Vector3(0, 0, endValue), duration) + .SetOptions(AxisConstraint.Z, snapping).SetTarget(target); + } + + /// Tweens a RectTransform's anchorMax to the given value. + /// Also stores the RectTransform as the tween's target so it can be used for filtered operations + /// The end value to reachThe duration of the tween + /// If TRUE the tween will smoothly snap all values to integers + public static Tweener DOAnchorMax(this RectTransform target, Vector2 endValue, float duration, bool snapping = false) + { + return DOTween.To(() => target.anchorMax, x => target.anchorMax = x, endValue, duration) + .SetOptions(snapping).SetTarget(target); + } + + /// Tweens a RectTransform's anchorMin to the given value. + /// Also stores the RectTransform as the tween's target so it can be used for filtered operations + /// The end value to reachThe duration of the tween + /// If TRUE the tween will smoothly snap all values to integers + public static Tweener DOAnchorMin(this RectTransform target, Vector2 endValue, float duration, bool snapping = false) + { + return DOTween.To(() => target.anchorMin, x => target.anchorMin = x, endValue, duration) + .SetOptions(snapping).SetTarget(target); + } + + /// Tweens a RectTransform's pivot to the given value. + /// Also stores the RectTransform as the tween's target so it can be used for filtered operations + /// The end value to reachThe duration of the tween + public static Tweener DOPivot(this RectTransform target, Vector2 endValue, float duration) + { + return DOTween.To(() => target.pivot, x => target.pivot = x, endValue, duration) + .SetTarget(target); + } + /// Tweens a RectTransform's pivot X to the given value. + /// Also stores the RectTransform as the tween's target so it can be used for filtered operations + /// The end value to reachThe duration of the tween + public static Tweener DOPivotX(this RectTransform target, float endValue, float duration) + { + return DOTween.To(() => target.pivot, x => target.pivot = x, new Vector2(endValue, 0), duration) + .SetOptions(AxisConstraint.X).SetTarget(target); + } + /// Tweens a RectTransform's pivot Y to the given value. + /// Also stores the RectTransform as the tween's target so it can be used for filtered operations + /// The end value to reachThe duration of the tween + public static Tweener DOPivotY(this RectTransform target, float endValue, float duration) + { + return DOTween.To(() => target.pivot, x => target.pivot = x, new Vector2(0, endValue), duration) + .SetOptions(AxisConstraint.Y).SetTarget(target); + } + + /// Tweens a RectTransform's sizeDelta to the given value. + /// Also stores the RectTransform as the tween's target so it can be used for filtered operations + /// The end value to reachThe duration of the tween + /// If TRUE the tween will smoothly snap all values to integers + public static Tweener DOSizeDelta(this RectTransform target, Vector2 endValue, float duration, bool snapping = false) + { + return DOTween.To(() => target.sizeDelta, x => target.sizeDelta = x, endValue, duration) + .SetOptions(snapping).SetTarget(target); + } + + /// Punches a RectTransform's anchoredPosition towards the given direction and then back to the starting one + /// as if it was connected to the starting position via an elastic. + /// Also stores the RectTransform as the tween's target so it can be used for filtered operations + /// The direction and strength of the punch (added to the RectTransform's current position) + /// The duration of the tween + /// Indicates how much will the punch vibrate + /// Represents how much (0 to 1) the vector will go beyond the starting position when bouncing backwards. + /// 1 creates a full oscillation between the punch direction and the opposite direction, + /// while 0 oscillates only between the punch and the start position + /// If TRUE the tween will smoothly snap all values to integers + public static Tweener DOPunchAnchorPos(this RectTransform target, Vector2 punch, float duration, int vibrato = 10, float elasticity = 1, bool snapping = false) + { + return DOTween.Punch(() => target.anchoredPosition, x => target.anchoredPosition = x, punch, duration, vibrato, elasticity) + .SetTarget(target).SetOptions(snapping); + } + + /// Shakes a RectTransform's anchoredPosition with the given values. + /// Also stores the RectTransform as the tween's target so it can be used for filtered operations + /// The duration of the tween + /// The shake strength + /// Indicates how much will the shake vibrate + /// Indicates how much the shake will be random (0 to 180 - values higher than 90 kind of suck, so beware). + /// Setting it to 0 will shake along a single direction. + /// If TRUE the tween will smoothly snap all values to integers + /// If TRUE the shake will automatically fadeOut smoothly within the tween's duration, otherwise it will not + public static Tweener DOShakeAnchorPos(this RectTransform target, float duration, float strength = 100, int vibrato = 10, float randomness = 90, bool snapping = false, bool fadeOut = true) + { + return DOTween.Shake(() => target.anchoredPosition, x => target.anchoredPosition = x, duration, strength, vibrato, randomness, true, fadeOut) + .SetTarget(target).SetSpecialStartupMode(SpecialStartupMode.SetShake).SetOptions(snapping); + } + /// Shakes a RectTransform's anchoredPosition with the given values. + /// Also stores the RectTransform as the tween's target so it can be used for filtered operations + /// The duration of the tween + /// The shake strength on each axis + /// Indicates how much will the shake vibrate + /// Indicates how much the shake will be random (0 to 180 - values higher than 90 kind of suck, so beware). + /// Setting it to 0 will shake along a single direction. + /// If TRUE the tween will smoothly snap all values to integers + /// If TRUE the shake will automatically fadeOut smoothly within the tween's duration, otherwise it will not + public static Tweener DOShakeAnchorPos(this RectTransform target, float duration, Vector2 strength, int vibrato = 10, float randomness = 90, bool snapping = false, bool fadeOut = true) + { + return DOTween.Shake(() => target.anchoredPosition, x => target.anchoredPosition = x, duration, strength, vibrato, randomness, fadeOut) + .SetTarget(target).SetSpecialStartupMode(SpecialStartupMode.SetShake).SetOptions(snapping); + } + + #region Special + + /// Tweens a RectTransform's anchoredPosition to the given value, while also applying a jump effect along the Y axis. + /// Returns a Sequence instead of a Tweener. + /// Also stores the RectTransform as the tween's target so it can be used for filtered operations + /// The end value to reach + /// Power of the jump (the max height of the jump is represented by this plus the final Y offset) + /// Total number of jumps + /// The duration of the tween + /// If TRUE the tween will smoothly snap all values to integers + public static Sequence DOJumpAnchorPos(this RectTransform target, Vector2 endValue, float jumpPower, int numJumps, float duration, bool snapping = false) + { + if (numJumps < 1) numJumps = 1; + float startPosY = 0; + float offsetY = -1; + bool offsetYSet = false; + + // Separate Y Tween so we can elaborate elapsedPercentage on that insted of on the Sequence + // (in case users add a delay or other elements to the Sequence) + Sequence s = DOTween.Sequence(); + Tween yTween = DOTween.To(() => target.anchoredPosition, x => target.anchoredPosition = x, new Vector2(0, jumpPower), duration / (numJumps * 2)) + .SetOptions(AxisConstraint.Y, snapping).SetEase(Ease.OutQuad).SetRelative() + .SetLoops(numJumps * 2, LoopType.Yoyo) + .OnStart(()=> startPosY = target.anchoredPosition.y); + s.Append(DOTween.To(() => target.anchoredPosition, x => target.anchoredPosition = x, new Vector2(endValue.x, 0), duration) + .SetOptions(AxisConstraint.X, snapping).SetEase(Ease.Linear) + ).Join(yTween) + .SetTarget(target).SetEase(DOTween.defaultEaseType); + s.OnUpdate(() => { + if (!offsetYSet) { + offsetYSet = true; + offsetY = s.isRelative ? endValue.y : endValue.y - startPosY; + } + Vector2 pos = target.anchoredPosition; + pos.y += DOVirtual.EasedValue(0, offsetY, s.ElapsedDirectionalPercentage(), Ease.OutQuad); + target.anchoredPosition = pos; + }); + return s; + } + + #endregion + + #endregion + + #region ScrollRect + + /// Tweens a ScrollRect's horizontal/verticalNormalizedPosition to the given value. + /// Also stores the ScrollRect as the tween's target so it can be used for filtered operations + /// The end value to reachThe duration of the tween + /// If TRUE the tween will smoothly snap all values to integers + public static Tweener DONormalizedPos(this ScrollRect target, Vector2 endValue, float duration, bool snapping = false) + { + return DOTween.To(() => new Vector2(target.horizontalNormalizedPosition, target.verticalNormalizedPosition), + x => { + target.horizontalNormalizedPosition = x.x; + target.verticalNormalizedPosition = x.y; + }, endValue, duration) + .SetOptions(snapping).SetTarget(target); + } + /// Tweens a ScrollRect's horizontalNormalizedPosition to the given value. + /// Also stores the ScrollRect as the tween's target so it can be used for filtered operations + /// The end value to reachThe duration of the tween + /// If TRUE the tween will smoothly snap all values to integers + public static Tweener DOHorizontalNormalizedPos(this ScrollRect target, float endValue, float duration, bool snapping = false) + { + return DOTween.To(() => target.horizontalNormalizedPosition, x => target.horizontalNormalizedPosition = x, endValue, duration) + .SetOptions(snapping).SetTarget(target); + } + /// Tweens a ScrollRect's verticalNormalizedPosition to the given value. + /// Also stores the ScrollRect as the tween's target so it can be used for filtered operations + /// The end value to reachThe duration of the tween + /// If TRUE the tween will smoothly snap all values to integers + public static Tweener DOVerticalNormalizedPos(this ScrollRect target, float endValue, float duration, bool snapping = false) + { + return DOTween.To(() => target.verticalNormalizedPosition, x => target.verticalNormalizedPosition = x, endValue, duration) + .SetOptions(snapping).SetTarget(target); + } + + #endregion + + #region Slider + + /// Tweens a Slider's value to the given value. + /// Also stores the Slider as the tween's target so it can be used for filtered operations + /// The end value to reachThe duration of the tween + /// If TRUE the tween will smoothly snap all values to integers + public static Tweener DOValue(this Slider target, float endValue, float duration, bool snapping = false) + { + return DOTween.To(() => target.value, x => target.value = x, endValue, duration) + .SetOptions(snapping).SetTarget(target); + } + + #endregion + + #region Text + + /// Tweens a Text's color to the given value. + /// Also stores the Text as the tween's target so it can be used for filtered operations + /// The end value to reachThe duration of the tween + public static Tweener DOColor(this Text target, Color endValue, float duration) + { + return DOTween.To(() => target.color, x => target.color = x, endValue, duration).SetTarget(target); + } + + /// Tweens a Text's alpha color to the given value. + /// Also stores the Text as the tween's target so it can be used for filtered operations + /// The end value to reachThe duration of the tween + public static Tweener DOFade(this Text target, float endValue, float duration) + { + return DOTween.ToAlpha(() => target.color, x => target.color = x, endValue, duration) + .SetTarget(target); + } + + /// Tweens a Text's text to the given value. + /// Also stores the Text as the tween's target so it can be used for filtered operations + /// The end string to tween toThe duration of the tween + /// If TRUE (default), rich text will be interpreted correctly while animated, + /// otherwise all tags will be considered as normal text + /// The type of scramble mode to use, if any + /// A string containing the characters to use for scrambling. + /// Use as many characters as possible (minimum 10) because DOTween uses a fast scramble mode which gives better results with more characters. + /// Leave it to NULL (default) to use default ones + public static Tweener DOText(this Text target, string endValue, float duration, bool richTextEnabled = true, ScrambleMode scrambleMode = ScrambleMode.None, string scrambleChars = null) + { + return DOTween.To(() => target.text, x => target.text = x, endValue, duration) + .SetOptions(richTextEnabled, scrambleMode, scrambleChars) + .SetTarget(target); + } + + #endregion + + #region Blendables + + #region Graphic + + /// Tweens a Graphic's color to the given value, + /// in a way that allows other DOBlendableColor tweens to work together on the same target, + /// instead than fight each other as multiple DOColor would do. + /// Also stores the Graphic as the tween's target so it can be used for filtered operations + /// The value to tween toThe duration of the tween + public static Tweener DOBlendableColor(this Graphic target, Color endValue, float duration) + { + endValue = endValue - target.color; + Color to = new Color(0, 0, 0, 0); + return DOTween.To(() => to, x => { + Color diff = x - to; + to = x; + target.color += diff; + }, endValue, duration) + .Blendable().SetTarget(target); + } + + #endregion + + #region Image + + /// Tweens a Image's color to the given value, + /// in a way that allows other DOBlendableColor tweens to work together on the same target, + /// instead than fight each other as multiple DOColor would do. + /// Also stores the Image as the tween's target so it can be used for filtered operations + /// The value to tween toThe duration of the tween + public static Tweener DOBlendableColor(this Image target, Color endValue, float duration) + { + endValue = endValue - target.color; + Color to = new Color(0, 0, 0, 0); + return DOTween.To(() => to, x => { + Color diff = x - to; + to = x; + target.color += diff; + }, endValue, duration) + .Blendable().SetTarget(target); + } + + #endregion + + #region Text + + /// Tweens a Text's color BY the given value, + /// in a way that allows other DOBlendableColor tweens to work together on the same target, + /// instead than fight each other as multiple DOColor would do. + /// Also stores the Text as the tween's target so it can be used for filtered operations + /// The value to tween toThe duration of the tween + public static Tweener DOBlendableColor(this Text target, Color endValue, float duration) + { + endValue = endValue - target.color; + Color to = new Color(0, 0, 0, 0); + return DOTween.To(() => to, x => { + Color diff = x - to; + to = x; + target.color += diff; + }, endValue, duration) + .Blendable().SetTarget(target); + } + + #endregion + + #endregion + + #endregion + + // █████████████████████████████████████████████████████████████████████████████████████████████████████████████████████ + // ███ INTERNAL CLASSES ████████████████████████████████████████████████████████████████████████████████████████████████ + // █████████████████████████████████████████████████████████████████████████████████████████████████████████████████████ + + public static class Utils + { + /// + /// Converts the anchoredPosition of the first RectTransform to the second RectTransform, + /// taking into consideration offset, anchors and pivot, and returns the new anchoredPosition + /// + public static Vector2 SwitchToRectTransform(RectTransform from, RectTransform to) + { + Vector2 localPoint; + Vector2 fromPivotDerivedOffset = new Vector2(from.rect.width * 0.5f + from.rect.xMin, from.rect.height * 0.5f + from.rect.yMin); + Vector2 screenP = RectTransformUtility.WorldToScreenPoint(null, from.position); + screenP += fromPivotDerivedOffset; + RectTransformUtility.ScreenPointToLocalPointInRectangle(to, screenP, null, out localPoint); + Vector2 pivotDerivedOffset = new Vector2(to.rect.width * 0.5f + to.rect.xMin, to.rect.height * 0.5f + to.rect.yMin); + return to.anchoredPosition + localPoint - pivotDerivedOffset; + } + } + } +} +#endif diff --git a/_DOTween.Assembly/bin/Modules/DOTweenModuleUnityVersion.cs b/_DOTween.Assembly/bin/Modules/DOTweenModuleUnityVersion.cs new file mode 100644 index 0000000..d8d0997 --- /dev/null +++ b/_DOTween.Assembly/bin/Modules/DOTweenModuleUnityVersion.cs @@ -0,0 +1,252 @@ +// Author: Daniele Giardini - http://www.demigiant.com +// Created: 2018/07/13 + +using System; +using UnityEngine; +using DG.Tweening.Core; + +#pragma warning disable 1591 +namespace DG.Tweening +{ + /// + /// Shortcuts/functions that are not strictly related to specific Modules + /// but are available only on some Unity versions + /// + public static class DOTweenModuleUnityVersion + { +#if UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_5 || UNITY_2017_0_OR_NEWER + #region Unity 4.3 or Newer + + #region Material + + /// Tweens a Material's color using the given gradient + /// (NOTE 1: only uses the colors of the gradient, not the alphas - NOTE 2: creates a Sequence, not a Tweener). + /// Also stores the image as the tween's target so it can be used for filtered operations + /// The gradient to useThe duration of the tween + public static Sequence DOGradientColor(this Material target, Gradient gradient, float duration) + { + Sequence s = DOTween.Sequence(); + GradientColorKey[] colors = gradient.colorKeys; + int len = colors.Length; + for (int i = 0; i < len; ++i) { + GradientColorKey c = colors[i]; + if (i == 0 && c.time <= 0) { + target.color = c.color; + continue; + } + float colorDuration = i == len - 1 + ? duration - s.Duration(false) // Verifies that total duration is correct + : duration * (i == 0 ? c.time : c.time - colors[i - 1].time); + s.Append(target.DOColor(c.color, colorDuration).SetEase(Ease.Linear)); + } + return s; + } + /// Tweens a Material's named color property using the given gradient + /// (NOTE 1: only uses the colors of the gradient, not the alphas - NOTE 2: creates a Sequence, not a Tweener). + /// Also stores the image as the tween's target so it can be used for filtered operations + /// The gradient to use + /// The name of the material property to tween (like _Tint or _SpecColor) + /// The duration of the tween + public static Sequence DOGradientColor(this Material target, Gradient gradient, string property, float duration) + { + Sequence s = DOTween.Sequence(); + GradientColorKey[] colors = gradient.colorKeys; + int len = colors.Length; + for (int i = 0; i < len; ++i) { + GradientColorKey c = colors[i]; + if (i == 0 && c.time <= 0) { + target.color = c.color; + continue; + } + float colorDuration = i == len - 1 + ? duration - s.Duration(false) // Verifies that total duration is correct + : duration * (i == 0 ? c.time : c.time - colors[i - 1].time); + s.Append(target.DOColor(c.color, property, colorDuration).SetEase(Ease.Linear)); + } + return s; + } + + #endregion + + #endregion +#endif + +#if UNITY_5_3_OR_NEWER || UNITY_2017_0_OR_NEWER + #region CustomYieldInstructions (Unity 5.3 or Newer) + + /// + /// Returns a that waits until the tween is killed or complete. + /// It can be used inside a coroutine as a yield. + /// Example usage:yield return myTween.WaitForCompletion(true); + /// + public static CustomYieldInstruction WaitForCompletion(this Tween t, bool returnCustomYieldInstruction) + { + if (!t.active) { + if (Debugger.logPriority > 0) Debugger.LogInvalidTween(t); + return null; + } + return new DOTweenCYInstruction.WaitForCompletion(t); + } + + /// + /// Returns a that waits until the tween is killed or rewinded. + /// It can be used inside a coroutine as a yield. + /// Example usage:yield return myTween.WaitForRewind(); + /// + public static CustomYieldInstruction WaitForRewind(this Tween t, bool returnCustomYieldInstruction) + { + if (!t.active) { + if (Debugger.logPriority > 0) Debugger.LogInvalidTween(t); + return null; + } + return new DOTweenCYInstruction.WaitForRewind(t); + } + + /// + /// Returns a that waits until the tween is killed. + /// It can be used inside a coroutine as a yield. + /// Example usage:yield return myTween.WaitForKill(); + /// + public static CustomYieldInstruction WaitForKill(this Tween t, bool returnCustomYieldInstruction) + { + if (!t.active) { + if (Debugger.logPriority > 0) Debugger.LogInvalidTween(t); + return null; + } + return new DOTweenCYInstruction.WaitForKill(t); + } + + /// + /// Returns a that waits until the tween is killed or has gone through the given amount of loops. + /// It can be used inside a coroutine as a yield. + /// Example usage:yield return myTween.WaitForElapsedLoops(2); + /// + /// Elapsed loops to wait for + public static CustomYieldInstruction WaitForElapsedLoops(this Tween t, int elapsedLoops, bool returnCustomYieldInstruction) + { + if (!t.active) { + if (Debugger.logPriority > 0) Debugger.LogInvalidTween(t); + return null; + } + return new DOTweenCYInstruction.WaitForElapsedLoops(t, elapsedLoops); + } + + /// + /// Returns a that waits until the tween is killed or has reached the given position (loops included, delays excluded). + /// It can be used inside a coroutine as a yield. + /// Example usage:yield return myTween.WaitForPosition(2.5f); + /// + /// Position (loops included, delays excluded) to wait for + public static CustomYieldInstruction WaitForPosition(this Tween t, float position, bool returnCustomYieldInstruction) + { + if (!t.active) { + if (Debugger.logPriority > 0) Debugger.LogInvalidTween(t); + return null; + } + return new DOTweenCYInstruction.WaitForPosition(t, position); + } + + /// + /// Returns a that waits until the tween is killed or started + /// (meaning when the tween is set in a playing state the first time, after any eventual delay). + /// It can be used inside a coroutine as a yield. + /// Example usage:yield return myTween.WaitForStart(); + /// + public static CustomYieldInstruction WaitForStart(this Tween t, bool returnCustomYieldInstruction) + { + if (!t.active) { + if (Debugger.logPriority > 0) Debugger.LogInvalidTween(t); + return null; + } + return new DOTweenCYInstruction.WaitForStart(t); + } + + #endregion +#endif + } + + // █████████████████████████████████████████████████████████████████████████████████████████████████████████████████████ + // ███ CLASSES █████████████████████████████████████████████████████████████████████████████████████████████████████████ + // █████████████████████████████████████████████████████████████████████████████████████████████████████████████████████ + +#if UNITY_5_3_OR_NEWER || UNITY_2017_0_OR_NEWER + public static class DOTweenCYInstruction + { + public class WaitForCompletion : CustomYieldInstruction + { + public override bool keepWaiting { get { + return t.active && !t.IsComplete(); + }} + readonly Tween t; + public WaitForCompletion(Tween tween) + { + t = tween; + } + } + + public class WaitForRewind : CustomYieldInstruction + { + public override bool keepWaiting { get { + return t.active && (!t.playedOnce || t.position * (t.CompletedLoops() + 1) > 0); + }} + readonly Tween t; + public WaitForRewind(Tween tween) + { + t = tween; + } + } + + public class WaitForKill : CustomYieldInstruction + { + public override bool keepWaiting { get { + return t.active; + }} + readonly Tween t; + public WaitForKill(Tween tween) + { + t = tween; + } + } + + public class WaitForElapsedLoops : CustomYieldInstruction + { + public override bool keepWaiting { get { + return t.active && t.CompletedLoops() < elapsedLoops; + }} + readonly Tween t; + readonly int elapsedLoops; + public WaitForElapsedLoops(Tween tween, int elapsedLoops) + { + t = tween; + this.elapsedLoops = elapsedLoops; + } + } + + public class WaitForPosition : CustomYieldInstruction + { + public override bool keepWaiting { get { + return t.active && t.position * (t.CompletedLoops() + 1) < position; + }} + readonly Tween t; + readonly float position; + public WaitForPosition(Tween tween, float position) + { + t = tween; + this.position = position; + } + } + + public class WaitForStart : CustomYieldInstruction + { + public override bool keepWaiting { get { + return t.active && !t.playedOnce; + }} + readonly Tween t; + public WaitForStart(Tween tween) + { + t = tween; + } + } + } +#endif +} diff --git a/_DOTween.Assembly/bin/Modules/DOTweenModuleUtils.cs b/_DOTween.Assembly/bin/Modules/DOTweenModuleUtils.cs new file mode 100644 index 0000000..a768721 --- /dev/null +++ b/_DOTween.Assembly/bin/Modules/DOTweenModuleUtils.cs @@ -0,0 +1,108 @@ +// Author: Daniele Giardini - http://www.demigiant.com +// Created: 2018/07/13 + +using System; +using UnityEngine; +using DG.Tweening.Core; +using DG.Tweening.Plugins.Core.PathCore; +using DG.Tweening.Plugins.Options; + +#pragma warning disable 1591 +namespace DG.Tweening +{ + /// + /// Utility functions that deal with available Modules. + /// Modules defines: + /// - DOTAUDIO + /// - DOTPHYSICS + /// - DOTPHYSICS2D + /// - DOTSPRITE + /// - DOTUI + /// Extra defines set and used for implementation of external assets: + /// - DOTWEEN_TMP ► TextMesh Pro + /// - DOTWEEN_TK2D ► 2D Toolkit + /// + public static class DOTweenModuleUtils + { + static bool _initialized; + + /// + /// Called via Reflection by DOTweenComponent on Awake + /// + public static void Init() + { + if (_initialized) return; + + _initialized = true; + DOTweenExternalCommand.SetOrientationOnPath += Physics.SetOrientationOnPath; + } + + // █████████████████████████████████████████████████████████████████████████████████████████████████████████████████████ + // ███ INTERNAL CLASSES ████████████████████████████████████████████████████████████████████████████████████████████████ + // █████████████████████████████████████████████████████████████████████████████████████████████████████████████████████ + + public static class Physics + { + // Called via DOTweenExternalCommand callback + public static void SetOrientationOnPath(PathOptions options, Tween t, Quaternion newRot, Transform trans) + { +#if DOTPHYSICS + if (options.isRigidbody) ((Rigidbody)t.target).rotation = newRot; + else trans.rotation = newRot; +#else + trans.rotation = newRot; +#endif + } + + // Returns FALSE if the DOTween's Physics2D Module is disabled, or if there's no Rigidbody2D attached + public static bool HasRigidbody2D(Component target) + { +#if DOTPHYSICS2D + return target.GetComponent() != null; +#else + return false; +#endif + } + + #region Called via Reflection + + + // Called via Reflection by DOTweenPathInspector + // Returns FALSE if the DOTween's Physics Module is disabled, or if there's no rigidbody attached + public static bool HasRigidbody(Component target) + { +#if DOTPHYSICS + return target.GetComponent() != null; +#else + return false; +#endif + } + + // Called via Reflection by DOTweenPath + public static TweenerCore CreateDOTweenPathTween( + MonoBehaviour target, bool tweenRigidbody, bool isLocal, Path path, float duration, PathMode pathMode + ){ + TweenerCore t; +#if DOTPHYSICS + Rigidbody rBody = tweenRigidbody ? target.GetComponent() : null; + if (tweenRigidbody && rBody != null) { + t = isLocal + ? rBody.DOLocalPath(path, duration, pathMode) + : rBody.DOPath(path, duration, pathMode); + } else { + t = isLocal + ? target.transform.DOLocalPath(path, duration, pathMode) + : target.transform.DOPath(path, duration, pathMode); + } +#else + t = isLocal + ? target.transform.DOLocalPath(path, duration, pathMode) + : target.transform.DOPath(path, duration, pathMode); +#endif + return t; + } + + #endregion + } + } +}