示例#1
0
        // Window GUI function
        void OnWindowGUI(int id)
        {
            // It can update the button position info on a repaint event.
            var rectUpdate = (Event.current.type == EventType.Repaint);

            // Draw the inlet labels and buttons.
            foreach (var inlet in _inlets)
            {
                if (inlet.DrawGUI(rectUpdate))
                {
                    // The inlet button was pressed; nofity via FeedbackQueue.
                    FeedbackQueue.Enqueue(new FeedbackQueue.InletButtonRecord(this, inlet));
                }
            }

            // Draw the outlet labels and buttons.
            foreach (var outlet in _outlets)
            {
                if (outlet.DrawGUI(rectUpdate))
                {
                    // The outlet button was pressed; nofity via FeedbackQueue.
                    FeedbackQueue.Enqueue(new FeedbackQueue.OutletButtonRecord(this, outlet));
                }
            }

            // The standard GUI behavior.
            _controlID = GUIUtility.GetControlID(FocusType.Keyboard);
            GUI.DragWindow();

            // Is this window clicked?
            if (Event.current.type == EventType.Used)
            {
                // Then assume it's active one.
                _activeWindowID = id;
                // Grab the keyboard focus.
                EditorGUIUtility.keyboardControl = _controlID;
            }

            var e = Event.current;

            if (e.GetTypeForControl(_controlID) == EventType.ValidateCommand)
            {
                if (e.commandName == "Delete" || e.commandName == "SoftDelete")
                {
                    e.Use();
                }
            }

            if (e.GetTypeForControl(_controlID) == EventType.ExecuteCommand)
            {
                if (e.commandName == "Delete" || e.commandName == "SoftDelete")
                {
                    FeedbackQueue.Enqueue(new FeedbackQueue.DeleteNodeRecord(this));
                }
            }
        }
        // GUI function for the main view
        void DrawMainViewGUI()
        {
            FeedbackQueue.Reset();

            _scrollMain = EditorGUILayout.BeginScrollView(
                _scrollMain, false, false,
                GUIStyles.horizontalScrollbar,
                GUIStyles.verticalScrollbar,
                GUIStyles.background
                );

            // Draw the link lines.
            if (Event.current.type == EventType.Repaint)
            {
                foreach (var node in _patch.nodeList)
                {
                    if (!node.DrawLinkLines(_patch))
                    {
                        // Request repaint if position info is not ready.
                        Repaint();
                        break;
                    }
                }
            }

            // Draw all the nodes and make the bounding box.
            BeginWindows();
            foreach (var node in _patch.nodeList)
            {
                node.DrawWindowGUI();
                _mainViewSize = Vector2.Max(_mainViewSize, node.windowPosition);
            }
            EndWindows();

            // Place an empty box to expand the scroll view.
            GUILayout.Box(
                "", EditorStyles.label,
                GUILayout.Width(_mainViewSize.x + 256),
                GUILayout.Height(_mainViewSize.y + 128)
                );

            // Draw working link line while wiring.
            if (_wiring != null)
            {
                DrawWorkingLink();
            }

            EditorGUILayout.EndScrollView();

            // Process all the feedback from the leaf UI elements.
            while (!FeedbackQueue.IsEmpty)
            {
                ProcessUIFeedback(FeedbackQueue.Dequeue());
            }
        }
示例#3
0
        // Process feedback from the leaf UI elemets.
        void ProcessUIFeedback(FeedbackQueue.RecordBase record)
        {
            // Delete request
            if (record is FeedbackQueue.DeleteNodeRecord)
            {
                var removeNode = ((FeedbackQueue.DeleteNodeRecord)record).node;

                // Remove related links.
                foreach (var node in _patch.nodeList)
                    node.RemoveLinksTo(removeNode, _patch);

                // Remove the node.
                removeNode.RemoveFromPatch(_patch);

                // Rescan the patch and repaint.
                _patch.Rescan();
                Repaint();
            }

            // Inlet button pressed
            if (record is FeedbackQueue.InletButtonRecord)
            {
                var info = (FeedbackQueue.InletButtonRecord)record;
                if (_wiring == null)
                    // Not in wiring: show the context menu.
                    ShowNodeButtonMenu(info.node, info.inlet, null);
                else
                    // Currently in wiring: try to make a link.
                    _wiring.node.TryLinkTo(_wiring.outlet, info.node, info.inlet);
            }

            // Outlet button pressed
            if (record is FeedbackQueue.OutletButtonRecord)
            {
                var info = (FeedbackQueue.OutletButtonRecord)record;
                if (_wiring == null)
                    // Not in wiring: show the context menu.
                    ShowNodeButtonMenu(info.node, null, info.outlet);
                else
                    // Currently in wiring: try to make a link.
                    info.node.TryLinkTo(info.outlet, _wiring.node, _wiring.inlet);
            }

            // Force to end wiring.
            _wiring = null;
        }
        void DrawMainViewGUI()
        {
            _scrollPosition = EditorGUILayout.BeginScrollView(_scrollPosition, true, true);

            EditorGUILayout.BeginHorizontal(GUIStyles.background);
            GUILayout.FlexibleSpace();

            var canvasRect = EditorGUILayout.BeginVertical();

            GUILayout.FlexibleSpace();

            //canvasRect.height -= 100;
            //var pivot = new Vector2(Screen.width / 2f, (Screen.height / 2f) + 50);
            //GUIUtility.ScaleAroundPivot(new Vector2(_zoom, _zoom), pivot);

            if (Event.current.button == 2 && Event.current.type == EventType.MouseDrag ||
                Event.current.button == 0 && Event.current.type == EventType.MouseDrag && Event.current.modifiers == EventModifiers.Alt)
            {
                _scrollPosition += -Event.current.delta;
                Event.current.Use();
            }
            if (Event.current.button == 1 && Event.current.type == EventType.MouseDown)
            {
                var menu = _nodeFactory.DrawMenu(_patch, Event.current.mousePosition);
                menu.DropDown(new Rect(Event.current.mousePosition, Vector2.one));
                Event.current.Use();
            }

            //canvasRect.y -= _scrollPosition.y;
            //canvasRect.x -= _scrollPosition.x;
            //GUIScaleUtility.BeginScale(ref canvasRect, pivot, 1 / _zoom, false);

            // Draw the link lines.
            if (Event.current.type == EventType.Repaint)
            {
                foreach (var node in _patch.nodeList)
                {
                    if (!node.DrawLinkLines(_patch))
                    {
                        // Request repaint if position info is not ready.
                        Repaint();
                        break;
                    }
                }
            }

            _mainViewMax = Vector2.zero;
            var mainViewMin = Vector2.one * 10000;

            // Draw all the nodes and make the bounding box.

            BeginWindows();
            var h = 0f;

            foreach (var node in _patch.nodeList)
            {
                node.DrawWindowGUI();
                _mainViewMax = Vector2.Max(_mainViewMax, node.windowPosition);
                mainViewMin  = Vector2.Min(mainViewMin, node.windowPosition);
                h            = Mathf.Max(h, node.LastRect.y);
            }
            _mainViewMax.x += 256;
            mainViewMin.x  -= 50;
            mainViewMin.y  -= 50;
            foreach (var node in _patch.nodeList)
            {
                node.windowPosition -= mainViewMin;
            }
            EndWindows();

            var x = Mathf.Max(_mainViewMax.x * _zoom, Screen.width);
            var y = Mathf.Max((_mainViewMax.y + 128) * _zoom, Screen.height - 50);


            //Place an empty box to expand the scroll view.
            GUILayout.Box(
                "", GUIStyle.none,
                GUILayout.Width(x),
                GUILayout.Height(y));
            // Draw working link line while wiring.
            if (_wiring != null)
            {
                DrawWorkingLink();
            }

            //GUIScaleUtility.EndScale();


            GUILayout.FlexibleSpace();
            EditorGUILayout.EndVertical();

            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.EndScrollView();

            // Process all the feedback from the leaf UI elements.
            while (!FeedbackQueue.IsEmpty)
            {
                ProcessUIFeedback(FeedbackQueue.Dequeue());
            }
        }
        private void EventHandler()
        {
            FeedbackQueue.Reset();

            var e          = Event.current;
            var activeNode = GetActiveNode();

            if (e.isKey && e.keyCode == KeyCode.Delete)
            {
                if (NodeLink.SelectedLink == null)
                {
                    return;
                }
                NodeLink.SelectedLink.RemoveLink();
                _patch.Rescan();
                Repaint();
            }
            else if (e.isKey && e.keyCode == KeyCode.C && e.modifiers == EventModifiers.Control)
            {
                if (activeNode == null)
                {
                    return;
                }
                _currentCopiedNode = activeNode;
            }
            else if (e.isKey && e.keyCode == KeyCode.V && e.modifiers == EventModifiers.Control && _currentCopiedNode != null)
            {
                var nodeBase = Instantiate(_currentCopiedNode._instance);
                nodeBase.name = ObjectNames.NicifyVariableName(_currentCopiedNode.typeName);
                nodeBase.wiringNodePosition += Vector2.one * 50;
                var copiedNode = _patch.AddNodeInstance(nodeBase);
                copiedNode.RemoveAllLinks(_patch);

                foreach (var node in _patch.nodeList)
                {
                    node.RemoveLinksTo(copiedNode, _patch);
                }

                Undo.RegisterCreatedObjectUndo(nodeBase.gameObject, "Paste Node");
            }
            else if (e.isMouse && e.button == 0 && e.modifiers == EventModifiers.None)
            {
                NodeLink.SelectedLink = null;
                foreach (var node in _patch.nodeList)
                {
                    if (node.CachedLinks == null)
                    {
                        node.CacheLinks(_patch);
                    }

                    foreach (var link in node.CachedLinks)
                    {
                        var pos = (e.mousePosition - new Vector2(0, 16 / _zoom) + _scrollPosition) / _zoom;
                        if (link.OnLine(pos))
                        {
                            NodeLink.SelectedLink = link;
                            Node.ActiveNode       = null;
                        }
                    }
                }
            }
        }