/// <summary> /// Initializes a new CreateNodeFromSearcherCommand. /// </summary> /// <param name="position">The position where to create the node.</param> /// <param name="selectedItem">The searcher item representing the node to create.</param> /// <param name="guid">The SerializableGUID to assign to the newly created item. If none is provided, a new /// SerializableGUID will be generated for it.</param> public CreateNodeFromSearcherCommand(Vector2 position, GraphNodeModelSearcherItem selectedItem, SerializableGUID guid = default) : this() { Position = position; SelectedItem = selectedItem; Guid = guid.Valid ? guid : SerializableGUID.Generate(); }
/// <summary> /// Initializes a new CreateNodeFromSearcherCommand. /// </summary> /// <param name="edgeModel">The edge model on which to insert the newly created node.</param> /// <param name="position">The position where to create the node.</param> /// <param name="selectedItem">The searcher item representing the node to create.</param> /// <param name="guid">The SerializableGUID to assign to the newly created item. If none is provided, a new /// SerializableGUID will be generated for it.</param> public CreateNodeOnEdgeCommand(IEdgeModel edgeModel, Vector2 position, GraphNodeModelSearcherItem selectedItem, SerializableGUID guid = default) : this() { EdgeModel = edgeModel; Position = position; SelectedItem = selectedItem; Guid = guid.Valid ? guid : SerializableGUID.Generate(); }
/// <summary> /// Initializes a new instance of the <see cref="CreateNodeFromPortCommand"/> class. /// </summary> /// <param name="portModel">The ports to which to connect the new node.</param> /// <param name="position">The position where to create the node.</param> /// <param name="selectedItem">The searcher item representing the node to create.</param> /// <param name="edgesToDelete">Edges to delete.</param> public CreateNodeFromPortCommand(IReadOnlyList <IPortModel> portModel, Vector2 position, GraphNodeModelSearcherItem selectedItem, IReadOnlyList <IEdgeModel> edgesToDelete = null) : this() { PortModels = portModel; Position = position; SelectedItem = selectedItem; EdgesToDelete = edgesToDelete; }
/// <summary> /// Adds a <see cref="SearcherItem"/> for each node marked with <see cref="SearcherItemAttribute"/> to the database. /// </summary> /// <returns>The database with the elements.</returns> public GraphElementSearcherDatabase AddNodesWithSearcherItemAttribute() { var types = TypeCache.GetTypesWithAttribute <SearcherItemAttribute>(); foreach (var type in types) { var attributes = type.GetCustomAttributes <SearcherItemAttribute>().ToList(); if (!attributes.Any()) { continue; } foreach (var attribute in attributes) { if (!attribute.StencilType.IsInstanceOfType(Stencil)) { continue; } var name = attribute.Path.Split('/').Last(); var path = attribute.Path.Remove(attribute.Path.LastIndexOf('/') + 1); switch (attribute.Context) { case SearcherContext.Graph: { var node = new GraphNodeModelSearcherItem( Stencil.GraphModel, new NodeSearcherItemData(type), data => data.CreateNode(type, name), name ); Items.AddAtPath(node, path); break; } default: Debug.LogWarning($"The node {type} is not a " + $"{SearcherContext.Graph} node, so it cannot be add in the Searcher"); break; } break; } } return(this); }
/// <summary> /// Adds a searcher item for Sticky Note to the database. /// </summary> /// <returns>The database with the elements.</returns> public GraphElementSearcherDatabase AddStickyNote() { var node = new GraphNodeModelSearcherItem( Stencil.GraphModel, new TagSearcherItemData(CommonSearcherTags.StickyNote), data => { var rect = new Rect(data.Position, StickyNote.defaultSize); var graphModel = data.GraphModel; return(graphModel.CreateStickyNote(rect, data.SpawnFlags)); }, k_Sticky ); Items.AddAtPath(node); return(this); }