"int" support for Tween.Custom() #87
Replies: 2 comments
-
If I'm understanding, you can cast like this for font size (int): Tween.Custom(Text.fontSize, 110, duration: 1f, onValueChange: v => Text.fontSize = (int)v); Sidenote, Scale should be Vector3 instead of Float... |
Beta Was this translation helpful? Give feedback.
-
Hey! As @st4rdog mentioned, it's possible to just round float to an int like this: Tween.Custom(text, startValue: 10f, endValue: 100f, duration: 1f, (target, val) => target.fontSize = Mathf.RoundToInt(val)); But this problem goes deeper than just rounding float to an int. I experimented with a version of Tween.Custom() that works with int and the problem with it much deeper than appears at first sight. First, linearly interpolating an int is ambiguous in the sense that there is no mathematically correct behavior that will satisfy all use cases. Here are a few examples:
tween = Tween.Custom(this, 0f, sprites.Length, settings, static (_this, val) => {
int newIndex = (int)val;
var _sprites = _this.sprites;
if (newIndex < _sprites.Length && _this.curIndex != newIndex) {
_this.curIndex = newIndex;
_this.spriteRenderer.sprite = _sprites[newIndex];
}
}); There are many other different examples of how one may want to animate an int value. But, unfortunately, I haven't found yet a solution that will satisfy all use cases for an int animation. It almost feels like animating an int value doesn't make any mathematical sense :) |
Beta Was this translation helpful? Give feedback.
-
Hello, when using DOTween, I found incredible DOVirtual functions. Now I'm migrating to PrimeTween and I found Tween.Custom() do the same things as DoVirtual in DOTween. But why you support only float, Color, Vector, Quaternion and Rect but int? What if I need int overridden version of the Tween.Custom() in PrimeTween, because I use DoVirtual.Int() frequently in DOTween. I want to migrate thoroughly to PrimeTween due to the performance it brings. Thanks for your efforts.
Beta Was this translation helpful? Give feedback.
All reactions