void CreateLinkBetweenPins(GraphPin outputPin, GraphPin inputPin) { if (outputPin.PinType != GraphPinType.Output && inputPin.PinType != GraphPinType.Input) { Debug.LogError("Pin type mismatch"); return; } // Make sure they are not from the same node if (outputPin.Node == inputPin.Node) { Debug.LogError("Linking pins from the same node"); return; } // Create a link var link = GraphOperations.CreateLink <GraphLink>(graph, outputPin, inputPin); if (link != null) { DungeonEditorHelper.AddToAsset(graph, link); graph.NotifyStateChanged(); } else { Debug.Log("GraphSchema: Link not allowed"); } }
void PerformPaste(Event e) { var copyText = EditorGUIUtility.systemCopyBuffer; var serializer = new System.Xml.Serialization.XmlSerializer(typeof(string[])); string[] copyNodeIds = (string[])serializer.Deserialize(new System.IO.StringReader(copyText)); var mouseWorld = camera.ScreenToWorld(e.mousePosition); float offsetXDelta = 130; float offsetX = 0; foreach (var id in copyNodeIds) { var sourceNode = graph.GetNode(id); var copiedNode = GraphOperations.DuplicateNode(graph, sourceNode); // Add the copied node to the asset file DungeonEditorHelper.AddToAsset(graph, copiedNode); // Update the bounds of the node to move it near the cursor var bounds = copiedNode.Bounds; bounds.x = mouseWorld.x + offsetX; bounds.y = mouseWorld.y; copiedNode.Bounds = bounds; offsetX += offsetXDelta; } }
/// <summary> /// Creates a new node in the specified screen coordinate /// </summary> /// <typeparam name="T">The type of node to created. Should be a subclass of GraphNode</typeparam> /// <param name="screenCoord">The screen coordinate to place the node at</param> /// <returns>The created graph node</returns> public T CreateNode <T>(Vector2 screenCoord) where T : GraphNode, new() { var node = GraphOperations.CreateNode <T>(graph); DungeonEditorHelper.AddToAsset(graph, node); var screenPosition = screenCoord - node.Bounds.size / 2; node.Position = camera.ScreenToWorld(screenPosition); BringToFront(node); return(node); }
public virtual GraphNode CreateNode(Vector2 screenCoord, UnityEngine.Object hostAsset, System.Type nodeType) { var node = GraphOperations.CreateNode(graph, nodeType); DungeonEditorHelper.AddToAsset(hostAsset, node); var nodeScreenSize = node.Bounds.size / camera.ZoomLevel; var screenPosition = screenCoord - nodeScreenSize / 2; node.Position = camera.ScreenToWorld(screenPosition); BringToFront(node); events.OnNodeCreated.Notify(new GraphNodeEventArgs(node)); return(node); }