Skip to content

Commit cb65034

Browse files
committed
Queue fixes
1 parent 3c745f7 commit cb65034

6 files changed

Lines changed: 47 additions & 42 deletions

File tree

Assets/SlimTween/Scripts/STweenExtended.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -712,15 +712,11 @@ public static void lerpPunch(this GameObject stween, float punchFactor, float pu
712712

713713
Vector3 scale = new Vector3(vec.x + tmp, vec.y + tmp, vec.z + tmp);
714714
var main = stween.transform.lerpScale(new Vector3(punchSize, punchSize, punchSize), duration).setPingPong(1);
715-
var sub = stween.transform.lerpRotateAround(new Vector3(0, 0, -val), 45, duration/2.1f).setEase(Ease.EaseInOutQuad);
715+
var sub = stween.transform.lerpRotation(new Vector3(0, 0, -val), duration/2.1f).setEase(Ease.EaseInOutQuad);
716716
(sub as ISlimRegister).RegisterLastOnComplete(()=>
717717
{
718718
stween.transform.rotation = defrotation;
719719
var t = stween.transform.lerpRotation(new Vector3(0, 0, val * 2f), duration/2.1f).setPingPong(1).setEase(Ease.EaseInOutQuad);
720-
(t as ISlimRegister).RegisterLastOnComplete(()=>
721-
{
722-
stween.transform.rotation = defrotation;
723-
});
724720
});
725721
}
726722
}

Assets/SlimTween/Scripts/TweenClasses.cs

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ public class TweenClass : ISlimRegister
5353
/// </summary>
5454
protected ISlimTween islim => this as ISlimTween;
5555
protected ISlimRegister ireg => this as ISlimRegister;
56+
TweenMode ISlimRegister.TweenMode
57+
{
58+
get => islim.TweenMode;
59+
set
60+
{
61+
islim.TweenMode = value;
62+
}
63+
}
5664
/// <summary>The tween state of this instance.</summary>
5765
protected TweenState state = TweenState.None;
5866
/// <summary>The on update function.</summary>
@@ -335,7 +343,7 @@ protected void Clear()
335343
if (this is ISlimTween sl)
336344
{
337345
RemoveFromTransformPool(tprops.id);
338-
sl.CombineMode = false;
346+
sl.TweenMode = TweenMode.Tweeen;
339347
}
340348

341349
TweenManager.RemoveFromActiveTween(this);
@@ -426,11 +434,11 @@ protected void PoolTransformID(int id)
426434
if (TryUpdateCounterTransform(id, true))
427435
{
428436
islim.BackupPreviousPosition();
429-
islim.CombineMode = true;
437+
islim.TweenMode = TweenMode.Combine;
430438

431439
if (TweenExtension.GetTween(id, out var tween))
432440
{
433-
(tween as ISlimTween).CombineMode = true;
441+
(tween as ISlimTween).TweenMode = TweenMode.Combine;
434442
}
435443
}
436444
else
@@ -625,6 +633,7 @@ public void SetLerpType()
625633
/// </summary>
626634
public interface ISlimRegister
627635
{
636+
public TweenMode TweenMode{get;set;}
628637
public bool FlipTickIs { get; }
629638
/// <summary> An object can only be revived once and MUST NOT be pooled.</summary>
630639
public bool wasResurected { get; set; }
@@ -668,11 +677,11 @@ public SlimTransform()
668677
TransformType type = TransformType.None;
669678
/// <summary>Locality.</summary>
670679
bool isLocal = false;
671-
bool combineMode;
672-
bool ISlimTween.CombineMode
680+
TweenMode tweenMode;
681+
TweenMode ISlimTween.TweenMode
673682
{
674-
get => combineMode;
675-
set => combineMode = value;
683+
get => tweenMode;
684+
set => tweenMode = value;
676685
}
677686
/// <summary>Locality.</summary>
678687
bool ISlimTween.Locality { get => isLocal; set => isLocal = value; }
@@ -681,12 +690,12 @@ bool ISlimTween.CombineMode
681690
protected override void InternalOnComplete()
682691
{
683692
InvokeLerps(tprops.pingpong ? 0f : 1f);
684-
combineMode = false;
693+
tweenMode = TweenMode.Tweeen;
685694
}
686695
///<summary>Resets properties shuffle from/to value.</summary>
687696
protected override void ResetLoop()
688697
{
689-
if (combineMode && GetTransformCount(tprops.id) == 1)
698+
if (tweenMode == TweenMode.Combine && GetTransformCount(tprops.id) == 1)
690699
{
691700
islim.RestorePreviousPosition();
692701
}
@@ -698,7 +707,7 @@ protected override void InternalOnUpdate()
698707
{
699708
base.InternalOnUpdate();
700709

701-
if (combineMode)
710+
if (tweenMode == TweenMode.Combine)
702711
{
703712
islim.UpdateTransform();
704713
}
@@ -734,7 +743,7 @@ void ISlimTween.UpdateTransform()
734743
{
735744
if (type == TransformType.Move || type == TransformType.Translate)
736745
{
737-
if(!combineMode)
746+
if(tweenMode != TweenMode.Combine)
738747
{
739748
interp.SetFrom(!isLocal ? transform.position : transform.localPosition);
740749
}
@@ -744,8 +753,7 @@ void ISlimTween.UpdateTransform()
744753
// Calculate weighted average of the positions
745754
//Vector3 weightedAverage = interp.from * (1 - weight) + transform.position * weight;
746755
//interp.SetFrom(Vector3.Lerp(interp.from, Vector3.Lerp(weightedAverage, interp.to, tick), tick));
747-
var a = Vector3.LerpUnclamped(interp.from, transform.position, tick);
748-
var b = Vector3.LerpUnclamped(interp.previousPos, a, tick);
756+
var b = Vector3.LerpUnclamped(interp.previousPos, Vector3.LerpUnclamped(interp.from, transform.position, tick), tick);
749757
interp.SetFrom(b);
750758
}
751759
}
@@ -768,7 +776,7 @@ void ISlimTween.BackupPreviousPosition()
768776
}
769777
void ISlimTween.RestorePreviousPosition()
770778
{
771-
combineMode = false;
779+
tweenMode = TweenMode.Tweeen;
772780
interp.SetFrom(interp.previousPos);
773781
}
774782
(Vector3 from, Vector3 to) ISlimTween.FromTo { get { return (interp.from, interp.to); } set { interp.SetFrom(value.from); interp.SetTo(value.to); } }
@@ -898,11 +906,11 @@ public SlimRect()
898906
TransformType type = TransformType.None;
899907
/// <summary>Locality.</summary>
900908
bool isLocal = false;
901-
bool combineMode;
902-
bool ISlimTween.CombineMode
909+
TweenMode tweenMode;
910+
TweenMode ISlimTween.TweenMode
903911
{
904-
get => combineMode;
905-
set => combineMode = value;
912+
get => tweenMode;
913+
set => tweenMode = value;
906914
}
907915
(Vector3 from, Vector3 to) ISlimTween.FromTo { get { return (interp.from, interp.to); } set { interp.SetFrom(value.from); interp.SetTo(value.to); } }
908916
bool ISlimTween.Locality { get => isLocal; set => isLocal = value; }
@@ -984,7 +992,7 @@ protected override void InternalOnComplete()
984992
///<summary>Resets properties shuffle from/to value.</summary>
985993
protected override void ResetLoop()
986994
{
987-
if (combineMode && GetTransformCount(tprops.id) == 1)
995+
if (tweenMode == TweenMode.Combine && GetTransformCount(tprops.id) == 1)
988996
{
989997
islim.RestorePreviousPosition();
990998
}
@@ -996,7 +1004,7 @@ protected override void InternalOnUpdate()
9961004
{
9971005
base.InternalOnUpdate();
9981006

999-
if (combineMode)
1007+
if (tweenMode == TweenMode.Combine)
10001008
{
10011009
islim.UpdateTransform();
10021010
}
@@ -1034,14 +1042,13 @@ void ISlimTween.UpdateTransform()
10341042
{
10351043
if (type == TransformType.Move)
10361044
{
1037-
if(!combineMode)
1045+
if(tweenMode != TweenMode.Combine)
10381046
{
10391047
interp.SetFrom(!isLocal ? transform.position : transform.localPosition);
10401048
}
10411049
else
10421050
{
1043-
var a = Vector3.LerpUnclamped(interp.from, transform.position, tick);
1044-
var b = Vector3.LerpUnclamped(interp.previousPos, a, tick);
1051+
var b = Vector3.LerpUnclamped(interp.previousPos, Vector3.LerpUnclamped(interp.from, transform.position, tick), tick);
10451052
interp.SetFrom(b);
10461053
}
10471054
}
@@ -1071,7 +1078,7 @@ void ISlimTween.BackupPreviousPosition()
10711078
}
10721079
void ISlimTween.RestorePreviousPosition()
10731080
{
1074-
combineMode = false;
1081+
tweenMode = TweenMode.Tweeen;
10751082
interp.SetFrom(interp.previousPos);
10761083
}
10771084
/// <summary>Interpoaltes world position.</summary>
@@ -1139,7 +1146,7 @@ void LerpSizeAnchored(float value)
11391146
public interface ISlimTween
11401147
{
11411148
public bool Locality { get; set; }
1142-
public bool CombineMode { get; set; }
1149+
public TweenMode TweenMode { get; set; }
11431150
public TransformType GetTransformType { get; set; }
11441151
public void UpdateTransform();
11451152
public void BackupPreviousPosition();
@@ -1224,6 +1231,12 @@ public Vector3 Interpolate(float tick)
12241231
}
12251232

12261233
}
1234+
public enum TweenMode
1235+
{
1236+
Combine,
1237+
Queue,
1238+
Tweeen
1239+
}
12271240
/// <summary>
12281241
///
12291242
public struct TFloat6

Assets/SlimTween/Scripts/TweenExtensionExtended.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ public static STFluent<TweenClass> next(this TweenClass tween, TweenClass nextTw
177177
fluent.Add(nextTween);
178178

179179
var reg = tween as ISlimRegister;
180+
reg.TweenMode = TweenMode.Queue;
180181

181182
if(tween != null)
182183
{
@@ -192,6 +193,7 @@ public static STFluent<TweenClass> next(this TweenClass tween, TweenClass nextTw
192193
}
193194

194195
var regNext = nextTween as ISlimRegister;
196+
regNext.TweenMode = TweenMode.Queue;
195197

196198
if(regNext != null)
197199
{
@@ -225,6 +227,7 @@ public static STFluent<TweenClass> next(this STFluent<TweenClass> fluent, TweenC
225227
}
226228

227229
fluent.Add(nextTween);
230+
(nextTween as ISlimRegister).TweenMode = TweenMode.Queue;
228231

229232
if(lastween != null)
230233
{

Assets/SlimTween/Scripts/TweenManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public sealed class TweenManager
4545
public static TweenClass[] removeList = new TweenClass[30];
4646
public static int removeCount { get; set; }
4747
public static int poolsLength { get; private set; } = 50;
48-
public static int mainPoolLength { get; private set; } = 300;
48+
public static int mainPoolLength { get; private set; } = 50;
4949
///<summary>Fast worker loop.</summary>
5050
public static bool editorPaused { get; set; }
5151
/// <summary> Playmode state. </summary>

Assets/SlimTween/Scripts/TweenUtility.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ public static STCombine<TweenClass> CombineLerps(TweenClass atransform, TweenCla
7676
var islimA = atransform as ISlimTween;
7777
var islimB = btransform as ISlimTween;
7878

79-
islimA.CombineMode = true;
80-
islimB.CombineMode = true;
79+
islimA.TweenMode = TweenMode.Combine;
80+
islimB.TweenMode = TweenMode.Combine;
8181

8282
Transform transform = null;
8383

@@ -221,7 +221,7 @@ public static STCombine<TweenClass> CombineLerps(TweenClass atransform, TweenCla
221221
fluent.Add(btransform);
222222

223223
var islimB = btransform as ISlimTween;
224-
islimB.CombineMode = true;
224+
islimB.TweenMode = TweenMode.Combine;
225225

226226
Transform transform = null;
227227

@@ -453,24 +453,17 @@ public static Matrix4x4 FMatrixLerp(Matrix4x4 a, Matrix4x4 b, float t)
453453
/// <summary>
454454
/// The clamping only happening for greater than 1(tail).
455455
/// </summary>
456-
/// <param name="a"></param>
457-
/// <param name="b"></param>
458-
/// <param name=""></param>
459456
public static float Flerp(float a, float b, float t)
460457
{
461458
return a + (b - a) * Clamp1(t);
462459
}
463460
/// <summary>
464461
/// The clamping only happening for less than 0 (head).
465462
/// </summary>
466-
/// <param name="a"></param>
467-
/// <param name="b"></param>
468-
/// <param name="t"></param>
469463
public static float Flerp0(float a, float b, float t)
470464
{
471465
return a + (b - a) * Clamp0(t);
472466
}
473-
474467
public static float FSmoothStep1(float from, float to, float t)
475468
{
476469
t = Clamp1(t);

Assets/SlimTween/Tests/VT_TEST.unity

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56130,7 +56130,7 @@ MonoBehaviour:
5613056130
m_Name:
5613156131
m_EditorClassIdentifier:
5613256132
loopCount: 1
56133-
pingPong: 2
56133+
pingPong: 0
5613456134
textVal: {fileID: 285644081}
5613556135
floatVecJoinTest: {x: 0, y: 33, z: 0}
5613656136
obj: {fileID: 1256568957}

0 commit comments

Comments
 (0)