コード例 #1
0
        private void OnGUI()
        {
            // Initiation
            NodeEditor.checkInit();
            if (NodeEditor.InitiationError)
            {
                GUILayout.Label("Node Editor Initiation failed! Check console for more information!");
                return;
            }
            AssureEditor();
            AssureCanvas();

            // Specify the Canvas rect in the EditorState
            mainEditorState.canvasRect = canvasWindowRect;
            // If you want to use GetRect:
//			Rect canvasRect = GUILayoutUtility.GetRect (600, 600);
//			if (Event.current.type != EventType.Layout)
//				mainEditorState.canvasRect = canvasRect;

            // Perform drawing with error-handling
            try
            {
                NodeEditor.DrawCanvas(mainNodeCanvas, mainEditorState);
            }
            catch (Exception e)
            {             // on exceptions in drawing flush the canvas to avoid locking the ui.
                NewNodeCanvas();
                NodeEditor.ReInit(true);
                Debug.LogError("Unloaded Canvas due to exception when drawing!");
                Debug.LogException(e);
            }

            // Draw Side Window
            sideWindowWidth = Math.Min(600, Math.Max(200, (int)(position.width / 5)));
            NodeEditorGUI.StartNodeGUI();
            GUILayout.BeginArea(sideWindowRect, GUI.skin.box);
            DrawSideWindow();
            GUILayout.EndArea();
            NodeEditorGUI.EndNodeGUI();
        }
コード例 #2
0
        /// <summary>
        /// Draws the node curves
        /// </summary>
        protected internal virtual void DrawConnections()
        {
            CheckNodeKnobMigration();
            if (Event.current.type != EventType.Repaint)
            {
                return;
            }
            foreach (NodeOutput output in Outputs)
            {
                Vector2 startPos = output.GetGUIKnob().center;
                Vector2 startDir = output.GetDirection();

                foreach (NodeInput input in output.connections)
                {
                    NodeEditorGUI.DrawConnection(startPos,
                                                 startDir,
                                                 input.GetGUIKnob().center,
                                                 input.GetDirection(),
                                                 ConnectionTypes.GetTypeData(output.type, true).Color);
                }
            }
        }
コード例 #3
0
ファイル: NodeEditor.cs プロジェクト: leeeennyy/ETSM
        /// <summary>
        /// Re-Inits the NodeCanvas regardless of whetehr it was initiated before
        /// </summary>
        public static void ReInit(bool GUIFunction)
        {
            CheckEditorPath();

            // Init Resource system. Can be called anywhere else, too, if it's needed before.
            ResourceManager.SetDefaultResourcePath(editorPath + "Resources/");

            // Init NE GUI. I may throw an error if a texture was not found.
            if (!NodeEditorGUI.Init(GUIFunction))
            {
                InitiationError = true;
                return;
            }

            // Run fetching algorithms searching the script assemblies for Custom Nodes / Connection Types
            ConnectionTypes.FetchTypes();
            NodeTypes.FetchNodes();


            NodeCanvasManager.GetAllCanvasTypes();

            // Setup Callback system
            NodeEditorCallbacks.SetupReceivers();
            NodeEditorCallbacks.IssueOnEditorStartUp();

            // Init GUIScaleUtility. This fetches reflected calls and my throw a message notifying about incompability.
            GUIScaleUtility.CheckInit();

            // Init input
            NodeEditorInputSystem.SetupInput();

        #if UNITY_EDITOR
            UnityEditor.EditorApplication.update -= Update;
            UnityEditor.EditorApplication.update += Update;
            RepaintClients();
        #endif
            initiated = GUIFunction;
        }
コード例 #4
0
        /// <summary>
        /// Setup of the GUI. Only called when a GUI representation is actually used.
        /// </summary>
        private static void setupGUI()
        {
            if (!initiatedBase)
            {
                setupBaseFramework();
            }
            initiatedGUI = false;

            // Init GUIScaleUtility. This fetches reflected calls and my throw a message notifying about incompability.
            GUIScaleUtility.CheckInit();

            if (!NodeEditorGUI.Init())
            {
                InitiationError = true;
                return;
            }

                #if UNITY_EDITOR
            RepaintClients();
                #endif

            initiatedGUI = true;
        }
コード例 #5
0
        /// <summary>
        /// Draws the node curves
        /// </summary>
        protected internal virtual void DrawConnections()
        {
            CheckNodeKnobMigration();
            if (Event.current.type != EventType.Repaint)
            {
                return;
            }
            for (int outCnt = 0; outCnt < Outputs.Count; outCnt++)
            {
                NodeOutput output   = Outputs [outCnt];
                Vector2    startPos = output.GetGUIKnob().center;
                Vector2    startDir = output.GetDirection();

                for (int conCnt = 0; conCnt < output.connections.Count; conCnt++)
                {
                    NodeInput input  = output.connections [conCnt];
                    Vector2   endPos = input.GetGUIKnob().center;
                    Vector2   endDir = input.GetDirection();
                    NodeEditorGUI.OptimiseBezierDirections(startPos, ref startDir, endPos, ref endDir);
                    NodeEditorGUI.DrawConnection(startPos, startDir, endPos, endDir, output.typeData.Color);
                }
            }
        }
コード例 #6
0
 public void CheckTexture()
 {
     if (knobTexture == null)
     {
         knobTexture = ConnectionTypes.GetTypeData(type).InputKnob;
         if (knobTexture == null)
         {
             throw new UnityException("Connection type " + type + " has no knob texture assigned!");
         }
         if (side != NodeSide.Left)
         {
             int cur = (int)NodeSide.Left, next = (int)side;
             if (next < cur)
             {
                 next += 4;
             }
             while (cur < next)
             {
                 knobTexture = NodeEditorGUI.RotateTexture90Degrees(knobTexture);
                 cur++;
             }
         }
     }
 }
コード例 #7
0
        /// <summary>
        /// Draws the node curves
        /// </summary>
        protected internal virtual void DrawConnections()
        {
            CheckNodeKnobMigration();
            if (Event.current.type != EventType.Repaint)
            {
                return;
            }
            for (int outCnt = 0; outCnt < Outputs.Count; outCnt++)
            {
                NodeOutput output   = Outputs [outCnt];
                Vector2    startPos = output.GetGUIKnob().center;
                Vector2    startDir = output.GetDirection();

                for (int conCnt = 0; conCnt < output.connections.Count; conCnt++)
                {
                    NodeInput input = output.connections [conCnt];
                    NodeEditorGUI.DrawConnection(startPos,
                                                 startDir,
                                                 input.GetGUIKnob().center,
                                                 input.GetDirection(),
                                                 ConnectionTypes.GetTypeData(output.type).col);
                }
            }
        }
コード例 #8
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 (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();
        }
コード例 #9
0
ファイル: NodeEditor.cs プロジェクト: gouki04/Node_Editor
        /// <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;
        }
コード例 #10
0
        /// <summary>
        /// Draws the Node Canvas on the screen in the rect specified by editorState
        /// </summary>
        public 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)
            {             // Draw Background when Repainting
                GUI.BeginClip(curEditorState.canvasRect);

                float   width  = NodeEditorGUI.Background.width / curEditorState.zoom;
                float   height = NodeEditorGUI.Background.height / curEditorState.zoom;
                Vector2 offset = new Vector2((curEditorState.panOffset.x / curEditorState.zoom) % width - width,
                                             (curEditorState.panOffset.y / curEditorState.zoom) % 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++)
                    {
                        Rect texRect = new Rect(offset.x + x * width,
                                                offset.y + y * height,
                                                width, height);

                        GUI.DrawTexture(texRect, NodeEditorGUI.Background);
                    }
                }
                GUI.EndClip();
            }

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


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

            curEditorState.zoomPanAdjust = GUIScaleUtility.BeginScale(ref canvasRect, curEditorState.zoomPos, curEditorState.zoom, true);
            //GUILayout.Label ("Scaling is Great!"); -> Test by changin 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
                NodeEditorGUI.DrawLine(curEditorState.activeNode != null? curEditorState.activeNode.rect.center + curEditorState.zoomPanAdjust : curEditorState.panOffset,
                                       ScreenToGUIPos(mousePos) + curEditorState.zoomPos * curEditorState.zoom,
                                       Color.black, null, 3);
                if (Repaint != null)
                {
                    Repaint();
                }
            }
            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);
                if (Repaint != null)
                {
                    Repaint();
                }
            }
            if (curEditorState.makeTransition != null)
            {             // Draw the currently made transition
                NodeEditorGUI.DrawLine(curEditorState.makeTransition.rect.center + curEditorState.zoomPanAdjust,
                                       ScreenToGUIPos(mousePos) + curEditorState.zoomPos * curEditorState.zoom,
                                       Color.grey, null, 3);
                if (Repaint != null)
                {
                    Repaint();
                }
            }

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

            // 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;
        }
コード例 #11
0
 public void GenerateColor()
 {         // Generate consistent color for a type - using string because it delivers greater variety of colors than type hashcode
     color = NodeEditorGUI.RandomColorHSV(Identifier.GetHashCode(), 0, 1, 0.6f, 0.8f, 0.8f, 1.4f);
 }
コード例 #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>
        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();
            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);
            //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;
                Vector2    startPos = output.GetGUIKnob().center;
                Vector2    endPos   = ScreenToGUIPos(mousePos) + curEditorState.zoomPos * curEditorState.zoom;
                Vector2    endDir   = output.GetDirection();
                NodeEditorGUI.DrawConnection(startPos, endDir, endPos,
                                             NodeEditorGUI.GetSecondConnectionVector(startPos, endPos, endDir),
                                             ConnectionTypes.GetTypeData(output.type, true).Color);
                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 and connections. Has to be drawn before nodes as transitions originate from node centers
            foreach (Node node in curNodeCanvas.nodes)
            {
                node.DrawConnections();
            }

            // Draw the nodes
            foreach (Node node in curNodeCanvas.nodes)
            {
                node.DrawNode();
                if (Event.current.type == EventType.Repaint)
                {
                    node.DrawKnobs();
                }
            }

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

            // End scaling group
            GUIScaleUtility.EndScale();

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

            curNodeCanvas  = prevNodeCanvas;
            curEditorState = prevEditorState;
        }
コード例 #13
0
 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;
     }
 }