Untiy插件组件编写【3】 – 插件窗口界面绘制
在我们编写插件的时候。我们经常要用到窗口来选择东西。这时。就需要我们自己给我们的插件绘制一个窗口界面了。
本节我们所讲的就是插件窗口界面的绘制。
我们本节讲的的窗口的绘制。同时。与NGUI的字体和图集关联。从而选择图集和字体。对我们的预设进行批处理。
绘制的窗口效果图。
菜单。(菜单添加在前面。已经讲过。可以翻看之前的博文。第一讲。)
好。看完效果图。老规矩。先贴代码。
using UnityEngine; using UnityEditor; using System.Collections.Generic; public class UIOnKeyRelation : EditorWindow { /// <summary> 保存到内存.</summary> void OnSelectFont(Object obj) { NGUISettings.ambigiousFont = obj as UIFont; Repaint(); } void OnSelectAtlas(Object obj) { NGUISettings.atlas = obj as UIAtlas; Repaint(); } /// <summary> 刷新窗口. </summary> void OnSelectionChange() { Repaint(); } public static bool IsSetNullFont; /// <summary>UI绘制区域.</summary> void OnGUI() { try { Debug.Log("窗口开始绘制"); EditorGUIUtility.labelWidth = 80f; NGUIEditorTools.DrawHeader("选择字体"); ComponentSelector.Draw<UIFont>("UIFont", (UIFont)NGUISettings.ambigiousFont, OnSelectFont, true, GUILayout.MinWidth(200f)); EditorGUIUtility.labelWidth = 160f; NGUIEditorTools.DrawHeader("选择图集"); ComponentSelector.Draw<UIAtlas>("UIAtlas", NGUISettings.atlas, OnSelectAtlas, true, GUILayout.MinWidth(200f)); NGUIEditorTools.DrawSeparator(); Debug.Log("窗口绘制结束"); } catch (System.Exception ex) { Debug.LogError(ex.Message); NGUISettings.ambigiousFont = null; NGUISettings.atlas = null; } } }
这里的绘制。绘制的是窗口内的内容。和第二讲讲的组件绘制差不多。代码也简单。看下就懂了。就不多讲了。
以下为菜单的添加。及窗口的创建。代码如下
using UnityEngine; using System.Collections; using UnityEditor; using System.IO; public class ResourceEdit { [MenuItem("Tools/Open Connect Atlas Panel", false, 9)] static public void OpenConnectAtlasPanel() { EditorWindow.GetWindow<UIOnKeyRelation>(false, "ConnectAtlasPanel", true); } }
如上。两个布尔值。中间的为标题。两个布尔值。第一个是是否是实体窗口。第二个是焦点。false和true。都没什么区别。
泛型部分传入我们绘制窗口内容 的脚本。就完成了。我们窗口的绘制。
[…] http://www.bobsong.net/288.html […]