Ejemplo n.º 1
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            SerializedProperty sourceProperty = property.FindPropertyRelative("SourceNode");

            if (sourceProperty.objectReferenceValue != null)
            {
                Rect inputNoteRect = EditorGUI.PrefixLabel(position, label);
                if (label != GUIContent.none)
                {
                    EditorGUI.LabelField(inputNoteRect, "Input", EditorStyles.centeredGreyMiniLabel);
                }
            }
            else
            {
                SerializedProperty valueProperty = property.FindPropertyRelative("defaultValue");

                if (valueProperty != null)
                {
                    EditorGUI.BeginChangeCheck();
                    EditorGUI.PropertyField(position, valueProperty, label);
                    if (EditorGUI.EndChangeCheck())
                    {
                        InputSocket inputSocket = (InputSocket)PropertyUtility.GetTargetObjectOfProperty(property);
                        property.serializedObject.ApplyModifiedProperties();
                        inputSocket.AfterContentChanged();
                    }
                }
            }

            property.FindPropertyRelative("drawRect").rectValue = position;
        }
Ejemplo n.º 2
0
        private void Detatch(InputSocket socket)
        {
            SerializedObject obj = SerializedObjectPool.Grab(socket.ParentNode);

            SerializedProperty socketProperty = obj.FindProperty(socket.SocketName);

            SerializedProperty sourceNodeProperty  = socketProperty.FindPropertyRelative("SourceNode");
            SerializedProperty sourceFieldProperty = socketProperty.FindPropertyRelative("SourceField");

            sourceNodeProperty.objectReferenceValue = null;
            sourceFieldProperty.stringValue         = "";

            obj.ApplyModifiedProperties();

            Repaint();
        }
Ejemplo n.º 3
0
        private void Attach(OutputSocket start, InputSocket end)
        {
            if (!IsValidAttach(start, end))
            {
                return;
            }

            SerializedObject obj = SerializedObjectPool.Grab(end.ParentNode);

            SerializedProperty socketProperty = obj.FindProperty(end.SocketName);

            SerializedProperty sourceNodeProperty  = socketProperty.FindPropertyRelative("SourceNode");
            SerializedProperty sourceFieldProperty = socketProperty.FindPropertyRelative("SourceField");

            sourceNodeProperty.objectReferenceValue = start.ParentNode;
            sourceFieldProperty.stringValue         = start.SocketName;

            obj.ApplyModifiedProperties();

            Repaint();
        }
Ejemplo n.º 4
0
        private bool IsValidAttach(OutputSocket start, InputSocket end)
        {
            if (start.GetType() == typeof(EventOutput))
            {
                return(end.GetType() == typeof(EventInput));
            }
            else if (end.GetType() == typeof(EventInput))
            {
                return(false);
            }

            if (start.GetType() == typeof(OutputSocket) ||
                end.GetType() == typeof(InputSocket))
            {
                return(true);
            }

            Type endInputType     = typeof(ISocketConvertable <>).MakeGenericType(end.GetType().BaseType.GenericTypeArguments[0]);
            Type outputConnection = start.GetType().BaseType.GenericTypeArguments[2];

            return(endInputType.IsAssignableFrom(outputConnection));
        }
Ejemplo n.º 5
0
        private void DrawSockets()
        {
            Color originalColor = GUI.color;

            for (int i = 0; i < targetGraph.Nodes.Count; i++)
            {
                BehaviourNode node = targetGraph.Nodes[i];

                if (node == null)
                {
                    continue;
                }

                foreach (InputSocket thisInput in node.Inputs)
                {
                    if (thisInput == null)
                    {
                        continue;
                    }

                    Rect socketRect = thisInput.socketRect;
                    socketRect = new Rect(socketRect.x + node.Position.x + dragging_Position.x,
                                          socketRect.y + node.Position.y + dragging_Position.y,
                                          socketRect.width, socketRect.height);

                    thisInput.DrawSocket(socketRect);

#if HOVER_EFFECTS
                    if (connection_CanEdit)
                    {
                        OutputSocket linkedSocket = thisInput.SourceSocket;
                        if (connection_Start != null)
                        {
                            if (IsValidAttach(connection_Start, thisInput))
                            {
                                if (linkedSocket == null)
                                {
                                    EditorGUIUtility.AddCursorRect(socketRect, MouseCursor.ArrowPlus);
                                }
                                else
                                {
                                    EditorGUIUtility.AddCursorRect(socketRect, MouseCursor.ArrowMinus);
                                }
                            }
                        }
                        else
                        {
                            if (linkedSocket == null)
                            {
                                EditorGUIUtility.AddCursorRect(socketRect, MouseCursor.ArrowPlus);
                            }
                            else
                            {
                                EditorGUIUtility.AddCursorRect(socketRect, MouseCursor.ArrowMinus);
                            }
                        }
                    }
#endif
                    if (connection_CanEdit && (currentEvent.type == EventType.MouseDown || currentEvent.type == EventType.MouseUp) &&
                        socketRect.Contains(currentEvent.mousePosition))
                    {
                        if (currentEvent.button == 0)
                        {
                            if (connection_Start != null || currentEvent.type != EventType.MouseUp)
                            {
                                connection_End = thisInput;
                            }

                            if (connection_Start != null)
                            {
                                Attach(connection_Start, connection_End);

                                connection_End   = null;
                                connection_Start = null;
                                currentEvent.Use();
                            }
                        }
                        else if (currentEvent.button == 1)
                        {
                            Detatch(thisInput);
                        }

                        currentEvent.Use();
                    }
                }

                foreach (OutputSocket thisOutput in node.Outputs)
                {
                    if (thisOutput == null)
                    {
                        continue;
                    }

                    Rect socketRect = thisOutput.socketRect;
                    socketRect = new Rect(socketRect.x + node.Position.x + dragging_Position.x,
                                          socketRect.y + node.Position.y + dragging_Position.y,
                                          socketRect.width, socketRect.height);

                    thisOutput.DrawSocket(socketRect);

                    if (connection_CanEdit)
                    {
#if HOVER_EFFECTS
                        if (connection_End != null)
                        {
                            if (IsValidAttach(thisOutput, connection_End))
                            {
                                EditorGUIUtility.AddCursorRect(socketRect, MouseCursor.ArrowPlus);
                            }
                        }
                        else
                        {
                            EditorGUIUtility.AddCursorRect(socketRect, MouseCursor.ArrowPlus);
                        }
#endif
                        if ((currentEvent.type == EventType.MouseDown || currentEvent.type == EventType.MouseUp) &&
                            socketRect.Contains(currentEvent.mousePosition))
                        {
                            if (currentEvent.button == 0)
                            {
                                if (connection_End != null || currentEvent.type != EventType.MouseUp)
                                {
                                    connection_Start = thisOutput;
                                }

                                if (connection_End != null)
                                {
                                    Attach(connection_Start, connection_End);

                                    connection_End   = null;
                                    connection_Start = null;
                                }

                                currentEvent.Use();
                            }
                            else if (currentEvent.button == 1)
                            {
                                Detatch(thisOutput);

                                Repaint();
                                currentEvent.Use();
                            }
                        }
                    }
                }
            }
            GUI.color = originalColor;
        }
Ejemplo n.º 6
0
        private void HandleInput()
        {
            if (currentEvent.type == EventType.KeyDown)
            {
                if (currentEvent.keyCode == KeyCode.D)
                {
                    if (selectedWindow != -1)
                    {
                        DuplicateNode(targetGraph.Nodes[selectedWindow]);
                    }
                }
                else if (currentEvent.keyCode == KeyCode.Delete)
                {
                    if (selectedWindow != -1)
                    {
                        DeleteAction(targetGraph.Nodes[selectedWindow]);
                    }
                }
            }
            else if (currentEvent.type == EventType.MouseDrag && dragging_IsDragging)
            {
                dragging_Position += currentEvent.delta;
                Repaint();
            }
            else if (screenRect.Contains(currentEvent.mousePosition))
            {
                if (currentEvent.type == EventType.MouseDown)
                {
                    GUI.UnfocusWindow();
                    GUI.FocusControl("");

                    if (currentEvent.button != 2)
                    {
                        if (connection_Start != null || connection_End != null)
                        {
                            connection_Start = null;
                            connection_End   = null;

                            currentEvent.Use();
                            Repaint();
                        }

                        if (currentEvent.button == 1)
                        {
                            dragging_IsDragging  = false;
                            rightClickedPosition = currentEvent.mousePosition;
                            AddNodeMenu.ShowAsContext();
                        }
                        else
                        {
                            dragging_IsDragging = true;
                        }
                    }
                    else
                    {
                        dragging_IsDragging = true;
                    }

                    currentEvent.Use();
                    Repaint();
                }
            }
        }