Skip to content

Commit dfa332d

Browse files
committed
Combine fixes, new static for cancels, implement ScaleAround
1 parent cb65034 commit dfa332d

3 files changed

Lines changed: 300 additions & 196 deletions

File tree

Assets/SlimTween/Scripts/STween.cs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1160,6 +1160,25 @@ public static SlimTransform scaleZ(Transform transform, float to, float duration
11601160
/// <param name="transform">The transform to scale.</param>
11611161
/// <param name="to">Target scale value.</param>
11621162
/// <param name="duration">Duration to reach the target.</param>
1163+
/// <param name="pivot">Target pivot.</param>
1164+
/// <exception cref="STweenException"></exception>
1165+
public static STFloat scaleAround(Transform transform, Vector3 pivot, Vector3 to, float duration)
1166+
{
1167+
if (transform is null)
1168+
{
1169+
throw new STweenException("Transform can't be null.");
1170+
}
1171+
1172+
var instance = STPool.GetInstance<STFloat>(transform.gameObject.GetInstanceID());
1173+
Vector3 from = transform.localScale;
1174+
1175+
instance.SetBase(0, 1, duration, x=>{ lerpScaleAround(transform, pivot, Vector3.LerpUnclamped(from, to, x));});
1176+
return instance;
1177+
}
1178+
///<summary>Scales a transform.</summary>
1179+
/// <param name="transform">The transform to scale.</param>
1180+
/// <param name="to">Target scale value.</param>
1181+
/// <param name="duration">Duration to reach the target.</param>
11631182
/// <exception cref="STweenException"></exception>
11641183
public static SlimTransform scale(Transform transform, Vector3 to, float duration)
11651184
{
@@ -1947,7 +1966,20 @@ private static IEnumerable<TweenClass> GetActiveTweens(TweenClass t)
19471966
}
19481967
///<summary>Checks if an instance is tweening.</summary>
19491968
public static bool IsTweening(TweenClass vtween) { return vtween.IsTweening; }
1969+
/// <summary>Check pause state of a tween instance.</summary>
1970+
/// <param name="vtween">Tween instance.</param>
19501971
public static bool IsPaused(TweenClass vtween) { return vtween.IsPaused;}
1972+
/// <summary>Tries to find active tween.</summary>
1973+
/// <param name="gameObject">GameObject.</param>
1974+
/// <param name="stween">Tween instance.</param>
1975+
public static bool TryFindTween(GameObject gameObject, out TweenClass stween)
1976+
{
1977+
var t = TweenExtension.GetTween(gameObject.GetInstanceID(), out var obj);
1978+
stween = obj;
1979+
return t;
1980+
}
1981+
/// <summary>Check pause state of a tween instance.</summary>
1982+
/// <param name="id">Tween id.</param>
19511983
public static bool IsPaused(int id)
19521984
{
19531985
return TweenExtension.GetTween(id, out var tw) && tw.IsPaused;
@@ -1957,7 +1989,7 @@ public static bool IsTweening(int customId)
19571989
{
19581990
return TweenExtension.GetTween(customId, out var tw) && tw.IsTweening;
19591991
}
1960-
///<summary>Reinitialize the max tweens.</summary>
1992+
///<summary>(EXPERIMENTAL!) Reinitialize the max tweens pool.</summary>
19611993
public static void Init(int newSize) { TweenManager.InitSize(newSize); }
19621994
#endregion
19631995
}

Assets/SlimTween/Scripts/STweenExtended.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -712,11 +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.lerpRotation(new Vector3(0, 0, -val), duration/2.1f).setEase(Ease.EaseInOutQuad);
715+
var sub = stween.transform.lerpRotationLocal(new Vector3(0, 0, -val), duration/2.1f).setEase(Ease.EaseInOutQuad);
716716
(sub as ISlimRegister).RegisterLastOnComplete(()=>
717717
{
718718
stween.transform.rotation = defrotation;
719-
var t = stween.transform.lerpRotation(new Vector3(0, 0, val * 2f), duration/2.1f).setPingPong(1).setEase(Ease.EaseInOutQuad);
719+
var t = stween.transform.lerpPositionLocal(new Vector3(0, 0, val * 2f), duration/2.1f).setPingPong(1).setEase(Ease.EaseInOutQuad);
720720
});
721721
}
722722
}
@@ -734,5 +734,20 @@ public static void punch(GameObject stween, float punchFactor, float punchSize,
734734
(sub as ISlimRegister).RegisterLastOnComplete(()=> stween.transform.lerpRotation(new Vector3(0, 0, val * 2f), duration/2.1f).setPingPong(1).setEase(Ease.EaseInOutElastic));
735735
}
736736
}
737+
/// <summary>
738+
/// Lerps localScale based on pivot point.
739+
/// </summary>
740+
/// <param name="gameObject"></param>
741+
/// <param name="target"></param>
742+
/// <param name="newScale"></param>
743+
public static void lerpScaleAround(Transform transform, Vector3 target, Vector3 newScale)
744+
{
745+
Vector3 a = transform.localPosition;
746+
Vector3 c = a - target;
747+
float RS = newScale.x / transform.localScale.x;
748+
Vector3 FP = target + c * RS;
749+
transform.localScale = newScale;
750+
transform.localPosition = FP;
751+
}
737752
}
738753
}

0 commit comments

Comments
 (0)