/// <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 static T CreateSpatialConstraintNode <T>(SpatialConstraintAsset constraintAsset, Vector2 worldPosition) where T : SCBaseDomainNode { var graph = constraintAsset.Graph; var node = GraphOperations.CreateNode <T>(graph); node.Position = worldPosition; node.SnapNode(); var hostAsset = constraintAsset.hostThemeNode.Graph; AddToAsset(hostAsset, 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); }
/// <summary> /// Creates default marker nodes when a new graph is created /// </summary> static void CreateDefaultMarkerNodes(Graph graph) { if (graph == null) { Debug.LogWarning("Cannot create default marker nodes. graph is null"); return; } var markerNames = new string[] { DungeonConstants.ST_GROUND, DungeonConstants.ST_WALL, DungeonConstants.ST_WALLSEPARATOR, DungeonConstants.ST_FENCE, DungeonConstants.ST_FENCESEPARATOR, DungeonConstants.ST_DOOR, DungeonConstants.ST_STAIR, DungeonConstants.ST_STAIR2X, DungeonConstants.ST_WALLHALF, DungeonConstants.ST_WALLHALFSEPARATOR }; // Make sure we don't have any nodes in the graph if (graph.Nodes.Count > 0) { return; } const int INTER_NODE_X = 200; const int INTER_NODE_Y = 300; int itemsPerRow = markerNames.Length / 2; for (int i = 0; i < markerNames.Length; i++) { int ix = i % itemsPerRow; int iy = i / itemsPerRow; int x = ix * INTER_NODE_X; int y = iy * INTER_NODE_Y; var node = GraphOperations.CreateNode <MarkerNode>(graph); AddToAsset(graph, node); node.Position = new Vector2(x, y); node.Caption = markerNames[i]; } }