コード例 #1
0
        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;
                }
            }
        }
コード例 #2
0
        public void OnEnable()
        {
            hideFlags = HideFlags.HideAndDontSave;
            if (camera == null)
            {
                camera = new GraphCamera();
            }
            if (selectionBox == null)
            {
                selectionBox = new GraphSelectionBox();
                selectionBox.SelectionPerformed += HandleBoxSelection;
            }
            if (keyboardState == null)
            {
                keyboardState = new KeyboardState();
            }
            if (cursorDragLink == null)
            {
                cursorDragLink = new CursorDragLink(this);
                cursorDragLink.DraggedLinkReleased += HandleMouseDraggedLinkReleased;
            }
            if (contextMenu == null)
            {
                contextMenu = new GraphContextMenu();
                contextMenu.RequestContextMenuCreation += OnRequestContextMenuCreation;
                contextMenu.MenuItemClicked            += OnMenuItemClicked;
            }

            RemoveGraphListeners();
            AddGraphListeners();

            InitializeNodeRenderers();

            Undo.undoRedoPerformed += OnUndoRedoPerformed;
        }
コード例 #3
0
ファイル: GraphOperations.cs プロジェクト: Borgeshc/Game
        /// <summary>
        /// Handles user input (keyboard and mouse)
        /// </summary>
        /// <param name="e">Input event</param>
        /// <param name="camera">Graph camera to convert to / from screen to world coordinates</param>
        /// <returns>true if the input was processed, false otherwise.</returns>
        public static bool HandleNodeInput(GraphNode node, Event e, GraphCamera camera)
        {
            bool inputProcessed = false;

            if (!node.Dragging)
            {
                // let the pins handle the input first
                foreach (var pin in node.InputPins)
                {
                    if (inputProcessed)
                    {
                        break;
                    }
                    inputProcessed |= HandlePinInput(pin, e, camera);
                }
                foreach (var pin in node.OutputPins)
                {
                    if (inputProcessed)
                    {
                        break;
                    }
                    inputProcessed |= HandlePinInput(pin, e, camera);
                }
            }

            var mousePosition      = e.mousePosition;
            var mousePositionWorld = camera.ScreenToWorld(mousePosition);
            int dragButton         = 0;

            // If the pins didn't already handle the input, then let the node handle it
            if (!inputProcessed)
            {
                bool insideRect = node.Bounds.Contains(mousePositionWorld);
                if (e.type == EventType.MouseDown && insideRect && e.button == dragButton)
                {
                    node.Dragging  = true;
                    inputProcessed = true;
                }
                else if (e.type == EventType.MouseUp && insideRect && e.button == dragButton)
                {
                    node.Dragging = false;
                }
            }

            if (node.Dragging && !node.Selected)
            {
                node.Dragging = false;
            }

            if (node.Dragging && e.type == EventType.MouseDrag)
            {
                inputProcessed = true;
            }

            return(inputProcessed);
        }
コード例 #4
0
ファイル: CommentNodeEditor.cs プロジェクト: kabirules/Kenny
        void DrawMessage(GraphRendererContext rendererContext, CommentNode node, GraphCamera camera)
        {
            var style = new GUIStyle(GUI.skin.GetStyle("Label"));

            style.alignment = TextAnchor.UpperLeft;

            var miniFontBaseSize = 20;

            style.normal.textColor = node.Selected ? GraphEditorConstants.TEXT_COLOR_SELECTED : GraphEditorConstants.TEXT_COLOR;
            if (camera.ZoomLevel >= 2)
            {
                float scaledFontSize = style.fontSize;
                if (scaledFontSize == 0)
                {
                    scaledFontSize = miniFontBaseSize;
                }
                scaledFontSize = Mathf.Max(1.0f, scaledFontSize / camera.ZoomLevel);

                style.fontSize = Mathf.RoundToInt(scaledFontSize);
                style.font     = CommentNodeRenderUtils.GetRenderFont();
            }

            GUI.backgroundColor = node.background;

            // Update the node bounds
            var padding  = new Vector2(10, 10);
            var textSize = style.CalcSize(new GUIContent(node.message));
            var nodeSize = textSize + padding * 2;

            Rect boxBounds;
            {
                var positionScreen = camera.WorldToScreen(node.Position);
                var sizeScreen     = nodeSize / camera.ZoomLevel;
                boxBounds = new Rect(positionScreen, sizeScreen);
            }

            Rect textBounds;

            {
                var positionScreen = camera.WorldToScreen(node.Position + padding);
                var sizeScreen     = textSize / camera.ZoomLevel;
                textBounds = new Rect(positionScreen, sizeScreen);
            }

            GUI.Box(boxBounds, "");
            style.normal.textColor = textColor;
            GUI.Label(textBounds, node.message, style);

            {
                var nodeBounds = node.Bounds;
                nodeBounds.size = nodeSize;
                node.Bounds     = nodeBounds;
            }
        }
コード例 #5
0
ファイル: GraphEditor.cs プロジェクト: kabirules/Kenny
        /// <summary>
        /// Initializes the graph editor with the specified graph
        /// </summary>
        /// <param name="graph">The owning graph</param>
        /// <param name="editorBounds">The bounds of the editor window</param>
        public virtual void Init(Graph graph, Rect editorBounds)
        {
            events = new GraphEditorEvents();

            SetGraph(graph);

            // Reset the camera
            camera = new GraphCamera();
            FocusCameraOnBestFit(editorBounds);

            editorStyle = CreateEditorStyle();
        }
コード例 #6
0
        /// <summary>
        /// Initializes the graph editor with the specified graph
        /// </summary>
        /// <param name="graph">The owning graph</param>
        /// <param name="editorBounds">The bounds of the editor window</param>
        public void Init(Graph graph, Rect editorBounds)
        {
            if (this.graph != graph)
            {
                RemoveGraphListeners();
                this.graph = graph;
                AddGraphListeners();

                // Reset the camera
                camera = new GraphCamera();
                FocusCameraOnBestFit(editorBounds);
            }
        }
コード例 #7
0
ファイル: GraphOperations.cs プロジェクト: Borgeshc/Game
        /// <summary>
        /// Handles the mouse input and returns true if handled
        /// </summary>
        public static bool HandlePinInput(GraphPin pin, Event e, GraphCamera camera)
        {
            var mousePosition        = e.mousePosition;
            var mousePositionWorld   = camera.ScreenToWorld(mousePosition);
            int buttonIdDrag         = 0;
            int buttonIdDestroyLinks = 1;

            if (pin.ContainsPoint(mousePositionWorld))
            {
                if (e.type == EventType.MouseDown && e.button == buttonIdDrag)
                {
                    pin.ClickState = GraphPinMouseState.Clicked;
                    return(true);
                }

                if (e.button == buttonIdDestroyLinks)
                {
                    if (e.type == EventType.MouseDown)
                    {
                        pin.RequestLinkDeletionInitiated = true;
                    }
                    else if (e.type == EventType.MouseDrag)
                    {
                        pin.RequestLinkDeletionInitiated = false;
                    }
                    else if (e.type == EventType.MouseUp)
                    {
                        if (pin.RequestLinkDeletionInitiated)
                        {
                            DestroyPinLinks(pin);
                            if (pin.Node != null && pin.Node.Graph != null)
                            {
                                pin.Node.Graph.NotifyStateChanged();
                            }
                        }
                    }
                    return(true);
                }

                if (pin.ClickState != GraphPinMouseState.Clicked)
                {
                    pin.ClickState = GraphPinMouseState.Hover;
                }
            }
            else
            {
                pin.ClickState = GraphPinMouseState.None;
            }

            return(false);
        }
コード例 #8
0
ファイル: GraphPinRenderer.cs プロジェクト: kabirules/Kenny
        public static void Draw(GraphRendererContext rendererContext, GraphPin pin, GraphCamera camera)
        {
            var pinBounds      = new Rect(pin.GetBounds());
            var positionWorld  = pin.Node.Position + pinBounds.position;
            var positionScreen = camera.WorldToScreen(positionWorld);

            pinBounds.position = positionScreen;
            pinBounds.size    /= camera.ZoomLevel;

            var originalColor = GUI.backgroundColor;

            GUI.backgroundColor = GetPinColor(pin);
            GUI.Box(pinBounds, "");
            GUI.backgroundColor = originalColor;

            // Draw the pin texture
            var pinTexture = rendererContext.Resources.GetResource <Texture2D>(DungeonEditorResources.TEXTURE_PIN_GLOW);

            if (pinTexture != null)
            {
                GUI.DrawTexture(pinBounds, pinTexture);
            }
        }
コード例 #9
0
        protected virtual void DrawThumbnail(GraphRendererContext rendererContext, GraphNode node, GraphCamera camera)
        {
            var thumbObject   = GetThumbObject(node);
            var visualNode    = node as VisualNode;
            var thumbnailSize = 96 / camera.ZoomLevel;

            if (thumbObject != null)
            {
                Texture texture = AssetThumbnailCache.Instance.GetThumb(thumbObject);
                if (texture != null)
                {
                    var positionWorld  = new Vector2(12, 12) + visualNode.Position;
                    var positionScreen = camera.WorldToScreen(positionWorld);
                    GUI.DrawTexture(new Rect(positionScreen.x, positionScreen.y, thumbnailSize, thumbnailSize), texture);
                }
            }
            else
            {
                DrawTextCentered(rendererContext, node, camera, "None");
            }
        }
コード例 #10
0
 protected override void DrawFrameTexture(GraphRendererContext rendererContext, GraphNode node, GraphCamera camera)
 {
     DrawNodeTexture(rendererContext, node, camera, DungeonEditorResources.TEXTURE_GO_NODE_FRAME);
     DrawNodeTexture(rendererContext, node, camera, DungeonEditorResources.TEXTURE_MULTI_GO_NODE_FRAME);
 }
コード例 #11
0
ファイル: MarkerNodeEditor.cs プロジェクト: kabirules/Kenny
        public override void Draw(GraphRendererContext rendererContext, GraphNode node, GraphCamera camera)
        {
            // Draw the background base texture
            DrawNodeTexture(rendererContext, node, camera, DungeonEditorResources.TEXTURE_MARKER_NODE_BG);

            var pinHeight = node.OutputPins[0].BoundsOffset.height;

            DrawTextCentered(rendererContext, node, camera, node.Caption, new Vector2(0, -3));

            // Draw the foreground frame textures
            DrawNodeTexture(rendererContext, node, camera, DungeonEditorResources.TEXTURE_MARKER_NODE_FRAME);

            if (node.Selected)
            {
                DrawNodeTexture(rendererContext, node, camera, DungeonEditorResources.TEXTURE_MARKER_NODE_SELECTION);
            }

            // Draw the pins
            base.Draw(rendererContext, node, camera);
        }
コード例 #12
0
        public override void Draw(GraphRendererContext rendererContext, GraphNode node, GraphCamera camera)
        {
            // Draw the background base texture
            DrawNodeTexture(rendererContext, node, camera, DungeonEditorResources.TEXTURE_MARKER_NODE_BG);

            var style = GUI.skin.GetStyle("Label");

            style.alignment = TextAnchor.MiddleCenter;

            var emitterNode = node as MarkerEmitterNode;
            var title       = (emitterNode.Marker != null) ? emitterNode.Marker.Caption : "{NONE}";

            DrawTextCentered(rendererContext, node, camera, title, new Vector2(0, -2));

            // Draw the foreground frame textures
            DrawNodeTexture(rendererContext, node, camera, DungeonEditorResources.TEXTURE_MARKER_EMITTER_NODE_FRAME);

            if (node.Selected)
            {
                DrawNodeTexture(rendererContext, node, camera, DungeonEditorResources.TEXTURE_MARKER_NODE_SELECTION);
            }

            // Draw the pins
            base.Draw(rendererContext, node, camera);
        }
コード例 #13
0
        public override void Draw(GraphRendererContext rendererContext, GraphNode node, GraphCamera camera)
        {
            var domainNode  = node as SCBaseDomainNode;
            var ringTexture = rendererContext.Resources.GetResource <Texture2D>(DungeonEditorResources.TEXTURE_CURSOR_RING_SOLID);
            var bounds      = camera.WorldToScreen(node.Bounds);
            var color       = GetNodeColor(domainNode);

            GUI.DrawTexture(bounds, ringTexture, ScaleMode.ScaleToFit, true, 1.0f, color, 0, 0);

            // Draw the domain, if we are snapped
            if (domainNode.IsSnapped && !domainNode.Dragging)
            {
                const float DomainSizeHi   = 0.75f;
                const float DomainSizeLo   = 0.15f;
                var         domainRectSize = bounds.size;
                if (domainNode.RuleDomain == SCRuleNodeDomain.Corner)
                {
                    domainRectSize = Vector2.one * (SCBaseDomainNode.TileSize * DomainSizeLo);
                }
                else if (domainNode.RuleDomain == SCRuleNodeDomain.Tile)
                {
                    domainRectSize = Vector2.one * (SCBaseDomainNode.TileSize * DomainSizeHi);
                }
                else if (domainNode.RuleDomain == SCRuleNodeDomain.Edge)
                {
                    var coords    = domainNode.GetHalfGridLogicalCoords();
                    var localSize = (coords.x == 1) ? new Vector2(DomainSizeHi, DomainSizeLo) : new Vector2(DomainSizeLo, DomainSizeHi);
                    domainRectSize = localSize * SCBaseDomainNode.TileSize;
                }
                domainRectSize /= camera.ZoomLevel;
                var domainBounds = new Rect(bounds.center - domainRectSize / 2.0f, domainRectSize);
                var domainColor  = color;
                domainColor.a *= 0.5f;
                var origColor = GUI.color;
                GUI.color = domainColor;
                GUI.Box(domainBounds, "");
                GUI.color = origColor;
            }
        }
コード例 #14
0
        protected void DrawNodeTexture(GraphRendererContext rendererContext, GraphNode node, GraphCamera camera, string textureName)
        {
            var nodeTexture = rendererContext.Resources.GetResource <Texture2D>(textureName);
            var textureSize = new Vector2(nodeTexture.width, nodeTexture.height);

            if (nodeTexture != null)
            {
                var center = camera.WorldToScreen(node.Bounds.center);

                var size     = textureSize / camera.ZoomLevel;
                var position = center - size / 2.0f;

                var rect = new Rect(position.x, position.y, size.x, size.y);
                GUI.DrawTexture(rect, nodeTexture);
            }
        }
コード例 #15
0
        protected virtual void DrawTextCentered(GraphRendererContext rendererContext, GraphNode node, GraphCamera camera, string text, Vector2 offset)
        {
            var style = GUI.skin.GetStyle("Label");

            style.alignment = TextAnchor.MiddleCenter;

            var positionScreen = camera.WorldToScreen(node.Position + offset);
            var labelSize      = new Vector2(node.Bounds.width, node.Bounds.height) / camera.ZoomLevel;
            var labelBounds    = new Rect(positionScreen.x, positionScreen.y, labelSize.x, labelSize.y);

            style.normal.textColor = node.Selected ? GraphEditorConstants.TEXT_COLOR_SELECTED : GraphEditorConstants.TEXT_COLOR;

            var originalFont     = style.font;
            var originalFontSize = style.fontSize;
            var miniFontBaseSize = 20;

            if (camera.ZoomLevel >= 2)
            {
                float scaledFontSize = originalFontSize;
                if (scaledFontSize == 0)
                {
                    scaledFontSize = miniFontBaseSize;
                }
                scaledFontSize = Mathf.Max(1.0f, scaledFontSize / camera.ZoomLevel);

                style.fontSize = Mathf.RoundToInt(scaledFontSize);
                style.font     = UnityEditor.EditorStyles.miniFont;
            }

            GUI.Label(labelBounds, text, style);

            style.font     = originalFont;
            style.fontSize = originalFontSize;
        }
コード例 #16
0
 protected virtual void DrawTextCentered(GraphRendererContext rendererContext, GraphNode node, GraphCamera camera, string text)
 {
     DrawTextCentered(rendererContext, node, camera, text, Vector2.zero);
 }
コード例 #17
0
        protected void DrawBackgroundBox(GraphRendererContext rendererContext, GraphNode node, GraphCamera camera)
        {
            var screenPosition = camera.WorldToScreen(node.Bounds.position);
            var screenBounds   = new Rect(screenPosition.x, screenPosition.y, node.Bounds.width, node.Bounds.height);

            GUI.backgroundColor = getBackgroundColor(node);
            GUI.Box(screenBounds, "");
        }
コード例 #18
0
        public override void Draw(GraphRendererContext rendererContext, GraphNode node, GraphCamera camera)
        {
            DrawNodeTexture(rendererContext, node, camera, DungeonEditorResources.TEXTURE_GO_NODE_BG);

            var thumbObject = GetThumbObject(node);
            var visualNode  = node as VisualNode;

            if (thumbObject != null)
            {
                Texture texture = AssetThumbnailCache.Instance.GetThumb(thumbObject);
                if (texture != null)
                {
                    var positionWorld  = new Vector2(12, 12) + visualNode.Position;
                    var positionScreen = camera.WorldToScreen(positionWorld);
                    GUI.DrawTexture(new Rect(positionScreen.x, positionScreen.y, 96, 96), texture);
                }
            }
            else
            {
                var style = GUI.skin.GetStyle("Label");
                style.alignment = TextAnchor.MiddleCenter;

                var positionScreen = camera.WorldToScreen(visualNode.Position);
                var labelBounds    = new Rect(positionScreen.x, positionScreen.y, visualNode.Bounds.width, visualNode.Bounds.height);
                style.normal.textColor = visualNode.Selected ? GraphEditorConstants.TEXT_COLOR_SELECTED : GraphEditorConstants.TEXT_COLOR;
                GUI.Label(labelBounds, "None", style);
            }

            DrawNodeTexture(rendererContext, node, camera, DungeonEditorResources.TEXTURE_GO_NODE_FRAME);

            base.Draw(rendererContext, node, camera);

            if (node.Selected)
            {
                DrawNodeTexture(rendererContext, node, camera, DungeonEditorResources.TEXTURE_GO_NODE_SELECTION);
            }
        }
コード例 #19
0
 protected virtual void DrawBackgroundTexture(GraphRendererContext rendererContext, GraphNode node, GraphCamera camera)
 {
     DrawNodeTexture(rendererContext, node, camera, DungeonEditorResources.TEXTURE_GO_NODE_BG);
 }
コード例 #20
0
        public override void Draw(GraphRendererContext rendererContext, GraphNode node, GraphCamera camera)
        {
            // Draw the background base texture
            DrawNodeTexture(rendererContext, node, camera, DungeonEditorResources.TEXTURE_MARKER_NODE_BG);

            var style = GUI.skin.GetStyle("Label");

            style.alignment = TextAnchor.MiddleCenter;

            var emitterNode = node as MarkerEmitterNode;
            var title       = (emitterNode.Marker != null) ? emitterNode.Marker.Caption : "{NONE}";

            var positionScreen = camera.WorldToScreen(node.Position);
            var labelBounds    = new Rect(positionScreen.x, positionScreen.y, node.Bounds.width, node.Bounds.height - 5);

            style.normal.textColor = node.Selected ? GraphEditorConstants.TEXT_COLOR_SELECTED : GraphEditorConstants.TEXT_COLOR;
            GUI.Label(labelBounds, title, style);

            // Draw the foreground frame textures
            DrawNodeTexture(rendererContext, node, camera, DungeonEditorResources.TEXTURE_MARKER_EMITTER_NODE_FRAME);

            if (node.Selected)
            {
                DrawNodeTexture(rendererContext, node, camera, DungeonEditorResources.TEXTURE_MARKER_NODE_SELECTION);
            }

            // Draw the pins
            base.Draw(rendererContext, node, camera);
        }
コード例 #21
0
        public static void DrawGraphLink(GraphRendererContext rendererContext, GraphLink link, GraphCamera camera)
        {
            if (link.Input == null || link.Output == null)
            {
                // Link not initialized yet. nothing to draw
                return;
            }

            Vector2 startPos        = camera.WorldToScreen(link.Output.WorldPosition);
            Vector2 endPos          = camera.WorldToScreen(link.Input.WorldPosition);
            var     tangentStrength = link.GetTangentStrength();
            Vector3 startTan        = startPos + link.Output.Tangent * tangentStrength;
            Vector3 endTan          = endPos + link.Input.Tangent * tangentStrength;
            var     lineColor       = new Color(1, 1, 1, 0.75f);

            Handles.DrawBezier(startPos, endPos, startTan, endTan, lineColor, null, 3);

            // Draw the arrow cap
            var   rotation   = Quaternion.FromToRotation(new Vector3(1, 0, 0), link.Input.Tangent.normalized);
            float arrowSize  = 10.0f;
            float arrowWidth = 0.5f;
            var   arrowTails = new Vector2[] {
                rotation *new Vector3(1, arrowWidth) * arrowSize,
                rotation *new Vector3(1, -arrowWidth) * arrowSize,
            };

            Handles.color = lineColor;

            //Handles.DrawPolyLine(arrowTails);
            Handles.DrawLine(endPos, endPos + arrowTails[0]);
            Handles.DrawLine(endPos, endPos + arrowTails[1]);
            Handles.DrawLine(endPos + arrowTails[0], endPos + arrowTails[1]);
        }
コード例 #22
0
        public override void Draw(GraphRendererContext rendererContext, GraphNode node, GraphCamera camera)
        {
            DrawBackgroundTexture(rendererContext, node, camera);

            DrawThumbnail(rendererContext, node, camera);

            DrawFrameTexture(rendererContext, node, camera);

            base.Draw(rendererContext, node, camera);

            if (node.Selected)
            {
                DrawNodeTexture(rendererContext, node, camera, DungeonEditorResources.TEXTURE_GO_NODE_SELECTION);
            }
        }
コード例 #23
0
 public virtual void Draw(GraphRendererContext rendererContext, GraphNode node, GraphCamera camera)
 {
     // Draw the pins
     foreach (var pin in node.InputPins)
     {
         GraphPinRenderer.Draw(rendererContext, pin, camera);
     }
     foreach (var pin in node.OutputPins)
     {
         GraphPinRenderer.Draw(rendererContext, pin, camera);
     }
 }
コード例 #24
0
        public override void Draw(GraphRendererContext rendererContext, GraphNode node, GraphCamera camera)
        {
            // Draw the background base texture
            DrawNodeTexture(rendererContext, node, camera, DungeonEditorResources.TEXTURE_MARKER_NODE_BG);

            var style = GUI.skin.GetStyle("Label");

            style.alignment = TextAnchor.MiddleCenter;

            var positionScreen = camera.WorldToScreen(node.Position);
            var pinHeight      = node.OutputPins[0].BoundsOffset.height;
            var labelBounds    = new Rect(positionScreen.x, positionScreen.y, node.Bounds.width, node.Bounds.height - pinHeight / 2);

            style.normal.textColor = node.Selected ? GraphEditorConstants.TEXT_COLOR_SELECTED : GraphEditorConstants.TEXT_COLOR;
            GUI.Label(labelBounds, node.Caption, style);

            // Draw the foreground frame textures
            DrawNodeTexture(rendererContext, node, camera, DungeonEditorResources.TEXTURE_MARKER_NODE_FRAME);

            if (node.Selected)
            {
                DrawNodeTexture(rendererContext, node, camera, DungeonEditorResources.TEXTURE_MARKER_NODE_SELECTION);
            }

            // Draw the pins
            base.Draw(rendererContext, node, camera);
        }
コード例 #25
0
ファイル: CommentNodeEditor.cs プロジェクト: kabirules/Kenny
        public override void Draw(GraphRendererContext rendererContext, GraphNode node, GraphCamera camera)
        {
            var commentNode = node as CommentNode;

            DrawMessage(rendererContext, commentNode, camera);

            // Draw the pins
            base.Draw(rendererContext, node, camera);
        }