Today I have studied how to modify preset objects in batches. project requirements must be studied ~~
The main purpose is to replace all the placed objects with another object.
The last time we talked about creating presets in batches (Address: Creating presets in batches), we just need to modify the settings.
The Code is as follows:
using UnityEngine;using System.Collections;using UnityEditor;public class DJH_Unity : MonoBehaviour { [MenuItem("Tools/ChangePrefab")] public static void BatchPrefab() { Transform tParent = ((GameObject)Selection.activeObject).transform; Object tempPrefab; GameObject tt = GameObject.Find("XXX"); int i = 0; foreach (Transform child in tParent) { tempPrefab = EditorUtility.CreateEmptyPrefab("Assets/Prefab" + child.name + ".prefab"); tt.transform.position = child.position; tt.transform.rotation = child.rotation; tempPrefab = EditorUtility.ReplacePrefab(tt, tempPrefab); i++; } }}
First, you need to place the preset in the scenario, and delete it wherever you are.
GameObject tt = GameObject. Find ("XXX"); here XXX is your default name,
The final result is that all the preset after replacement are placed under Assets.
You can drag it into the scenario.