Tanoda
EditorResources.cs
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) Ultraleap, Inc. 2011-2020. *
3 * *
4 * Use subject to the terms of the Apache License 2.0 available at *
5 * http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
6 * between Ultraleap and you, your company or other organization. *
7 ******************************************************************************/
8
9using System.IO;
10using System.Linq;
11using UnityEngine;
12#if UNITY_EDITOR
13using UnityEditor;
14#endif
15
16namespace Leap.Unity {
17
18#if UNITY_EDITOR
19 public static class EditorResources {
20
25 public static T[] FindAllAssetsOfType<T>() where T : Object {
26 return AssetDatabase.FindAssets("t:" + typeof(T).Name).
27 Select(guid => AssetDatabase.GUIDToAssetPath(guid)).
28 Select(path => AssetDatabase.LoadAssetAtPath<T>(path)).
29 ToArray();
30 }
31
37 public static T Load<T>(string name) where T : Object {
38 foreach (var rootDir in Directory.GetDirectories("Assets", "EditorResources", SearchOption.AllDirectories)) {
39 string fullPath = Path.Combine(rootDir, name + ".dummy");
40 string fullDir = Path.GetDirectoryName(fullPath);
41 string fileName = Path.GetFileNameWithoutExtension(fullPath);
42
43 if (!Directory.Exists(fullDir)) {
44 continue;
45 }
46
47 foreach (var filename in Directory.GetFiles(fullDir, fileName + ".*")) {
48 if (!string.IsNullOrEmpty(AssetDatabase.AssetPathToGUID(filename))) {
49 return AssetDatabase.LoadAssetAtPath<T>(filename);
50 }
51 }
52 }
53 return null;
54 }
55 }
56#endif
57}
UnityEngine.Object Object