I’ve just started creating custom windows and I’m not understanding how to interact with EditorGUILayout objects.
I don’t see any documentation of how to use EditorGUILayout.TextField other than create it.
I’m getting the feeling I’m using these objects wrong, can someone explain a bit?
Thank you.
EditorGUI is immediate mode. Meaning it is always changed all the time. It sets it every loop, whether you changed it or not. To find in something specifically changed, there are two ways:
First is check the GUI.changed value. This will be set to true if anything is changed. So something like this:
m_Obj.FindProperty("testValue").stringValue = EditorGUILayout.TextField("Test:",m_Obj.FindProperty("testValue").stringValue);
// check to see if anything changed
if(GUI.changed)
{
Debug.Log("Something changed");
// do something here
}
The downside is that will be called if any of the controls are changed.
The second way is to just store the value, and check after the control if it is different. so you could do :
string temp_val = m_Obj.FindProperty("testValue").stringValue;
m_Obj.FindProperty("testValue").stringValue = EditorGUILayout.TextField("Test:",m_Obj.FindProperty("testValue").stringValue);
// checks to see if a specifc value changed
if(m_Obj.FindProperty("testValue").stringValue != temp_val)
{
Debug.Log("testValue changed");
// do something here
}
1 Like