提取Unity内置资源图标

作者:追风剑情 发布于:2017-12-27 11:37 分类:Unity3d

参考 http://blog.csdn.net/warrenmondeville/article/details/53247181

示例代码


using UnityEngine;
using UnityEditor;
using System;
using System.Collections;
using System.Reflection;
using System.Collections.Generic;

public class BuiltInResourceWindow : EditorWindow
{
    [MenuItem("Example/BuiltInResourceWindow")]
    static void Init()
    {
        EditorWindow window = EditorWindow.CreateInstance<BuiltInResourceWindow>();
        window.Show();
    }

    List<Texture2D> builtInTexs = new List<Texture2D>();
    void GetBultinAsset()
    {
        var flags = BindingFlags.Static | BindingFlags.NonPublic;
        var info = typeof(EditorGUIUtility).GetMethod("GetEditorAssetBundle", flags);
        var bundle = info.Invoke(null, new object[0]) as AssetBundle;
        UnityEngine.Object[] objs = bundle.LoadAll();
        if (null != objs)
        {
            for (int i = 0; i < objs.Length; i++)
            {
                if (objs[i] is Texture2D)
                {
                    builtInTexs.Add(objs[i] as Texture2D);
                }
            }
        }
    }

    void OnEnable()
    {
        GetBultinAsset();
    }

    Vector2 scrollPos = Vector2.zero;
    void OnGUI()
    {
        EditorGUILayout.BeginVertical();
        scrollPos = EditorGUILayout.BeginScrollView(scrollPos);
        for (int i = 0; i < builtInTexs.Count; i++)
        {
            EditorGUILayout.ObjectField(builtInTexs[i], typeof(Texture2D));
        }
        EditorGUILayout.EndScrollView();
        EditorGUILayout.EndVertical();
    }
}


效果

11111.png

Unity2017内置字体
Font font = Resources.GetBuiltinResource<Font>("Arial.ttf");

标签: Unity3d

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号