Exemple #1
0
        ///Create a new nested graph for the provided INestedNode parent.
        public static Graph CreateNested(INestedNode parent, System.Type type, string name)
        {
            var newGraph = new GameObject(name).AddComponent(type) as Graph;

            newGraph.name = name;
            Undo.RegisterCreatedObjectUndo(newGraph.gameObject, "New Graph");

            if (parent != null)
            {
                Undo.RecordObject(parent as Node, "New Graph");
                newGraph.transform.parent        = (parent as Node).graph.transform;
                newGraph.transform.localPosition = Vector3.zero;
            }

            parent.nestedGraph = newGraph;
            return(newGraph);
        }
Exemple #2
0
        ///Disconnects and then removes a node from this graph
        public void RemoveNode(Node node)
        {
            if (!allNodes.Contains(node))
            {
                Debug.LogWarning("Node is not part of this graph", gameObject);
                return;
            }

                        #if UNITY_EDITOR
            if (node is IAutoSortable && node.inConnections.Count == 1 && node.outConnections.Count == 1)
            {
                var relinkNode = node.outConnections[0].targetNode;
                RemoveConnection(node.outConnections[0]);
                node.inConnections[0].Relink(relinkNode);
            }
                        #endif

            foreach (Connection outConnection in node.outConnections.ToArray())
            {
                RemoveConnection(outConnection);
            }

            foreach (Connection inConnection in node.inConnections.ToArray())
            {
                RemoveConnection(inConnection);
            }

                        #if UNITY_EDITOR
            Undo.RecordObject(this, "Delete Node");
                        #endif

            allNodes.Remove(node);

                        #if UNITY_EDITOR
            Undo.DestroyObjectImmediate(node.gameObject);
                        #else
            DestroyImmediate(node.gameObject, true);
                        #endif

                        #if UNITY_EDITOR
            Undo.RecordObject(this, "Delete Node");
                        #endif

            UpdateNodeIDsInGraph();

            if (node == primeNode)
            {
                primeNode = GetNodeWithID(1);
            }

                        #if UNITY_EDITOR
            INestedNode nestNode = node as INestedNode;
            if (nestNode != null && nestNode.nestedGraph != null)
            {
                var isPrefab = PrefabUtility.GetPrefabType(nestNode.nestedGraph) == PrefabType.Prefab;
                if (!isPrefab && EditorUtility.DisplayDialog("Deleting Nested Node", "Delete assign nested graph '" + nestNode.nestedGraph.name + "' as well?", "Yes", "No"))
                {
                    Undo.DestroyObjectImmediate(nestNode.nestedGraph.gameObject);
                }
            }
                        #endif
        }