/// <summary> /// Context Click selection. Here you'll need to register your own using a string identifier /// </summary> public static void ContextCallback(object obj) { NodeEditorMenuCallback callback = obj as NodeEditorMenuCallback; curNodeCanvas = callback.canvas; curEditorState = callback.editor; switch (callback.message) { case "deleteNode": if (curEditorState.focusedNode != null) { curEditorState.focusedNode.Delete(); } break; case "duplicateNode": if (curEditorState.focusedNode != null) { ContextCallback(new NodeEditorMenuCallback(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(callback.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; } RepaintClients(); }
/// <summary> /// Evaluates context callbacks previously registered /// </summary> public static void ContextCallback(object obj) { NodeEditorMenuCallback callback = obj as NodeEditorMenuCallback; if (callback == null) { throw new UnityException("Callback Object passed by context is not of type NodeEditorMenuCallback!"); } curNodeCanvas = callback.canvas; curEditorState = callback.editor; switch (callback.message) { case "deleteNode": // Delete request if (curEditorState.focusedNode != null) { curEditorState.focusedNode.Delete(); } break; case "duplicateNode": // Duplicate request if (curEditorState.focusedNode != null) { ContextCallback(new NodeEditorMenuCallback(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": // Starting a new transition if (curEditorState.focusedNode != null) { curEditorState.makeTransition = curEditorState.focusedNode; curEditorState.connectOutput = null; } curEditorState.dragNode = false; curEditorState.panWindow = false; break; default: // Node creation request Node node = Node.Create(callback.message, ScreenToGUIPos(callback.contextClickPos)); // Handle auto-connection 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 (input.CanApplyConnection(curEditorState.connectOutput)) { // If it can connect (type is equals, it does not cause recursion, ...) input.ApplyConnection(curEditorState.connectOutput); break; } } } curEditorState.makeTransition = null; curEditorState.connectOutput = null; curEditorState.dragNode = false; curEditorState.panWindow = false; break; } RepaintClients(); }