public FileDependencyFinder(Object target) { Asr.IsTrue(target, "Asset you're trying to search is corrupted"); Target = new SearchTarget(target, FindModeEnum.File); FindDependencies(); var path = AssetDatabase.GetAssetPath(Target.Target); Title = path; TabContent = new GUIContent { text = target.name, image = AssetDatabase.GetCachedIcon(path) }; }
public static T FirstOfType <T>() where T : Object { var typeName = typeof(T).Name; var guids = AssetDatabase.FindAssets(string.Format("t:{0}", typeName)); if (!guids.Any()) { AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate); } Asr.IsTrue(guids.Length > 0, string.Format("No '{0}' assets found", typeName)); return(guids.Select(g => AssetDatabase.GUIDToAssetPath(g)).Select(t => (T)AssetDatabase.LoadAssetAtPath(t, typeof(T))).First()); }
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; } }