I have an object with some components on it.
I wish to fold off (collapse) all component’s properties on selected object.
I have a button in the EditorWindow which runs this code:
Component[] components = go.GetComponents<Component>();
foreach (Component component in components)
{
SerializedObject so = new SerializedObject(component);
SerializedProperty iterator = so.GetIterator();
do
{
iterator.isExpanded = false;
}
while (iterator.NextVisible(true));
so.ApplyModifiedProperties();
EditorUtility.SetDirty(component);
}
EditorUtility.SetDirty(go);
go - is a selected object.
Code does job I need. But for the some reason I can see changes only if I deselect and re-select that object again.
Both
AssetDatabase.Refresh();
and
InternalEditorUtility.RepaintAllViews()
doesn’t help here.
Am I missing something obvious (I bet I do)?
Thanks!
"But for the some reason I can see changes only if I deselect and re-select that object again." This symptom makes me want to see the code where you set the gameObject reference go.
I know, old question but I was just looking for this, having forgotten that I did do it in one of my old projects before. So I’ll post a solution in case someone else happens on this.
This assumes you want to force a repaint on a custom inspector.
public static void RepaintInspector(System.Type t)
{
Editor[] ed = (Editor[])Resources.FindObjectsOfTypeAll<Editor>();
for (int i = 0; i < ed.Length; i++)
{
if (ed.GetType() == t)
{
ed.Repaint();
return;
}
}
}
and to use
RepaintInspector( typeof(SomeTypeInspector) );
where
[CustomEditor(typeof(SomeType))]
public class SomeTypeInspector: Editor
{
//...
}
"But for the some reason I can see changes only if I deselect and re-select that object again." This symptom makes me want to see the code where you set the gameObject reference
– Glurthgo.Also, Editor class itself has http://docs.unity3d.com/ScriptReference/Editor.Repaint.html did you try:
– Glurththis.Repaint()yet?