示例#1
0
    private void NodeMakeTransition(NodeValue currentNode, List <NodeValue> nodeList)
    {
        Event _event = Event.current;

        mousePosition = _event.mousePosition;

        if (_event.type == EventType.MouseDown)
        {
            if (_event.button == 0)  // 鼠标左键
            {
                if (makeTransitionMode)
                {
                    NodeValue nodeValue = GetMouseInNode(nodeList);
                    // 如果按下鼠标时,选中了一个节点,则将 新选中根节点 添加为 selectNode 的子节点
                    if (null != nodeValue && currentNode.id != nodeValue.id)
                    {
                        if (null != BehaviorManager.behaviorNodeAddChild)
                        {
                            BehaviorManager.behaviorNodeAddChild(currentNode.id, nodeValue.id);
                        }
                    }

                    // 取消连线状态
                    makeTransitionMode = false;
                }
                else
                {
                    NodeValue nodeValue = GetMouseInNode(nodeList);
                    if (BehaviorManager.behaviorChangeSelectId != null)
                    {
                        int nodeId = (null != nodeValue) ? nodeValue.id : -1;
                        BehaviorManager.behaviorChangeSelectId(nodeId);
                    }
                }
            }

            if (_event.button == 1)  // 鼠标右键
            {
                if ((!makeTransitionMode))
                {
                    NodeValue nodeValue = GetMouseInNode(nodeList);
                    ShowMenu(currentNode, nodeValue);
                }
            }
        }

        if (makeTransitionMode && currentNode != null)
        {
            RectT mouseRect = new RectT(mousePosition.x, mousePosition.y, 10, 10);
            DrawNodeCurve(currentNode.position, mouseRect);
        }
    }