Exemplo n.º 1
0
        private void DrawNodes(Event activeEvent)
        {
            var mousePos = Event.current.mousePosition;

            if (activeEvent.type != EventType.Layout)
            {
                hoveredNode = null;
                hoveredPort = null;
            }

            var preSelection = preBoxSelection != null
                ? new List <int>(preBoxSelection)
                : new List <int>();

            // Selection box stuff
            var boxStartPos = GridToWindowPositionNoClipped(dragBoxStart);

            var boxSize = mousePos - boxStartPos;

            if (boxSize.x < 0)
            {
                boxStartPos.x += boxSize.x;
                boxSize.x      = Mathf.Abs(boxSize.x);
            }

            if (boxSize.y < 0)
            {
                boxStartPos.y += boxSize.y;
                boxSize.y      = Mathf.Abs(boxSize.y);
            }

            var selectionBox = new Rect(boxStartPos, boxSize);

            if (activeEvent.type == EventType.Layout)
            {
                culledNodes = new List <INode>();
            }

            var serializableNodes = ActiveObject.FindProperty(nameof(ActiveGraph.serializableNodes));
            var assetNodes        = ActiveObject.FindProperty(nameof(ActiveGraph.nodes));

            UpdateNodes(serializableNodes, ActiveGraph.SerializableNodes);
            UpdateNodes(assetNodes, ActiveGraph.ObjectNodes);

            var eventType = activeEvent.type == EventType.Ignore ||
                            activeEvent.rawType == EventType.Ignore
                ? EventType.Ignore
                : activeEvent.type;

            var editorGuiState = new NodeEditorGuiState()
            {
                MousePosition = mousePos,
                PreSelection  = preSelection,
                Event         = activeEvent,
                EventType     = eventType,
            };

            EditorDrawerUtils.DrawAndRevertColor(() => {
                DrawNodes(regularNodes, editorGuiState);
                DrawNodes(selectedNodes, editorGuiState);
            });

            regularNodes.Clear();
            selectedNodes.Clear();

            if (activeEvent.type != EventType.Layout && currentActivity == NodeActivity.DragGrid)
            {
                selection.Where(x => preSelection.Contains(x.Id)).
                ForEach(x => x.AddToEditorSelection(true));
            }
        }