UnityEditor Windows Event(3)

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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值