Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Recreating the dynamic range functionality of the Unity slider in the inspector

Discussion in 'Editor & General Support' started by ChickenVegetable, Nov 28, 2021.

  1. ChickenVegetable

    ChickenVegetable

    Joined:
    May 3, 2020
    Posts:
    87
    Hi,

    I have created my own UI slider that has some features I need that the default Unity one is missing. However I'd like the representation of the slider in the inspector to behave like the Unity one when you edit the min / max values of the slider.

    Ie, when you change min and max values in the inspector, the value slider underneath is updated to reflect those values dynamically. Obviously you can't use the [Range(0,1)] attribute for this.

    I read through the source code for the Unity slider but to be honest it's beyond me.

    Is it necessary to create an inspector slider asset from scratch? If anyone could point me in the right direction would be great.
     
  2. altepTest

    altepTest

    Joined:
    Jul 5, 2012
    Posts:
    1,101
    what do you mean by dynamic range? that the value of the slider is updated in real time while you drag it?
     
  3. ChickenVegetable

    ChickenVegetable

    Joined:
    May 3, 2020
    Posts:
    87
    That the min / max values that the slider will accept is updated in the inspector after you edit those values above it.

    So if you set the slider to a value of 0, with a min of 0 and a max of 1, the handle will be at the far far left of its range.

    Then if you set the min value to -1, the handle will be in the center of its range.