I am creating a custom editor and wanted to include a FloatField.
This works fine but I wanted the float field to change by clicking and sliding it, as most default unity components do. As shown in the image bellow.
I wasn’t abel to achieve this and would appriciate it if someone could point me in the right direction.
The FloatField does this by default. The internal function DoFloatField has a parameter for the dragHotZone. The rect of this zone is automatically calculated from the PrefixLabel size of the FloatField. When you don’t display a label the dragHotZone will be emtpy.
Unfortunately the DoFloatField function is an internal function so you can’t call it manually unless you use reflection.
For anyone wanting to do the same for int fields, you have to pass the drag sensitivity float as well. You could probably reflect EditorGUI.CalculateIntDragSensitivity() but you wouldn’t be able to cache it so I decided to just pass 1f which seems to work fine. Here’s the cached implementation (you could probably cache the params array as well and just update the indexes but *shrug*):