Пример #1
0
    private void OnGUI()
    {
        Event e = Event.current;

        mousePos = e.mousePosition;
        if (e.type == EventType.MouseDown)
        {
            BaseNode tempNode = ClickedOnANode();
            if (e.button == 1)
            {
                if (tempNode == null)
                {
                    GenericMenu menu = new GenericMenu();
                    menu.AddItem(new GUIContent("Create Node"), false, AddNode, typeof(EmptyNode));
                    menu.ShowAsContext();
                    e.Use();
                }
                else
                {
                    GUI.BringWindowToFront(tempNode.id);
                    GenericMenu menu = new GenericMenu();
                    menu.AddItem(new GUIContent("Delete Node"), false, DeleteNode, tempNode);
                    menu.ShowAsContext();
                    e.Use();
                }
            }
            else if (e.button == 0)
            {
                if (tempNode != null)
                {
                    selectedElement = tempNode.ClickedOn(mousePos); //!= tempNode ? tempNode.ClickedOn(mousePos) : null;
                    if (selectedElement)
                    {
                    }
                    //Debug.Log(selectedElement.GetType());
                }
            }
        }
        if (e.type == EventType.mouseDrag)
        {
            Debug.Log("calling this");
            if (selectedElement != null)//&& !(selectedElement is BaseNode))
            {
                selectedElement.IncrementElementRect(e.delta);
                //selectedElement.GetBaseNode().CalculateRect();
                Event.current.Use();
            }
        }
        if (e.type == EventType.mouseUp)
        {
            selectedElement = null;
        }
        BeginWindows();
        for (int i = 0; i < nodes.Count; i++)
        {
            nodes[i].localElementRect = GUI.Window(i, nodes[i].localElementRect, showNode, nodes[i].windowName);
        }
        EndWindows();
    }