Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Showcase An editor window to show you prefab properties

Discussion in 'Prefabs' started by idbrii, Oct 17, 2020.

  1. idbrii

    idbrii

    Joined:
    Aug 18, 2014
    Posts:
    24
    I get confused when working with prefabs, so I made an editor window to show you prefab properties. It doesn't cover the whole PrefabUtility API (modifications and arrays are notably absent), but useful for when you're trying to figure out which function returns True in the right cases.

    upload_2020-10-17_6-33-5.png

    See the gist for more elegance, but the code is essentially this:

    Code (CSharp):
    1. using UnityEditor.Experimental.SceneManagement;
    2. using UnityEditor.SceneManagement;
    3. using UnityEditor;
    4. using UnityEngine;
    5. public class PrefabDetector : EditorWindow {
    6.     [MenuItem("Tools/PrefabDetector")]
    7.     static void ShowToolbar() {
    8.         EditorWindow.GetWindow<PrefabDetector>("PrefabDetector");
    9.     }
    10.     public void OnGUI() {
    11.         var go = Selection.activeGameObject;
    12.         EditorGUIUtility.labelWidth = 300;
    13.         EditorGUILayout.ObjectField("Selection", go, typeof(GameObject), allowSceneObjects: true);
    14.         EditorGUILayout.Space();
    15.         EditorGUILayout.LabelField("PrefabStageUtility", EditorStyles.boldLabel);
    16.         var stage = PrefabStageUtility.GetCurrentPrefabStage();
    17.         EditorGUILayout.LabelField("GetCurrentPrefabStage", stage != null ? "has stage" : "null");
    18.         if (stage != null) {
    19.             EditorGUILayout.LabelField("IsPartOfPrefabContents", "" + stage.IsPartOfPrefabContents(go));
    20.         }
    21.         EditorGUILayout.Space();
    22.         EditorGUILayout.LabelField("PrefabUtility", EditorStyles.boldLabel);
    23.         EditorGUILayout.LabelField("IsAddedComponentOverride", "" + PrefabUtility.IsAddedComponentOverride(go));
    24.         EditorGUILayout.LabelField("IsAddedGameObjectOverride", "" + PrefabUtility.IsAddedGameObjectOverride(go));
    25.         EditorGUILayout.LabelField("IsAnyPrefabInstanceRoot", "" + PrefabUtility.IsAnyPrefabInstanceRoot(go));
    26.         EditorGUILayout.LabelField("IsDisconnectedFromPrefabAsset", "" + PrefabUtility.IsDisconnectedFromPrefabAsset(go));
    27.         EditorGUILayout.LabelField("IsOutermostPrefabInstanceRoot", "" + PrefabUtility.IsOutermostPrefabInstanceRoot(go));
    28.         EditorGUILayout.LabelField("IsPartOfAnyPrefab", "" + PrefabUtility.IsPartOfAnyPrefab(go));
    29.         EditorGUILayout.LabelField("IsPartOfImmutablePrefab", "" + PrefabUtility.IsPartOfImmutablePrefab(go));
    30.         EditorGUILayout.LabelField("IsPartOfModelPrefab", "" + PrefabUtility.IsPartOfModelPrefab(go));
    31.         EditorGUILayout.LabelField("IsPartOfNonAssetPrefabInstance", "" + PrefabUtility.IsPartOfNonAssetPrefabInstance(go));
    32.         EditorGUILayout.LabelField("IsPartOfPrefabAsset", "" + PrefabUtility.IsPartOfPrefabAsset(go));
    33.         EditorGUILayout.LabelField("IsPartOfPrefabInstance", "" + PrefabUtility.IsPartOfPrefabInstance(go));
    34.         EditorGUILayout.LabelField("IsPartOfPrefabThatCanBeAppliedTo", "" + PrefabUtility.IsPartOfPrefabThatCanBeAppliedTo(go));
    35.         EditorGUILayout.LabelField("IsPartOfRegularPrefab", "" + PrefabUtility.IsPartOfRegularPrefab(go));
    36.         EditorGUILayout.LabelField("IsPartOfVariantPrefab", "" + PrefabUtility.IsPartOfVariantPrefab(go));
    37.         EditorGUILayout.LabelField("IsPrefabAssetMissing", "" + PrefabUtility.IsPrefabAssetMissing(go));
    38.         EditorGUILayout.ObjectField("GetCorrespondingObjectFromOriginalSource", PrefabUtility.GetCorrespondingObjectFromOriginalSource(go), typeof(GameObject), allowSceneObjects: true);
    39.         EditorGUILayout.ObjectField("GetCorrespondingObjectFromSource", PrefabUtility.GetCorrespondingObjectFromSource(go), typeof(GameObject), allowSceneObjects: true);
    40.         EditorGUILayout.ObjectField("GetIconForGameObject", PrefabUtility.GetIconForGameObject(go), typeof(Texture), allowSceneObjects: true);
    41.         EditorGUILayout.ObjectField("GetNearestPrefabInstanceRoot", PrefabUtility.GetNearestPrefabInstanceRoot(go), typeof(GameObject), allowSceneObjects: true);
    42.         EditorGUILayout.ObjectField("GetOutermostPrefabInstanceRoot", PrefabUtility.GetOutermostPrefabInstanceRoot(go), typeof(GameObject), allowSceneObjects: true);
    43.         EditorGUILayout.TextField("GetPrefabAssetPathOfNearestInstanceRoot", PrefabUtility.GetPrefabAssetPathOfNearestInstanceRoot(go));
    44.         EditorGUILayout.LabelField("GetPrefabAssetType", PrefabUtility.GetPrefabAssetType(go).ToString());
    45.         EditorGUILayout.ObjectField("GetPrefabInstanceHandle", PrefabUtility.GetPrefabInstanceHandle(go), typeof(GameObject), allowSceneObjects: true);
    46.         EditorGUILayout.LabelField("GetPrefabInstanceStatus", PrefabUtility.GetPrefabInstanceStatus(go).ToString());
    47.     }
    48. }
    49.  
     
    Baste and SugoiDev like this.
unityunity