Пример #1
0
        /// <summary>
        /// Adds a SerializedBTNode as child of this node
        /// </summary>
        /// <param name="child">The child to be added</param>
        /// <returns>True if the child was added, false otherwise</returns>
        public virtual bool AddChild(SerializedBTNode child)
        {
            UnityEditor.Undo.RecordObject(this, "Behaviour Tree (Add Child)");
            child.parent = this;
            childs.Add(child);
            SortChildren();

            UnityEditor.EditorUtility.SetDirty(this);
            return(true);
        }
Пример #2
0
        public override bool RemoveChild(SerializedBTNode child)
        {
            if (_child != child)
            {
                return(false);
            }

            _child = null;
            return(base.RemoveChild(child));
        }
Пример #3
0
        /// <summary>
        /// Utility Function to create a SerializedBTNode
        /// </summary>
        /// <param name="t">The node type</param>
        /// <param name="pos">Where to spawn it</param>
        /// <returns>The created SerializedBTNode</returns>
        private static SerializedBTNode CreateBTNode(Type t, Vector2 pos)
        {
            SerializedBTNode node      = ScriptableObject.CreateInstance(t) as SerializedBTNode;
            string           finalName = t.Name.Replace("Node", "").Replace("Decorator", "").Replace("Action", "")
                                         .Replace("Composite", "").Replace("Serialized", "");

            node.name = finalName;
            node.guid = UnityEditor.GUID.Generate().ToString();
            node.pos  = pos;

            return(node);
        }
Пример #4
0
        /// <summary>
        /// Creates a node inside te Behaviour Tree Editor Graph View
        /// </summary>
        /// <param name="t">The type of the node to create</param>
        /// <param name="pos">Where in the editor ot spawn it</param>
        /// <returns>The SerializedBTNode</returns>
        public SerializedBTNode CreateNode(Type t, Vector2 pos)
        {
            SerializedBTNode serialized = CreateBTNode(t, pos);

            _inspectorNodes.Add(serialized);

            UnityEditor.AssetDatabase.AddObjectToAsset(serialized, this);
            UnityEditor.EditorUtility.SetDirty(this);
            UnityEditor.AssetDatabase.SaveAssets();

            return(serialized);
        }
Пример #5
0
        /// <summary>
        /// Removes a child from the SerializedBTNode child list
        /// </summary>
        /// <param name="child">The child to be removed</param>
        /// <returns>True if the child was added. False otherwise</returns>
        public virtual bool RemoveChild(SerializedBTNode child)
        {
            UnityEditor.Undo.RecordObject(this, "Behaviour Tree (Remove Child)");

            bool removed = childs.Remove(child);

            if (removed)
            {
                child.parent = null;
                SortChildren();
            }

            UnityEditor.EditorUtility.SetDirty(this);
            return(removed);
        }
Пример #6
0
        public override bool AddChild(SerializedBTNode child)
        {
            _child = child;

            if (childs.Count == 0)
            {
                childs.Add(child);
            }
            else
            {
                childs[0] = child;
            }

            return(true);
        }
Пример #7
0
        /// <summary>
        /// Removes a node from the Behaviour Tree Editor Graph View
        /// </summary>
        /// <param name="node">The Serialized node to remove</param>
        /// <returns>True if it was removed. False otherwise</returns>
        public bool RemoveNode(SerializedBTNode node)
        {
            bool removed = _inspectorNodes.Remove(node);

            if (removed)
            {
                if (node == _root)
                {
                    _root = null;
                }

                UnityEditor.AssetDatabase.RemoveObjectFromAsset(node);
                UnityEditor.AssetDatabase.SaveAssets();
            }

            return(removed);
        }