Unity Editor自定义窗口
简单的介绍一下 自定义窗口,将大部分考虑的布局都写了一下
希望有需要的朋友能够通过这片帖子,学到一些东西
先看效果图
直接上代码,一切尽在不言中
* 脚本必须在Editor 文件夹下*
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
public class FirstWindow : EditorWindow
{
string Label = "";
string description = "";
GameObject GameObject;
Texture2D Texture2D;
//利用构造函数来设置窗口名称
FirstWindow()
{
this.titleContent = new GUIContent("第一个窗口");
}
//添加菜单栏用于打开窗口
[MenuItem("Tool/打开窗口")]
static void showWindow()
{
EditorWindow.GetWindow(typeof(FirstWindow));
}
void OnGUI()
{
GUILayout.BeginVertical();
//标题
GUILayout.Space(10);
GUI.skin.label.fontSize = 24;
GUI.skin.label.alignment = TextAnchor.MiddleCenter;
GUILayout.Label("我的第一个窗口");
//时间
GUILayout.Space(10);
GUILayout.Label("Time:" + System.DateTime.Now);
//文本
GUILayout.Space(10);
Label = EditorGUILayout.TextField("标题:", "二月封");
Label = EditorGUILayout.TextField("时间:", "2018-9-7", GUILayout.Width(300));
//描述文本区域
GUILayout.Space(10);
GUILayout.BeginHorizontal();
GUI.skin.label.fontSize = 12;
GUI.skin.label.alignment = TextAnchor.UpperLeft;
GUILayout.Label("区域", GUILayout.MaxWidth(80));
description = EditorGUILayout.TextArea(description, GUILayout.MaxHeight(75));
GUILayout.EndHorizontal();
//对象
GUILayout.Space(10);
GameObject = (GameObject)EditorGUILayout.ObjectField("GameObject", GameObject, typeof(GameObject), true);
Texture2D = (Texture2D)EditorGUILayout.ObjectField("Texture2D", Texture2D, typeof(Texture2D), true);
//按钮
EditorGUILayout.Space();
if (GUILayout.Button("button"))
{
Debug.Log("这是第一个按钮");
}
//再加一层布局的按钮
GUILayout.BeginHorizontal();
if (GUILayout.Button("按钮二") )
{
Debug.Log("这是第二个按钮");
}
if (GUILayout.Button("按钮三"))
{
Debug.Log("这是第三个按钮");
}
GUILayout.EndHorizontal();
//再加一层布局的设置大小的按钮
GUILayout.BeginHorizontal();
if (GUILayout.Button("按钮四", GUILayout.Height(60), GUILayout.Width(200)))
{
Debug.Log("这是第四个按钮");
}
if (GUILayout.Button("按钮五", GUILayout.Height(60), GUILayout.Width(200)))
{
Debug.Log("这是第五个按钮");
}
if (GUILayout.Button("按钮六", GUILayout.Height(60), GUILayout.Width(200)))
{
Debug.Log("这是第六个按钮");
}
GUILayout.EndHorizontal();
GUILayout.EndVertical();
}
}
这就是全部的脚本了,各个布局直接分的很开,又看不懂的同学,也可以在评论里说一下