private static void CreatePrefabs(MenuCommand menuCommand) { if (Selection.objects.Length > 1 && menuCommand.context != Selection.objects[0]) { return; } if (GetSavingPopupOption()) { PrefabSaverSettings.ShowPopup(true).SaveButtonPressed += IterateObjects; } else { IterateObjects(); } void IterateObjects() { string path = GetPrefabsPath(); EditorTools.CreateDirectoryFromAssetPath($"{path}a.prefab"); foreach (GameObject gameObject in Selection.gameObjects) { string localPath = $"{path}{gameObject.name}.prefab"; localPath = AssetDatabase.GenerateUniqueAssetPath(localPath); PrefabUtility.SaveAsPrefabAssetAndConnect(gameObject, localPath, InteractionMode.UserAction); } } }
public static PrefabSaverSettings ShowPopup(bool showButtons = false) { if (showButtons) { GetWindow(typeof(PrefabSaverSettings)).Close(); } PrefabSaverSettings window = GetWindow(typeof(PrefabSaverSettings)) as PrefabSaverSettings; window.titleContent = new GUIContent("Prefab Saver"); window.minSize = new Vector2(300f, 100f); window.maxSize = new Vector2(500f, 150f); window._showButtons = showButtons; return(window); }