Пример #1
0
        void BatchPrefabWindowUI()
        {
            QuickToolsHelp.BatchMakePrefabsInstructions(); // displays the instructions for this tool

            destinationFolder = EditorGUILayout.TextField("Destination Folder:", destinationFolder);
            if (GUILayout.Button("Set Destination Folder"))
            {
                destinationFolder = AssetDatabase.GetAssetPath(Selection.activeObject);
            }
            if (GUILayout.Button("Make Prefabs"))
            {
                // Loop through every GameObject in the array above
                foreach (GameObject gameObject in Selection.objects)
                {
                    // Set the path as within the Assets folder,
                    // and name it as the GameObject's name with the .Prefab format
                    string localPath = destinationFolder + "/" + gameObject.name + ".prefab";
                    // Make sure the file name is unique, in case an existing Prefab has the same name.
                    localPath = AssetDatabase.GenerateUniqueAssetPath(localPath);
                    // Create the new Prefab.
                    PrefabUtility.SaveAsPrefabAssetAndConnect(gameObject, localPath, InteractionMode.UserAction);
                }
            }
        }