Skip to content

Commit

Permalink
Combine fixes, new static for cancels, implement ScaleAround
Browse files Browse the repository at this point in the history
  • Loading branch information
breadnone committed Mar 2, 2024
1 parent cb65034 commit dfa332d
Show file tree
Hide file tree
Showing 3 changed files with 300 additions and 196 deletions.
34 changes: 33 additions & 1 deletion Assets/SlimTween/Scripts/STween.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,25 @@ public static SlimTransform scaleZ(Transform transform, float to, float duration
/// <param name="transform">The transform to scale.</param>
/// <param name="to">Target scale value.</param>
/// <param name="duration">Duration to reach the target.</param>
/// <param name="pivot">Target pivot.</param>
/// <exception cref="STweenException"></exception>
public static STFloat scaleAround(Transform transform, Vector3 pivot, Vector3 to, float duration)
{
if (transform is null)
{
throw new STweenException("Transform can't be null.");
}

var instance = STPool.GetInstance<STFloat>(transform.gameObject.GetInstanceID());
Vector3 from = transform.localScale;

instance.SetBase(0, 1, duration, x=>{ lerpScaleAround(transform, pivot, Vector3.LerpUnclamped(from, to, x));});
return instance;
}
///<summary>Scales a transform.</summary>
/// <param name="transform">The transform to scale.</param>
/// <param name="to">Target scale value.</param>
/// <param name="duration">Duration to reach the target.</param>
/// <exception cref="STweenException"></exception>
public static SlimTransform scale(Transform transform, Vector3 to, float duration)
{
Expand Down Expand Up @@ -1947,7 +1966,20 @@ private static IEnumerable<TweenClass> GetActiveTweens(TweenClass t)
}
///<summary>Checks if an instance is tweening.</summary>
public static bool IsTweening(TweenClass vtween) { return vtween.IsTweening; }
/// <summary>Check pause state of a tween instance.</summary>
/// <param name="vtween">Tween instance.</param>
public static bool IsPaused(TweenClass vtween) { return vtween.IsPaused;}
/// <summary>Tries to find active tween.</summary>
/// <param name="gameObject">GameObject.</param>
/// <param name="stween">Tween instance.</param>
public static bool TryFindTween(GameObject gameObject, out TweenClass stween)
{
var t = TweenExtension.GetTween(gameObject.GetInstanceID(), out var obj);
stween = obj;
return t;
}
/// <summary>Check pause state of a tween instance.</summary>
/// <param name="id">Tween id.</param>
public static bool IsPaused(int id)
{
return TweenExtension.GetTween(id, out var tw) && tw.IsPaused;
Expand All @@ -1957,7 +1989,7 @@ public static bool IsTweening(int customId)
{
return TweenExtension.GetTween(customId, out var tw) && tw.IsTweening;
}
///<summary>Reinitialize the max tweens.</summary>
///<summary>(EXPERIMENTAL!) Reinitialize the max tweens pool.</summary>
public static void Init(int newSize) { TweenManager.InitSize(newSize); }
#endregion
}
Expand Down
19 changes: 17 additions & 2 deletions Assets/SlimTween/Scripts/STweenExtended.cs
Original file line number Diff line number Diff line change
Expand Up @@ -712,11 +712,11 @@ public static void lerpPunch(this GameObject stween, float punchFactor, float pu

Vector3 scale = new Vector3(vec.x + tmp, vec.y + tmp, vec.z + tmp);
var main = stween.transform.lerpScale(new Vector3(punchSize, punchSize, punchSize), duration).setPingPong(1);
var sub = stween.transform.lerpRotation(new Vector3(0, 0, -val), duration/2.1f).setEase(Ease.EaseInOutQuad);
var sub = stween.transform.lerpRotationLocal(new Vector3(0, 0, -val), duration/2.1f).setEase(Ease.EaseInOutQuad);
(sub as ISlimRegister).RegisterLastOnComplete(()=>
{
stween.transform.rotation = defrotation;
var t = stween.transform.lerpRotation(new Vector3(0, 0, val * 2f), duration/2.1f).setPingPong(1).setEase(Ease.EaseInOutQuad);
var t = stween.transform.lerpPositionLocal(new Vector3(0, 0, val * 2f), duration/2.1f).setPingPong(1).setEase(Ease.EaseInOutQuad);
});
}
}
Expand All @@ -734,5 +734,20 @@ public static void punch(GameObject stween, float punchFactor, float punchSize,
(sub as ISlimRegister).RegisterLastOnComplete(()=> stween.transform.lerpRotation(new Vector3(0, 0, val * 2f), duration/2.1f).setPingPong(1).setEase(Ease.EaseInOutElastic));
}
}
/// <summary>
/// Lerps localScale based on pivot point.
/// </summary>
/// <param name="gameObject"></param>
/// <param name="target"></param>
/// <param name="newScale"></param>
public static void lerpScaleAround(Transform transform, Vector3 target, Vector3 newScale)
{
Vector3 a = transform.localPosition;
Vector3 c = a - target;
float RS = newScale.x / transform.localScale.x;
Vector3 FP = target + c * RS;
transform.localScale = newScale;
transform.localPosition = FP;
}
}
}
Loading

0 comments on commit dfa332d

Please sign in to comment.