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)
            };
        }
示例#2
0
        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());
        }
示例#3
0
        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;
            }
        }
示例#4
0
        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, }
                }