EditorGUI.ProgressBar()

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

示例

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

[CustomEditor(typeof(Test))]
[CanEditMultipleObjects]
public class TestInspector : Editor
{
    protected Test mTest;
    Gradient gradient;
    bool foldout = true;

    protected virtual void OnEnable()
    {
        mTest = target as Test;
        gradient = new Gradient();
    }

    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        EditorGUILayout.BeginVertical();

        EditorGUILayout.InspectorTitlebar(true, this);
        EditorGUILayout.InspectorTitlebar(false, this);

        //文件夹图标
        //FindTexture()与IconContent()都可以获取到内建图标资源
        //内建资源列表参见:
        //https://www.cnblogs.com/CloudLiu/archive/2018/11/14/9957335.html
        Texture image = EditorGUIUtility.FindTexture("aboutwindow.mainheader");
        GUIContent content = EditorGUIUtility.IconContent("PointLight Gizmo", "Foldout");
        content.text = "Foldout";
        //content.image = image;
        //折叠图标
        foldout = EditorGUILayout.Foldout(foldout, content, true);
        if (foldout)
        {
            EditorGUILayout.LabelField("singleLineHeight=" + EditorGUIUtility.singleLineHeight);
            EditorGUILayout.LabelField("standardVerticalSpacing=" + EditorGUIUtility.standardVerticalSpacing);
            EditorGUILayout.Separator();
        }

        //渐变色
        gradient = EditorGUILayout.GradientField(gradient);

        //可选中文本的Label
        EditorGUILayout.SelectableLabel("ProgressBar", GUILayout.Height(18));
        EditorGUILayout.Separator();

        //获取下一个GUI绘画区域
        Rect rect = GUILayoutUtility.GetLastRect();
        rect.height = 20;
        //进度条
        EditorGUI.ProgressBar(rect, 0.5f, "50%");

        EditorGUILayout.Space();
        EditorGUILayout.Space();
        EditorGUILayout.Separator();

        EditorGUILayout.EndVertical();
    }
}

效果

1111.png

标签: Unity3d

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号