mirror of
https://github.com/Cardidi/dotween-upm-fork.git
synced 2026-02-14 02:58:46 +08:00
Implemented QuaternionSurrogatePlugin that uses Vector3Surrogate and works on WP8.1
This commit is contained in:
parent
b4648112eb
commit
6ecc10cb6f
@ -565,7 +565,7 @@
|
||||
<param name="axisConstraint">Selecting an axis will tween the vector only on that axis, leaving the others untouched</param>
|
||||
<param name="snapping">If TRUE the tween will smoothly snap all values to integers</param>
|
||||
</member>
|
||||
<member name="M:DG.Tweening.TweenSettingsExtensions.SetOptions(DG.Tweening.Core.TweenerCore{UnityEngine.Quaternion,UnityEngine.Vector3,DG.Tweening.Plugins.Options.QuaternionOptions},System.Boolean)">
|
||||
<member name="M:DG.Tweening.TweenSettingsExtensions.SetOptions(DG.Tweening.Core.TweenerCore{UnityEngine.Quaternion,DG.Tweening.Core.Surrogates.Vector3Surrogate,DG.Tweening.Plugins.Options.QuaternionOptions},System.Boolean)">
|
||||
<summary>Options for Quaternion tweens</summary>
|
||||
<param name="useShortest360Route">If TRUE (default) the rotation will take the shortest route, and will not rotate more than 360°.
|
||||
If FALSE the rotation will be fully accounted. Is always FALSE if the tween is set as relative</param>
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -565,7 +565,7 @@
|
||||
<param name="axisConstraint">Selecting an axis will tween the vector only on that axis, leaving the others untouched</param>
|
||||
<param name="snapping">If TRUE the tween will smoothly snap all values to integers</param>
|
||||
</member>
|
||||
<member name="M:DG.Tweening.TweenSettingsExtensions.SetOptions(DG.Tweening.Core.TweenerCore{UnityEngine.Quaternion,UnityEngine.Vector3,DG.Tweening.Plugins.Options.QuaternionOptions},System.Boolean)">
|
||||
<member name="M:DG.Tweening.TweenSettingsExtensions.SetOptions(DG.Tweening.Core.TweenerCore{UnityEngine.Quaternion,DG.Tweening.Core.Surrogates.Vector3Surrogate,DG.Tweening.Plugins.Options.QuaternionOptions},System.Boolean)">
|
||||
<summary>Options for Quaternion tweens</summary>
|
||||
<param name="useShortest360Route">If TRUE (default) the rotation will take the shortest route, and will not rotate more than 360°.
|
||||
If FALSE the rotation will be fully accounted. Is always FALSE if the tween is set as relative</param>
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -565,7 +565,7 @@
|
||||
<param name="axisConstraint">Selecting an axis will tween the vector only on that axis, leaving the others untouched</param>
|
||||
<param name="snapping">If TRUE the tween will smoothly snap all values to integers</param>
|
||||
</member>
|
||||
<member name="M:DG.Tweening.TweenSettingsExtensions.SetOptions(DG.Tweening.Core.TweenerCore{UnityEngine.Quaternion,UnityEngine.Vector3,DG.Tweening.Plugins.Options.QuaternionOptions},System.Boolean)">
|
||||
<member name="M:DG.Tweening.TweenSettingsExtensions.SetOptions(DG.Tweening.Core.TweenerCore{UnityEngine.Quaternion,DG.Tweening.Core.Surrogates.Vector3Surrogate,DG.Tweening.Plugins.Options.QuaternionOptions},System.Boolean)">
|
||||
<summary>Options for Quaternion tweens</summary>
|
||||
<param name="useShortest360Route">If TRUE (default) the rotation will take the shortest route, and will not rotate more than 360°.
|
||||
If FALSE the rotation will be fully accounted. Is always FALSE if the tween is set as relative</param>
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -42,6 +42,10 @@ namespace DG.Tweening.Core.Surrogates
|
||||
{
|
||||
return new Vector3Surrogate(v1.x - v2.x, v1.y - v2.y, v1.z - v2.z);
|
||||
}
|
||||
public static Vector3Surrogate operator -(Vector3Surrogate v1)
|
||||
{
|
||||
return new Vector3Surrogate(-v1.x, -v1.y, -v1.z);
|
||||
}
|
||||
|
||||
public static Vector3Surrogate operator *(Vector3Surrogate v1, float f)
|
||||
{
|
||||
|
||||
@ -346,8 +346,13 @@ namespace DG.Tweening
|
||||
/// <param name="setter">A setter for the field or property to tween
|
||||
/// <para>Example usage with lambda:</para><code>x=> myProperty = x</code></param>
|
||||
/// <param name="endValue">The end value to reach</param><param name="duration">The tween's duration</param>
|
||||
#if WP81
|
||||
public static TweenerCore<Quaternion, Vector3Surrogate, QuaternionOptions> To(DOGetter<Quaternion> getter, DOSetter<Quaternion> setter, Vector3 endValue, float duration)
|
||||
{ return ApplyTo<Quaternion, Vector3Surrogate, QuaternionOptions>(getter, setter, endValue, duration); }
|
||||
#else
|
||||
public static TweenerCore<Quaternion, Vector3, QuaternionOptions> To(DOGetter<Quaternion> getter, DOSetter<Quaternion> setter, Vector3 endValue, float duration)
|
||||
{ return ApplyTo<Quaternion, Vector3, QuaternionOptions>(getter, setter, endValue, duration); }
|
||||
#endif
|
||||
/// <summary>Tweens a property or field to the given value using default plugins</summary>
|
||||
/// <param name="getter">A getter for the field or property to tween.
|
||||
/// <para>Example usage with lambda:</para><code>()=> myProperty</code></param>
|
||||
|
||||
@ -91,6 +91,7 @@
|
||||
<Compile Include="Plugins\Options\PathOptions.cs" />
|
||||
<Compile Include="Plugins\Options\QuaternionOptions.cs" />
|
||||
<Compile Include="Plugins\Options\Vector3ArrayOptions.cs" />
|
||||
<Compile Include="Plugins\QuaternionSurrogatePlugin.cs" />
|
||||
<Compile Include="Plugins\UlongPlugin.cs" />
|
||||
<Compile Include="Plugins\Vector2SurrogatePlugin.cs" />
|
||||
<Compile Include="Plugins\Vector3ArrayPlugin.cs" />
|
||||
|
||||
@ -67,7 +67,11 @@ namespace DG.Tweening.Plugins.Core
|
||||
else if (t1 == typeof(Quaternion)) {
|
||||
if (t2 == typeof(Quaternion)) Debugger.LogError("Quaternion tweens require a Vector3 endValue");
|
||||
else {
|
||||
#if WP81
|
||||
if (_quaternionPlugin == null) _quaternionPlugin = new QuaternionSurrogatePlugin();
|
||||
#else
|
||||
if (_quaternionPlugin == null) _quaternionPlugin = new QuaternionPlugin();
|
||||
#endif
|
||||
plugin = _quaternionPlugin;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
// Author: Daniele Giardini - http://www.demigiant.com
|
||||
#if !WP81
|
||||
// Author: Daniele Giardini - http://www.demigiant.com
|
||||
// Created: 2014/07/07 20:02
|
||||
//
|
||||
// License Copyright (c) Daniele Giardini.
|
||||
@ -108,4 +109,5 @@ namespace DG.Tweening.Plugins
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
111
_DOTween.Assembly/DOTween/Plugins/QuaternionSurrogatePlugin.cs
Normal file
111
_DOTween.Assembly/DOTween/Plugins/QuaternionSurrogatePlugin.cs
Normal file
@ -0,0 +1,111 @@
|
||||
#if WP81
|
||||
// Author: Daniele Giardini - http://www.demigiant.com
|
||||
// Created: 2015/04/15 12:32
|
||||
|
||||
using DG.Tweening.Core;
|
||||
using DG.Tweening.Core.Easing;
|
||||
using DG.Tweening.Core.Surrogates;
|
||||
using DG.Tweening.Plugins.Core;
|
||||
using DG.Tweening.Plugins.Options;
|
||||
using UnityEngine;
|
||||
|
||||
#pragma warning disable 1591
|
||||
namespace DG.Tweening.Plugins
|
||||
{
|
||||
public class QuaternionSurrogatePlugin : ABSTweenPlugin<Quaternion, Vector3Surrogate, QuaternionOptions>
|
||||
{
|
||||
public override void Reset(TweenerCore<Quaternion, Vector3Surrogate, QuaternionOptions> t) { }
|
||||
|
||||
public override void SetFrom(TweenerCore<Quaternion, Vector3Surrogate, QuaternionOptions> t, bool isRelative)
|
||||
{
|
||||
Vector3Surrogate prevEndVal = t.endValue;
|
||||
t.endValue = t.getter().eulerAngles;
|
||||
if (t.plugOptions.rotateMode == RotateMode.Fast && !t.isRelative) {
|
||||
t.startValue = prevEndVal;
|
||||
} else if (t.plugOptions.rotateMode == RotateMode.FastBeyond360) {
|
||||
t.startValue = t.endValue + prevEndVal;
|
||||
} else {
|
||||
Quaternion rot = t.getter();
|
||||
if (t.plugOptions.rotateMode == RotateMode.WorldAxisAdd) {
|
||||
t.startValue = (rot * Quaternion.Inverse(rot) * Quaternion.Euler(prevEndVal) * rot).eulerAngles;
|
||||
} else {
|
||||
t.startValue = (rot * Quaternion.Euler(prevEndVal)).eulerAngles;
|
||||
}
|
||||
t.endValue = -prevEndVal;
|
||||
}
|
||||
t.setter(Quaternion.Euler(t.startValue));
|
||||
}
|
||||
|
||||
public override Vector3Surrogate ConvertToStartValue(TweenerCore<Quaternion, Vector3Surrogate, QuaternionOptions> t, Quaternion value)
|
||||
{
|
||||
return value.eulerAngles;
|
||||
}
|
||||
|
||||
public override void SetRelativeEndValue(TweenerCore<Quaternion, Vector3Surrogate, QuaternionOptions> t)
|
||||
{
|
||||
t.endValue += t.startValue;
|
||||
}
|
||||
|
||||
public override void SetChangeValue(TweenerCore<Quaternion, Vector3Surrogate, QuaternionOptions> t)
|
||||
{
|
||||
if (t.plugOptions.rotateMode == RotateMode.Fast && !t.isRelative) {
|
||||
// Rotation will be adapted to 360° and will take the shortest route
|
||||
// - Adapt to 360°
|
||||
Vector3Surrogate ev = t.endValue;
|
||||
if (ev.x > 360) ev.x = ev.x % 360;
|
||||
if (ev.y > 360) ev.y = ev.y % 360;
|
||||
if (ev.z > 360) ev.z = ev.z % 360;
|
||||
Vector3Surrogate changeVal = ev - t.startValue;
|
||||
// - Find shortest rotation
|
||||
float abs = (changeVal.x > 0 ? changeVal.x : -changeVal.x);
|
||||
if (abs > 180) changeVal.x = changeVal.x > 0 ? -(360 - abs) : 360 - abs;
|
||||
abs = (changeVal.y > 0 ? changeVal.y : -changeVal.y);
|
||||
if (abs > 180) changeVal.y = changeVal.y > 0 ? -(360 - abs) : 360 - abs;
|
||||
abs = (changeVal.z > 0 ? changeVal.z : -changeVal.z);
|
||||
if (abs > 180) changeVal.z = changeVal.z > 0 ? -(360 - abs) : 360 - abs;
|
||||
// - Assign
|
||||
t.changeValue = changeVal;
|
||||
} else if (t.plugOptions.rotateMode == RotateMode.FastBeyond360 || t.isRelative) {
|
||||
t.changeValue = t.endValue - t.startValue;
|
||||
} else {
|
||||
t.changeValue = t.endValue;
|
||||
}
|
||||
}
|
||||
|
||||
public override float GetSpeedBasedDuration(QuaternionOptions options, float unitsXSecond, Vector3Surrogate changeValue)
|
||||
{
|
||||
return changeValue.magnitude / unitsXSecond;
|
||||
}
|
||||
|
||||
public override void EvaluateAndApply(QuaternionOptions options, Tween t, bool isRelative, DOGetter<Quaternion> getter, DOSetter<Quaternion> setter, float elapsed, Vector3Surrogate startValue, Vector3Surrogate changeValue, float duration, bool usingInversePosition)
|
||||
{
|
||||
Vector3Surrogate endValue = startValue;
|
||||
|
||||
if (t.loopType == LoopType.Incremental) endValue += changeValue * (t.isComplete ? t.completedLoops - 1 : t.completedLoops);
|
||||
if (t.isSequenced && t.sequenceParent.loopType == LoopType.Incremental) {
|
||||
endValue += changeValue * (t.loopType == LoopType.Incremental ? t.loops : 1)
|
||||
* (t.sequenceParent.isComplete ? t.sequenceParent.completedLoops - 1 : t.sequenceParent.completedLoops);
|
||||
}
|
||||
|
||||
float easeVal = EaseManager.Evaluate(t.easeType, t.customEase, elapsed, duration, t.easeOvershootOrAmplitude, t.easePeriod);
|
||||
switch (options.rotateMode) {
|
||||
case RotateMode.WorldAxisAdd:
|
||||
case RotateMode.LocalAxisAdd:
|
||||
Quaternion startRot = Quaternion.Euler(startValue); // Reset rotation
|
||||
endValue.x = changeValue.x * easeVal;
|
||||
endValue.y = changeValue.y * easeVal;
|
||||
endValue.z = changeValue.z * easeVal;
|
||||
if (options.rotateMode == RotateMode.WorldAxisAdd) setter(startRot * Quaternion.Inverse(startRot) * Quaternion.Euler(endValue) * startRot);
|
||||
else setter(startRot * Quaternion.Euler(endValue));
|
||||
break;
|
||||
default:
|
||||
endValue.x += changeValue.x * easeVal;
|
||||
endValue.y += changeValue.y * easeVal;
|
||||
endValue.z += changeValue.z * easeVal;
|
||||
setter(Quaternion.Euler(endValue));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -294,7 +294,11 @@ namespace DG.Tweening
|
||||
/// <param name="mode">Rotation mode</param>
|
||||
public static Tweener DORotate(this Rigidbody target, Vector3 endValue, float duration, RotateMode mode = RotateMode.Fast)
|
||||
{
|
||||
#if WP81
|
||||
TweenerCore<Quaternion, Vector3Surrogate, QuaternionOptions> t = DOTween.To(() => target.rotation, target.MoveRotation, endValue, duration);
|
||||
#else
|
||||
TweenerCore<Quaternion, Vector3, QuaternionOptions> t = DOTween.To(() => target.rotation, target.MoveRotation, endValue, duration);
|
||||
#endif
|
||||
t.SetTarget(target);
|
||||
t.plugOptions.rotateMode = mode;
|
||||
return t;
|
||||
@ -307,7 +311,11 @@ namespace DG.Tweening
|
||||
/// <param name="up">The vector that defines in which direction up is (default: Vector3.up)</param>
|
||||
public static Tweener DOLookAt(this Rigidbody target, Vector3 towards, float duration, AxisConstraint axisConstraint = AxisConstraint.None, Vector3? up = null)
|
||||
{
|
||||
#if WP81
|
||||
TweenerCore<Quaternion, Vector3Surrogate, QuaternionOptions> t = DOTween.To(() => target.rotation, target.MoveRotation, towards, duration)
|
||||
#else
|
||||
TweenerCore<Quaternion, Vector3, QuaternionOptions> t = DOTween.To(() => target.rotation, target.MoveRotation, towards, duration)
|
||||
#endif
|
||||
.SetTarget(target).SetSpecialStartupMode(SpecialStartupMode.SetLookAt);
|
||||
t.plugOptions.axisConstraint = axisConstraint;
|
||||
t.plugOptions.up = (up == null) ? Vector3.up : (Vector3)up;
|
||||
@ -430,7 +438,11 @@ namespace DG.Tweening
|
||||
/// <param name="mode">Rotation mode</param>
|
||||
public static Tweener DORotate(this Transform target, Vector3 endValue, float duration, RotateMode mode = RotateMode.Fast)
|
||||
{
|
||||
#if WP81
|
||||
TweenerCore<Quaternion, Vector3Surrogate, QuaternionOptions> t = DOTween.To(() => target.rotation, x => target.rotation = x, endValue, duration);
|
||||
#else
|
||||
TweenerCore<Quaternion, Vector3, QuaternionOptions> t = DOTween.To(() => target.rotation, x => target.rotation = x, endValue, duration);
|
||||
#endif
|
||||
t.SetTarget(target);
|
||||
t.plugOptions.rotateMode = mode;
|
||||
return t;
|
||||
@ -442,7 +454,11 @@ namespace DG.Tweening
|
||||
/// <param name="mode">Rotation mode</param>
|
||||
public static Tweener DOLocalRotate(this Transform target, Vector3 endValue, float duration, RotateMode mode = RotateMode.Fast)
|
||||
{
|
||||
#if WP81
|
||||
TweenerCore<Quaternion, Vector3Surrogate, QuaternionOptions> t = DOTween.To(() => target.localRotation, x => target.localRotation = x, endValue, duration);
|
||||
#else
|
||||
TweenerCore<Quaternion, Vector3, QuaternionOptions> t = DOTween.To(() => target.localRotation, x => target.localRotation = x, endValue, duration);
|
||||
#endif
|
||||
t.SetTarget(target);
|
||||
t.plugOptions.rotateMode = mode;
|
||||
return t;
|
||||
@ -502,7 +518,11 @@ namespace DG.Tweening
|
||||
/// <param name="up">The vector that defines in which direction up is (default: Vector3.up)</param>
|
||||
public static Tweener DOLookAt(this Transform target, Vector3 towards, float duration, AxisConstraint axisConstraint = AxisConstraint.None, Vector3? up = null)
|
||||
{
|
||||
#if WP81
|
||||
TweenerCore<Quaternion, Vector3Surrogate, QuaternionOptions> t = DOTween.To(() => target.rotation, x => target.rotation = x, towards, duration)
|
||||
#else
|
||||
TweenerCore<Quaternion, Vector3, QuaternionOptions> t = DOTween.To(() => target.rotation, x => target.rotation = x, towards, duration)
|
||||
#endif
|
||||
.SetTarget(target).SetSpecialStartupMode(SpecialStartupMode.SetLookAt);
|
||||
t.plugOptions.axisConstraint = axisConstraint;
|
||||
t.plugOptions.up = (up == null) ? Vector3.up : (Vector3)up;
|
||||
@ -746,7 +766,11 @@ namespace DG.Tweening
|
||||
public static Tweener DOBlendableRotateBy(this Transform target, Vector3 byValue, float duration, RotateMode mode = RotateMode.Fast)
|
||||
{
|
||||
Quaternion to = target.rotation;
|
||||
#if WP81
|
||||
TweenerCore<Quaternion, Vector3Surrogate, QuaternionOptions> t = DOTween.To(() => to, x => {
|
||||
#else
|
||||
TweenerCore<Quaternion, Vector3, QuaternionOptions> t = DOTween.To(() => to, x => {
|
||||
#endif
|
||||
Quaternion diff = x * Quaternion.Inverse(to);
|
||||
to = x;
|
||||
target.rotation = target.rotation * Quaternion.Inverse(target.rotation) * diff * target.rotation;
|
||||
@ -765,7 +789,11 @@ namespace DG.Tweening
|
||||
public static Tweener DOBlendableLocalRotateBy(this Transform target, Vector3 byValue, float duration, RotateMode mode = RotateMode.Fast)
|
||||
{
|
||||
Quaternion to = target.localRotation;
|
||||
#if WP81
|
||||
TweenerCore<Quaternion, Vector3Surrogate, QuaternionOptions> t = DOTween.To(() => to, x => {
|
||||
#else
|
||||
TweenerCore<Quaternion, Vector3, QuaternionOptions> t = DOTween.To(() => to, x => {
|
||||
#endif
|
||||
Quaternion diff = x * Quaternion.Inverse(to);
|
||||
to = x;
|
||||
target.localRotation = target.localRotation * Quaternion.Inverse(target.localRotation) * diff * target.localRotation;
|
||||
|
||||
@ -672,7 +672,11 @@ namespace DG.Tweening
|
||||
/// <summary>Options for Quaternion tweens</summary>
|
||||
/// <param name="useShortest360Route">If TRUE (default) the rotation will take the shortest route, and will not rotate more than 360°.
|
||||
/// If FALSE the rotation will be fully accounted. Is always FALSE if the tween is set as relative</param>
|
||||
#if WP81
|
||||
public static Tweener SetOptions(this TweenerCore<Quaternion, Vector3Surrogate, QuaternionOptions> t, bool useShortest360Route = true)
|
||||
#else
|
||||
public static Tweener SetOptions(this TweenerCore<Quaternion, Vector3, QuaternionOptions> t, bool useShortest360Route = true)
|
||||
#endif
|
||||
{
|
||||
if (t == null || !t.active) return t;
|
||||
|
||||
|
||||
@ -565,7 +565,7 @@
|
||||
<param name="axisConstraint">Selecting an axis will tween the vector only on that axis, leaving the others untouched</param>
|
||||
<param name="snapping">If TRUE the tween will smoothly snap all values to integers</param>
|
||||
</member>
|
||||
<member name="M:DG.Tweening.TweenSettingsExtensions.SetOptions(DG.Tweening.Core.TweenerCore{UnityEngine.Quaternion,UnityEngine.Vector3,DG.Tweening.Plugins.Options.QuaternionOptions},System.Boolean)">
|
||||
<member name="M:DG.Tweening.TweenSettingsExtensions.SetOptions(DG.Tweening.Core.TweenerCore{UnityEngine.Quaternion,DG.Tweening.Core.Surrogates.Vector3Surrogate,DG.Tweening.Plugins.Options.QuaternionOptions},System.Boolean)">
|
||||
<summary>Options for Quaternion tweens</summary>
|
||||
<param name="useShortest360Route">If TRUE (default) the rotation will take the shortest route, and will not rotate more than 360°.
|
||||
If FALSE the rotation will be fully accounted. Is always FALSE if the tween is set as relative</param>
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user