Is there a way to add our own Tweens (as part of original library) #122
-
For example, I added a custom tween as follows:
but to call this I need to use something like:
What I would like is to be able to add Tweens as part of the same namespace so you'd call the new Tween something like this:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hey Anthony, There is no simple way to add a built-in animation. You can, of course, embed the library by copying its source code to the Packages folder, but that's not a good long-term solution. The reason why this animation can't be built-in is because it would break PrimeTween's zero-allocation design. Your example allocates garbage because the delegate captures formattedString and arg1 arguments into a closure. Here is an example of a possible solution: [SerializeField] Image SampleFillImage;
[SerializeField] TextAnimationData textAnimationData;
[SerializeField] TweenSettings TweenSettings;
public Sequence Animate() {
return Sequence.Create()
.Group(Tween.UIFillAmount(SampleFillImage, 0.5f, TweenSettings))
.Group(textAnimationData.Animate(100, 200, TweenSettings));
}
[Serializable]
public class TextAnimationData {
public TMP_Text text;
public string formattedString;
public int arg1;
public Tween Animate(float startValue, float endValue, TweenSettings tweenSettings)
{
return Tween.Custom(this, startValue, endValue, tweenSettings, (t, v) => t.text.SetText(t.formattedString, v, t.arg1));
}
} |
Beta Was this translation helpful? Give feedback.
Hey Anthony,
There is no simple way to add a built-in animation. You can, of course, embed the library by copying its source code to the Packages folder, but that's not a good long-term solution.
The reason why this animation can't be built-in is because it would break PrimeTween's zero-allocation design. Your example allocates garbage because the delegate captures formattedString and arg1 arguments into a closure. Here is an example of a possible solution: