chenxin
2020-10-26 6f16dfb8bcebe67aeb95ded0d8b644af4932e690
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using UnityEngine;
 
namespace UnityEditor.PostProcessing
{
    using UnityObject = Object;
 
    static class EditorResources
    {
        static string m_EditorResourcesPath = string.Empty;
 
        internal static string editorResourcesPath
        {
            get
            {
                if (string.IsNullOrEmpty(m_EditorResourcesPath))
                {
                    string path;
 
                    if (SearchForEditorResourcesPath(out path))
                        m_EditorResourcesPath = path;
                    else
                        Debug.LogError("Unable to locate editor resources. Make sure the PostProcessing package has been installed correctly.");
                }
 
                return m_EditorResourcesPath;
            }
        }
 
        internal static T Load<T>(string name)
            where T : UnityObject
        {
            return AssetDatabase.LoadAssetAtPath<T>(editorResourcesPath + name);
        }
 
        static bool SearchForEditorResourcesPath(out string path)
        {
            path = string.Empty;
 
            string searchStr = "/PostProcessing/Editor Resources/";
            string str = null;
 
            foreach (var assetPath in AssetDatabase.GetAllAssetPaths())
            {
                if (assetPath.Contains(searchStr))
                {
                    str = assetPath;
                    break;
                }
            }
 
            if (str == null)
                return false;
 
            path = str.Substring(0, str.LastIndexOf(searchStr) + searchStr.Length);
            return true;
        }
    }
}