Ejemplo n.º 1
0
        void ProcessEvents(Node node, Rect rect, bool selected, HashSet <Node> selection, float scale)
        {
            Event     currentEvent = Event.current;
            EventType eventType    = currentEvent.type;

            if ((eventType == EventType.MouseUp && currentEvent.button == 0 || eventType == EventType.Used) && rect.Contains(currentEvent.mousePosition))
            {
                if (!selected)
                {
                    EditorGUI.FocusTextInControl("");
                }
                if (currentEvent.control)
                {
                    if (selected)
                    {
                        selection.Remove(node);
                    }
                    else
                    {
                        selection.Add(node);
                    }
                }
                else
                {
                    selection.Clear();
                    selection.Add(node);
                }
            }

            if (Event.current.type == EventType.ContextClick && rect.Contains(currentEvent.mousePosition))
            {
                GenericMenu nodeMenu = new GenericMenu();
                string      s        = node.GetType().Name + "s[" + node.NodeId + "]";
                nodeMenu.AddItem(new GUIContent("To Clipboard: " + s), false, (st) => { EditorGUIUtility.systemCopyBuffer = (string)st; }, s);
                if (node.Controllable)
                {
                    nodeMenu.AddItem(new GUIContent("Remove"), false, (n) =>
                    {
                        _nodeEditorWindow.RemoveSelected();
                    }, node);
                    nodeMenu.AddItem(new GUIContent("Duplicate"), false, (sel) =>
                    {
                        _nodeEditorWindow.DuplicateSelected();
                    }, selection);
                    ExternalValueNode external = node as ExternalValueNode;
                    if (external != null)
                    {
                        nodeMenu.AddItem(new GUIContent(external.UseAsExternal ? "Close" : "Open"), false, n =>
                        {
                            Undo.RecordObject(_nodeDataContainer, "Change External Settings");
                            ExternalValueNode ext = (ExternalValueNode)n;
                            ext.UseAsExternal     = !ext.UseAsExternal;
                            _nodeData.Externals.InitializeFrom(_nodeData);
                        }, external);
                    }
                }
                Matrix4x4 m = GUI.matrix;
                GUI.matrix *= Matrix4x4.Scale(new Vector3(1f / scale, 1f / scale, 1));
                nodeMenu.ShowAsContext();
                GUI.matrix = m;
                Event.current.Use();
            }
            bool    startDraging;
            Vector2 newPos = _draging.Drag(rect, node.Position, node, out startDraging, scale);

            Styles.SnapPosition(ref newPos);
            if (startDraging)
            {
                Undo.RecordObject(_nodeDataContainer, "Draging");
                if (!selection.Contains(node))
                {
                    selection.Clear();
                    selection.Add(node);
                }
            }
            if (node.Position != newPos)
            {
                Vector2 delta = newPos - node.Position;
                foreach (Node n in selection)
                {
                    n.Position += delta;
                }
                node.Position = newPos;
            }
        }
Ejemplo n.º 2
0
        void DrawInputs(Node node, float x, float y, float nodeWidth, float nodeHeight)
        {
            float CellSize = Styles.CellSize;

            Rect  inputRect         = new Rect(x, y, nodeWidth, CellSize);
            Rect  graphicRect       = new Rect(node.Position.x + Styles.InputShift.x, y + Styles.InputShift.y, Styles.IOSize, Styles.IOSize);
            float interactionOffset = Mathf.Max(graphicRect.width, CellSize * 2);
            Rect  interactionRect   = new Rect(node.Position.x - interactionOffset, y, inputRect.width + interactionOffset, CellSize);
            Rect  smallInputRect    = new Rect(interactionRect.x, interactionRect.y, interactionOffset, CellSize);

            for (int i = 0; i < node.Inputs.Length; i++)
            {
                Link link   = node.Inputs[i];
                Node inNode = _nodeData.GetNode(link);

                GUI.Label(inputRect, link.Name);

                if (inNode is DefaultNode)
                {
                    Rect defaultRect = inputRect;
                    defaultRect.width = inNode.NodeWidth * CellSize;
                    defaultRect.x    -= defaultRect.width;
                    GUI.color         = Styles.GetColor(inNode.OutputType);
                    Rect defaultBackRect = defaultRect;
                    defaultBackRect.height += 1;
                    GUI.Box(defaultBackRect, "", Styles.DefaultValue);
                    GUI.color = Color.white;
                    float savedLabelWidth = EditorGUIUtility.labelWidth;
                    EditorGUIUtility.labelWidth = 8;
                    string name = (inNode.OutputType == ValueType.Float || inNode.OutputType == ValueType.Int) ? " " : "";
                    DrawProperty(defaultRect, inNode, "Value", name);
                    EditorGUIUtility.labelWidth = savedLabelWidth;
                    defaultRect.xMax           += inputRect.width;
                    _linkDraging.ProcessNodeInput(node, i, defaultRect, smallInputRect);
                }
                else
                {
                    GUIStyle gs = inNode != null ? Styles.GraphicPointActive : Styles.GraphicPoint;

                    GUI.color = inNode != null?NodeEditorWindow.GetLinkColor(inNode, node) : Styles.GetColor(link.Type);

                    GUI.Box(graphicRect, "", gs);
                    GUI.color = Color.white;
                    _linkDraging.ProcessNodeInput(node, i, interactionRect, smallInputRect);
                }
                //_linkDraging.ProcessNodeInput(node, i, interactionRect, smallInputRect);
                inputRect.y       = y += inputRect.height;
                graphicRect.y     = inputRect.y + Styles.InputShift.y;
                interactionRect.y = inputRect.y;
                smallInputRect.y  = inputRect.y;
            }
        }