Exemplo n.º 1
0
            /// <summary>
            /// function which handles node creation
            /// </summary>
            /// <param name="nodeType">the type of node to create, e.g. typeof(DialogueNode)</param>
            /// <param name="nodeToCopy">optional argument used to handle copying of nodes</param>
            public BaseNode AddNode(System.Type type, BaseNode nodeToCopy = null)
            {
                Scene currentScene = NodeEditor.GetScene(); // retrieve current scene

                // create a new node asset
                BaseNode node = ScriptableObject.CreateInstance(type) as BaseNode;

                if (nodeToCopy != null)
                {
                    node.Copy(nodeToCopy, NodeEditor.GetMousePosition()); // perform copy
                }
                else
                {
                    node.Init(NodeEditor.GetMousePosition()); // perform initialisation
                }
                // disallow undo functionality for StartNode
                if (type != typeof(StartNode))
                {
                    Undo.RecordObject(currentScene.GetCurrentPage(), "New Node"); // record changes to the current page
                    m_nodes.Add(node);                                            // add node to list of all nodes in scene

                    Undo.RegisterCreatedObjectUndo(node, "New Node");             // record creation
                }

                // if an input point is selected, immediately connect new node with the selected node
                ConnectionManager connectionManager = NodeEditor.GetConnectionManager();
                BaseNode          selectedLeftNode  = connectionManager.GetSelectedLeftNode();

                if (selectedLeftNode != null)
                {
                    connectionManager.SetSelectedRightNode(node);
                    connectionManager.CreateConnection();         // connect the two nodes
                    connectionManager.ClearConnectionSelection(); // clear selection
                }

                // parent node to scene asset
                string path = AssetDatabase.GetAssetPath(currentScene);

                AssetDatabase.AddObjectToAsset(node, path);

                // hide node asset from unity project window
                node.hideFlags = HideFlags.HideInHierarchy;
                AssetDatabase.SaveAssets(); // save!

                return(node);
            }
Exemplo n.º 2
0
        public BaseNode AddNode(System.Type type, BaseNode nodeToCopy = null)
        {
            Scene currentScene = NodeEditor.GetScene();

            BaseNode node = ScriptableObject.CreateInstance(type) as BaseNode;

            if (nodeToCopy != null)
            {
                node.Copy(nodeToCopy, NodeEditor.GetMousePosition());
            }
            else
            {
                node.Init(NodeEditor.GetMousePosition());
            }

            if (type != typeof(StartNode))
            {
                Undo.RecordObject(currentScene.GetCurrentPage(), "Новый узелок");
                m_nodes.Add(node);

                Undo.RegisterCreatedObjectUndo(node, "Новый узелок");
            }

            ConnectionManager connectionManager = NodeEditor.GetConnectionManager();
            BaseNode          selectedLeftNode  = connectionManager.GetSelectedLeftNode();

            if (selectedLeftNode != null)
            {
                connectionManager.SetSelectedRightNode(node);
                connectionManager.CreateConnection();
                connectionManager.ClearConnectionSelection();
            }

            string path = AssetDatabase.GetAssetPath(currentScene);

            AssetDatabase.AddObjectToAsset(node, path);

            node.hideFlags = HideFlags.HideInHierarchy;
            AssetDatabase.SaveAssets();

            return(node);
        }