Skip to content

Commit 3c745f7

Browse files
committed
Fix transform pool removal, re-init transform pool on edit mode
1 parent 066e431 commit 3c745f7

2 files changed

Lines changed: 22 additions & 4 deletions

File tree

Assets/SlimTween/Scripts/Editor/EditorWorker.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ static void PlayModeState(PlayModeStateChange state)
185185

186186
EditorApplication.delayCall += () =>
187187
{
188+
TweenClass.ClearTransformPool();
188189
TweenManager.isPlayMode = false;
189190
STPool.ClearCache();
190191
SessionState.SetBool("STplaying", false);

Assets/SlimTween/Scripts/TweenClasses.cs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ namespace Breadnone.Extension
3939
[Serializable]
4040
public class TweenClass : ISlimRegister
4141
{
42+
/// <summary>Cancels all running tweens.</summary>
43+
public static void CancelAll()=> STween.CancelAll();
44+
/// <summary>Clears the transform pools used for combining tweens. This might break things when not done properly.</summary>
45+
public static void ClearTransformPool()=> transforms = new(8);
4246
/// <summary>Running transforms.</summary>
4347
public static List<(int id, int counter)> transforms { get; private set; } = new(8);
4448
bool ISlimRegister.wasResurected { get; set; }
@@ -457,15 +461,19 @@ bool TryUpdateCounterTransform(int id, bool increaseElseDecrease)
457461
if (TransformDataExists(id, out var index))
458462
{
459463
var tmp = transforms[index];
460-
transforms[index] = (tmp.id, increaseElseDecrease ? tmp.counter++ : tmp.counter--);
464+
transforms[index] = (tmp.id, increaseElseDecrease ? tmp.counter + 1 : tmp.counter - 1);
461465

462-
if (transforms[index].counter == 0)
466+
if(!increaseElseDecrease && transforms[index].counter == 0)
463467
{
464-
RemoveFromTransformPool(id);
468+
transforms.RemoveAt(index);
465469
}
466470

467471
return true;
468472
}
473+
else
474+
{
475+
476+
}
469477

470478
return false;
471479
}
@@ -1026,7 +1034,16 @@ void ISlimTween.UpdateTransform()
10261034
{
10271035
if (type == TransformType.Move)
10281036
{
1029-
interp.SetFrom(!isLocal ? transform.position : transform.localPosition);
1037+
if(!combineMode)
1038+
{
1039+
interp.SetFrom(!isLocal ? transform.position : transform.localPosition);
1040+
}
1041+
else
1042+
{
1043+
var a = Vector3.LerpUnclamped(interp.from, transform.position, tick);
1044+
var b = Vector3.LerpUnclamped(interp.previousPos, a, tick);
1045+
interp.SetFrom(b);
1046+
}
10301047
}
10311048
else if (type == TransformType.Scale)
10321049
{

0 commit comments

Comments
 (0)