EditorGUILayout.Toggle()

作者:追风剑情 发布于:2019-5-7 11:47 分类:Unity3d

示例

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

public class GUIStyleWindow : EditorWindow
{
    private bool group = true;
    private bool A = true;
    private bool B = false;
    private bool C = true;
    private bool D = false;
    private bool E = false;

    void OnGUI()
    {
        group = EditorGUILayout.BeginToggleGroup("Toggle Group", group);
        //复选按钮风格
        A = EditorGUILayout.ToggleLeft("Select A", A);
        B = EditorGUILayout.ToggleLeft("Select B", B);

        GUILayout.Space(10);

        //单选按钮风格
        // EditorStyles只会影响右侧风格
        EditorGUI.BeginChangeCheck();
        C = EditorGUILayout.Toggle("Select C", C, EditorStyles.radioButton);
        if (EditorGUI.EndChangeCheck())
        {
            if (C) D = E = false;
            else C = true;
        }

        EditorGUI.BeginChangeCheck();
        D = EditorGUILayout.Toggle("Select D", D, EditorStyles.radioButton);
        if (EditorGUI.EndChangeCheck())
        {
            if (D) C = E = false;
            else D = true;
        }

        EditorGUI.BeginChangeCheck();
        E = EditorGUILayout.Toggle("Select E", E, EditorStyles.radioButton);
        if (EditorGUI.EndChangeCheck())
        {
            if (E) C = D = false;
            else E = true;
        }
        EditorGUILayout.EndToggleGroup();
    }

    [MenuItem("MyWindow/ToggleGroup")]
    static void ShowWindow()
    {
        var window = GetWindow<GUIStyleWindow>();
        window.titleContent = new GUIContent("My Window");
        window.Show();
    }
}

效果

11111.png

标签: Unity3d

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号