yasirkula / UnityRuntimeInspector

Runtime Inspector and Hierarchy solution for Unity for debugging and runtime editing purposes
MIT License
1.68k stars 135 forks source link

Slider (Feature request) #8

Closed Scraft closed 4 years ago

Scraft commented 5 years ago

Would you be willing to add a Slider, that works in the same way as the normal Unity slider (where the Range attribute is added that specifies a minimum and maximum value)? It would be really helpful for adjusting values currently set up as sliders in the Unity Inspector. If you are not likely to be able to make the time if you can add some notes about how I may be able to do this myself that would be helpful. I did take a quick look, but I couldn't really see how the various bits hook together.

yasirkula commented 5 years ago

I think the most ideal place for it would be here: https://github.com/yasirkula/UnityRuntimeInspector/blob/6c72753db6621536f4e26dd46cae25d8703e6bdc/Plugins/RuntimeInspector/Scripts/RuntimeInspector/Fields/InspectorField.cs#L390-L401

You can check if the variable is a float/int with [Range] attribute and if so, you can call Inspector.CreateDrawerForType( typeof( RangeAttribute ), drawArea, Depth + 1 );. Then, you need to create a new field prefab for the RangeAttribute and add it to the RuntimeInspector's Settings asset. RangeAttribute's prefab should have the following function:

public override bool SupportsType( Type type )
{
    return type == typeof( RangeAttribute );
}

You can see BoolField for a simple field prefab example.

Scraft commented 5 years ago

Thank you, I have created a PR here:

https://github.com/yasirkula/UnityRuntimeInspector/pull/9

The extra complications were the fact I need to set the slider min/max values, which isn't available from the type, so I went for the solution of passing the MemberInfo into OnBound. Hopefully, the pull request/commit message explains everything.

yasirkula commented 4 years ago

Added feature in https://github.com/yasirkula/UnityRuntimeInspector/commit/fa012110fd3d7ad60bef6d6b721f00dd019f3dab