EditorGUI.ProgressBar()

作者:追风剑情 发布于:2019-6-15 21:15 分类:Unity3d

示例

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEditor;
  5.  
  6. [CustomEditor(typeof(Test))]
  7. [CanEditMultipleObjects]
  8. public class TestInspector : Editor
  9. {
  10. protected Test mTest;
  11. Gradient gradient;
  12. bool foldout = true;
  13.  
  14. protected virtual void OnEnable()
  15. {
  16. mTest = target as Test;
  17. gradient = new Gradient();
  18. }
  19.  
  20. public override void OnInspectorGUI()
  21. {
  22. base.OnInspectorGUI();
  23.  
  24. EditorGUILayout.BeginVertical();
  25.  
  26. EditorGUILayout.InspectorTitlebar(true, this);
  27. EditorGUILayout.InspectorTitlebar(false, this);
  28.  
  29. //文件夹图标
  30. //FindTexture()与IconContent()都可以获取到内建图标资源
  31. //内建资源列表参见:
  32. //https://www.cnblogs.com/CloudLiu/archive/2018/11/14/9957335.html
  33. Texture image = EditorGUIUtility.FindTexture("aboutwindow.mainheader");
  34. GUIContent content = EditorGUIUtility.IconContent("PointLight Gizmo", "Foldout");
  35. content.text = "Foldout";
  36. //content.image = image;
  37. //折叠图标
  38. foldout = EditorGUILayout.Foldout(foldout, content, true);
  39. if (foldout)
  40. {
  41. EditorGUILayout.LabelField("singleLineHeight=" + EditorGUIUtility.singleLineHeight);
  42. EditorGUILayout.LabelField("standardVerticalSpacing=" + EditorGUIUtility.standardVerticalSpacing);
  43. EditorGUILayout.Separator();
  44. }
  45.  
  46. //渐变色
  47. gradient = EditorGUILayout.GradientField(gradient);
  48.  
  49. //可选中文本的Label
  50. EditorGUILayout.SelectableLabel("ProgressBar", GUILayout.Height(18));
  51. EditorGUILayout.Separator();
  52.  
  53. //获取下一个GUI绘画区域
  54. Rect rect = GUILayoutUtility.GetLastRect();
  55. rect.height = 20;
  56. //进度条
  57. EditorGUI.ProgressBar(rect, 0.5f, "50%");
  58.  
  59. EditorGUILayout.Space();
  60. EditorGUILayout.Space();
  61. EditorGUILayout.Separator();
  62.  
  63. EditorGUILayout.EndVertical();
  64. }
  65. }

效果

1111.png

标签: Unity3d

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号