提取Unity内置资源图标

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

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

示例代码


  1. using UnityEngine;
  2. using UnityEditor;
  3. using System;
  4. using System.Collections;
  5. using System.Reflection;
  6. using System.Collections.Generic;
  7.  
  8. public class BuiltInResourceWindow : EditorWindow
  9. {
  10. [MenuItem("Example/BuiltInResourceWindow")]
  11. static void Init()
  12. {
  13. EditorWindow window = EditorWindow.CreateInstance<BuiltInResourceWindow>();
  14. window.Show();
  15. }
  16.  
  17. List<Texture2D> builtInTexs = new List<Texture2D>();
  18. void GetBultinAsset()
  19. {
  20. var flags = BindingFlags.Static | BindingFlags.NonPublic;
  21. var info = typeof(EditorGUIUtility).GetMethod("GetEditorAssetBundle", flags);
  22. var bundle = info.Invoke(null, new object[0]) as AssetBundle;
  23. UnityEngine.Object[] objs = bundle.LoadAll();
  24. if (null != objs)
  25. {
  26. for (int i = 0; i < objs.Length; i++)
  27. {
  28. if (objs[i] is Texture2D)
  29. {
  30. builtInTexs.Add(objs[i] as Texture2D);
  31. }
  32. }
  33. }
  34. }
  35.  
  36. void OnEnable()
  37. {
  38. GetBultinAsset();
  39. }
  40.  
  41. Vector2 scrollPos = Vector2.zero;
  42. void OnGUI()
  43. {
  44. EditorGUILayout.BeginVertical();
  45. scrollPos = EditorGUILayout.BeginScrollView(scrollPos);
  46. for (int i = 0; i < builtInTexs.Count; i++)
  47. {
  48. EditorGUILayout.ObjectField(builtInTexs[i], typeof(Texture2D));
  49. }
  50. EditorGUILayout.EndScrollView();
  51. EditorGUILayout.EndVertical();
  52. }
  53. }


效果

11111.png

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

标签: Unity3d

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号