public void Draw(GraphRendererContext rendererContext, GraphCamera camera)
        {
            if (!active)
            {
                return;
            }

            var mouseWorld = camera.ScreenToWorld(mouseScreenPosition);

            mousePin.Position = mouseWorld;


            GraphLinkRenderer.DrawGraphLink(rendererContext, link, camera);

            // Check the pin that comes under the mouse pin
            var targetPin = graphEditor.GetPinUnderPosition(mouseWorld);

            if (targetPin != null)
            {
                var sourcePin = attachedPin;
                var pins      = new GraphPin[] { sourcePin, targetPin };
                Array.Sort(pins, new GraphPinHierarchyComparer());
                string errorMessage;
                if (!GraphSchema.CanCreateLink(pins[0], pins[1], out errorMessage))
                {
                    GraphTooltip.message = errorMessage;
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Creates a graph link between the two specified pins
        /// </summary>
        /// <typeparam name="T">The type of the link. Should be GraphLink or one of its subclass</typeparam>
        /// <param name="output">The output pin from where the link originates</param>
        /// <param name="input">The input pin, where the link points to</param>
        /// <returns></returns>
        public static T CreateLink <T>(Graph graph, GraphPin output, GraphPin input) where T : GraphLink
        {
            // Make sure the pin types are correct
            if (output.PinType != GraphPinType.Output || input.PinType != GraphPinType.Input)
            {
                throw new System.ApplicationException("Invalid pin types while creating a link");
            }

            if (!GraphSchema.CanCreateLink(output, input))
            {
                return(null);
            }

            // Make sure a link doesn't already exists
            foreach (T link in graph.Links)
            {
                if (link.Input == input && link.Output == output)
                {
                    return(link);
                }
            }

            {
                Undo.RecordObject(graph, "Create Link");

                T link = CreateLink <T>(graph);
                link.Input  = input;
                link.Output = output;

                Undo.RegisterCreatedObjectUndo(link, "Create Link");
                return(link);
            }
        }