EditorHelper.cs 1.13 KB
Newer Older
cann-alberto's avatar
cann-alberto committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEngine;

namespace Mirror
{
    public static class EditorHelper
    {
        public static string FindPath<T>()
        {
            string typeName = typeof(T).Name;

            string[] guidsFound = AssetDatabase.FindAssets($"t:Script {typeName}");
            if (guidsFound.Length >= 1 && !string.IsNullOrWhiteSpace(guidsFound[0]))
            {
                if (guidsFound.Length > 1)
                {
                    Debug.LogWarning($"Found more than one{typeName}");
                }

                string path = AssetDatabase.GUIDToAssetPath(guidsFound[0]);
                return Path.GetDirectoryName(path);
            }
            else
            {
                Debug.LogError($"Could not find path of {typeName}");
                return string.Empty;
            }
        }


        public static IEnumerable<string> IterateOverProject(string filter)
        {
            foreach (string guid in AssetDatabase.FindAssets(filter))
            {
                yield return AssetDatabase.GUIDToAssetPath(guid);
            }
        }
    }
}