Ejemplo n.º 1
0
        private void Detatch(OutputSocket socket)
        {
            foreach (var detachNode in targetGraph.AllNodes)
            {
                foreach (var detachInput in detachNode.InputSockets)
                {
                    if (detachInput.SourceNode == socket.ParentNode &&
                        detachInput.SourcePath == socket.SocketPath)
                    {
                        var detatchObject = SerializedObjectPool.Grab(detachNode);

                        string[] paths = socket.SocketPath.Split('.');
                        var      detatchSocketProperty = detatchObject.FindProperty(paths[0]);
                        for (int i = 1; i < paths.Length; i++)
                        {
                            detatchSocketProperty = detatchSocketProperty.FindPropertyRelative(paths[i]);
                        }

                        var detatchSourceNodeProperty = detatchSocketProperty.FindPropertyRelative("SourceNode");
                        var detatchSourcePathProperty = detatchSocketProperty.FindPropertyRelative("SourcePath");

                        detatchSourceNodeProperty.objectReferenceValue = null;
                        detatchSourcePathProperty.stringValue          = "";

                        detatchObject.ApplyModifiedProperties();
                    }
                }
            }
            Repaint();
        }
Ejemplo n.º 2
0
        private void Detatch(OutputSocket socket)
        {
            foreach (BehaviourNode detachNode in targetGraph.AllNodes)
            {
                foreach (InputSocket detachInput in detachNode.Inputs)
                {
                    if (detachInput.SourceNode == socket.ParentNode &&
                        detachInput.SourceField == socket.SocketName)
                    {
                        SerializedObject detatchObject = SerializedObjectPool.Grab(detachNode);

                        SerializedProperty detatchSocketProperty = detatchObject.FindProperty(detachInput.SocketName);

                        SerializedProperty detatchSourceNodeProperty  = detatchSocketProperty.FindPropertyRelative("SourceNode");
                        SerializedProperty detatchSourceFieldProperty = detatchSocketProperty.FindPropertyRelative("SourceField");

                        detatchSourceNodeProperty.objectReferenceValue = null;
                        detatchSourceFieldProperty.stringValue         = "";

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

            string[] paths          = end.SocketPath.Split('.');
            var      obj            = SerializedObjectPool.Grab(end.ParentNode);
            var      socketProperty = obj.FindProperty(paths[0]);

            UnityEngine.Debug.Log(socketProperty.displayName);

            for (int i = 1; i < paths.Length; i++)
            {
                socketProperty = socketProperty.FindPropertyRelative(paths[i]);
            }

            var sourceNodeProperty = socketProperty.FindPropertyRelative("SourceNode");
            var sourcePathProperty = socketProperty.FindPropertyRelative("SourcePath");

            sourceNodeProperty.objectReferenceValue = start.ParentNode;
            sourcePathProperty.stringValue          = start.SocketPath;

            obj.ApplyModifiedProperties();

            Repaint();
        }
Ejemplo n.º 4
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.º 5
0
        public virtual Vector2 GetDiamentions()
        {
            SerializedObject serializedObject = SerializedObjectPool.Grab(this);

            float height = 0.0f;
            SerializedProperty iterator = serializedObject.GetIterator();

            iterator.Next(true);
            iterator.NextVisible(false);
            iterator.NextVisible(false);

            while (iterator.NextVisible(false))
            {
                height += EditorGUI.GetPropertyHeight(iterator, true) + EditorGUIUtility.standardVerticalSpacing;
            }

            return(new Vector2(200, height));
        }
Ejemplo n.º 6
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.º 7
0
        private void Detatch(InputSocket socket)
        {
            var obj = SerializedObjectPool.Grab(socket.ParentNode);

            string[] paths          = socket.SocketPath.Split('.');
            var      socketProperty = obj.FindProperty(paths[0]);

            for (int i = 1; i < paths.Length; i++)
            {
                socketProperty = socketProperty.FindPropertyRelative(paths[i]);
            }

            var sourceNodeProperty = socketProperty.FindPropertyRelative("SourceNode");
            var sourcePathProperty = socketProperty.FindPropertyRelative("SourcePath");

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

            obj.ApplyModifiedProperties();

            Repaint();
        }
Ejemplo n.º 8
0
        private void DrawNodeWindow(int id)
        {
            if (Event.current.type == EventType.Layout)
            {
                return;
            }

            BehaviourNode node = targetGraph.AllNodes[id];

            if (EventType.MouseDown == currentEvent.type || EventType.MouseUp == currentEvent.type ||
                EventType.MouseDrag == currentEvent.type || EventType.MouseMove == currentEvent.type)
            {
                selectedWindow = id;
                EditorUtility.SetDirty(node);
            }

            if (!node.LastRect.Overlaps(screenRect))
            {
                return;
            }

            Rect settingsRect = new Rect(node.LastRect.width - 20, 5, 20, 20);
            Rect iconRect     = new Rect(0, 0, 18, 18);

            if (GUI.Button(settingsRect, "", BehaviourGUIStyles.Instance.settingsStyle))
            {
                rightClickedNode = node;
                BasicNodeMenu.ShowAsContext();
            }

            Color originalColour = GUI.color;

            GUI.color = new Color(1.0f, 1.0f, 1.0f, 0.65f);
            EditorGUI.LabelField(iconRect, new GUIContent(AssetPreview.GetMiniThumbnail(node)));
            GUI.color = originalColour;

            if (currentEvent.type == EventType.MouseDown)
            {
                if (iconRect.Contains(currentEvent.mousePosition))
                {
                    if (currentEvent.button == 0)
                    {
                        if (currentEvent.clickCount == 1)
                        {
                            rightClickedNode = node;
                            PingSourceCallback();
                        }
                        else
                        {
                            rightClickedNode = node;
                            OpenScriptCallback();
                        }
                        currentEvent.Use();
                    }
                }
            }

            SerializedObject serializedObject = SerializedObjectPool.Grab(node);

            //Undo.RecordObject (node, "Edit Node");

            float originalLabelWidth = EditorGUIUtility.labelWidth;

            EditorGUIUtility.labelWidth = node.LastRect.width / 2;

            serializedObject.FindProperty("Position").vector2Value = node.Position;

            //EditorGUI.BeginChangeCheck ();
            //string newName = EditorGUILayout.DelayedTextField (node.name);
            //if (EditorGUI.EndChangeCheck ())
            //{
            //	RenameAction (node, newName);
            //}

            Rect contentRect = BehaviourGraphResources.Instance.NodeStyle.padding.Remove(node.LastRect);

            node.DrawGUI(serializedObject, new Rect(contentRect.x - node.Position.x - dragging_Position.x,
                                                    contentRect.y - node.Position.y - dragging_Position.y,
                                                    contentRect.width, contentRect.height));

            serializedObject.ApplyModifiedProperties();

            if (currentEvent.type == EventType.MouseDown)
            {
                if (currentEvent.button == 1)
                {
                    rightClickedNode = node;
                    BasicNodeMenu.ShowAsContext();
                }
            }

            EditorGUIUtility.labelWidth = originalLabelWidth;

#if HOVER_EFFECTS
            if (connection_Start == null && connection_End == null)
            {
                EditorGUIUtility.AddCursorRect(new Rect(node.LastRect.x - node.Position.x - dragging_Position.x,
                                                        node.LastRect.y - node.Position.y - dragging_Position.y,
                                                        node.LastRect.width, node.LastRect.height), MouseCursor.MoveArrow);
            }
#endif

            if (currentEvent.button != 2)
            {
                GUI.DragWindow();
            }
        }