UnityEditor Windows Event(3)

来源:互联网 发布:fifa online4数据库 编辑:程序博客网 时间:2024/06/08 05:36

1.自定义窗口点击Window/MyCustom下的菜单栏

using UnityEditor;using UnityEngine;public class CustomEditors : EditorWindow {    public static CustomEditors instance;    private string search = string.Empty;    private Vector2 scrollPos;    private Rect my = new Rect(100,50,100,40);    [MenuItem("Window/MyCustom")]    public static void Init()    {        EditorWindow.GetWindow<CustomEditors>();    }    private void OnGUI()    {        if (instance == null)        {            instance = this;        }        DrapPlane();        GUILayout.BeginArea(new Rect(0, GraphConfig.Top_INDENT, position.width, position.height - GraphConfig.Top_INDENT), "");        {            GUILayout.Box("YSL1111", new GUILayoutOption[] { GUILayout.ExpandWidth(true), GUILayout.Height(1) });            scrollPos = EditorGUILayout.BeginScrollView(scrollPos, GUILayout.Width(position.width), GUILayout.Height(position.height));            GUILayout.Box("", GUIStyle.none, new GUILayoutOption[] { GUILayout.ExpandWidth(true), GUILayout.Height(position.height) });            BeginWindows();            my =  GUI.Window(1, my, ViewRender.Render, "YSL");            //EditorCurveDrawing.bezierLine(new Vector2(100, 1) ,Vector2.one, new Vector2(300,1) , new Vector2(1.67f,-1), Color.yellow, 5.0f, true,5.0f);            EndWindows();            EditorGUILayout.EndScrollView();        }        GUILayout.EndArea();    }    private void DrapPlane()    {        GUIStyle myPlane = new GUIStyle(EditorStyles.label);        myPlane.fontSize = 15;        if (position.width > 735f)        {            GUILayout.BeginArea(new Rect(10, 9, 70, 30), "");            {                GUILayout.Label("Search: ", myPlane);                GUILayout.Label("",myPlane);            }            GUILayout.EndArea();            GUILayout.BeginArea(new Rect(80, 11, 150, 30), "");            {                GUIStyle s = new GUIStyle(EditorStyles.textField);                s.fontSize = 13;                s.padding.top = 2;                search = EditorGUILayout.TextField("", search, s, new GUILayoutOption[] { GUILayout.Width(120), GUILayout.Height(20) });            }            GUILayout.EndArea();        }        else        {            search = string.Empty;        }        float x = 460;        GUILayout.BeginArea(new Rect(position.width - x - 70, 9, 70, 30), "");        {            GUILayout.Label("Collaps",myPlane);            GUILayout.Label("",myPlane);        }GUILayout.EndArea();        string[] Option = new string[3];        Option[0] = "Nothing";        Option[1] = "Only Listern";        Option[2] = "All Matcher";        GUIStyle optionStyle = new GUIStyle(EditorStyles.popup);        optionStyle.padding = new RectOffset(-10,0,-1,0);        optionStyle.fixedHeight = 20;        optionStyle.alignment = TextAnchor.MiddleCenter;        optionStyle.fontSize = 10;        OptionType.CurrentOption = EditorGUI.Popup(            new Rect(position.width - x , 10 , 100 ,20 ),OptionType.CurrentOption,Option,optionStyle);    }}
  1. 渲染处理事件信息
using UnityEngine;using UnityEditor;public class ViewRender  {    public static void Render(int viewId)    {        BaseNode y = new BaseNode();        ProcessInput(y);        GUI.DragWindow(new Rect(0,0,1000,10000));    }    /// <summary>    /// 回调    /// </summary>    /// <param name="_data"></param>    private static void MenuCallBacks(object _data)    {        bool success;        ContextMenuItem m_item = _data as ContextMenuItem;        m_item.node.name = "YSL";        //m_item.node.gameObject = GameObject.Find("Cube") as GameObject ;        switch (m_item.type)        {            case EventGraphContextMenu.OPEN_IN_EDITOR:                success = EventGraphAction.OpenInEditor(m_item.node.name);                if(!success)                {                    CustomEditors.instance.ShowNotification(new GUIContent("Class Not Found"));                }                break;            case EventGraphContextMenu.SHOW_IN_HIERARCHY:                success = EventGraphAction.selectInHierarchy(m_item.node);                if (!success)                {                    CustomEditors.instance.ShowNotification(new GUIContent("Class Not Found"));                }                break;            case EventGraphContextMenu.SELECT_EVENT_TREE:                break;        }        EventGraphAction.OpenInEditor("YSL");    }     public static void ProcessInput(BaseNode name )    {        if (Event.current.button == 1 && (Event.current.type == EventType.MouseDown))        {            GenericMenu menu = new GenericMenu();            menu.AddItem(new GUIContent("Open In Editor"),false,MenuCallBacks,new ContextMenuItem(name, EventGraphContextMenu.OPEN_IN_EDITOR)) ;            menu.AddItem(new GUIContent("Show In Hierarcy"),false ,MenuCallBacks , new ContextMenuItem(name ,EventGraphContextMenu.SHOW_IN_HIERARCHY));            menu.AddItem(new GUIContent("SelectEditor"),false,MenuCallBacks,new ContextMenuItem(name,EventGraphContextMenu.SELECT_EVENT_TREE));            menu.ShowAsContext();        }     }}
0 0
原创粉丝点击