Beispiel #1
0
        private bool ShouldBeCulled(INode node)
        {
            var nodePos = GridToWindowPositionNoClipped(node.Position);

            if (nodePos.x / _zoom > position.width)
            {
                return(true);                                     // Right
            }
            if (nodePos.y / _zoom > position.height)
            {
                return(true);                                     // Bottom
            }
            if (NodeSizes.ContainsKey(node))
            {
                var size = NodeSizes[node];
                if (nodePos.x + size.x < 0)
                {
                    return(true);                        // Left
                }
                if (nodePos.y + size.y < 0)
                {
                    return(true);                        // Top
                }
            }

            return(false);
        }
Beispiel #2
0
        private void DrawNodeEditorArea(
            NodeEditor nodeEditor,
            EditorNode editorNode,
            NodeEditorGuiState state)
        {
            var eventType  = state.EventType;
            var stateEvent = state.Event;
            var node       = editorNode.Node;

            if (eventType == EventType.Ignore ||
                stateEvent.type == EventType.Ignore ||
                stateEvent.rawType == EventType.Ignore)
            {
                return;
            }

            var guiColor = GUI.color;

            var selected = IsSelected(node);

            if (selected)
            {
                var style          = new GUIStyle(nodeEditor.GetBodyStyle());
                var highlightStyle = new GUIStyle(NodeEditorResources.styles.nodeHighlight);
                highlightStyle.padding = style.padding;
                style.padding          = new RectOffset();
                GUI.color = nodeEditor.GetTint();
                GUILayout.BeginVertical(style);
                GUI.color = this.GetSettings().highlightColor;

                //TODO fix style
                GUILayout.BeginVertical(new GUIStyle(highlightStyle));
            }
            else
            {
                var style = new GUIStyle(nodeEditor.GetBodyStyle());
                GUI.color = nodeEditor.GetTint();
                GUILayout.BeginVertical(style);
            }

            GUI.color = guiColor;

            EditorGUI.BeginChangeCheck();

            //Draw node contents
            nodeEditor.OnHeaderGUI();
            nodeEditor.OnBodyGUI();

            //If user changed a value, notify other scripts through onUpdateNode
            if (EditorGUI.EndChangeCheck())
            {
                if (NodeEditor.OnUpdateNode != null)
                {
                    NodeEditor.OnUpdateNode(node);
                }
                node.SetDirty();
            }

            GUILayout.EndVertical();

            //Cache data about the node for next frame
            if (state.EventType == EventType.Repaint)
            {
                var size = GUILayoutUtility.GetLastRect().size;
                if (NodeSizes.ContainsKey(node))
                {
                    NodeSizes[node] = size;
                }
                else
                {
                    NodeSizes.Add(node, size);
                }

                foreach (var portPairs in NodeEditor.PortPositions)
                {
                    var id            = portPairs.Key;
                    var portHandlePos = portPairs.Value;
                    portHandlePos += node.Position;
                    var rect = new Rect(portHandlePos.x - 8, portHandlePos.y - 8, 16, 16);
                    PortConnectionPoints[id] = rect;
                }
            }

            if (selected)
            {
                GUILayout.EndVertical();
            }
        }