- Home /
Multi Object Editing
I am creating a custom script editor where I wish to be able to edit multiple objects.
The key points as I understand them are:
-the [CanEditMultipleObjects] attribute is obviously required -I need to use a serialised property for each variable I wish to be able to edit on a multiple basis (I think) I'm a little unsure of exactly how serialised properties work, only that they do. -I am obtaining the serialised object from all targets OnEnable, and then finding the relevant properties for each property from this object. - I need to use serialisedObject.Update() and .ApplyModifiedProperties() at the beginning and end of my OnInspectorGUI.
My queries are: In all examples, properties are assigned in a way similar to this:
EditorGUILayout.IntSlider(MyPropertyX, 0, 100);
Now without actually using MyPropertyX = before this statement, I am unsure as to how this is assigning the value to MyPropertyX.
On top of this whenever I try to do:
EditorGUILayout.Toggle("My bool toggle", MyPropertyY);
The console throws an error stating that I need to use a bool, so properties can't simply used as bools? Meaning I am currently doing this.
MyPropertyY.boolValue = EditorGUILayout.Toggle("My bool toggle", MyPropertyY.boolValue);
Without specifically assigning the value with the "=" then the value isn't changed when editing, this inconsistency between how the properties is assigned is confusing me somewhat.
Also as a last point, how do I achieve the same result as Unity's own multiple object editing where inconsistent values across multiple objects are represented by a dash "-" but I have no idea how this is achieved.
Answer by FlightOfOne · Apr 06, 2016 at 04:28 PM
I know this is an old post, and author probably found the answer.
I needed to know part of this question (your last point), and when I 'googled' this is where it brought me. Now that I have figured it out, here's how to do it. I think the official term for this is "Mixed Value".
EditorGUI.showMixedValue = nameProperty.hasMultipleDifferentValues; //this turns on mixed value
nameProperty.stringValue=EditorGUILayout.TextField(new GUIContent("Name "), nameProperty.stringValue);
EditorGUI.showMixedValue = false; //If you don't want this to happen for the rest of the code
Also, if I wanted the same for 'GameObject' or 'Transform', this is what worked for me.
EditorGUI.BeginChangeCheck(); //This way change will only take effect if this code block changes
EditorGUI.showMixedValue = rootProp.hasMultipleDifferentValues;
GameObject temp =EditorGUILayout.ObjectField(new GUIContent("Weapon Root"), rootProp.objectReferenceValue, typeof(GameObject), true) as GameObject;
if (EditorGUI.EndChangeCheck())
{
rootProp.objectReferenceValue = temp;
}
Your answer
Follow this Question
Related Questions
how do i change the color of basic water 0 Answers
Blender terrain in unity 1 Answer
Changing sprite properties at runtime 2 Answers