コード例 #1
0
        /// <summary>
        /// A Unity callback called when the object is loaded.
        /// </summary>
        void OnEnable () {
            m_Tree = target as InternalBehaviourTree;
            BehaviourWindow.activeNodeChanged += this.ActiveNodeChanged;

            m_StatesEditor = new ParentStatesEditor(m_Tree, serializedObject.FindProperty("m_Position"));

            // Try to create an editor for the current active node
            this.ActiveNodeChanged();
        }
コード例 #2
0
        /// <summary> 
        /// Paste the node in BehaviourTreeUtility.nodeToPaste in the supplied tree.
        /// <param name="tree">The target tree.</param>
        /// <param name="parent">Optional parent to paste the node; or null to paste as a root node.</param>
        /// <returns>The pasted node.</returns>
        /// </summary>
        public static ActionNode PasteNode (InternalBehaviourTree tree, BranchNode parent = null) {
            // Get the node to be pasted
            var node = BehaviourTreeUtility.nodeToPaste;

            // Validate parameters
            if (node != null && tree != null) {
                // Register Undo
                #if UNITY_4_0_0 || UNITY_4_1 || UNITY_4_2
                Undo.RegisterUndo(tree,"Paste Node");
                #else
                Undo.RecordObject(tree,"Paste Node");
                #endif

                var newNode = node.Copy(tree);

                if (newNode != null) {
                    // Add to parent branch?
                    if (parent != null) {
                        parent.Add(newNode);

                        // Call OnValidate on the parent
                        parent.OnValidate();
                    }

                    // Saves node and sets dirty flag
                    StateUtility.SetDirty(tree);

                    // Reload tree to update variables
                    tree.LoadNodes();
                }
                return newNode;
            }
            return null;
        }
コード例 #3
0
        /// <summary> 
        /// Adds a new node to the tree, automatically handles undo, dirty flag and save node.
        /// <param name="tree">The tree to add a new node.</param>
        /// <param name="nodeType">The type of the new node.</param>
        /// <returns>The new node.</returns>
        /// </summary>
        public static ActionNode AddNode (InternalBehaviourTree tree, System.Type nodeType) {
            // Validate parameters
            if (tree != null && nodeType != null && nodeType.IsSubclassOf(typeof(ActionNode)) && !nodeType.IsAbstract) {
                // Register Undo
                #if UNITY_4_0_0 || UNITY_4_1 || UNITY_4_2
                Undo.RegisterUndo(tree,"Add New Node");
                #else
                Undo.RecordObject(tree,"Add New Node");
                #endif

                // Create new node
                var newNode = tree.AddNode(nodeType);

                if (newNode != null) {                    
                    // Saves node and sets dirty flag
                    StateUtility.SetDirty(tree);
                    return newNode;
                }
            }

            return null;
        }