赞
踩
目录
EditorWindow的简单用法之前都用过了,这里介绍一些特殊的用法
在Editor下创建脚本如下:
using UnityEditor;
using UnityEngine;
public class WindowExample1 : EditorWindow
{
[MenuItem("Window/WindowExample1")]
static void Open ()
{
GetWindow<WindowExample1> ();
}
ExamplePupupContent popupContent = new ExamplePupupContent ();
void OnGUI ()
{
if (GUILayout.Button ("PopupContent",GUILayout.Width(128))) {
var activatorRect = GUILayoutUtility.GetLastRect ();
PopupWindow.Show (activatorRect, popupContent);
}
}
}
//弹窗
public class ExamplePupupContent : PopupWindowContent
{
public override void OnGUI (Rect rect)
{
EditorGUILayout.LabelField ("Lebel");
}
public override void OnOpen ()
{
Debug.Log ("打开窗口");
}
public override void OnClose ()
{
Debug.Log ("关闭窗口");
}
public override Vector2 GetWindowSize ()
{
//Popup 弹窗的大小
return new Vector2 (300, 200);
}
}
效果如下:
在Editor下创建脚本如下:
using UnityEditor;
using UnityEngine;
public class WindowExample2 : ScriptableWizard
{
public string gameObjectName;
[MenuItem("Window/WindowExample2")]
static void Open ()
{
DisplayWizard<WindowExample2> ("TitleName", "Create", "Find");
}
// 创建一个GameObject
void OnWizardCreate ()
{
new GameObject (gameObjectName);
}
void OnWizardOtherButton ()
{
var gameObject = GameObject.Find (gameObjectName);
if (gameObject == null)
{
Debug.Log ("没有找到相关物体");
}
}
void OnWizardUpdate ()
{
Debug.Log ("Update");
}
}
效果如下:
在Editor下创建脚本如下:
using UnityEditor;
using UnityEngine;
public class WindowExample3 : EditorWindow,IHasCustomMenu
{
// 给窗口添加菜单
public void AddItemsToMenu (GenericMenu menu)
{
menu.AddItem (new GUIContent ("example"), false, () => {
});
menu.AddItem (new GUIContent ("example2"), true, () => {
});
}
[MenuItem ("Window/WindowExample3")]
static void Open ()
{
var window = GetWindow<WindowExample3> ();
// 设置窗口最大和最小尺寸,这里最大和最小相等,相当于尺寸不可改变
window.maxSize = window.minSize = new Vector2 (300, 300);
// 设置窗口图标
var icon = AssetDatabase.LoadAssetAtPath<Texture> ("Assets/Editor/Mondeville.png");
// 设置窗口标题
window.titleContent = new GUIContent ("Hoge", icon);
}
}
效果如下:
本文工程:http://download.csdn.net/detail/warrenmondeville/9700712
本文链接:http://write.blog.csdn.net/mdeditor#!postId=53444808
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。