public IEnumerable <BehaviourTreeTask> getAllChildren(BehaviourTreeTask parentNode) { foreach (BehaviourTreeTask bt in parentNode.NodeChildren) { yield return(bt); } }
public void OnBeforeSerialize() { #if UNITY_EDITOR if (nodes.Count == 0) { Texture2D root = Resources.Load("root") as Texture2D; BehaviourTreeTask node = CreateInstance <RootTreeTask>(); node.editorTexture = root; node.taskTypeName = "ROOT"; node.taskType = TaskType.ROOT; node.name = System.Guid.NewGuid().ToString(); Rect oldRect = node.NodeRect; node.NodeRect = new Rect(100, 100, oldRect.width, oldRect.height); AddNode(node); } if (AssetDatabase.GetAssetPath(this) != "") { foreach (BehaviourTreeTask n in nodes) { if (AssetDatabase.GetAssetPath(n) == "") { AssetDatabase.AddObjectToAsset(n, this); } } } #endif }
/// <summary> /// add empty child for selected node /// </summary> /// <param name="createNode"></param> public void createNode(BehaviourTreeTask parent, Vector2 createAt) { BehaviourTreeTask newNode = MakeNode(parent, createAt); Undo.RegisterCreatedObjectUndo(newNode, "Undo Create Node"); Undo.RecordObject(this, "Add new node"); AddNode(newNode); }
public BehaviourTreeTask createNodeOfType(Type t, BehaviourTreeTask parent, Vector2 createAt) { BehaviourTreeTask newNode = MakeNodeOfType(t, parent, createAt); newNode.name = System.Guid.NewGuid().ToString(); Rect oldRect = newNode.NodeRect; newNode.NodeRect = new Rect(createAt.x, createAt.y, oldRect.width, oldRect.height); Undo.RegisterCreatedObjectUndo(newNode, "Undo Create Node"); Undo.RecordObject(this, "Add new node"); AddNode(newNode); return(newNode); }
public void createExternalNode(BehaviourTreeTask newNode, BehaviourTreeTask parent, Vector2 createAt) { newNode.name = System.Guid.NewGuid().ToString(); Rect oldRect = newNode.NodeRect; newNode.NodeRect = new Rect(createAt.x, createAt.y, oldRect.width, oldRect.height); if (parent != null) { parent.addNewChild(newNode); } Undo.RegisterCreatedObjectUndo(newNode, "Undo Create Node"); Undo.RecordObject(this, "Add new node"); AddNode(newNode); }
//Change parent of parentFor for a newParent, clear all old connections public static bool Reparent(BehaviourTreeTask newParent, BehaviourTreeTask parentFor) { if (newParent.taskType == TaskType.DECORATOR) { if (((DecoratorTreeTask)newParent).OnlySingleChildAllowed == true && newParent.children.Count > 0) { //cant add another child when flag only one children is enabled return(false); } } parentFor.parent.removeChildConnection(parentFor); parentFor.parent = newParent; newParent.addNewChild(parentFor); return(true); }
private static BehaviourTreeTask MakeNodeOfType(Type t, BehaviourTreeTask parent, Vector2 createAt) { BehaviourTreeTask newNode = CreateInstance(t.Name) as BehaviourTreeTask; newNode.name = System.Guid.NewGuid().ToString(); Rect oldRect = newNode.NodeRect; newNode.NodeRect = new Rect(createAt.x, createAt.y, oldRect.width, oldRect.height); if (parent != null) { parent.addNewChild(newNode); } return(newNode); }
/// <summary> /// remove node and all his connections /// </summary> /// <param name="node"></param> public void removeNode(BehaviourTreeTask node) { List <BehaviourTreeTask> childrenTemp = new List <BehaviourTreeTask>(node.children); foreach (BehaviourTreeTask t in childrenTemp) { removeNode(t); } nodes.Remove(node); //remove all connections foreach (BehaviourTreeTask n in nodes) { n.removeChildConnection(node); } OnValidate(); Undo.DestroyObjectImmediate(node); }
///node may have 0 children public bool hasAnyChildren(BehaviourTreeTask forNode) { return(forNode.NodeChildren.Count > 0 ? true : false); }
private void AddNode(BehaviourTreeTask newNode) { nodes.Add(newNode); newNode.treeOwner = this; OnValidate(); }