From eb74216d6a038d1f854816e36e24da5575d286df Mon Sep 17 00:00:00 2001 From: Daniele Giardini Date: Tue, 14 Apr 2015 12:51:04 +0200 Subject: [PATCH] Implementing Vector2/3/4 surrogates that don't break C# rules as Unity does, so they will work on WP8.1 --- .../Core/Surrogates/Vector2Surrogate.cs | 58 ++++++++ .../Core/Surrogates/Vector3Surrogate.cs | 59 ++++++++ .../Core/Surrogates/Vector4Surrogate.cs | 108 ++++++++++++++ _DOTween.Assembly/DOTween/DOTween.csproj | 2 + .../DOTween/Plugins/Core/PluginsManager.cs | 109 +++++++------- .../DOTween/Plugins/Vector2SurrogatePlugin.cs | 109 ++++++++++++++ .../DOTween/Plugins/Vector3SurrogatePlugin.cs | 123 ++++++++++++++++ .../DOTween/Plugins/Vector4SurrogatePlugin.cs | 139 ++++++++++++++++++ _DOTween.Assembly/DOTween/Tweener.cs | 58 ++++---- 9 files changed, 685 insertions(+), 80 deletions(-) create mode 100644 _DOTween.Assembly/DOTween/Core/Surrogates/Vector2Surrogate.cs create mode 100644 _DOTween.Assembly/DOTween/Core/Surrogates/Vector3Surrogate.cs create mode 100644 _DOTween.Assembly/DOTween/Core/Surrogates/Vector4Surrogate.cs create mode 100644 _DOTween.Assembly/DOTween/Plugins/Vector2SurrogatePlugin.cs create mode 100644 _DOTween.Assembly/DOTween/Plugins/Vector3SurrogatePlugin.cs create mode 100644 _DOTween.Assembly/DOTween/Plugins/Vector4SurrogatePlugin.cs diff --git a/_DOTween.Assembly/DOTween/Core/Surrogates/Vector2Surrogate.cs b/_DOTween.Assembly/DOTween/Core/Surrogates/Vector2Surrogate.cs new file mode 100644 index 0000000..844c60a --- /dev/null +++ b/_DOTween.Assembly/DOTween/Core/Surrogates/Vector2Surrogate.cs @@ -0,0 +1,58 @@ +#if WP81 +// Author: Daniele Giardini - http://www.demigiant.com +// Created: 2015/04/14 12:42 + +using UnityEngine; + +#pragma warning disable 1591 +namespace DG.Tweening.Core.Surrogates +{ + /// + /// A surrogate for Vector2/3/4 values to work around Unity's bug when trying to cast to + /// a Vector2/3/4 plugin on WP8.1 + /// + public struct Vector2Surrogate + { + public float x, y; + + public float magnitude { + get { return Mathf.Sqrt(x * x + y * y); } + } + + public Vector2Surrogate(float x, float y) + : this() + { + this.x = x; + this.y = y; + } + + #region Operations + + public static Vector2Surrogate operator +(Vector2Surrogate v1, Vector2Surrogate v2) + { + return new Vector2Surrogate(v1.x + v2.x, v1.y + v2.y); + } + + public static Vector2Surrogate operator -(Vector2Surrogate v1, Vector2Surrogate v2) + { + return new Vector2Surrogate(v1.x - v2.x, v1.y - v2.y); + } + + public static Vector2Surrogate operator *(Vector2Surrogate v1, float f) + { + return new Vector2Surrogate(v1.x * f, v1.y * f); + } + + #endregion + + #region Conversions + + public static explicit operator Vector3(Vector2Surrogate v) + { + return new Vector3(v.x, v.y); + } + + #endregion + } +} +#endif \ No newline at end of file diff --git a/_DOTween.Assembly/DOTween/Core/Surrogates/Vector3Surrogate.cs b/_DOTween.Assembly/DOTween/Core/Surrogates/Vector3Surrogate.cs new file mode 100644 index 0000000..0ec9c8f --- /dev/null +++ b/_DOTween.Assembly/DOTween/Core/Surrogates/Vector3Surrogate.cs @@ -0,0 +1,59 @@ +#if WP81 +// Author: Daniele Giardini - http://www.demigiant.com +// Created: 2015/04/14 12:37 + +using UnityEngine; + +#pragma warning disable 1591 +namespace DG.Tweening.Core.Surrogates +{ + /// + /// A surrogate for Vector2/3/4 values to work around Unity's bug when trying to cast to + /// a Vector2/3/4 plugin on WP8.1 + /// + public struct Vector3Surrogate + { + public float x, y, z; + + public float magnitude { + get { return Mathf.Sqrt(x * x + y * y + z * z); } + } + + public Vector3Surrogate(float x, float y, float z) + : this() + { + this.x = x; + this.y = y; + this.z = z; + } + + #region Operations + + public static Vector3Surrogate operator +(Vector3Surrogate v1, Vector3Surrogate v2) + { + return new Vector3Surrogate(v1.x + v2.x, v1.y + v2.y, v1.z + v2.z); + } + + public static Vector3Surrogate operator -(Vector3Surrogate v1, Vector3Surrogate v2) + { + return new Vector3Surrogate(v1.x - v2.x, v1.y - v2.y, v1.z - v2.z); + } + + public static Vector3Surrogate operator *(Vector3Surrogate v1, float f) + { + return new Vector3Surrogate(v1.x * f, v1.y * f, v1.z * f); + } + + #endregion + + #region Conversions + + public static explicit operator Vector3(Vector3Surrogate v) + { + return new Vector3(v.x, v.y, v.z); + } + + #endregion + } +} +#endif \ No newline at end of file diff --git a/_DOTween.Assembly/DOTween/Core/Surrogates/Vector4Surrogate.cs b/_DOTween.Assembly/DOTween/Core/Surrogates/Vector4Surrogate.cs new file mode 100644 index 0000000..1c29b17 --- /dev/null +++ b/_DOTween.Assembly/DOTween/Core/Surrogates/Vector4Surrogate.cs @@ -0,0 +1,108 @@ +#if WP81 +// Author: Daniele Giardini - http://www.demigiant.com +// Created: 2015/04/14 12:10 + +using UnityEngine; + +#pragma warning disable 1591 +namespace DG.Tweening.Core.Surrogates +{ + /// + /// A surrogate for Vector2/3/4 values to work around Unity's bug when trying to cast to + /// a Vector2/3/4 plugin on WP8.1 + /// + public struct Vector4Surrogate + { + public float x, y, z, w; + + public float magnitude { + get { return Mathf.Sqrt(x * x + y * y + z * z + w * w); } + } + + public Vector4Surrogate(float x, float y, float z, float w) + { + this.x = x; + this.y = y; + this.z = z; + this.w = w; + } + + #region Operations + + public static Vector4Surrogate operator +(Vector4Surrogate v1, Vector4Surrogate v2) + { + return new Vector4Surrogate(v1.x + v2.x, v1.y + v2.y, v1.z + v2.z, v1.w + v2.w); + } + + public static Vector4Surrogate operator -(Vector4Surrogate v1, Vector4Surrogate v2) + { + return new Vector4Surrogate(v1.x - v2.x, v1.y - v2.y, v1.z - v2.z, v1.w - v2.w); + } + + public static Vector4Surrogate operator *(Vector4Surrogate v1, float f) + { + return new Vector4Surrogate(v1.x * f, v1.y * f, v1.z * f, v1.w * f); + } + +// public static Vector4Surrogate operator /(Vector4Surrogate v1, float f) +// { +// return new Vector4Surrogate(v1.x / f, v1.y / f, v1.z / f, v1.w / f); +// } + + #endregion + + #region Comparisons + + // public static bool operator <(Vector4Surrogate v1, Vector4Surrogate v2) +// { +// return v1.magnitude < v2.magnitude; +// } +// +// public static bool operator <=(Vector4Surrogate v1, Vector4Surrogate v2) +// { +// return v1.magnitude <= v2.magnitude; +// } +// +// public static bool operator >(Vector4Surrogate v1, Vector4Surrogate v2) +// { +// return v1.magnitude > v2.magnitude; +// } +// +// public static bool operator >=(Vector4Surrogate v1, Vector4Surrogate v2) +// { +// return v1.magnitude >= v2.magnitude; +// } +// +// public static bool operator ==(Vector4Surrogate v1, Vector4Surrogate v2) +// { +// return v1.x == v2.x && v1.y == v2.y && v1.z == v2.z && v1.w == v2.w; +// } +// +// public static bool operator !=(Vector4Surrogate v1, Vector4Surrogate v2) +// { +// return !(v1 == v2); + // } + + #endregion + + #region Conversions + +// public static explicit operator Vector2(Vector4Surrogate v) +// { +// return new Vector2(v.x, v.y); +// } +// +// public static explicit operator Vector3(Vector4Surrogate v) +// { +// return new Vector3(v.x, v.y, v.z); +// } + + public static explicit operator Vector4(Vector4Surrogate v) + { + return new Vector4(v.x, v.y, v.z, v.w); + } + + #endregion + } +} +#endif \ No newline at end of file diff --git a/_DOTween.Assembly/DOTween/DOTween.csproj b/_DOTween.Assembly/DOTween/DOTween.csproj index 0373e35..c2cb172 100644 --- a/_DOTween.Assembly/DOTween/DOTween.csproj +++ b/_DOTween.Assembly/DOTween/DOTween.csproj @@ -73,6 +73,7 @@ + @@ -95,6 +96,7 @@ + diff --git a/_DOTween.Assembly/DOTween/Plugins/Core/PluginsManager.cs b/_DOTween.Assembly/DOTween/Plugins/Core/PluginsManager.cs index 1665a9a..2758a3d 100644 --- a/_DOTween.Assembly/DOTween/Plugins/Core/PluginsManager.cs +++ b/_DOTween.Assembly/DOTween/Plugins/Core/PluginsManager.cs @@ -99,61 +99,62 @@ namespace DG.Tweening.Plugins.Core #if !WP81 if (plugin != null) return plugin as ABSTweenPlugin; #else + if (plugin != null) return plugin as ABSTweenPlugin; // WP8.1 fix tries - if (plugin != null) { - Debug.Log("PLUGIN FOUND, trying to assign it correctly..."); - ABSTweenPlugin p; - ABSTweenPlugin pExplicit; - // Explicit casting to Vector3Plugin - try { - pExplicit = (ABSTweenPlugin)plugin; - if (pExplicit != null) Debug.Log("- EXPLICIT CAST SUCCESS X"); - p = pExplicit as ABSTweenPlugin; - if (p != null) { - Debug.Log("- PLUGIN SUCCESS X"); - return p; - } - } catch (Exception e) { - Debug.Log("- PLUGIN FAIL X > " + e.Message); - } - // More regular ways - try { - p = plugin as ABSTweenPlugin; - if (p != null) { - Debug.Log("- PLUGIN SUCCESS A"); - return p; - } - } catch (Exception e) { - Debug.Log("- PLUGIN FAIL A > " + e.Message); - } - try { - System.Object obj = (object)plugin; - p = obj as ABSTweenPlugin; - if (p != null) { - Debug.Log("- PLUGIN SUCCESS A2"); - return p; - } - } catch (Exception e) { - Debug.Log("- PLUGIN FAIL A2 > " + e.Message); - } - try { - p = (ABSTweenPlugin)plugin; - Debug.Log("- PLUGIN SUCCESS B"); - return p; - } catch (Exception e) { - Debug.Log("- PLUGIN FAIL B > " + e.Message); - } - try { - System.Object obj = (object)plugin; - p = (ABSTweenPlugin)obj; - Debug.Log("- PLUGIN SUCCESS B2"); - return p; - } catch (Exception e) { - Debug.Log("- PLUGIN FAIL B2 > " + e.Message); - } - return null; - } - Debug.Log("PLUGIN NOT FOUND"); +// if (plugin != null) { +// Debug.Log("PLUGIN FOUND, trying to assign it correctly..."); +// ABSTweenPlugin p; +// ABSTweenPlugin pExplicit; +// // Explicit casting to Vector3Plugin +// try { +// pExplicit = (ABSTweenPlugin)plugin; +// if (pExplicit != null) Debug.Log("- EXPLICIT CAST SUCCESS X"); +// p = pExplicit as ABSTweenPlugin; +// if (p != null) { +// Debug.Log("- PLUGIN SUCCESS X"); +// return p; +// } +// } catch (Exception e) { +// Debug.Log("- PLUGIN FAIL X > " + e.Message); +// } +// // More regular ways +// try { +// p = plugin as ABSTweenPlugin; +// if (p != null) { +// Debug.Log("- PLUGIN SUCCESS A"); +// return p; +// } +// } catch (Exception e) { +// Debug.Log("- PLUGIN FAIL A > " + e.Message); +// } +// try { +// System.Object obj = (object)plugin; +// p = obj as ABSTweenPlugin; +// if (p != null) { +// Debug.Log("- PLUGIN SUCCESS A2"); +// return p; +// } +// } catch (Exception e) { +// Debug.Log("- PLUGIN FAIL A2 > " + e.Message); +// } +// try { +// p = (ABSTweenPlugin)plugin; +// Debug.Log("- PLUGIN SUCCESS B"); +// return p; +// } catch (Exception e) { +// Debug.Log("- PLUGIN FAIL B > " + e.Message); +// } +// try { +// System.Object obj = (object)plugin; +// p = (ABSTweenPlugin)obj; +// Debug.Log("- PLUGIN SUCCESS B2"); +// return p; +// } catch (Exception e) { +// Debug.Log("- PLUGIN FAIL B2 > " + e.Message); +// } +// return null; +// } +// Debug.Log("PLUGIN NOT FOUND"); // WP8.1 fix tries END #endif diff --git a/_DOTween.Assembly/DOTween/Plugins/Vector2SurrogatePlugin.cs b/_DOTween.Assembly/DOTween/Plugins/Vector2SurrogatePlugin.cs new file mode 100644 index 0000000..7201161 --- /dev/null +++ b/_DOTween.Assembly/DOTween/Plugins/Vector2SurrogatePlugin.cs @@ -0,0 +1,109 @@ +#if WP81 +// Author: Daniele Giardini - http://www.demigiant.com +// Created: 2015/04/14 12:46 + +using System; +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 Vector2SurrogatePlugin : ABSTweenPlugin + { + public override void Reset(TweenerCore t) { } + + public override void SetFrom(TweenerCore t, bool isRelative) + { + Vector2Surrogate prevEndVal = t.endValue; + t.endValue = t.getter(); + t.startValue = isRelative ? t.endValue + prevEndVal : prevEndVal; + Vector2Surrogate to = t.endValue; + switch (t.plugOptions.axisConstraint) { + case AxisConstraint.X: + to.x = t.startValue.x; + break; + case AxisConstraint.Y: + to.y = t.startValue.y; + break; + default: + to = t.startValue; + break; + } + if (t.plugOptions.snapping) { + to.x = (float)Math.Round(to.x); + to.y = (float)Math.Round(to.y); + } + t.setter(to); + } + + public override Vector2Surrogate ConvertToStartValue(TweenerCore t, Vector2Surrogate value) + { + return value; + } + + public override void SetRelativeEndValue(TweenerCore t) + { + t.endValue += t.startValue; + } + + public override void SetChangeValue(TweenerCore t) + { + switch (t.plugOptions.axisConstraint) { + case AxisConstraint.X: + t.changeValue = new Vector2Surrogate(t.endValue.x - t.startValue.x, 0); + break; + case AxisConstraint.Y: + t.changeValue = new Vector2Surrogate(0, t.endValue.y - t.startValue.y); + break; + default: + t.changeValue = t.endValue - t.startValue; + break; + } + } + + public override float GetSpeedBasedDuration(VectorOptions options, float unitsXSecond, Vector2Surrogate changeValue) + { + return changeValue.magnitude / unitsXSecond; + } + + public override void EvaluateAndApply(VectorOptions options, Tween t, bool isRelative, DOGetter getter, DOSetter setter, float elapsed, Vector2Surrogate startValue, Vector2Surrogate changeValue, float duration, bool usingInversePosition) + { + if (t.loopType == LoopType.Incremental) startValue += changeValue * (t.isComplete ? t.completedLoops - 1 : t.completedLoops); + if (t.isSequenced && t.sequenceParent.loopType == LoopType.Incremental) { + startValue += 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.axisConstraint) { + case AxisConstraint.X: + Vector2Surrogate resX = getter(); + resX.x = startValue.x + changeValue.x * easeVal; + if (options.snapping) resX.x = (float)Math.Round(resX.x); + setter(resX); + break; + case AxisConstraint.Y: + Vector2Surrogate resY = getter(); + resY.y = startValue.y + changeValue.y * easeVal; + if (options.snapping) resY.y = (float)Math.Round(resY.y); + setter(resY); + break; + default: + startValue.x += changeValue.x * easeVal; + startValue.y += changeValue.y * easeVal; + if (options.snapping) { + startValue.x = (float)Math.Round(startValue.x); + startValue.y = (float)Math.Round(startValue.y); + } + setter(startValue); + break; + } + } + } +} +#endif \ No newline at end of file diff --git a/_DOTween.Assembly/DOTween/Plugins/Vector3SurrogatePlugin.cs b/_DOTween.Assembly/DOTween/Plugins/Vector3SurrogatePlugin.cs new file mode 100644 index 0000000..af29d5f --- /dev/null +++ b/_DOTween.Assembly/DOTween/Plugins/Vector3SurrogatePlugin.cs @@ -0,0 +1,123 @@ +#if WP81 +// Author: Daniele Giardini - http://www.demigiant.com +// Created: 2015/04/14 12:44 + +using System; +using DG.Tweening.Core; +using DG.Tweening.Core.Easing; +using DG.Tweening.Core.Surrogates; +using DG.Tweening.Plugins.Core; +using DG.Tweening.Plugins.Options; + +#pragma warning disable 1591 +namespace DG.Tweening.Plugins +{ + public class Vector3SurrogatePlugin : ABSTweenPlugin + { + public override void Reset(TweenerCore t) { } + + public override void SetFrom(TweenerCore t, bool isRelative) + { + Vector3Surrogate prevEndVal = t.endValue; + t.endValue = t.getter(); + t.startValue = isRelative ? t.endValue + prevEndVal : prevEndVal; + Vector3Surrogate to = t.endValue; + switch (t.plugOptions.axisConstraint) { + case AxisConstraint.X: + to.x = t.startValue.x; + break; + case AxisConstraint.Y: + to.y = t.startValue.y; + break; + case AxisConstraint.Z: + to.z = t.startValue.z; + break; + default: + to = t.startValue; + break; + } + if (t.plugOptions.snapping) { + to.x = (float)Math.Round(to.x); + to.y = (float)Math.Round(to.y); + to.z = (float)Math.Round(to.z); + } + t.setter(to); + } + + public override Vector3Surrogate ConvertToStartValue(TweenerCore t, Vector3Surrogate value) + { + return value; + } + + public override void SetRelativeEndValue(TweenerCore t) + { + t.endValue += t.startValue; + } + + public override void SetChangeValue(TweenerCore t) + { + switch (t.plugOptions.axisConstraint) { + case AxisConstraint.X: + t.changeValue = new Vector3Surrogate(t.endValue.x - t.startValue.x, 0, 0); + break; + case AxisConstraint.Y: + t.changeValue = new Vector3Surrogate(0, t.endValue.y - t.startValue.y, 0); + break; + case AxisConstraint.Z: + t.changeValue = new Vector3Surrogate(0, 0, t.endValue.z - t.startValue.z); + break; + default: + t.changeValue = t.endValue - t.startValue; + break; + } + } + + public override float GetSpeedBasedDuration(VectorOptions options, float unitsXSecond, Vector3Surrogate changeValue) + { + return changeValue.magnitude / unitsXSecond; + } + + public override void EvaluateAndApply(VectorOptions options, Tween t, bool isRelative, DOGetter getter, DOSetter setter, float elapsed, Vector3Surrogate startValue, Vector3Surrogate changeValue, float duration, bool usingInversePosition) + { + if (t.loopType == LoopType.Incremental) startValue += changeValue * (t.isComplete ? t.completedLoops - 1 : t.completedLoops); + if (t.isSequenced && t.sequenceParent.loopType == LoopType.Incremental) { + startValue += 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.axisConstraint) { + case AxisConstraint.X: + Vector3Surrogate resX = getter(); + resX.x = startValue.x + changeValue.x * easeVal; + if (options.snapping) resX.x = (float)Math.Round(resX.x); + setter(resX); + break; + case AxisConstraint.Y: + Vector3Surrogate resY = getter(); + resY.y = startValue.y + changeValue.y * easeVal; + if (options.snapping) resY.y = (float)Math.Round(resY.y); + setter(resY); + break; + case AxisConstraint.Z: + Vector3Surrogate resZ = getter(); + resZ.z = startValue.z + changeValue.z * easeVal; + if (options.snapping) resZ.z = (float)Math.Round(resZ.z); + setter(resZ); + break; + default: + startValue.x += changeValue.x * easeVal; + startValue.y += changeValue.y * easeVal; + startValue.z += changeValue.z * easeVal; + if (options.snapping) { + startValue.x = (float)Math.Round(startValue.x); + startValue.y = (float)Math.Round(startValue.y); + startValue.z = (float)Math.Round(startValue.z); + } + setter(startValue); + break; + } + } + } +} +#endif \ No newline at end of file diff --git a/_DOTween.Assembly/DOTween/Plugins/Vector4SurrogatePlugin.cs b/_DOTween.Assembly/DOTween/Plugins/Vector4SurrogatePlugin.cs new file mode 100644 index 0000000..17c0df0 --- /dev/null +++ b/_DOTween.Assembly/DOTween/Plugins/Vector4SurrogatePlugin.cs @@ -0,0 +1,139 @@ +#if WP81 +// Author: Daniele Giardini - http://www.demigiant.com +// Created: 2015/04/14 12:19 + +using System; +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 Vector4SurrogatePlugin : ABSTweenPlugin + { + public override void Reset(TweenerCore t) { } + + public override void SetFrom(TweenerCore t, bool isRelative) + { + Vector4Surrogate prevEndVal = t.endValue; + t.endValue = t.getter(); + t.startValue = isRelative ? t.endValue + prevEndVal : prevEndVal; + Vector4Surrogate to = t.endValue; + switch (t.plugOptions.axisConstraint) { + case AxisConstraint.X: + to.x = t.startValue.x; + break; + case AxisConstraint.Y: + to.y = t.startValue.y; + break; + case AxisConstraint.Z: + to.z = t.startValue.z; + break; + case AxisConstraint.W: + to.w = t.startValue.w; + break; + default: + to = t.startValue; + break; + } + if (t.plugOptions.snapping) { + to.x = (float)Math.Round(to.x); + to.y = (float)Math.Round(to.y); + to.z = (float)Math.Round(to.z); + to.w = (float)Math.Round(to.w); + } + t.setter(to); + } + + public override Vector4Surrogate ConvertToStartValue(TweenerCore t, Vector4Surrogate value) + { + return value; + } + + public override void SetRelativeEndValue(TweenerCore t) + { + t.endValue += t.startValue; + } + + public override void SetChangeValue(TweenerCore t) + { + switch (t.plugOptions.axisConstraint) { + case AxisConstraint.X: + t.changeValue = new Vector4Surrogate(t.endValue.x - t.startValue.x, 0, 0, 0); + break; + case AxisConstraint.Y: + t.changeValue = new Vector4Surrogate(0, t.endValue.y - t.startValue.y, 0, 0); + break; + case AxisConstraint.Z: + t.changeValue = new Vector4Surrogate(0, 0, t.endValue.z - t.startValue.z, 0); + break; + case AxisConstraint.W: + t.changeValue = new Vector4Surrogate(0, 0, 0, t.endValue.w - t.startValue.w); + break; + default: + t.changeValue = t.endValue - t.startValue; + break; + } + } + + public override float GetSpeedBasedDuration(VectorOptions options, float unitsXSecond, Vector4Surrogate changeValue) + { + return changeValue.magnitude / unitsXSecond; + } + + public override void EvaluateAndApply(VectorOptions options, Tween t, bool isRelative, DOGetter getter, DOSetter setter, float elapsed, Vector4Surrogate startValue, Vector4Surrogate changeValue, float duration, bool usingInversePosition) + { + if (t.loopType == LoopType.Incremental) startValue += changeValue * (t.isComplete ? t.completedLoops - 1 : t.completedLoops); + if (t.isSequenced && t.sequenceParent.loopType == LoopType.Incremental) { + startValue += 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.axisConstraint) { + case AxisConstraint.X: + Vector4Surrogate resX = getter(); + resX.x = startValue.x + changeValue.x * easeVal; + if (options.snapping) resX.x = (float)Math.Round(resX.x); + setter(resX); + break; + case AxisConstraint.Y: + Vector4Surrogate resY = getter(); + resY.y = startValue.y + changeValue.y * easeVal; + if (options.snapping) resY.y = (float)Math.Round(resY.y); + setter(resY); + break; + case AxisConstraint.Z: + Vector4Surrogate resZ = getter(); + resZ.z = startValue.z + changeValue.z * easeVal; + if (options.snapping) resZ.z = (float)Math.Round(resZ.z); + setter(resZ); + break; + case AxisConstraint.W: + Vector4Surrogate resW = getter(); + resW.w = startValue.w + changeValue.w * easeVal; + if (options.snapping) resW.w = (float)Math.Round(resW.w); + setter(resW); + break; + default: + startValue.x += changeValue.x * easeVal; + startValue.y += changeValue.y * easeVal; + startValue.z += changeValue.z * easeVal; + startValue.w += changeValue.w * easeVal; + if (options.snapping) { + startValue.x = (float)Math.Round(startValue.x); + startValue.y = (float)Math.Round(startValue.y); + startValue.z = (float)Math.Round(startValue.z); + startValue.w = (float)Math.Round(startValue.w); + } + setter(startValue); + break; + } + } + } +} +#endif \ No newline at end of file diff --git a/_DOTween.Assembly/DOTween/Tweener.cs b/_DOTween.Assembly/DOTween/Tweener.cs index b1ac107..a0bcffe 100644 --- a/_DOTween.Assembly/DOTween/Tweener.cs +++ b/_DOTween.Assembly/DOTween/Tweener.cs @@ -75,37 +75,43 @@ namespace DG.Tweening return false; } #else - // WP8.1 fix tries - if (t.tweenPlugin == null) { - Debug.Log("Assigning plugin to ABSTweenPlugin var"); - ABSTweenPlugin plug = PluginsManager.GetDefaultPlugin(); - if (plug != null) { - Debug.Log(">> Plugin found"); - t.tweenPlugin = plug; - Debug.Log(">> Plugin assigned > " + t.tweenPlugin + " (t.tweenPlugin is null: " + (t.tweenPlugin == null) + ")"); - if (t.tweenPlugin == null) Debug.Log(">> Plugin assignment failed"); - } else Debug.Log(">> Plugin NOT found"); - } - if (t.tweenPlugin == null) { - Debug.Log("Assigning plugin to ITweenPlugin var"); - ITweenPlugin iplug = PluginsManager.GetDefaultPlugin(); - if (iplug != null) { - Debug.Log(">> IPlugin found"); - try { - System.Object pObj = (object)iplug; - t.tweenPlugin = (ABSTweenPlugin)pObj; - } catch (Exception e) { - Debug.Log(">> Error while assigning IPlugin > " + e.Message); - } - Debug.Log(">> IPlugin assigned > " + t.tweenPlugin + " (t.tweenPlugin is null: " + (t.tweenPlugin == null) + ")"); - if (t.tweenPlugin == null) Debug.Log(">> IPlugin assignment failed"); - } else Debug.Log(">> IPlugin NOT found"); - } + if (t.tweenPlugin == null) t.tweenPlugin = PluginsManager.GetDefaultPlugin(); if (t.tweenPlugin == null) { // No suitable plugin found. Kill Debugger.LogError("No suitable plugin found for this type"); return false; } + // WP8.1 fix tries +// if (t.tweenPlugin == null) { +// Debug.Log("Assigning plugin to ABSTweenPlugin var"); +// ABSTweenPlugin plug = PluginsManager.GetDefaultPlugin(); +// if (plug != null) { +// Debug.Log(">> Plugin found"); +// t.tweenPlugin = plug; +// Debug.Log(">> Plugin assigned > " + t.tweenPlugin + " (t.tweenPlugin is null: " + (t.tweenPlugin == null) + ")"); +// if (t.tweenPlugin == null) Debug.Log(">> Plugin assignment failed"); +// } else Debug.Log(">> Plugin NOT found"); +// } +// if (t.tweenPlugin == null) { +// Debug.Log("Assigning plugin to ITweenPlugin var"); +// ITweenPlugin iplug = PluginsManager.GetDefaultPlugin(); +// if (iplug != null) { +// Debug.Log(">> IPlugin found"); +// try { +// System.Object pObj = (object)iplug; +// t.tweenPlugin = (ABSTweenPlugin)pObj; +// } catch (Exception e) { +// Debug.Log(">> Error while assigning IPlugin > " + e.Message); +// } +// Debug.Log(">> IPlugin assigned > " + t.tweenPlugin + " (t.tweenPlugin is null: " + (t.tweenPlugin == null) + ")"); +// if (t.tweenPlugin == null) Debug.Log(">> IPlugin assignment failed"); +// } else Debug.Log(">> IPlugin NOT found"); +// } +// if (t.tweenPlugin == null) { +// // No suitable plugin found. Kill +// Debugger.LogError("No suitable plugin found for this type"); +// return false; +// } // WP8.1 fix tries END #endif }