Unity/기타

AssetPostprocessor.OnPostprocessPrefab 프리팹, 생성전, 저장전에 호출되는 함수

소나무꼴 2021. 11. 26. 16:44

https://docs.unity3d.com/ScriptReference/AssetPostprocessor.OnPostprocessPrefab.html

 

Unity - Scripting API: AssetPostprocessor.OnPostprocessPrefab(GameObject root)

To use this function, add it to a subclass. It lets you modify the imported GameObject. GameObjects only exist during the import and Unity destroys them immediately after import. This function is called before the final Prefab is created and before it is w

docs.unity3d.com

 

 

2020.3 버전

 

using UnityEngine;
using UnityEditor;

// Adds a mesh collider to each game object that contains collider in its name
public class Example : AssetPostprocessor
{
    void OnPostprocessPrefab(GameObject g)
    {
        Apply(g.transform);
    }

    void Apply(Transform t)
    {
        if (t.name.ToLower().Contains("collider"))
            t.gameObject.AddComponent<MeshCollider>();

        // Recurse
        foreach (Transform child in t)
            Apply(child);
    }
}