GameObject rootObject = contentsRoot.transform.root.gameObject; var all = rootObject.GetComponentsInChildren<Transform>(true); foreach (var el in all) { if(PrefabUtility.IsPartOfRegularPrefab(el.gameObject)) { PrefabUtility.UnpackPrefabInstance(el.gameObject, PrefabUnpackMode.Completely, InteractionMode.AutomatedAction); } } |
using UnityEngine; using UnityEditor;
public class Example { [MenuItem("Examples/Add BoxCollider to Prefab Asset")] static void AddBoxColliderToPrefab() { // Get the Prefab Asset root GameObject and its asset path. GameObject assetRoot = Selection.activeObject as GameObject; string assetPath = AssetDatabase.GetAssetPath(assetRoot);
// Load the contents of the Prefab Asset. GameObject contentsRoot = PrefabUtility.LoadPrefabContents(assetPath);
// Modify Prefab contents. contentsRoot.AddComponent<BoxCollider>(); // Save contents back to Prefab Asset and unload contents. PrefabUtility.SaveAsPrefabAsset(contentsRoot, assetPath); PrefabUtility.UnloadPrefabContents(contentsRoot); }
[MenuItem("Examples/Add BoxCollider to Prefab Asset", true)] static bool ValidateAddBoxColliderToPrefab() { GameObject go = Selection.activeObject as GameObject; if (go == null) return false;
return PrefabUtility.IsPartOfPrefabAsset(go); } }
|
|
'게임엔진(GameEngine) > Unity3D' 카테고리의 다른 글
부모 자식간의 콜리전 분리 (0) | 2021.04.20 |
---|---|
Vector3.Scale : Multiplies two vectors component-wise. (0) | 2021.01.13 |
모바일 기기의 Tile Based Rendering(타일 기반 렌더링) (0) | 2020.02.24 |
[InitializeOnLoad] : 에티더 UnityEditor 에디터 스크립트 생성자 호출하기 (0) | 2019.09.07 |
에디터에서 해당 오브젝트에 대한 prefab path 얻어오기 : Get a prefabs file location in Unity (0) | 2019.09.07 |