{
InitDataIfNeeded();
EditorGUILayout.Separator();
EditorGUILayout.PropertyField(replaceObjectField);
EditorGUILayout.LabelField("Selected objects to replace", EditorStyles.boldLabel);
// Saving number of objects to replace.
int objectToReplaceCount = data.objectsToReplace != null ? data.objectsToReplace.Length : 0;
EditorGUILayout.IntField("Object count", objectToReplaceCount);
EditorGUI.indentLevel++;
if (objectToReplaceCount == 0)
EditorGUILayout.LabelField("Select objects in the hierarchy to replace them", EditorStyles.wordWrappedLabel);
}
// Read-only scroll view with selected game objects.
selectObjectScrollPosition = EditorGUILayout.BeginScrollView(selectObjectScrollPosition);
GUI.enabled = false;
if (data && data.objectsToReplace != null)
foreach (var go in data.objectsToReplace)
EditorGUILayout.ObjectField(go, typeof(GameObject), true);
GUI.enabled = true;
EditorGUILayout.EndScrollView();
EditorGUI.indentLevel--;
if (GUILayout.Button("Replace"))
// Check if replace object is assigned.
if (!replaceObjectField.objectReferenceValue)
Debug.LogErrorFormat("{0}", "No prefab to replace with!");
return;
// Check if there are objects to replace.
if (data.objectsToReplace.Length == 0)
Debug.LogErrorFormat("{0}", "No objects to replace!");
ReplaceSelectedObjects(data.objectsToReplace, data.replacementPrefab);
serializedData.ApplyModifiedProperties();
private void OnInspectorUpdate()