示例#1
0
        /// <summary>
        /// Context Click selection. Here you'll need to register your own using a string identifier
        /// </summary>
        public static void ContextCallback(object obj)
        {
            callbackObject cbObj = obj as callbackObject;

            curNodeCanvas  = cbObj.canvas;
            curEditorState = cbObj.editor;

            switch (cbObj.message)
            {
            case "deleteNode":
                if (curEditorState.focusedNode != null)
                {
                    curEditorState.focusedNode.Delete();
                }
                break;

            case "duplicateNode":
                if (curEditorState.focusedNode != null)
                {
                    ContextCallback(new callbackObject(curEditorState.focusedNode.GetID, curNodeCanvas, curEditorState));
                    Node duplicatedNode = curNodeCanvas.nodes [curNodeCanvas.nodes.Count - 1];

                    curEditorState.focusedNode    = duplicatedNode;
                    curEditorState.dragNode       = true;
                    curEditorState.makeTransition = null;
                    curEditorState.connectOutput  = null;
                    curEditorState.panWindow      = false;
                }
                break;

            case "startTransition":
                if (curEditorState.focusedNode != null)
                {
                    curEditorState.makeTransition = curEditorState.focusedNode;
                    curEditorState.connectOutput  = null;
                }
                curEditorState.dragNode  = false;
                curEditorState.panWindow = false;

                break;

            default:
                Vector2 createPos = ScreenToGUIPos(mousePos);

                Node node = NodeTypes.getDefaultNode(cbObj.message);
                if (node == null)
                {
                    break;
                }

                bool acceptTransitions = NodeTypes.nodes [node].transitions;

                node = node.Create(createPos);
                node.InitBase();
                NodeEditorCallbacks.IssueOnAddNode(node);

                if (curEditorState.connectOutput != null)
                {                 // If nodeOutput is defined, link it to the first input of the same type
                    foreach (NodeInput input in node.Inputs)
                    {
                        if (Node.CanApplyConnection(curEditorState.connectOutput, input))
                        {                         // If it can connect (type is equals, it does not cause recursion, ...)
                            Node.ApplyConnection(curEditorState.connectOutput, input);
                            break;
                        }
                    }
                }
                else if (acceptTransitions && curEditorState.makeTransition != null)
                {
                    Node.CreateTransition(curEditorState.makeTransition, node);
                }

                curEditorState.makeTransition = null;
                curEditorState.connectOutput  = null;
                curEditorState.dragNode       = false;
                curEditorState.panWindow      = false;

                break;
            }

            if (NodeEditor.Repaint != null)
            {
                NodeEditor.Repaint();
            }
        }