けいごのなんとか

Unityユーザーとしてのブログ。ギリギリ路線走ってます。

UnityEditorのAssetBundleを取得する

アイコンとかマテリアルとかいーっぱい

EditorGUIUtility.GetEditorAssetBundleで取得できる

実はEditorGUIUtility.LoadはこのAssetBundleからロードしていたりする

f:id:anchan828:20130717040755p:plain

使う時はこんな感じ

Texture2D icon = EditorGUIUtility.Load ("Icons/Generated/PrefabNormal Icon.asset") as Texture2D;
using UnityEngine;
using System.Reflection;
using UnityEditor;
public class EditorAssetBundle : EditorWindow
{
    Object[] objs;
    [MenuItem("Window/EditorAssetBundle")]
    static void Do ()
    {
        GetWindow<EditorAssetBundle> ();
    }
    void OnEnable ()
    {
        MethodInfo info = typeof(EditorGUIUtility).GetMethod ("GetEditorAssetBundle", BindingFlags.Static | BindingFlags.NonPublic);
        AssetBundle bundle = info.Invoke (null, new object[0]) as AssetBundle;
        objs = bundle.LoadAll ();
    }
    void OnDisable ()
    {
        objs = null;
        EditorUtility.UnloadUnusedAssets ();
    }

    Vector2 pos;
    void OnGUI ()
    {
        pos = EditorGUILayout.BeginScrollView (pos);
        foreach (Object texture in objs) {
            GUILayout.Label (EditorGUIUtility.ObjectContent (texture, texture.GetType ()));
        }
        EditorGUILayout.EndScrollView ();
    }
}