Пример #1
0
        /// <summary>
        /// Draws a node connection from start to end with specified vectors
        /// </summary>
        public static void DrawConnection(Vector2 startPos, Vector2 startDir, Vector2 endPos, Vector2 endDir, ConnectionDrawMethod drawMethod, Color col)
        {
            if (drawMethod == ConnectionDrawMethod.Bezier)
            {
                float dirFactor = 80;                //Mathf.Pow ((startPos-endPos).magnitude, 0.3f) * 20;
                //Debug.Log ("DirFactor is " + dirFactor + "with a bezier lenght of " + (startPos-endPos).magnitude);

                Color coluse = col;
                coluse.r += Node.m_Saturation;
                coluse.g += Node.m_Saturation;
                coluse.b += Node.m_Saturation;
                coluse.r  = Mathf.Clamp01(coluse.r);
                coluse.g  = Mathf.Clamp01(coluse.g);
                coluse.b  = Mathf.Clamp01(coluse.b);
                coluse.r *= Node.m_WireColbright;
                coluse.g *= Node.m_WireColbright;
                coluse.b *= Node.m_WireColbright;

                RTEditorGUI.DrawBezier(startPos, endPos, startPos + startDir * dirFactor, endPos + endDir * dirFactor, coluse, null, Node.m_WireSize);
                Vector2 sp = startPos + Vector2.one * Node.m_DropShadowOffset;
                Vector2 ep = endPos + Vector2.one * Node.m_DropShadowOffset;
                col   = Color.black;
                col.a = Node.m_DropShadowMult2;
                RTEditorGUI.DrawBezier(sp, ep, sp + startDir * dirFactor, ep + endDir * dirFactor, col * Color.black, null, Node.m_WireSize2);
            }
            else if (drawMethod == ConnectionDrawMethod.StraightLine)
            {
                RTEditorGUI.DrawLine(startPos, endPos, col * Color.gray, null, 3);
            }
        }
Пример #2
0
 public static void DrawConnection(Vector2 startPos, Vector2 startDir, Vector2 endPos, Vector2 endDir, ConnectionDrawMethod drawMethod, Color col)
 {
     if (drawMethod == ConnectionDrawMethod.Bezier)
     {
         float dirFactor = 80;
         RTEditorGUI.DrawBezier(startPos, endPos, startPos + startDir * dirFactor, endPos + endDir * dirFactor, col * Color.gray, null, 6);
     }
     else if (drawMethod == ConnectionDrawMethod.StraightLine)
     {
         RTEditorGUI.DrawLine(startPos, endPos, col * Color.gray, null, 3);
     }
 }
        public void Render(Rect rect, float width, Color colour)
        {
            EdgeType edgeType = this.edgeType;

            if (edgeType == EdgeType.GenericEdge)
            {
                goto IL_0013;
            }
            goto IL_0013;
IL_0013:
            RTEditorGUI.DrawLine(rect, SourcePos(), TargetPos(), colour, null, width);
        }
Пример #4
0
 /// <summary>
 /// Draws a node connection from start to end with specified vectors
 /// </summary>
 public static void DrawConnection(Vector2 startPos, Vector2 startDir, Vector2 endPos, Vector2 endDir, ConnectionDrawMethod drawMethod, Color col)
 {
     if (drawMethod == ConnectionDrawMethod.Bezier)
     {
         float dirFactor = 80;                //Mathf.Pow ((startPos-endPos).magnitude, 0.3f) * 20;
         //Debug.Log ("DirFactor is " + dirFactor + "with a bezier lenght of " + (startPos-endPos).magnitude);
         RTEditorGUI.DrawBezier(startPos, endPos, startPos + startDir * dirFactor, endPos + endDir * dirFactor, col * Color.gray, null, 3);
     }
     else if (drawMethod == ConnectionDrawMethod.StraightLine)
     {
         RTEditorGUI.DrawLine(startPos, endPos, col * Color.gray, null, 3);
     }
 }
        public static void DrawConnection(Vector2 startPos, Vector2 startDir, Vector2 endPos, Vector2 endDir, ConnectionDrawMethod drawMethod, Color col)
        {
            switch (drawMethod)
            {
            case ConnectionDrawMethod.Bezier:
            {
                float d = 80f;
                RTEditorGUI.DrawBezier(startPos, endPos, startPos + startDir * d, endPos + endDir * d, col * Color.gray, null, 3f);
                break;
            }

            case ConnectionDrawMethod.StraightLine:
                RTEditorGUI.DrawLine(startPos, endPos, col * Color.gray, null, 3f);
                break;
            }
        }
Пример #6
0
 /// <summary>
 /// Draws a node connection from start to end with specified vectors
 /// </summary>
 public static void DrawConnection(Vector2 startPos, Vector2 startDir, Vector2 endPos, Vector2 endDir, ConnectionDrawMethod drawMethod,
                                   Color col)
 {
     if (drawMethod == ConnectionDrawMethod.Bezier)
     {
         NodeEditorGUI.OptimiseBezierDirections(startPos, ref startDir, endPos, ref endDir);
         float dirFactor = 80; //Mathf.Pow ((startPos-endPos).magnitude, 0.3f) * 20;
         //Debug.Log ("DirFactor is " + dirFactor + "with a bezier lenght of " + (startPos-endPos).magnitude);
         RTEditorGUI.DrawBezier(startPos, endPos, startPos + startDir * dirFactor, endPos + endDir * dirFactor, col, null,
                                NodeEditor.curEditorState.zoom * 3);
     }
     else if (drawMethod == ConnectionDrawMethod.StraightLine)
     {
         RTEditorGUI.DrawLine(startPos, endPos, col, null, NodeEditor.curEditorState.zoom * 3);
     }
 }
Пример #7
0
        /// <summary>
        /// Draws the node transitions.
        /// </summary>
        public void DrawTransitions()
        {
            for (int cnt = 0; cnt < transitions.Count; cnt++)
            {
                Vector2 StartPoint = transitions[cnt].startNode.rect.center + NodeEditor.curEditorState.zoomPanAdjust;
                Vector2 EndPoint   = transitions[cnt].endNode.rect.center + NodeEditor.curEditorState.zoomPanAdjust;
                RTEditorGUI.DrawLine(StartPoint, EndPoint, Color.grey, null, 3);

                Rect selectRect = new Rect(0, 0, 20, 20);
                selectRect.center = Vector2.Lerp(StartPoint, EndPoint, 0.5f);

                if (GUI.Button(selectRect, "#"))
                {
                    // TODO: Select
                }
            }
        }
Пример #8
0
        /// <summary>
        /// Draws this transition as a line and a button to select it. Has to be called from the start node
        /// </summary>
        public void DrawFromStartNode()
        {
            Vector2 StartPoint = startNode.rect.center + NodeEditor.curEditorState.zoomPanAdjust;
            Vector2 EndPoint   = endNode.rect.center + NodeEditor.curEditorState.zoomPanAdjust;

            if (isTransitioning)
            {
                RTEditorGUI.DrawLine(StartPoint, Vector2.Lerp(StartPoint, EndPoint, transitionProgress()), Color.cyan, null, 4);
            }
            RTEditorGUI.DrawLine(StartPoint, EndPoint, Color.grey, null, 3);

            Rect selectRect = new Rect(0, 0, 20, 20);

            selectRect.center = Vector2.Lerp(StartPoint, EndPoint, 0.5f);
            if (GUI.Button(selectRect, "#"))
            {
                Debug.Log("Selected " + name);
                // TODO: Select
                #if UNITY_EDITOR
                UnityEditor.Selection.activeObject = this;
                #endif
            }
        }
        /// <summary>
        /// Draws the Node Canvas on the screen in the rect specified by editorState without one-time wrappers like GUISkin and OverlayGUI. Made for nested Canvases (WIP)
        /// </summary>
        private static void DrawSubCanvas(NodeCanvas nodeCanvas, NodeEditorState editorState)
        {
            if (!editorState.drawing)
            {
                return;
            }

            BeginEditingCanvas(nodeCanvas, editorState);

            if (Event.current.type == EventType.Repaint)
            {             // Draw Background when Repainting
                // Offset from origin in tile units
                Vector2 tileOffset = new Vector2(-(curEditorState.zoomPos.x * curEditorState.zoom + curEditorState.panOffset.x) / NodeEditorGUI.Background.width,
                                                 ((curEditorState.zoomPos.y - curEditorState.canvasRect.height) * curEditorState.zoom + curEditorState.panOffset.y) / NodeEditorGUI.Background.height);
                // Amount of tiles
                Vector2 tileAmount = new Vector2(Mathf.Round(curEditorState.canvasRect.width * curEditorState.zoom) / NodeEditorGUI.Background.width,
                                                 Mathf.Round(curEditorState.canvasRect.height * curEditorState.zoom) / NodeEditorGUI.Background.height);
                // Draw tiled background
                GUI.DrawTextureWithTexCoords(curEditorState.canvasRect, NodeEditorGUI.Background, new Rect(tileOffset, tileAmount));
            }

            // Handle input events
            NodeEditorInputSystem.HandleInputEvents(curEditorState);
            if (Event.current.type != EventType.Layout)
            {
                curEditorState.ignoreInput = new List <Rect> ();
            }

            // We're using a custom scale method, as default one is messing up clipping rect
            Rect canvasRect = curEditorState.canvasRect;

            curEditorState.zoomPanAdjust = GUIScaleUtility.BeginScale(ref canvasRect, curEditorState.zoomPos, curEditorState.zoom, NodeEditorGUI.isEditorWindow, false);

            // ---- BEGIN SCALE ----

            // Some features which require zoomed drawing:

            if (curEditorState.navigate)
            {             // Draw a curve to the origin/active node for orientation purposes
                Vector2 startPos = (curEditorState.selectedNode != null? curEditorState.selectedNode.rect.center : curEditorState.panOffset) + curEditorState.zoomPanAdjust;
                Vector2 endPos   = Event.current.mousePosition;
                RTEditorGUI.DrawLine(startPos, endPos, Color.green, null, 3);
                RepaintClients();
            }

            if (curEditorState.connectOutput != null)
            {             // Draw the currently drawn connection
                NodeOutput output   = curEditorState.connectOutput;
                Vector2    startPos = output.GetGUIKnob().center;
                Vector2    startDir = output.GetDirection();
                Vector2    endPos   = Event.current.mousePosition;
                Vector2    endDir   = -startDir;            // NodeEditorGUI.GetSecondConnectionVector (startPos, endPos, startDir); <- causes unpleasant jumping when switching polarity

                NodeEditorGUI.OptimiseBezierDirections(startPos, ref startDir, endPos, ref endDir);
                NodeEditorGUI.DrawConnection(startPos, startDir, endPos, endDir, output.typeData.Color);
                RepaintClients();
            }

            // Draw the groups below everything else
            for (int groupCnt = 0; groupCnt < curNodeCanvas.groups.Count; groupCnt++)
            {
                curNodeCanvas.groups [groupCnt].DrawGroup();
            }

            // Push the active node to the top of the draw order.
            if (Event.current.type == EventType.Layout && curEditorState.selectedNode != null)
            {
                curNodeCanvas.nodes.Remove(curEditorState.selectedNode);
                curNodeCanvas.nodes.Add(curEditorState.selectedNode);
            }

            // Draw the transitions and connections. Has to be drawn before nodes as transitions originate from node centers
            for (int nodeCnt = 0; nodeCnt < curNodeCanvas.nodes.Count; nodeCnt++)
            {
                curNodeCanvas.nodes [nodeCnt].DrawConnections();
            }

            // Draw the nodes
            for (int nodeCnt = 0; nodeCnt < curNodeCanvas.nodes.Count; nodeCnt++)
            {
                Node node = curNodeCanvas.nodes [nodeCnt];
                node.DrawNode();
                if (Event.current.type == EventType.Repaint)
                {
                    node.DrawKnobs();
                }
            }

            // ---- END SCALE ----

            // End scaling group
            GUIScaleUtility.EndScale();

            // Handle input events with less priority than node GUI controls
            NodeEditorInputSystem.HandleLateInputEvents(curEditorState);

            EndEditingCanvas();
        }
Пример #10
0
        /// <summary>
        /// Draws the Node Canvas on the screen in the rect specified by editorState without one-time wrappers like GUISkin and OverlayGUI. Made for nested Canvases (WIP)
        /// </summary>
        private static void DrawSubCanvas(NodeCanvas nodeCanvas, NodeEditorState editorState)
        {
            if (!editorState.drawing)
            {
                return;
            }

            // Store and restore later on in case of this being a nested Canvas
            NodeCanvas      prevNodeCanvas  = curNodeCanvas;
            NodeEditorState prevEditorState = curEditorState;

            curNodeCanvas  = nodeCanvas;
            curEditorState = editorState;

            if (Event.current.type == EventType.Repaint)
            {             // Draw Background when Repainting
                // Size in pixels the inividual background tiles will have on screen
                float width  = curEditorState.zoom / NodeEditorGUI.Background.width;
                float height = curEditorState.zoom / NodeEditorGUI.Background.height;
                // Offset of the grid relative to the GUI origin
                Vector2 offset = curEditorState.zoomPos + curEditorState.panOffset / curEditorState.zoom;
                // Rect in UV space that defines how to tile the background texture
                Rect uvDrawRect = new Rect(-offset.x * width,
                                           (offset.y - curEditorState.canvasRect.height) * height,
                                           curEditorState.canvasRect.width * width,
                                           curEditorState.canvasRect.height * height);
                GUI.DrawTextureWithTexCoords(curEditorState.canvasRect, NodeEditorGUI.Background, uvDrawRect);
            }

            // Handle input events
            NodeEditorInputSystem.HandleInputEvents(curEditorState);
            if (Event.current.type != EventType.Layout)
            {
                curEditorState.ignoreInput = new List <Rect> ();
            }

            // We're using a custom scale method, as default one is messing up clipping rect
            Rect canvasRect = curEditorState.canvasRect;

            curEditorState.zoomPanAdjust = GUIScaleUtility.BeginScale(ref canvasRect, curEditorState.zoomPos, curEditorState.zoom, false);

            // ---- BEGIN SCALE ----

            // Some features which require zoomed drawing:

            if (curEditorState.navigate)
            {             // Draw a curve to the origin/active node for orientation purposes
                Vector2 startPos = (curEditorState.selectedNode != null? curEditorState.selectedNode.rect.center : curEditorState.panOffset) + curEditorState.zoomPanAdjust;
                Vector2 endPos   = Event.current.mousePosition;
                RTEditorGUI.DrawLine(startPos, endPos, Color.green, null, 3);
                RepaintClients();
            }

            if (curEditorState.connectOutput != null)
            {             // Draw the currently drawn connection
                NodeOutput output   = curEditorState.connectOutput;
                Vector2    startPos = output.GetGUIKnob().center;
                Vector2    startDir = output.GetDirection();
                Vector2    endPos   = Event.current.mousePosition;
                // There is no specific direction of the end knob so we pick the best according to the relative position
                Vector2 endDir = NodeEditorGUI.GetSecondConnectionVector(startPos, endPos, startDir);
                NodeEditorGUI.DrawConnection(startPos, startDir, endPos, endDir, output.typeData.Color);
                RepaintClients();
            }

            // Push the active node to the top of the draw order.
            if (Event.current.type == EventType.Layout && curEditorState.selectedNode != null)
            {
                curNodeCanvas.nodes.Remove(curEditorState.selectedNode);
                curNodeCanvas.nodes.Add(curEditorState.selectedNode);
            }

            // Draw the transitions and connections. Has to be drawn before nodes as transitions originate from node centers
            for (int nodeCnt = 0; nodeCnt < curNodeCanvas.nodes.Count; nodeCnt++)
            {
                curNodeCanvas.nodes [nodeCnt].DrawConnections();
            }

            // Draw the nodes
            for (int nodeCnt = 0; nodeCnt < curNodeCanvas.nodes.Count; nodeCnt++)
            {
                Node node = curNodeCanvas.nodes [nodeCnt];
                node.DrawNode();
                if (Event.current.type == EventType.Repaint)
                {
                    node.DrawKnobs();
                }
            }

            // ---- END SCALE ----

            // End scaling group
            GUIScaleUtility.EndScale();

            // Handle input events with less priority than node GUI controls
            NodeEditorInputSystem.HandleLateInputEvents(curEditorState);

            curNodeCanvas  = prevNodeCanvas;
            curEditorState = prevEditorState;
        }
Пример #11
0
        private static void DrawSubCanvas(NodeCanvas nodeCanvas, NodeEditorState editorState)
        {
            if (!editorState.drawing)
            {
                return;
            }

            NodeCanvas      prevNodeCanvas  = curNodeCanvas;
            NodeEditorState prevEditorState = curEditorState;

            curNodeCanvas  = nodeCanvas;
            curEditorState = editorState;

            if (Event.current.type == EventType.Repaint)
            {
                float   width      = curEditorState.zoom / NodeEditorGUI.Background.width;
                float   height     = curEditorState.zoom / NodeEditorGUI.Background.height;
                Vector2 offset     = curEditorState.zoomPos + curEditorState.panOffset / curEditorState.zoom;
                Rect    uvDrawRect = new Rect(-offset.x * width,
                                              (offset.y - curEditorState.canvasRect.height) * height,
                                              curEditorState.canvasRect.width * width,
                                              curEditorState.canvasRect.height * height);
                GUI.DrawTextureWithTexCoords(curEditorState.canvasRect, NodeEditorGUI.Background, uvDrawRect);
            }

            NodeEditorInputSystem.HandleInputEvents(curEditorState);
            if (Event.current.type != EventType.Layout)
            {
                curEditorState.ignoreInput = new List <Rect>();
            }

            Rect canvasRect = curEditorState.canvasRect;

            curEditorState.zoomPanAdjust = GUIScaleUtility.BeginScale(ref canvasRect, curEditorState.zoomPos, curEditorState.zoom, false);
            if (curEditorState.navigate)
            {
                Vector2 startPos = (curEditorState.selectedNode != null ? curEditorState.selectedNode.rect.center : curEditorState.panOffset) + curEditorState.zoomPanAdjust;
                Vector2 endPos   = Event.current.mousePosition;
                RTEditorGUI.DrawLine(startPos, endPos, Color.green, null, 3);
                RepaintClients();
            }

            if (curEditorState.connectOutput != null)
            {
                NodeOutput output   = curEditorState.connectOutput;
                Vector2    startPos = output.GetGUIKnob().center;
                Vector2    startDir = output.GetDirection();
                Vector2    endPos   = Event.current.mousePosition;
                Vector2    endDir   = NodeEditorGUI.GetSecondConnectionVector(startPos, endPos, startDir);
                NodeEditorGUI.DrawConnection(startPos, startDir, endPos, endDir, output.typeData.Color);
                RepaintClients();
            }

            if (Event.current.type == EventType.Layout && curEditorState.selectedNode != null)
            {
                curNodeCanvas.nodes.Remove(curEditorState.selectedNode);
                curNodeCanvas.nodes.Add(curEditorState.selectedNode);
            }

            for (int nodeCnt = 0; nodeCnt < curNodeCanvas.nodes.Count; nodeCnt++)
            {
                curNodeCanvas.nodes[nodeCnt].DrawConnections();
            }

            for (int nodeCnt = 0; nodeCnt < curNodeCanvas.nodes.Count; nodeCnt++)
            {
                Node node = curNodeCanvas.nodes[nodeCnt];
                node.DrawNode();
                if (Event.current.type == EventType.Repaint)
                {
                    node.DrawKnobs();
                }
            }

            GUIScaleUtility.EndScale();

            GUI.DrawTexture(new Rect(12, 12, NodeEditorGUI.GuiShadero.width / 2, NodeEditorGUI.GuiShadero.height / 2), NodeEditorGUI.GuiShadero);
            GUIStyle g = new GUIStyle();

            g.fontSize         = 26;
            g.normal.textColor = Color.white;
            if (Node.ShaderNameX == "")
            {
                Node.ShaderNameX = "Default";
            }
            g          = new GUIStyle();
            g.fontSize = 22;

            if (FlagIsLoadedMaterial)
            {
                FlagIsLoadedMaterial = false;
            }
            if (FlagIsSavedMaterial)
            {
                FlagIsSavedMaterial = false;
            }

            g                  = new GUIStyle();
            g.fontSize         = 18;
            g.normal.textColor = Color.white;

            Texture2D preview = ResourceManager.LoadTexture("Textures/previews/shadero_firstscreen.jpg");

            g           = new GUIStyle();
            g.fontSize  = 18;
            g.fontStyle = FontStyle.Italic;
            Color yellow = new Color(0, 1, 1, UpdatePreview);

            UpdatePreview -= Time.deltaTime * 0.2f;
            if (UpdatePreview < 0)
            {
                UpdatePreview = 0;
            }
            g.normal.textColor = yellow;

            Rect position = _ShaderoShaderEditorFramework.Standard.NodeEditorWindow.editor.position;

            GUI.Label(new Rect(position.width - 320, position.height - 50, 150, 50), "*Updated*", g);

            Node.ShaderNameX = NodeEditor.curEditorState.ShaderName;

            if (curNodeCanvas.nodes.Count == 0)
            {
                preview = ResourceManager.LoadTexture("Textures/previews/shadero_firstscreen.jpg");
                Vector2 scr  = new Vector2(position.width / 2 - 120, position.height / 2);
                Vector2 size = new Vector2(1365 / 2, 781 / 2);
                GUI.DrawTexture(new Rect(scr.x - size.x / 2, scr.y - size.y / 2, size.x, size.y), preview);
            }

            NodeEditorInputSystem.HandleLateInputEvents(curEditorState);
            curNodeCanvas  = prevNodeCanvas;
            curEditorState = prevEditorState;
        }
Пример #12
0
        /// <summary>
        /// Draws the Node Canvas on the screen in the rect specified by editorState without one-time wrappers like GUISkin and OverlayGUI. Made for nested Canvases (WIP)
        /// </summary>
        private static void DrawSubCanvas(NodeCanvas nodeCanvas, NodeEditorState editorState)
        {
            if (!editorState.drawing)
            {
                return;
            }

            BeginEditingCanvas(nodeCanvas, editorState);
            if (curNodeCanvas == null || curEditorState == null || !curEditorState.drawing)
            {
                return;
            }

            if (Event.current.type == EventType.Repaint)
            {
                // Draw Background when Repainting
                // Offset from origin in tile units
                Vector2 tileOffset = new Vector2(
                    -(curEditorState.zoomPos.x * curEditorState.zoom + curEditorState.panOffset.x) / NodeEditorGUI.Background.width,
                    ((curEditorState.zoomPos.y - curEditorState.canvasRect.height) * curEditorState.zoom + curEditorState.panOffset.y) /
                    NodeEditorGUI.Background.height);
                // Amount of tiles
                Vector2 tileAmount = new Vector2(Mathf.Round(curEditorState.canvasRect.width * curEditorState.zoom) / NodeEditorGUI.Background.width,
                                                 Mathf.Round(curEditorState.canvasRect.height * curEditorState.zoom) / NodeEditorGUI.Background.height);
                // Draw tiled background
                GUI.DrawTextureWithTexCoords(curEditorState.canvasRect, NodeEditorGUI.Background, new Rect(tileOffset, tileAmount));
            }

            // Handle input events
            NodeEditorInputSystem.HandleInputEvents(curEditorState);

            HandleMultipleSelect();

            if (Event.current.type != EventType.Layout)
            {
                curEditorState.ignoreInput = new List <Rect>();
            }

            // We're using a custom scale method, as default one is messing up clipping rect
            Rect canvasRect = curEditorState.canvasRect;

            curEditorState.zoomPanAdjust = GUIScaleUtility.BeginScale(ref canvasRect, curEditorState.zoomPos, curEditorState.zoom,
                                                                      NodeEditorGUI.isEditorWindow, false);

            // ---- BEGIN SCALE ----

            // Some features which require zoomed drawing:

            if (curEditorState.navigate)
            {
                // Draw a curve to the origin/active node for orientation purposes
                Vector2 startPos = (curEditorState.selectedNodes.Count > 0? curEditorState.selectedNodes[0].rect.center : curEditorState.panOffset) +
                                   curEditorState.zoomPanAdjust;
                Vector2 endPos = Event.current.mousePosition;
                RTEditorGUI.DrawLine(startPos, endPos, Color.green, null, 3);
                RepaintClients();
            }

            if (curEditorState.connectKnob != null)
            {
                // Draw the currently drawn connection
                curEditorState.connectKnob.DrawConnection(Event.current.mousePosition);
                RepaintClients();
            }

            // Draw the groups below everything else
            for (int groupCnt = 0; groupCnt < curNodeCanvas.groups.Count; groupCnt++)
            {
                NodeGroup group = curNodeCanvas.groups[groupCnt];
                if (Event.current.type == EventType.Layout)
                {
                    group.isClipped = !curEditorState.canvasViewport.Overlaps(group.fullAABBRect);
                }
                if (!group.isClipped)
                {
                    group.DrawGroup();
                }
            }

            // Push the active node to the top of the draw order.
            if (Event.current.type == EventType.Layout && curEditorState.selectedNodes.Count > 0)
            {
                foreach (var node in curEditorState.selectedNodes)
                {
                    curNodeCanvas.nodes.Remove(node);
                    curNodeCanvas.nodes.Add(node);
                }
            }

            // Draw the transitions and connections. Has to be drawn before nodes as transitions originate from node centers
            for (int nodeCnt = 0; nodeCnt < curNodeCanvas.nodes.Count; nodeCnt++)
            {
                curNodeCanvas.nodes[nodeCnt].DrawConnections();
            }

            // Draw the nodes
            for (int nodeCnt = 0; nodeCnt < curNodeCanvas.nodes.Count; nodeCnt++)
            {
                Node node = curNodeCanvas.nodes[nodeCnt];
                if (Event.current.type == EventType.Layout)
                {
                    node.isClipped = !curEditorState.canvasViewport.Overlaps(curNodeCanvas.nodes[nodeCnt].fullAABBRect);
                }
                if (!node.isClipped || node.ForceGUIDawOffScreen)
                {
                    node.DrawNode();
                    if (Event.current.type == EventType.Repaint)
                    {
                        node.DrawKnobs();
                    }
                }
            }

            // ---- END SCALE ----

            // End scaling group
            GUIScaleUtility.EndScale();

            // Handle input events with less priority than node GUI controls
            NodeEditorInputSystem.HandleLateInputEvents(curEditorState);

            EndEditingCanvas();
        }
Пример #13
0
        /// <summary>
        /// Draws the Node Canvas on the screen in the rect specified by editorState without one-time wrappers like GUISkin and OverlayGUI. Made for nested Canvases (WIP)
        /// </summary>
        public static void DrawSubCanvas(NodeCanvas nodeCanvas, NodeEditorState editorState)
        {
            if (!editorState.drawing)
            {
                return;
            }

            // Store and restore later on in case of this being a nested Canvas
            NodeCanvas      prevNodeCanvas  = curNodeCanvas;
            NodeEditorState prevEditorState = curEditorState;

            curNodeCanvas  = nodeCanvas;
            curEditorState = editorState;

            if (Event.current.type == EventType.Repaint)
            {             // Draw Background when Repainting
                GUI.BeginClip(curEditorState.canvasRect);

                float   width  = NodeEditorGUI.Background.width / curEditorState.zoom;
                float   height = NodeEditorGUI.Background.height / curEditorState.zoom;
                Vector2 offset = curEditorState.zoomPos + curEditorState.panOffset / curEditorState.zoom;
                offset = new Vector2(offset.x % width - width, offset.y % height - height);
                int tileX = Mathf.CeilToInt((curEditorState.canvasRect.width + (width - offset.x)) / width);
                int tileY = Mathf.CeilToInt((curEditorState.canvasRect.height + (height - offset.y)) / height);

                for (int x = 0; x < tileX; x++)
                {
                    for (int y = 0; y < tileY; y++)
                    {
                        GUI.DrawTexture(new Rect(offset.x + x * width,
                                                 offset.y + y * height,
                                                 width, height),
                                        NodeEditorGUI.Background);
                    }
                }
                GUI.EndClip();
            }

            // Check the inputs
            InputEvents(curEditorState.ignoreInput);
            curEditorState.ignoreInput = new List <Rect> ();


            // We're using a custom scale method, as default one is messing up clipping rect
            Rect canvasRect = curEditorState.canvasRect;

            curEditorState.zoomPanAdjust = GUIScaleUtility.BeginScale(ref canvasRect, curEditorState.zoomPos, curEditorState.zoom, false);
            //GUILayout.Label ("Scaling is Great!"); -> TODO: Test by changing the last bool parameter

            // ---- BEGIN SCALE ----

            // Some features which require drawing (zoomed)
            if (curEditorState.navigate)
            {             // Draw a curve to the origin/active node for orientation purposes
                RTEditorGUI.DrawLine((curEditorState.selectedNode != null? curEditorState.selectedNode.rect.center : curEditorState.panOffset) + curEditorState.zoomPanAdjust,
                                     ScreenToGUIPos(mousePos) + curEditorState.zoomPos * curEditorState.zoom,
                                     Color.black, null, 3);
                RepaintClients();
            }
            if (curEditorState.connectOutput != null)
            {             // Draw the currently drawn connection
                NodeOutput output = curEditorState.connectOutput;
                DrawConnection(output.GetGUIKnob().center,
                               output.GetDirection(),
                               ScreenToGUIPos(mousePos) + curEditorState.zoomPos * curEditorState.zoom,
                               Vector2.right,
                               ConnectionTypes.GetTypeData(output.type).col);
                RepaintClients();
            }
            if (curEditorState.makeTransition != null)
            {             // Draw the currently made transition
                RTEditorGUI.DrawLine(curEditorState.makeTransition.rect.center + curEditorState.zoomPanAdjust,
                                     ScreenToGUIPos(mousePos) + curEditorState.zoomPos * curEditorState.zoom,
                                     Color.grey, null, 3);
                RepaintClients();
            }

            // Push the active node at the bottom of the draw order.
            if (Event.current.type == EventType.Layout && curEditorState.selectedNode != null)
            {
                curNodeCanvas.nodes.Remove(curEditorState.selectedNode);
                curNodeCanvas.nodes.Add(curEditorState.selectedNode);
            }

            // Draw the transitions. Has to be called before nodes as transitions originate from node centers
            for (int nodeCnt = 0; nodeCnt < curNodeCanvas.nodes.Count; nodeCnt++)
            {
                curNodeCanvas.nodes [nodeCnt].DrawTransitions();
            }

            for (int nodeCnt = 0; nodeCnt < curNodeCanvas.nodes.Count; nodeCnt++)
            {
                curNodeCanvas.nodes [nodeCnt].DrawConnections();
            }

            // Draw the nodes
            for (int nodeCnt = 0; nodeCnt < curNodeCanvas.nodes.Count; nodeCnt++)
            {
                curNodeCanvas.nodes [nodeCnt].DrawNode();
                curNodeCanvas.nodes [nodeCnt].DrawKnobs();
            }

            // ---- END SCALE ----

            // End scaling group
            GUIScaleUtility.EndScale();

            // Check events with less priority than node GUI controls
            LateEvents(curEditorState.ignoreInput);

            curNodeCanvas  = prevNodeCanvas;
            curEditorState = prevEditorState;
        }
 private static void DrawSubCanvas(NodeCanvas nodeCanvas, NodeEditorState editorState)
 {
     if (editorState.drawing)
     {
         NodeCanvas      nodeCanvas2     = curNodeCanvas;
         NodeEditorState nodeEditorState = curEditorState;
         curNodeCanvas  = nodeCanvas;
         curEditorState = editorState;
         if (Event.current.type == EventType.Repaint)
         {
             float   num    = curEditorState.zoom / (float)NodeEditorGUI.Background.width;
             float   num2   = curEditorState.zoom / (float)NodeEditorGUI.Background.height;
             Vector2 vector = curEditorState.zoomPos + curEditorState.panOffset / curEditorState.zoom;
             GUI.DrawTextureWithTexCoords(texCoords: new Rect((0f - vector.x) * num, (vector.y - curEditorState.canvasRect.height) * num2, curEditorState.canvasRect.width * num, curEditorState.canvasRect.height * num2), position: curEditorState.canvasRect, image: NodeEditorGUI.Background);
         }
         NodeEditorInputSystem.HandleInputEvents(curEditorState);
         if (Event.current.type != EventType.Layout)
         {
             curEditorState.ignoreInput = new List <Rect>();
         }
         Rect rect = curEditorState.canvasRect;
         curEditorState.zoomPanAdjust = GUIScaleUtility.BeginScale(ref rect, curEditorState.zoomPos, curEditorState.zoom, false);
         if (curEditorState.navigate)
         {
             Vector2 startPos      = ((!((UnityEngine.Object)curEditorState.selectedNode != (UnityEngine.Object)null)) ? curEditorState.panOffset : curEditorState.selectedNode.rect.center) + curEditorState.zoomPanAdjust;
             Vector2 mousePosition = Event.current.mousePosition;
             RTEditorGUI.DrawLine(startPos, mousePosition, Color.green, null, 3f);
             RepaintClients();
         }
         if ((UnityEngine.Object)curEditorState.connectOutput != (UnityEngine.Object)null)
         {
             NodeOutput connectOutput          = curEditorState.connectOutput;
             Vector2    center                 = connectOutput.GetGUIKnob().center;
             Vector2    direction              = connectOutput.GetDirection();
             Vector2    mousePosition2         = Event.current.mousePosition;
             Vector2    secondConnectionVector = NodeEditorGUI.GetSecondConnectionVector(center, mousePosition2, direction);
             NodeEditorGUI.DrawConnection(center, direction, mousePosition2, secondConnectionVector, connectOutput.typeData.Color);
             RepaintClients();
         }
         if (Event.current.type == EventType.Layout && (UnityEngine.Object)curEditorState.selectedNode != (UnityEngine.Object)null)
         {
             curNodeCanvas.nodes.Remove(curEditorState.selectedNode);
             curNodeCanvas.nodes.Add(curEditorState.selectedNode);
         }
         for (int i = 0; i < curNodeCanvas.nodes.Count; i++)
         {
             curNodeCanvas.nodes[i].DrawConnections();
         }
         for (int j = 0; j < curNodeCanvas.nodes.Count; j++)
         {
             Node node = curNodeCanvas.nodes[j];
             node.DrawNode();
             if (Event.current.type == EventType.Repaint)
             {
                 node.DrawKnobs();
             }
         }
         GUIScaleUtility.EndScale();
         NodeEditorInputSystem.HandleLateInputEvents(curEditorState);
         curNodeCanvas  = nodeCanvas2;
         curEditorState = nodeEditorState;
     }
 }