1
0
mirror of https://github.com/Cardidi/dotween-upm-fork.git synced 2026-02-09 08:38:45 +08:00

Implemented EaseFactory and EaseFactory.StopMotion by Andrei Stanescu (reydanro)

This commit is contained in:
Daniele Giardini 2015-04-04 19:49:21 +02:00
parent 59737f5dc7
commit 5152a06e19
47 changed files with 459 additions and 11 deletions

View File

@ -1759,6 +1759,32 @@
Path plugin works exclusively with Transforms
</summary>
</member>
<member name="T:DG.Tweening.EaseFactory">
<summary>
Allows to wrap ease method in special ways, adding extra features
</summary>
</member>
<member name="M:DG.Tweening.EaseFactory.StopMotion(System.Int32,System.Nullable{DG.Tweening.Ease})">
<summary>
Converts the given ease so that it also creates a stop-motion effect, by playing the tween at the given FPS
</summary>
<param name="motionFps">FPS at which the tween should be played</param>
<param name="ease">Ease type</param>
</member>
<member name="M:DG.Tweening.EaseFactory.StopMotion(System.Int32,UnityEngine.AnimationCurve)">
<summary>
Converts the given ease so that it also creates a stop-motion effect, by playing the tween at the given FPS
</summary>
<param name="motionFps">FPS at which the tween should be played</param>
<param name="animCurve">AnimationCurve to use for the ease</param>
</member>
<member name="M:DG.Tweening.EaseFactory.StopMotion(System.Int32,DG.Tweening.EaseFunction)">
<summary>
Converts the given ease so that it also creates a stop-motion effect, by playing the tween at the given FPS
</summary>
<param name="motionFps">FPS at which the tween should be played</param>
<param name="customEase">Custom ease function to use</param>
</member>
<member name="T:DG.Tweening.LoopType">
<summary>
Types of loop
@ -1862,6 +1888,7 @@
<member name="T:DG.Tweening.Core.Easing.EaseCurve">
<summary>
Used to interpret AnimationCurves as eases.
Public so it can be used by external ease factories
</summary>
</member>
<member name="T:DG.Tweening.Core.Easing.Bounce">

View File

@ -1759,6 +1759,32 @@
Path plugin works exclusively with Transforms
</summary>
</member>
<member name="T:DG.Tweening.EaseFactory">
<summary>
Allows to wrap ease method in special ways, adding extra features
</summary>
</member>
<member name="M:DG.Tweening.EaseFactory.StopMotion(System.Int32,System.Nullable{DG.Tweening.Ease})">
<summary>
Converts the given ease so that it also creates a stop-motion effect, by playing the tween at the given FPS
</summary>
<param name="motionFps">FPS at which the tween should be played</param>
<param name="ease">Ease type</param>
</member>
<member name="M:DG.Tweening.EaseFactory.StopMotion(System.Int32,UnityEngine.AnimationCurve)">
<summary>
Converts the given ease so that it also creates a stop-motion effect, by playing the tween at the given FPS
</summary>
<param name="motionFps">FPS at which the tween should be played</param>
<param name="animCurve">AnimationCurve to use for the ease</param>
</member>
<member name="M:DG.Tweening.EaseFactory.StopMotion(System.Int32,DG.Tweening.EaseFunction)">
<summary>
Converts the given ease so that it also creates a stop-motion effect, by playing the tween at the given FPS
</summary>
<param name="motionFps">FPS at which the tween should be played</param>
<param name="customEase">Custom ease function to use</param>
</member>
<member name="T:DG.Tweening.LoopType">
<summary>
Types of loop
@ -1862,6 +1888,7 @@
<member name="T:DG.Tweening.Core.Easing.EaseCurve">
<summary>
Used to interpret AnimationCurves as eases.
Public so it can be used by external ease factories
</summary>
</member>
<member name="T:DG.Tweening.Core.Easing.Bounce">

View File

@ -1759,6 +1759,32 @@
Path plugin works exclusively with Transforms
</summary>
</member>
<member name="T:DG.Tweening.EaseFactory">
<summary>
Allows to wrap ease method in special ways, adding extra features
</summary>
</member>
<member name="M:DG.Tweening.EaseFactory.StopMotion(System.Int32,System.Nullable{DG.Tweening.Ease})">
<summary>
Converts the given ease so that it also creates a stop-motion effect, by playing the tween at the given FPS
</summary>
<param name="motionFps">FPS at which the tween should be played</param>
<param name="ease">Ease type</param>
</member>
<member name="M:DG.Tweening.EaseFactory.StopMotion(System.Int32,UnityEngine.AnimationCurve)">
<summary>
Converts the given ease so that it also creates a stop-motion effect, by playing the tween at the given FPS
</summary>
<param name="motionFps">FPS at which the tween should be played</param>
<param name="animCurve">AnimationCurve to use for the ease</param>
</member>
<member name="M:DG.Tweening.EaseFactory.StopMotion(System.Int32,DG.Tweening.EaseFunction)">
<summary>
Converts the given ease so that it also creates a stop-motion effect, by playing the tween at the given FPS
</summary>
<param name="motionFps">FPS at which the tween should be played</param>
<param name="customEase">Custom ease function to use</param>
</member>
<member name="T:DG.Tweening.LoopType">
<summary>
Types of loop
@ -1862,6 +1888,7 @@
<member name="T:DG.Tweening.Core.Easing.EaseCurve">
<summary>
Used to interpret AnimationCurves as eases.
Public so it can be used by external ease factories
</summary>
</member>
<member name="T:DG.Tweening.Core.Easing.Bounce">

View File

@ -5,7 +5,13 @@ using System.Collections;
public class PoolingTweens : BrainBase
{
public GameObject prefab;
public Transform container;
public bool spawnInContainer;
void Start()
{
container.DOMoveX(30, 40);
}
void Update()
{
@ -16,20 +22,20 @@ public class PoolingTweens : BrainBase
if (Input.GetKey(KeyCode.LeftShift)) {
// Spawn path
if (Input.GetKey(KeyCode.Space)) {
Transform t = HOPoolManager.Spawn(TestPOP.DOPathCubeasChild, wPos);
t.GetComponentInChildren<DOTweenPath>().DORestart(true);
HOPoolManager.Spawn(TestPOP.DOPathCubeasChild, wPos, spawnInContainer ? container : null);
// t.GetComponentInChildren<DOTweenPath>().DORestart(true);
} else {
Transform t = HOPoolManager.Spawn(TestPOP.DOPathCube, wPos);
t.GetComponent<DOTweenPath>().DORestart(true);
HOPoolManager.Spawn(TestPOP.DOPathCube, wPos, spawnInContainer ? container : null);
// t.GetComponent<DOTweenPath>().DORestart(true);
}
} else {
// Spawn dice
if (Input.GetKey(KeyCode.Space)) {
Transform t = HOPoolManager.Spawn(TestPOP.DOAnimationDiceasChild, wPos);
t.GetComponentInChildren<DOTweenAnimation>().DORestart(true);
HOPoolManager.Spawn(TestPOP.DOAnimationDiceasChild, wPos, spawnInContainer ? container : null);
// t.GetComponentInChildren<DOTweenAnimation>().DORestart(true);
} else {
Transform t = HOPoolManager.Spawn(TestPOP.DOAnimationDice, wPos);
t.GetComponent<DOTweenAnimation>().DORestart(true);
HOPoolManager.Spawn(TestPOP.DOAnimationDice, wPos, spawnInContainer ? container : null);
// t.GetComponent<DOTweenAnimation>().DORestart(true);
}
}
}

View File

@ -0,0 +1,41 @@
using UnityEngine;
using System.Collections;
using DG.Tweening;
using DG.Tweening.Core.Easing;
// Test class for EaseFactory feature created by Andrei Stanescu - https://github.com/reydanro
public class EaseFactoryTests : BrainBase
{
public enum EaseType
{
Default,
Ease,
AnimationCurve
}
public int stopMotionFPS = 5;
public EaseType easeType;
public Ease ease = Ease.Linear;
public AnimationCurve easeCurve;
public Transform target;
void Start()
{
Tween t = target.DOMove(new Vector3(0,4,0), 2);
// Tween t = target.DORotate(new Vector3(0,180,0), 2);
if (easeType == EaseType.AnimationCurve) t.SetEase(EaseFactory.StopMotion(stopMotionFPS, easeCurve));
else if (easeType == EaseType.Ease) t.SetEase(EaseFactory.StopMotion(stopMotionFPS, ease));
else t.SetEase(EaseFactory.StopMotion(stopMotionFPS));
t.SetAutoKill(false).SetLoops(3, LoopType.Yoyo).Pause();
}
void OnGUI()
{
if (GUILayout.Button("TogglePause")) DOTween.TogglePauseAll();
if (GUILayout.Button("Restart")) DOTween.RestartAll();
if (GUILayout.Button("Complete")) DOTween.CompleteAll();
if (GUILayout.Button("Rewind")) DOTween.RewindAll();
if (GUILayout.Button("Flip")) DOTween.FlipAll();
if (GUILayout.Button("Kill And Complete")) DOTween.KillAll(true);
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 8c9c25baad86b36448a7d4fc92de55d9
timeCreated: 1428149285
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ed4ff95cc82ecb248b3c26a48b6dac52
timeCreated: 1428149274
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,21 @@
using UnityEngine;
using DG.Tweening;
public class PooledAnimation : MonoBehaviour
{
public void OnSpawn()
{
DOTweenAnimation doanim = this.GetComponent<DOTweenAnimation>();
if (doanim) doanim.DORestart(true);
DOTweenPath dopath = this.GetComponent<DOTweenPath>();
if (dopath) dopath.DORestart(true);
}
public void OnDespawn()
{
DOTweenAnimation doanim = this.GetComponent<DOTweenAnimation>();
if (doanim) doanim.DORewind();
DOTweenPath dopath = this.GetComponent<DOTweenPath>();
if (dopath) dopath.DORewind();
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 816ee70192fc92f488253bb355e65ef1
timeCreated: 1428163637
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,21 @@
using UnityEngine;
using DG.Tweening;
public class PooledChildAnimation : MonoBehaviour
{
public void OnSpawn()
{
DOTweenAnimation doanim = this.GetComponentInChildren<DOTweenAnimation>();
if (doanim) doanim.DORestart(true);
DOTweenPath dopath = this.GetComponentInChildren<DOTweenPath>();
if (dopath) dopath.DORestart(true);
}
public void OnDespawn()
{
DOTweenAnimation doanim = this.GetComponentInChildren<DOTweenAnimation>();
if (doanim) doanim.DORewind();
DOTweenPath dopath = this.GetComponentInChildren<DOTweenPath>();
if (dopath) dopath.DORewind();
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: dde3517e948b0a143832c31dcfe25706
timeCreated: 1428163655
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -10,8 +10,9 @@ namespace DG.Tweening.Core.Easing
{
/// <summary>
/// Used to interpret AnimationCurves as eases.
/// Public so it can be used by external ease factories
/// </summary>
internal class EaseCurve
public class EaseCurve
{
readonly AnimationCurve _animCurve;

View File

@ -167,5 +167,153 @@ namespace DG.Tweening.Core.Easing
return -(time /= duration) * (time - 2);
}
}
public static EaseFunction ToEaseFunction(Ease ease)
{
switch (ease) {
case Ease.Linear:
return (float time, float duration, float overshootOrAmplitude, float period) =>
time / duration;
case Ease.InSine:
return (float time, float duration, float overshootOrAmplitude, float period) =>
-(float)Math.Cos(time / duration * _PiOver2) + 1;
case Ease.OutSine:
return (float time, float duration, float overshootOrAmplitude, float period) =>
(float)Math.Sin(time / duration * _PiOver2);
case Ease.InOutSine:
return (float time, float duration, float overshootOrAmplitude, float period) =>
-0.5f * ((float)Math.Cos(Mathf.PI * time / duration) - 1);
case Ease.InQuad:
return (float time, float duration, float overshootOrAmplitude, float period) =>
(time /= duration) * time;
case Ease.OutQuad:
return (float time, float duration, float overshootOrAmplitude, float period) =>
-(time /= duration) * (time - 2);
case Ease.InOutQuad:
return (float time, float duration, float overshootOrAmplitude, float period) => {
if ((time /= duration * 0.5f) < 1) return 0.5f * time * time;
return -0.5f * ((--time) * (time - 2) - 1);
};
case Ease.InCubic:
return (float time, float duration, float overshootOrAmplitude, float period) =>
(time /= duration) * time * time;
case Ease.OutCubic:
return (float time, float duration, float overshootOrAmplitude, float period) =>
((time = time / duration - 1) * time * time + 1);
case Ease.InOutCubic:
return (float time, float duration, float overshootOrAmplitude, float period) => {
if ((time /= duration * 0.5f) < 1) return 0.5f * time * time * time;
return 0.5f * ((time -= 2) * time * time + 2);
};
case Ease.InQuart:
return (float time, float duration, float overshootOrAmplitude, float period) =>
(time /= duration) * time * time * time;
case Ease.OutQuart:
return (float time, float duration, float overshootOrAmplitude, float period) =>
-((time = time / duration - 1) * time * time * time - 1);
case Ease.InOutQuart:
return (float time, float duration, float overshootOrAmplitude, float period) => {
if ((time /= duration * 0.5f) < 1) return 0.5f * time * time * time * time;
return -0.5f * ((time -= 2) * time * time * time - 2);
};
case Ease.InQuint:
return (float time, float duration, float overshootOrAmplitude, float period) =>
(time /= duration) * time * time * time * time;
case Ease.OutQuint:
return (float time, float duration, float overshootOrAmplitude, float period) =>
((time = time / duration - 1) * time * time * time * time + 1);
case Ease.InOutQuint:
return (float time, float duration, float overshootOrAmplitude, float period) => {
if ((time /= duration * 0.5f) < 1) return 0.5f * time * time * time * time * time;
return 0.5f * ((time -= 2) * time * time * time * time + 2);
};
case Ease.InExpo:
return (float time, float duration, float overshootOrAmplitude, float period) =>
(time == 0) ? 0 : (float)Math.Pow(2, 10 * (time / duration - 1));
case Ease.OutExpo:
return (float time, float duration, float overshootOrAmplitude, float period) => {
if (time == duration) return 1;
return (-(float)Math.Pow(2, -10 * time / duration) + 1);
};
case Ease.InOutExpo:
return (float time, float duration, float overshootOrAmplitude, float period) => {
if (time == 0) return 0;
if (time == duration) return 1;
if ((time /= duration * 0.5f) < 1) return 0.5f * (float)Math.Pow(2, 10 * (time - 1));
return 0.5f * (-(float)Math.Pow(2, -10 * --time) + 2);
};
case Ease.InCirc:
return (float time, float duration, float overshootOrAmplitude, float period) =>
-((float)Math.Sqrt(1 - (time /= duration) * time) - 1);
case Ease.OutCirc:
return (float time, float duration, float overshootOrAmplitude, float period) =>
(float)Math.Sqrt(1 - (time = time / duration - 1) * time);
case Ease.InOutCirc:
return (float time, float duration, float overshootOrAmplitude, float period) => {
if ((time /= duration * 0.5f) < 1) return -0.5f * ((float)Math.Sqrt(1 - time * time) - 1);
return 0.5f * ((float)Math.Sqrt(1 - (time -= 2) * time) + 1);
};
case Ease.InElastic:
return (float time, float duration, float overshootOrAmplitude, float period) => {
float s0;
if (time == 0) return 0;
if ((time /= duration) == 1) return 1;
if (period == 0) period = duration * 0.3f;
if (overshootOrAmplitude < 1) {
overshootOrAmplitude = 1;
s0 = period / 4;
} else s0 = period / _TwoPi * (float)Math.Asin(1 / overshootOrAmplitude);
return -(overshootOrAmplitude * (float)Math.Pow(2, 10 * (time -= 1)) * (float)Math.Sin((time * duration - s0) * _TwoPi / period));
};
case Ease.OutElastic:
return (float time, float duration, float overshootOrAmplitude, float period) => {
float s1;
if (time == 0) return 0;
if ((time /= duration) == 1) return 1;
if (period == 0) period = duration * 0.3f;
if (overshootOrAmplitude < 1) {
overshootOrAmplitude = 1;
s1 = period / 4;
} else s1 = period / _TwoPi * (float)Math.Asin(1 / overshootOrAmplitude);
return (overshootOrAmplitude * (float)Math.Pow(2, -10 * time) * (float)Math.Sin((time * duration - s1) * _TwoPi / period) + 1);
};
case Ease.InOutElastic:
return (float time, float duration, float overshootOrAmplitude, float period) => {
float s;
if (time == 0) return 0;
if ((time /= duration * 0.5f) == 2) return 1;
if (period == 0) period = duration * (0.3f * 1.5f);
if (overshootOrAmplitude < 1) {
overshootOrAmplitude = 1;
s = period / 4;
} else s = period / _TwoPi * (float)Math.Asin(1 / overshootOrAmplitude);
if (time < 1) return -0.5f * (overshootOrAmplitude * (float)Math.Pow(2, 10 * (time -= 1)) * (float)Math.Sin((time * duration - s) * _TwoPi / period));
return overshootOrAmplitude * (float)Math.Pow(2, -10 * (time -= 1)) * (float)Math.Sin((time * duration - s) * _TwoPi / period) * 0.5f + 1;
};
case Ease.InBack:
return (float time, float duration, float overshootOrAmplitude, float period) =>
(time /= duration) * time * ((overshootOrAmplitude + 1) * time - overshootOrAmplitude);
case Ease.OutBack:
return (float time, float duration, float overshootOrAmplitude, float period) =>
((time = time / duration - 1) * time * ((overshootOrAmplitude + 1) * time + overshootOrAmplitude) + 1);
case Ease.InOutBack:
return (float time, float duration, float overshootOrAmplitude, float period) => {
if ((time /= duration * 0.5f) < 1) return 0.5f * (time * time * (((overshootOrAmplitude *= (1.525f)) + 1) * time - overshootOrAmplitude));
return 0.5f * ((time -= 2) * time * (((overshootOrAmplitude *= (1.525f)) + 1) * time + overshootOrAmplitude) + 2);
};
case Ease.InBounce:
return (float time, float duration, float overshootOrAmplitude, float period) =>
Bounce.EaseIn(time, duration, overshootOrAmplitude, period);
case Ease.OutBounce:
return (float time, float duration, float overshootOrAmplitude, float period) =>
Bounce.EaseOut(time, duration, overshootOrAmplitude, period);
case Ease.InOutBounce:
return (float time, float duration, float overshootOrAmplitude, float period) =>
Bounce.EaseInOut(time, duration, overshootOrAmplitude, period);
default:
// OutQuad
return (float time, float duration, float overshootOrAmplitude, float period) => -(time /= duration) * (time - 2);
}
}
}
}

View File

@ -21,7 +21,7 @@ namespace DG.Tweening
public class DOTween
{
/// <summary>DOTween's version</summary>
public static readonly string Version = "1.0.426";
public static readonly string Version = "1.0.430";
///////////////////////////////////////////////
// Options ////////////////////////////////////

View File

@ -76,6 +76,7 @@
<Compile Include="DOTween.cs" />
<Compile Include="DOVirtual.cs" />
<Compile Include="Ease.cs" />
<Compile Include="EaseFactory.cs" />
<Compile Include="IDOTweenInit.cs" />
<Compile Include="PathMode.cs" />
<Compile Include="PathType.cs" />

View File

@ -0,0 +1,57 @@
// Author: Andrei Stanescu - https://github.com/reydanro
// Unity Forum Post: http://forum.unity3d.com/threads/dotween-hotween-v2-a-unity-tween-engine.260692/page-24#post-2052957
// Created: 2015/04/04 14:39
// Modified by: Daniele Giardini - http://www.demigiant.com
using DG.Tweening.Core.Easing;
using UnityEngine;
namespace DG.Tweening
{
/// <summary>
/// Allows to wrap ease method in special ways, adding extra features
/// </summary>
public class EaseFactory
{
#region StopMotion
/// <summary>
/// Converts the given ease so that it also creates a stop-motion effect, by playing the tween at the given FPS
/// </summary>
/// <param name="motionFps">FPS at which the tween should be played</param>
/// <param name="ease">Ease type</param>
public static EaseFunction StopMotion(int motionFps, Ease? ease = null)
{
EaseFunction easeFunc = EaseManager.ToEaseFunction(ease == null ? DOTween.defaultEaseType : (Ease)ease);
return StopMotion(motionFps, easeFunc);
}
/// <summary>
/// Converts the given ease so that it also creates a stop-motion effect, by playing the tween at the given FPS
/// </summary>
/// <param name="motionFps">FPS at which the tween should be played</param>
/// <param name="animCurve">AnimationCurve to use for the ease</param>
public static EaseFunction StopMotion(int motionFps, AnimationCurve animCurve)
{
return StopMotion(motionFps, new EaseCurve(animCurve).Evaluate);
}
/// <summary>
/// Converts the given ease so that it also creates a stop-motion effect, by playing the tween at the given FPS
/// </summary>
/// <param name="motionFps">FPS at which the tween should be played</param>
/// <param name="customEase">Custom ease function to use</param>
public static EaseFunction StopMotion(int motionFps, EaseFunction customEase)
{
// Compute the time interval in which we must re-evaluate the value
float motionDelay = 1.0f / motionFps;
return delegate(float time, float duration, float overshootOrAmplitude, float period) {
// Adjust the time so it's in steps
float steptime = time < duration ? time - (time % motionDelay) : time;
// Evaluate the ease value based on the new step time
return customEase(steptime, duration, overshootOrAmplitude, period);
};
}
#endregion
}
}

View File

@ -1759,6 +1759,32 @@
Path plugin works exclusively with Transforms
</summary>
</member>
<member name="T:DG.Tweening.EaseFactory">
<summary>
Allows to wrap ease method in special ways, adding extra features
</summary>
</member>
<member name="M:DG.Tweening.EaseFactory.StopMotion(System.Int32,System.Nullable{DG.Tweening.Ease})">
<summary>
Converts the given ease so that it also creates a stop-motion effect, by playing the tween at the given FPS
</summary>
<param name="motionFps">FPS at which the tween should be played</param>
<param name="ease">Ease type</param>
</member>
<member name="M:DG.Tweening.EaseFactory.StopMotion(System.Int32,UnityEngine.AnimationCurve)">
<summary>
Converts the given ease so that it also creates a stop-motion effect, by playing the tween at the given FPS
</summary>
<param name="motionFps">FPS at which the tween should be played</param>
<param name="animCurve">AnimationCurve to use for the ease</param>
</member>
<member name="M:DG.Tweening.EaseFactory.StopMotion(System.Int32,DG.Tweening.EaseFunction)">
<summary>
Converts the given ease so that it also creates a stop-motion effect, by playing the tween at the given FPS
</summary>
<param name="motionFps">FPS at which the tween should be played</param>
<param name="customEase">Custom ease function to use</param>
</member>
<member name="T:DG.Tweening.LoopType">
<summary>
Types of loop
@ -1862,6 +1888,7 @@
<member name="T:DG.Tweening.Core.Easing.EaseCurve">
<summary>
Used to interpret AnimationCurves as eases.
Public so it can be used by external ease factories
</summary>
</member>
<member name="T:DG.Tweening.Core.Easing.Bounce">

Binary file not shown.

Binary file not shown.

Binary file not shown.