반응형
Notice
Recent Posts
Recent Comments
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

Do Something IT

[Unity] Apply Prefab Editor 본문

Unity3D/Editor

[Unity] Apply Prefab Editor

아낙시만더 2016. 10. 31. 10:53
반응형

동적 프리펩 갱신 아래를 사용하자


  PrefabUtility.ReplacePrefab( go, PrefabUtility.GetPrefabParent( go ), ReplacePrefabOptions.ConnectToPrefab );


using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 #if UNITY_EDITOR
 using UnityEditor;
 #endif
 
 public class UnitEditorBulkApply : MonoBehaviour, ICheckForUnsafeChanges
 {
     public bool resetPosition = true;
     public bool resetScale = true;
     public bool resetRotation = true;
 
 
 #if UNITY_EDITOR
     [ContextMenu("Apply Bulk Prefab Apply")]
     public void CheckForUnsafeChanges()
     {
         for ( int i = 0; i < transform.childCount; i++)
         {
             GameObject go = transform.GetChild( i ).gameObject;
 
             if ( PrefabUtility.GetPrefabParent( go ) != null )
             {
                 Vector3 pos = go.transform.localPosition;
                 Vector3 scale = go.transform.localScale;
                 Quaternion rot = go.transform.localRotation;
 
                 if ( resetPosition ) go.transform.localPosition = Vector3.zero;
                 if ( resetScale ) go.transform.localScale = Vector3.one;
                 if ( resetRotation ) go.transform.localRotation = Quaternion.identity;
 
                 {
                     MonoBehaviour [] behaviours = go.GetComponents<MonoBehaviour>();
                     foreach ( MonoBehaviour b in behaviours )
                         if ( b is ICheckForUnsafeChanges )
                             ( b as ICheckForUnsafeChanges ).CheckForUnsafeChanges();
                 }
 
                 Debug.Log( "Applying changes to " + go.name, go );
                 PrefabUtility.ReplacePrefab( go, PrefabUtility.GetPrefabParent( go ), ReplacePrefabOptions.ConnectToPrefab );
 
                 if ( resetPosition ) go.transform.localPosition = pos;
                 if ( resetScale ) go.transform.localScale = scale;
                 if ( resetRotation ) go.transform.localRotation = rot;
             }
         }
     }
 #endif
 }
 
 public interface ICheckForUnsafeChanges {
 #if UNITY_EDITOR
     void CheckForUnsafeChanges();
 #endif
 }


반응형
Comments