Unity之EditorWindow-window
2017-09-14 本文已影响9人
循环渐进123456
转载:http://blog.csdn.net/liqiangeastsun/article/details/42173669
Unity编辑器类在菜单栏创建一个按钮,点击按钮创建一个Window(窗口)
点击 “Improved copy buffer”跳出如下界面
点击 按钮
点击 “Clear all saves” 将所有缓存清除
在Editor文件夹下创建脚本 dfdff
using UnityEngine;
using System.Collections;
using UnityEditor;
public class dfdff : EditorWindow {
public string[] savedCopies = new string[5]; //定义一个字符串数组
public bool load = false;
[MenuItem("Examples/Improved copy buffer")] //在工具栏创建按钮
static void Init() {
dfdff window = (dfdff)EditorWindow.GetWindow(typeof(dfdff)); //定义一个窗口对象
}
void OnGUI() {
load = EditorGUILayout.Toggle("Load:", load); //创建一个 Toggle
EditorGUILayout.BeginHorizontal(); //开始水平布局
for (int i = 0; i < savedCopies.Length; i++)
{
if (GUILayout.Button(i.ToString())) // 创建这些按钮,并且当点击按钮时触发条件
{
if (load)
{
EditorGUIUtility.systemCopyBuffer = savedCopies[i]; // 获取值
}
else
{
savedCopies[i] = "123"; //给每一个字符串赋值
}
}
}
EditorGUILayout.EndHorizontal(); //结束水平布局
for (int j = 0; j < savedCopies.Length; j++)
{
EditorGUILayout.LabelField("Saved " + j, savedCopies[j]); //将所有已字符串以Label的形式显示出来
}
EditorGUILayout.LabelField("Current buffer:", EditorGUIUtility.systemCopyBuffer); //将获取的值以Label的形式显示出来
if(GUILayout.Button("Clear all saves")) //清空所有的缓存
{
int i = 0;
foreach (string s in savedCopies)
{
savedCopies[i] = "";
i++;
}
}
}
void OnInspectorUpdate() {
this.Repaint(); //重新画窗口
}
}