I am trying to create an Editor utility that will let me replace all the prefabs of a certain type in a parent object with a different prefab. The big problem I am running into is that I can’t seem to find a way of determining what “type” a prefab is. Here is what I have so far. The problem part is the loop in ReplacePrefabs():
public class ReplacePrefabEditor : EditorWindow
{
Object removalObject;
Object replacementObject;
void OnGUI()
{
EditorGUILayout.BeginVertical();
removalObject = EditorGUILayout.ObjectField("Removal Object", removalObject, typeof(Object), true, null);
replacementObject = EditorGUILayout.ObjectField("Replacement Object", replacementObject, typeof(Object), true, null);
EditorGUILayout.EndVertical();
if (GUILayout.Button("Replace"))
{
if (!removalObject || !replacementObject)
{
Debug.LogError("Need to assign objects!");
return;
}
ReplacePrefabs();
}
}
[MenuItem("Prefab Helpers/Replace Prefabs")]
static void Init()
{
ReplacePrefabEditor window = (ReplacePrefabEditor)EditorWindow.GetWindow(typeof(ReplacePrefabEditor));
}
[MenuItem("Prefab Helpers/Replace Prefabs", true)]
static bool ValidateSelection()
{
return Selection.activeTransform != null;
}
void ReplacePrefabs()
{
Transform root = Selection.activeTransform;
int childCount = root.childCount;
for (int i = 0; i < childCount; ++i)
{
// determine if the current child is the same prefab type as removalObject
}
}
}