public SearchTarget(Object target, FindModeEnum findMode, string sceneOrStagePath = null) { Asr.IsNotNull(target, "Asset you're trying to search is corrupted"); Target = target; var path = sceneOrStagePath ?? AssetDatabase.GetAssetPath(Target); switch (findMode) { case FindModeEnum.File: Asr.IsTrue(string.IsNullOrEmpty(sceneOrStagePath)); Root = AssetDatabase.LoadMainAssetAtPath(path); Nested = AufUtils.LoadAllAssetsAtPath(path); break; case FindModeEnum.Scene: case FindModeEnum.Stage: Root = Target; if (Target is GameObject go) { Nested = go.GetComponents <Component>().OfType <Object>().ToArray(); Stage = PrefabStageUtility.GetCurrentPrefabStage(); if (findMode == FindModeEnum.Scene) { if (string.IsNullOrEmpty(sceneOrStagePath)) { sceneOrStagePath = go.scene.path; } Scene = SceneManager.GetSceneByPath(sceneOrStagePath); } } else if (Target is Component c) { Nested = default; if (findMode == FindModeEnum.Scene) { if (string.IsNullOrEmpty(sceneOrStagePath)) { sceneOrStagePath = c.gameObject.scene.path; } Scene = SceneManager.GetSceneByPath(sceneOrStagePath); } } else { Nested = default; } break; } }
public SearchTarget(Object target, FindModeEnum findMode, string sceneOrStagePath = null) { Asr.IsNotNull(target, "Asset you're trying to search is corrupted"); Target = target; var path = sceneOrStagePath ?? AssetDatabase.GetAssetPath(Target); PrefabProperties properties = null; if (target.GetType() == typeof(GameObject)) { properties = PrefabUtilities.GetPrefabProperties(target as GameObject); } if (string.IsNullOrEmpty(sceneOrStagePath) && AssetDatabase.IsSubAsset(Target)) { Root = AssetDatabase.LoadMainAssetAtPath(path); Nested = AufUtils.LoadAllAssetsAtPath(path); //Nested = new[] { Target }; } else if (!string.IsNullOrEmpty(sceneOrStagePath) && Target is GameObject && findMode == FindModeEnum.Stage) { // object in Stage var gg = (GameObject)Target; Nested = gg.GetComponents <Component>().OfType <Object>().ToArray(); Stage = UnityEditor.Experimental.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage(); } else if (properties != null && (properties.IsRootOfAnyPrefab || properties.IsAssetRoot)) { Root = AssetDatabase.LoadMainAssetAtPath(path); Nested = AufUtils.LoadAllAssetsAtPath(path); } else if (properties != null && (properties.IsPartOfAnyPrefab || properties.IsPartOfPrefabAsset)) { if (target is GameObject go) { Nested = new[] { Target, } }