-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathPopAssetDatabase.cs
More file actions
42 lines (35 loc) · 926 Bytes
/
PopAssetDatabase.cs
File metadata and controls
42 lines (35 loc) · 926 Bytes
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
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
#if UNITY_EDITOR
using UnityEditor;
#endif
public static class PopAssetDatabase
{
public static string GetTypeAssetTypeName(System.Type Type)
{
#if UNITY_EDITOR
// some special cases
if (Type == typeof(SceneAsset))
return "scene";
#endif
return Type.Name;
}
// gr: maybe should allow this in production, but find assets from somewhere else? resources?
#if UNITY_EDITOR
public static List<T> GetAssets<T>(string Filter=null) where T : UnityEngine.Object
{
var Assets = new List<T>();
// get all guids
var Typename = GetTypeAssetTypeName(typeof(T));
var Guids = AssetDatabase.FindAssets("t:" + Typename + " " + Filter );
foreach ( var Guid in Guids )
{
var Path = AssetDatabase.GUIDToAssetPath(Guid);
var Asset = AssetDatabase.LoadAssetAtPath<T>(Path);
Assets.Add(Asset);
}
return Assets;
}
#endif
}