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 PerformDelete(Event e)
        {
            var nodesToDelete = new List <GraphNode>();

            foreach (var node in graph.Nodes)
            {
                if (node.Selected)
                {
                    nodesToDelete.Add(node);
                }
            }
            var deletionList = nodesToDelete.ToArray();

            System.Array.Sort(deletionList, new NodeDeletionOrderComparer());
            foreach (var node in deletionList)
            {
                GraphOperations.DestroyNode(node);
            }

            if (deletionList.Length > 0)
            {
                graph.MarkAsDirty();
                graph.NotifyStateChanged();
            }
        }
        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);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Destroys all links connected to this pin
        /// </summary>
        private static void DestroyPinLinks(GraphPin pin)
        {
            var pinLinks = pin.GetConntectedLinks();

            foreach (var link in pinLinks)
            {
                GraphOperations.DestroyLink(link);
            }

            pin.NotifyPinLinksDestroyed();
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        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);
        }
        public void DeleteNodes(GraphNode[] nodesToDelete)
        {
            if (nodesToDelete.Length == 0)
            {
                return;
            }

            System.Array.Sort(nodesToDelete, new NodeDeletionOrderComparer());
            foreach (var node in nodesToDelete)
            {
                GraphOperations.DestroyNode(node);
            }

            graph.MarkAsDirty();
            graph.NotifyStateChanged();
        }
Ejemplo n.º 9
0
        /// <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];
            }
        }
Ejemplo n.º 10
0
 protected virtual void DestroyNode(GraphNode node)
 {
     GraphOperations.DestroyNode(node);
     HandleMarkedDirty();
 }