Search Unity

LeanTween a rect transforms size delta?

Discussion in 'Scripting' started by thevvulf, Nov 28, 2021.

  1. thevvulf

    thevvulf

    Joined:
    Oct 31, 2020
    Posts:
    36
    I have a simple tab system where I want the selected tab to be larger than the others. To do this I figured I'd use leantween as always. I tried using the scaleX method, which scaled the literal scale of the rect transform, not the width as I wanted. I looked around and couldn't find any leantween methods that modified a rect transforms width / size delta. I can't just change the scale since my tabs are under a horizontal layout group, meaning that changing the size doesn't modify the positions of any of the other tabs which means the selected tab covers the tabs besides it instead of pushing them away as it would if changing the width. Are there any ways to do this either with leantween or with something completely different? I don't want to use unitys animation system since I absolutely despise it and theres no way of getting my beloved easeOutExpo's.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,738
    I think you could pretty easily extend Leantween to have your own feature that tickles these RectTransforms. The asset store version comes with a DLL but the source is offered on Github.

    However, RectTransform values are extremely non-intuitive to manipulate in the general numeric sense.

    This is because RectTransforms always exist in the context of the parent Canvas(es) and Canvas Scalers and whatnot going all the way up.

    If you decide to take a whack at it, write some quick test code first to maintain your own sanity, and be sure to leverage the
    RectTransformUtility
    class to make things a bit easier.

    And lots of Debug.Log() output too probably, if my experience manipulating RectTransforms is any indication!