void MoveLastCallback() { BehaviourTreeNode parent = FindParentOfNodeByID(BehaviourTreeEditorWindow.behaviourTree, this.selectedNode.ID); int selectedNodeIndice = parent.GetChildren().IndexOf(this.selectedNode); if (selectedNodeIndice < parent.ChildrenCount() - 1) { BehaviourTreeNode node = parent.GetChildren()[selectedNodeIndice]; parent.GetChildren().Remove(node); parent.GetChildren().Insert(parent.ChildrenCount(), node); } SaveBehaviourTree(); }
void DrawChildrenRecursively(BehaviourTreeNode node) { List <BehaviourTreeNode> children = node.GetChildren(); for (int i = 0; i < node.ChildrenCount(); i++) { CreateNodeRect(children[i], node); Handles.BeginGUI(); Vector2 begin = new Vector2(node.rect.center.x, node.rect.yMax); Vector2 end = new Vector2(children[i].rect.center.x, children[i].rect.yMin + 2.0f); float xAverage = (node.rect.center.x + children[i].rect.center.x) / 2.0f; Vector2 beginTangente = new Vector2(xAverage, children[i].rect.yMin); Vector2 endTangente = new Vector2(xAverage, node.rect.yMax); Handles.DrawBezier(begin, end, beginTangente, endTangente, colorLine, null, 5f); Handles.EndGUI(); } for (int i = 0; i < node.ChildrenCount(); i++) { DrawChildrenRecursively(children[i]); } }
void DeleteRecursivelyBranchAssets(BehaviourTreeNode node) { DeleteNodeAsset(node); foreach (BehaviourTreeNode child in node.GetChildren()) { DeleteRecursivelyBranchAssets(child); } }
void CreateNodeRect(BehaviourTreeNode node, BehaviourTreeNode nodeParent) { SetColor(node); Vector2 position = new Vector2(nodeParent.rect.x, nodeParent.rect.y + (nodeSize.y + 50.0f) * zoomScale); node.rect = new Rect(position.x, position.y, nodeSize.x * zoomScale, nodeSize.y * zoomScale); GUI.WindowFunction func = ControlWindowFunction; if (node is BehaviourTreeExecutionNode) { func = ExecutionWindowFunction; } else if (node is BehaviourTreeDecoratorNode) { func = DecoratorWindowFunction; } else if (node is BehaviourTreeSubTreeNode) { func = SubTreeWindowFunction; } int nbChildren = nodeParent.ChildrenCount(); float xStart; float nodeSizeWithChildren = SizeOfNode(nodeParent); xStart = nodeParent.rect.x - (nodeSizeWithChildren - nodeSize.x * zoomScale) / 2.0f; List <BehaviourTreeNode> children = nodeParent.GetChildren(); for (int i = 0; i < nbChildren; i++) { if (children[i].rect != null) { float sizeCurrentChild = SizeOfNode(children[i]); children[i].rect.x = xStart + (sizeCurrentChild - nodeSize.x * zoomScale) / 2.0f; xStart += sizeCurrentChild + 20.0f * zoomScale; } } node.rect = GUI.Window(node.ID, node.rect, func, (zoomScale <= minZoomForDisplayTitle) ? "" : node.displayedName, style); }
float SizeOfNode(BehaviourTreeNode node) { float size = 0.0f; if (node is BehaviourTreeExecutionNode) { return(nodeSize.x * zoomScale); } int nbChildren = node.ChildrenCount(); List <BehaviourTreeNode> children = node.GetChildren(); for (int i = 0; i < nbChildren; i++) { size += SizeOfNode(children[i]); } size += Mathf.Max(20.0f * (nbChildren - 1) * zoomScale, 0.0f); return(Mathf.Max(nodeSize.x * zoomScale, size)); }
private static BehaviourTreeNode CopyNodesRecursively(BehaviourTreeNode original) { BehaviourTreeNode result = UnityEngine.ScriptableObject.Instantiate(original); for (int i = 0; i < result.ChildrenCount(); i++) { result.ReplaceChild(result.GetChildren()[i], CopyNodesRecursively(original.GetChildren()[i])); } if (original is BehaviourTreeExecutionNode) { ((BehaviourTreeExecutionNode)result).task = UnityEngine.ScriptableObject.Instantiate(((BehaviourTreeExecutionNode)original).task); } if (original is BehaviourTreeSubTreeNode) { ((BehaviourTreeSubTreeNode)result).subTree = Copy(((BehaviourTreeSubTreeNode)original).subTree); } return(result); }
BehaviourTreeNode FindParentOfNodeByID(BehaviourTreeNode node, int ID) { if (node.ID.Equals(ID)) { return(null); } foreach (BehaviourTreeNode child in node.GetChildren()) { if (child.ID.Equals(ID)) { return(node); } BehaviourTreeNode recursiveResult = FindParentOfNodeByID(child, ID); if (recursiveResult != null) { return(recursiveResult); } } return(null); }
public static void SaveNodeAnChildren(BehaviourTreeNode node) { if (node == null) { throw new System.NullReferenceException("null node can't be saved"); } SerializedObject nodeSerializedAsset = new SerializedObject(node); nodeSerializedAsset.Update(); SerializedProperty p = nodeSerializedAsset.FindProperty("displayedName"); p.stringValue = ""; p.stringValue = node.displayedName; nodeSerializedAsset.ApplyModifiedProperties(); foreach (BehaviourTreeNode child in node.GetChildren()) { SaveNodeAnChildren(child); } }