Unity编辑器中的所有窗口的绘制都继承自EditorWindow类,并且需要引入UnityEditor的命名空间,使用类中的方法自定义任何所需的窗口 ——窗口Window ——标签Label Project目录下右键—Create—GUI Skin可以看到所有可修改的属性 ——文本字段TextField ——密码字段PasswordField ——整数字段IntField、浮点数字段FloatField ——二维向量字段Vector2Field、三维向量字段Vector3Field ——物体字段ObjectField ——颜色字段ColorField ——标签字段TagField ——层级字段LayerField ——按钮Button ——多行文本TextArea ——单选框Toggle ——开关组 ——可选择文本SelectableLabel(用于需要复制的文本) ——滑动条Slider、整数滑动条IntSlider ——字符串类型的弹出选择菜单Popup ——枚举类型的弹出选择菜单Popup ——工具栏Toolbar ——显示提示信息 ——显示帮助信息HelpBox ——打开本地文件夹 一:实现思路
二:代码实现
[MenuItem("工具栏层级")] private static void ShowWindow() { GetWindow(typeof(TestWindow), true, "测试窗口"); }
private void OnGUI() { GUI.skin.label.fontSize = 20; GUI.skin.label.fontStyle = FontStyle.Bold; GUI.skin.label.alignment = TextAnchor.MiddleCenter; GUILayout.Label("测试窗口"); GUILayout.Label(Resources.Load<Texture>("Resources文件夹下的图片路径")); }
string txt; private void OnGUI() { txt = EditorGUILayout.TextField("输入文本:", txt); }
string txt; private void OnGUI() { txt = EditorGUILayout.PasswordField("密码:", txt); }
int value_int; float value_float; private void OnGUI() { value_int = EditorGUILayout.IntField("输入整数:", value_int); value_float = EditorGUILayout.FloatField("输入浮点数:", value_float); }
private Vector3 v3; private Vector3 v2; private void OnGUI() { v3 = EditorGUILayout.Vector3Field("三维向量", v3); v2 = EditorGUILayout.Vector2Field("二维向量", v2); }
GameObject go; Camera camera; private void OnGUI() { go = (GameObject)EditorGUILayout.ObjectField("赋值物体", go, typeof(GameObject), true); camera = (Camera)EditorGUILayout.ObjectField("赋值相机", camera, typeof(Camera), true); }
private Color color; private void OnGUI() { color = EditorGUILayout.ColorField("颜色", color); }
private string tag; private void OnGUI() { tag = EditorGUILayout.TagField("tag", tag); }
private int layer; private void OnGUI() { layer = EditorGUILayout.LayerField("layer", layer); }
private void OnGUI() { if (GUILayout.Button("按钮", GUILayout.Width(50), GUILayout.Height(50))) { //按下按钮后执行的方法 } }
string txt; private void OnGUI() { GUILayout.BeginHorizontal(); GUILayout.Label("输入文本:",GUILayout.MaxWidth(50)); txt = EditorGUILayout.TextArea(txt, GUILayout.MaxHeight(50)); GUILayout.EndHorizontal(); }
bool b; private void OnGUI() { b = EditorGUILayout.Toggle("单选框", b); }
GameObject go; string txt; bool b; private void OnGUI() { b = EditorGUILayout.BeginToggleGroup("开启区域", b); txt = EditorGUILayout.TextField("输入文本:", txt); go = (GameObject)EditorGUILayout.ObjectField("赋值物体", go, typeof(GameObject), true); EditorGUILayout.EndToggleGroup(); }
private void OnGUI() { EditorGUILayout.SelectableLabel("微信号:597094538"); }
int value_int; float value_float; private void OnGUI() { value_float = EditorGUILayout.Slider("滑动条", value_float, 1, 10); value_int = EditorGUILayout.IntSlider("滑动条", value_int, 1, 10); }
private int index = 0; string[] values = { "value1", "value2", "value3" }; private void OnGUI() { index = EditorGUILayout.Popup("选择", index, values); }
public enum Value { Value1, Value2, Value3, } private Value value; private void OnGUI() { value = (Value)EditorGUILayout.EnumPopup("选择", value); }
string[] values = { "Menu1", "Menu2", "Menu3" }; private int index = 0; //string[] values = { "value1", "value2", "value3" }; private void OnGUI() { index = GUILayout.Toolbar(index, values); if (index == 0) { EditorGUILayout.LabelField("this is menu1"); } else if (index == 1) { EditorGUILayout.LabelField("this is menu2"); } }
private void OnGUI() { if (GUILayout.Button("显示提示信息")) { ShowNotification(new GUIContent("this is a Notification")); } if (GUILayout.Button("关闭提示信息")) { RemoveNotification(); } }
private void OnGUI() { EditorGUILayout.HelpBox("帮助信息", MessageType.None); EditorGUILayout.HelpBox("警告提示", MessageType.Warning); }
private string path; private void OnGUI() { EditorGUILayout.TextField(path); if (GUILayout.Button("存储路径")) { path = EditorUtility.SaveFolderPanel("Path to Save", path, Application.dataPath); } }
三:绘制一个自定义的Debug窗口
using UnityEditor; using UnityEngine; using UnityEngine.SceneManagement; using System.IO; public class DebugWindow : EditorWindow { [MenuItem("Tools/Show DebugWindow")] private static void ShowWindow() { GetWindow(typeof(DebugWindow), true, "Debug窗口", true); } int toolbarIndex; string[] toolbarStr = { "Error反馈窗口", "Warning反馈窗口" }; bool haveError; bool haveErrorDes; string errorName; GameObject errorGo; string errorDes; string[] errorType = { "普通", "一般", "严重" }; private int errorTypeIndex; string errorPath; private void OnGUI() { toolbarIndex = GUILayout.Toolbar(toolbarIndex, toolbarStr); if (toolbarIndex == 0) { //标题标签 GUI.skin.label.fontSize = 20; GUI.skin.label.fontStyle = FontStyle.Bold; GUI.skin.label.alignment = TextAnchor.MiddleCenter; GUILayout.Label("Error反馈窗口"); haveError = EditorGUILayout.Toggle("是否有Error", haveError); if (haveError) { //问题名 errorName = EditorGUILayout.TextField("问题名", errorName); if (errorName != null) { if (errorName.Length == 0 || errorName == "") { EditorGUILayout.HelpBox("问题名不能为空", MessageType.Error); } else if (errorName.Length >= 5) { EditorGUILayout.HelpBox("问题名过长", MessageType.Warning); } else { EditorGUILayout.HelpBox("问题名合法", MessageType.Info); } } //出现问题的时间 EditorGUILayout.LabelField("当前时间", System.DateTime.Now.ToString()); //出现问题的场景 EditorGUILayout.LabelField("当前场景", SceneManager.GetActiveScene().name); //出现问题的物体 errorGo = (GameObject)EditorGUILayout.ObjectField("问题物体", errorGo, typeof(GameObject), true); //问题描述 haveErrorDes = EditorGUILayout.BeginToggleGroup("是否添加问题描述", haveErrorDes); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("问题描述:", GUILayout.MaxWidth(50)); EditorGUILayout.TextArea(errorDes, GUILayout.MaxHeight(50)); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndToggleGroup(); //问题类型 errorTypeIndex = EditorGUILayout.Popup("问题类型", errorTypeIndex, errorType); //问题保存路径 EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("选择路径")) { errorPath = EditorUtility.SaveFolderPanel("Path to Save", errorPath, Application.dataPath); } EditorGUILayout.TextField(errorPath); EditorGUILayout.EndHorizontal(); GUILayout.Space(50); //保存到本地 if (GUILayout.Button("保存")) { if (errorPath == null) { ShowNotification(new GUIContent("请先选择保存路径"), 1); } else { Directory.CreateDirectory(errorPath + "/BugReports"); StreamWriter sw = new StreamWriter(errorPath + "/BugReports/" + errorName + ".txt"); sw.WriteLine("Error or Warning:" + toolbarStr[toolbarIndex]); sw.WriteLine("问题名:" + errorName); sw.WriteLine("出现问题的时间:" + System.DateTime.Now.ToString()); sw.WriteLine("出现问题的场景:" + SceneManager.GetActiveScene().name); sw.WriteLine("问题描述:" + errorDes); sw.WriteLine("问题类型:" + errorType); sw.WriteLine("问题存储路径:" + errorPath); sw.Close(); } } } } else if (toolbarIndex == 1) { GUI.skin.label.fontSize = 20; GUI.skin.label.fontStyle = FontStyle.Bold; GUI.skin.label.alignment = TextAnchor.MiddleCenter; GUILayout.Label("Warning反馈窗口"); //其他的与Error反馈窗口基本相同 } } }
本网页所有视频内容由 imoviebox边看边下-网页视频下载, iurlBox网页地址收藏管理器 下载并得到。
ImovieBox网页视频下载器 下载地址: ImovieBox网页视频下载器-最新版本下载
本文章由: imapbox邮箱云存储,邮箱网盘,ImageBox 图片批量下载器,网页图片批量下载专家,网页图片批量下载器,获取到文章图片,imoviebox网页视频批量下载器,下载视频内容,为您提供.
阅读和此文章类似的: 全球云计算