[Unity3D self-learning Record] replaces preset objects in batches.

Source: Internet
Author: User

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.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.