Unity 界面编辑实现如图所示界面(类似Console界面)

Unity 界面编辑实现如图所示界面(类似Console界面)

在这里插入图片描述

using System;
using UnityEditor;
using UnityEngine;

public class ZZSTestWindow02 : EditorWindow
{
    private ZZSScriptableObject _zzsScriptableObject;
    private const string saveZzsObjPath = "Assets/Scripts/ScriptableObject/ZzsScriptableObject.asset";
    private GUIContent firstGUIContent;
    private GUIContent secondGUIContent;
    private int firstSelectIndex = 0;
    private int secondSelectIndex = 0;
    private void OnInspectorUpdate()
    {
        Repaint();
    }
    private void OnGUI()
    {
        if (_zzsScriptableObject == null)
        {
            var guids = AssetDatabase.FindAssets("t:ZZSScriptableObject");
            if (guids != null && guids.Length > 0)
            {
                _zzsScriptableObject = AssetDatabase.LoadAssetAtPath<ZZSScriptableObject>(AssetDatabase.GUIDToAssetPath(guids[0]));
            }
            GUILayout.Space(50);
            if (GUILayout.Button("Create ZzsScriptableObject"))
            {
                var zzsObj = CreateInstance<ZZSScriptableObject>();
                AssetDatabase.CreateAsset(zzsObj,saveZzsObjPath);
            }
            return;
        }
        GUILayout.BeginHorizontal(GUI.skin.box);
        {
            if (firstGUIContent == null)
                firstGUIContent = new GUIContent("First Test");
            var r1 = GUILayoutUtility.GetRect(firstGUIContent, EditorStyles.toolbarDropDown, GUILayout.Width(200));
            if (EditorGUI.DropdownButton(r1, firstGUIContent, FocusType.Passive, EditorStyles.toolbarDropDown))
            {
                var menu = new GenericMenu();
                for (int i = 0; i < 5; i++)
                {
                    menu.AddItem(new GUIContent($"Test{i}"),i==firstSelectIndex, (index) =>
                    {
                        firstSelectIndex = (int) index;
                    },i);
                }
                menu.DropDown(r1);
            }
            
            if(secondGUIContent == null)
                secondGUIContent = new GUIContent("Second Test");
            var r2 = GUILayoutUtility.GetRect(secondGUIContent, EditorStyles.toolbarDropDown, GUILayout.Width(200));
            if (EditorGUI.DropdownButton(r2, secondGUIContent, FocusType.Passive, EditorStyles.toolbarDropDown))
            {
                var menu = new GenericMenu();
                for (int i = 0; i < 5; i++)
                {
                    menu.AddItem(new GUIContent($"Test{i}"),i==secondSelectIndex, (index) =>
                    {
                        secondSelectIndex = (int) index;
                    },i);
                }
                menu.DropDown(r2);
            }
            
            GUILayout.FlexibleSpace();
            for (int i = 0; i < 3; i++)
            {
                var buttonGuiContent = new GUIContent("Test Button"+i);
                var r3 = GUILayoutUtility.GetRect(buttonGuiContent, EditorStyles.miniButton,GUILayout.Width(100));
                if(GUI.Button(r3,buttonGuiContent))
                    Debug.Log($"按钮{i}点击");
            }
        }
        GUILayout.EndHorizontal();
        
        //DrawLst
        foreach (var str in _zzsScriptableObject.allStr)
        {
            GUILayout.Label(str);
        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值