Skip to content

Instantly share code, notes, and snippets.

@unitycoder
Forked from idbrii/PrefabDetector.cs
Created March 5, 2023 09:43
Show Gist options
  • Select an option

  • Save unitycoder/41d14053cbec12359c93e16f86ae34cd to your computer and use it in GitHub Desktop.

Select an option

Save unitycoder/41d14053cbec12359c93e16f86ae34cd to your computer and use it in GitHub Desktop.

Revisions

  1. @idbrii idbrii created this gist Oct 17, 2020.
    84 changes: 84 additions & 0 deletions PrefabDetector.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,84 @@
    // public domain
    // Add to Scripts/Editor/PrefabDetector.cs
    using System.Collections.Generic;
    using System.Collections;
    using System.Linq;
    using System;
    using UnityEditor.Experimental.SceneManagement;
    using UnityEditor.SceneManagement;
    using UnityEditor;
    using UnityEngine;

    using Debug = UnityEngine.Debug;
    using Object = UnityEngine.Object;

    namespace idbrii
    {
    public class PrefabDetector : EditorWindow
    {
    [MenuItem("Tools/PrefabDetector")]
    static void ShowToolbar()
    {
    EditorWindow.GetWindow<PrefabDetector>("PrefabDetector");
    }

    private Vector2 scroll;
    public void OnGUI()
    {
    var go = Selection.activeGameObject;
    if (go == null)
    {
    EditorGUILayout.HelpBox("Select a gameobject to examine.", MessageType.Info);
    return;
    }

    EditorGUIUtility.labelWidth = 300;
    scroll = EditorGUILayout.BeginScrollView(scroll);
    {
    EditorGUILayout.ObjectField("Selection", go, typeof(GameObject), allowSceneObjects: true);

    EditorGUILayout.Space();
    EditorGUILayout.LabelField("PrefabStageUtility", EditorStyles.boldLabel);

    var stage = PrefabStageUtility.GetCurrentPrefabStage();
    EditorGUILayout.LabelField("GetCurrentPrefabStage", stage != null ? "has stage" : "null");
    if (stage != null)
    {
    EditorGUILayout.LabelField("IsPartOfPrefabContents", "" + stage.IsPartOfPrefabContents(go));
    }

    EditorGUILayout.Space();
    EditorGUILayout.LabelField("PrefabUtility", EditorStyles.boldLabel);

    EditorGUILayout.LabelField("IsAddedComponentOverride", "" + PrefabUtility.IsAddedComponentOverride(go));
    EditorGUILayout.LabelField("IsAddedGameObjectOverride", "" + PrefabUtility.IsAddedGameObjectOverride(go));
    EditorGUILayout.LabelField("IsAnyPrefabInstanceRoot", "" + PrefabUtility.IsAnyPrefabInstanceRoot(go));
    EditorGUILayout.LabelField("IsDisconnectedFromPrefabAsset", "" + PrefabUtility.IsDisconnectedFromPrefabAsset(go));
    EditorGUILayout.LabelField("IsOutermostPrefabInstanceRoot", "" + PrefabUtility.IsOutermostPrefabInstanceRoot(go));
    EditorGUILayout.LabelField("IsPartOfAnyPrefab", "" + PrefabUtility.IsPartOfAnyPrefab(go));
    EditorGUILayout.LabelField("IsPartOfImmutablePrefab", "" + PrefabUtility.IsPartOfImmutablePrefab(go));
    EditorGUILayout.LabelField("IsPartOfModelPrefab", "" + PrefabUtility.IsPartOfModelPrefab(go));
    EditorGUILayout.LabelField("IsPartOfNonAssetPrefabInstance", "" + PrefabUtility.IsPartOfNonAssetPrefabInstance(go));
    EditorGUILayout.LabelField("IsPartOfPrefabAsset", "" + PrefabUtility.IsPartOfPrefabAsset(go));
    EditorGUILayout.LabelField("IsPartOfPrefabInstance", "" + PrefabUtility.IsPartOfPrefabInstance(go));
    EditorGUILayout.LabelField("IsPartOfPrefabThatCanBeAppliedTo", "" + PrefabUtility.IsPartOfPrefabThatCanBeAppliedTo(go));
    EditorGUILayout.LabelField("IsPartOfRegularPrefab", "" + PrefabUtility.IsPartOfRegularPrefab(go));
    EditorGUILayout.LabelField("IsPartOfVariantPrefab", "" + PrefabUtility.IsPartOfVariantPrefab(go));
    EditorGUILayout.LabelField("IsPrefabAssetMissing", "" + PrefabUtility.IsPrefabAssetMissing(go));

    EditorGUILayout.ObjectField("GetCorrespondingObjectFromOriginalSource", PrefabUtility.GetCorrespondingObjectFromOriginalSource(go), typeof(GameObject), allowSceneObjects: true);
    EditorGUILayout.ObjectField("GetCorrespondingObjectFromSource", PrefabUtility.GetCorrespondingObjectFromSource(go), typeof(GameObject), allowSceneObjects: true);
    EditorGUILayout.ObjectField("GetIconForGameObject", PrefabUtility.GetIconForGameObject(go), typeof(Texture), allowSceneObjects: true);
    EditorGUILayout.ObjectField("GetNearestPrefabInstanceRoot", PrefabUtility.GetNearestPrefabInstanceRoot(go), typeof(GameObject), allowSceneObjects: true);
    EditorGUILayout.ObjectField("GetOutermostPrefabInstanceRoot", PrefabUtility.GetOutermostPrefabInstanceRoot(go), typeof(GameObject), allowSceneObjects: true);
    EditorGUILayout.TextField("GetPrefabAssetPathOfNearestInstanceRoot", PrefabUtility.GetPrefabAssetPathOfNearestInstanceRoot(go));
    EditorGUILayout.LabelField("GetPrefabAssetType", PrefabUtility.GetPrefabAssetType(go).ToString());
    EditorGUILayout.ObjectField("GetPrefabInstanceHandle", PrefabUtility.GetPrefabInstanceHandle(go), typeof(GameObject), allowSceneObjects: true);
    EditorGUILayout.LabelField("GetPrefabInstanceStatus", PrefabUtility.GetPrefabInstanceStatus(go).ToString());

    }
    EditorGUILayout.EndScrollView();
    }

    }
    }