- Home /
Inspector slider value?
Shader variables that represent range (e.g. Range(0.5, 1.3)
) can be set in the Inspector using a slider. The problem is - the slider doesn't show the actual value (given by a number) anywhere. I've set the shader variables in the Inspector so that my model looks nice but now I need to know what exact values the variables have so I can use them in code.
How the hell do I retrieve the exact values from variable sliders?
Edit: Look at this screen:
How do I know what exact values do Shininess
and Grad
have?
I'm not sure what you are asking for is all that doable. but you can change the variable type from Range(0.5, 1.3)
to Float
.
I can't - it's a built-in shader. :P Besides, sometimes I DO want to have Range
ins$$anonymous$$d of float
.
Temporarily changing it to a Float would retain the Range's value though, so you would be able to see it. Though i suppose this isn't all that much of a solution for built-in shaders.
You can use GetFloat() to get the current value from the material in code. An editor extension would allow you to select objects and display the value, or you could just output it in a Debug.Log() statement.
Am I to understand, that there is no possibility to check it without writing special scripts and "debugging" Unity? :/ As for the editor extension - how do I do that (any link)?
Answer by Wolfram · May 05, 2014 at 03:54 PM
You can switch the Inspector to the "Debug" view. All visible float properties of the shader will then be listed in the SavedProperties->Floats array, by property name and current value. You can use the same trick to set these properties to explicit values via the Inspector interface (as opposed to a script).
Yes, that's what I was looking for. Although the same functionality should be available for floats in Normal view, I$$anonymous$$O. On a different subject, now I see you posted that looooong time ago but the system never notified me. :( But now it's accepted and thank you.
Answer by robertbu · May 05, 2014 at 02:44 PM
Here is a quick editor script as an example. Put it in the Editor folder of your project. Pick the 'ShowSliderValues' from the Window menu. You have to hard code the property that you are interested in. Fortunately shaders tend to use the same property names:
using UnityEngine;
using UnityEditor;
using System.Collections.Generic;
public class ShowSliderProps : EditorWindow {
[MenuItem("Window/ShowSliderValues")]
public static void ShowWindow() {
EditorWindow.GetWindow(typeof(ShowSliderProps));
}
Transform curr;
void OnGUI() {
curr = Selection.activeTransform;
GUILayout.Label("Shininess: "+GetSlideProp("_Shininess"));
GUILayout.Label("Grad"+GetSlideProp("_Grad"));
GUILayout.Label("Blend"+GetSlideProp("_Blend"));
}
float GetSlideProp(string prop) {
if (curr == null) {
return -1.0f;
}
Renderer rend = curr.GetComponent<Renderer>();
if (rend == null) {
return -1.0f;
}
if (!rend.material.HasProperty(prop)) {
return -1.0f;
}
return rend.material.GetFloat(prop);
}
}
Note that if you are playing with the slider, you need to change the focus to the window this editor script brings up in order to see the changed value.
Thx for writing the script. I'll wait some time to see if anyone has any answer that doesn't use a script. If not, I'll accept this one.