IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 游戏开发 -> UnityEditor 默认样式大全 -> 正文阅读

[游戏开发]UnityEditor 默认样式大全

前提:使用EditorGUI写UnityEditor样式,想要好看点
设计:把unity 内置的样式查看一遍
GUI:
在这里插入图片描述

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

namespace ToolKits
{
    public class BuiltInResourcesWindow : EditorWindow
    {
        [MenuItem("Tools/GUIStyles Preview", priority = 4)]
        public static void ShowWindow()
        {
            BuiltInResourcesWindow w =
                (BuiltInResourcesWindow) EditorWindow.GetWindow<BuiltInResourcesWindow>("GUIStyles Preview");
            w.Show();
        }

        private struct Drawing
        {
            public Rect Rect;
            public System.Action Draw;
        }

        private List<Drawing> Drawings;

        private List<UnityEngine.Object> _objects;
        private float _scrollPos;
        private float _maxY;
        private Rect _oldPosition;

        private bool _showingStyles = true;
        private bool _showingIcons = false;

        private string _search = "";

        void OnGUI()
        {
            if (position.width != _oldPosition.width && Event.current.type == EventType.Layout)
            {
                Drawings = null;
                _oldPosition = position;
            }

            // GUILayout.BeginHorizontal();
            //
            // if (GUILayout.Toggle(_showingStyles, "Styles", EditorStyles.toolbarButton) != _showingStyles)
            // {
            //     _showingStyles = !_showingStyles;
            //     _showingIcons = !_showingStyles;
            //     Drawings = null;
            // }

            // if (GUILayout.Toggle(_showingIcons, "Icons", EditorStyles.toolbarButton) != _showingIcons)
            // {
            //     _showingIcons = !_showingIcons;
            //     _showingStyles = !_showingIcons;
            //     Drawings = null;
            // }

            // GUILayout.EndHorizontal();

            GUILayout.Button("Styles");
            string newSearch = GUILayout.TextField(_search);
            if (newSearch != _search)
            {
                _search = newSearch;
                Drawings = null;
            }

            float top = 36;

            if (Drawings == null)
            {
                string lowerSearch = _search.ToLower();

                Drawings = new List<Drawing>();

                GUIContent inactiveText = new GUIContent("inactive");
                GUIContent activeText = new GUIContent("active");

                float x = 5.0f;
                float y = 5.0f;

                if (_showingStyles)
                {
                    foreach (GUIStyle ss in GUI.skin)
                    {
                        if (lowerSearch != "" && !ss.name.ToLower().Contains(lowerSearch))
                            continue;

                        GUIStyle thisStyle = ss;

                        Drawing draw = new Drawing();

                        float width = Mathf.Max(
                            100.0f,
                            GUI.skin.button.CalcSize(new GUIContent(ss.name)).x,
                            ss.CalcSize(inactiveText).x + ss.CalcSize(activeText).x
                        ) + 16.0f;

                        float height = 60.0f;

                        if (x + width > position.width - 32 && x > 5.0f)
                        {
                            x = 5.0f;
                            y += height + 10.0f;
                        }

                        draw.Rect = new Rect(x, y, width, height);

                        width -= 8.0f;

                        draw.Draw = () =>
                        {
                            if (GUILayout.Button(thisStyle.name, GUILayout.Width(width)))
                                CopyText("(GUIStyle)\"" + thisStyle.name + "\"");

                            GUILayout.BeginHorizontal();
                            GUILayout.Toggle(true, inactiveText, thisStyle, GUILayout.Width(width / 2));
                            GUILayout.Toggle(false, activeText, thisStyle, GUILayout.Width(width / 2));
                            GUILayout.EndHorizontal();
                        };

                        x += width + 18.0f;

                        Drawings.Add(draw);
                    }
                }

                _maxY = y;
            }

            Rect r = position;
            r.y = top;
            r.height -= r.y;
            r.x = r.width - 16;
            r.width = 16;

            float areaHeight = position.height - top;
            _scrollPos = GUI.VerticalScrollbar(r, _scrollPos, areaHeight, 0.0f, _maxY);

            Rect area = new Rect(0, top, position.width - 16.0f, areaHeight);
            GUILayout.BeginArea(area);
            int count = 0;
            foreach (Drawing draw in Drawings)
            {
                Rect newRect = draw.Rect;
                newRect.y -= _scrollPos;

                if (newRect.y + newRect.height > 0 && newRect.y < areaHeight)
                {
                    GUILayout.BeginArea(newRect, GUI.skin.textField);
                    draw.Draw();
                    GUILayout.EndArea();

                    count++;
                }
            }

            GUILayout.EndArea();
        }

        void CopyText(string pText)
        {
            TextEditor editor = new TextEditor();

            //editor.content = new GUIContent(pText); // Unity 4.x code
            editor.text = pText; // Unity 5.x code

            editor.SelectAll();
            editor.Copy();
        }
    }
}
  游戏开发 最新文章
6、英飞凌-AURIX-TC3XX: PWM实验之使用 GT
泛型自动装箱
CubeMax添加Rtthread操作系统 组件STM32F10
python多线程编程:如何优雅地关闭线程
数据类型隐式转换导致的阻塞
WebAPi实现多文件上传,并附带参数
from origin ‘null‘ has been blocked by
UE4 蓝图调用C++函数(附带项目工程)
Unity学习笔记(一)结构体的简单理解与应用
【Memory As a Programming Concept in C a
上一篇文章      下一篇文章      查看所有文章
加:2021-08-07 12:24:41  更:2021-08-07 12:25:44 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年5日历 -2024/5/3 11:56:55-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码