Пример #1
0
        ///Relinks the target node of the connection
        public void SetTarget(Node newTarget, bool isRelink = true, int index = -1)
        {
            if (targetNode == newTarget)
            {
                return;
            }

            if (graph != null)
            {
                graph.RecordUndo("Set Target");
            }

            if (isRelink)
            {
                var i = targetNode.inConnections.IndexOf(this);
                targetNode.OnParentDisconnected(i);
                newTarget.OnParentConnected(i);
                targetNode.inConnections.Remove(this);
            }

            index = index == -1? newTarget.inConnections.Count : index;
            newTarget.inConnections.Insert(index, this);
            targetNode = newTarget;

                        #if UNITY_EDITOR
            targetNode.TrySortConnectionsByPositionX();
                        #endif
        }
Пример #2
0
        ///Sets the target node of the connection
        public int SetTargetNode(Node newTarget, int index = -1)
        {
            if (targetNode == newTarget)
            {
                return(-1);
            }

            if (graph != null)
            {
                graph.RecordUndo("Set Target");
            }

            //relink
            if (targetNode != null && targetNode.inConnections.Contains(this))
            {
                var i = targetNode.inConnections.IndexOf(this);
                targetNode.OnParentDisconnected(i);
                targetNode.inConnections.Remove(this);
            }

            index = index == -1 ? newTarget.inConnections.Count : index;
            newTarget.inConnections.Insert(index, this);
            newTarget.OnParentConnected(index);
            targetNode = newTarget;

#if UNITY_EDITOR
            if (sourceNode != null && targetNode != null)
            {
                targetNode.TrySortConnectionsByPositionX();
            }
#endif

            return(index);
        }
Пример #3
0
        ///<summary>Sets the target node of the connection</summary>
        public int SetTargetNode(Node newTarget, int index = -1)
        {
            if (targetNode == newTarget)
            {
                return(-1);
            }

            UndoUtility.RecordObject(graph, "Set Target");

            //relink
            if (targetNode != null && targetNode.inConnections.Contains(this))
            {
                var i = targetNode.inConnections.IndexOf(this);
                targetNode.OnParentDisconnected(i);
                targetNode.inConnections.Remove(this);
            }

            index = index == -1 ? newTarget.inConnections.Count : index;
            newTarget.inConnections.Insert(index, this);
            newTarget.OnParentConnected(index);
            targetNode = newTarget;

#if UNITY_EDITOR
            if (sourceNode != null && targetNode != null)
            {
                targetNode.TrySortConnectionsByPositionX();
            }
#endif

            OnValidate(sourceNode != null ? sourceNode.outConnections.IndexOf(this) : -1, index);
            UndoUtility.SetDirty(graph);
            return(index);
        }
        //Handles events, Mouse downs, ups etc.
        static void HandleEvents(Node node, Event e) {

            //Node click
            if ( e.type == EventType.MouseDown && GraphEditorUtility.allowClick && e.button != 2 ) {

                Undo.RegisterCompleteObjectUndo(node.graph, "Move Node");

                if ( !e.control ) {
                    GraphEditorUtility.activeElement = node;
                }

                if ( e.control ) {
                    if ( node.isSelected ) { GraphEditorUtility.activeElements.Remove(node); } else { GraphEditorUtility.activeElements.Add(node); }
                }

                if ( e.button == 0 ) {
                    node.nodeIsPressed = true;
                }

                //Double click
                if ( e.button == 0 && e.clickCount == 2 ) {
                    if ( node is IGraphAssignable && ( node as IGraphAssignable ).nestedGraph != null ) {
                        node.graph.currentChildGraph = ( node as IGraphAssignable ).nestedGraph;
                        node.nodeIsPressed = false;
                    } else if ( node is ITaskAssignable && ( node as ITaskAssignable ).task != null ) {
                        EditorUtils.OpenScriptOfType(( node as ITaskAssignable ).task.GetType());
                    } else {
                        EditorUtils.OpenScriptOfType(node.GetType());
                    }
                    e.Use();
                }

                node.OnNodePicked();
            }

            //Mouse up
            if ( e.type == EventType.MouseUp ) {
                if ( node.nodeIsPressed ) {
                    node.TrySortConnectionsByPositionX();
                }
                node.nodeIsPressed = false;
                node.OnNodeReleased();
            }
        }