public void RemoveChild(BehaviourNode child) { if (child != null) { m_children.Remove(child); } }
public void InsertChild(int index, BehaviourNode child) { if (child != null) { m_children.Insert(index, child); } }
public static string SerializeNode(BehaviourNode behaviourNode) { try { if (behaviourNode == null) { return(null); } StringBuilder builder = new StringBuilder(); JsonWriterSettings settings = new JsonWriterSettings(); settings.TypeHintName = TYPE_HINT_NAME; settings.TypeHintsOnlyWhenNeeded = true; settings.MaxDepth = MAX_TREE_DEPTH; using (JsonWriter writer = new JsonWriter(builder, settings)) { writer.Write(new object[] { behaviourNode }); } return(builder.ToString()); } catch (Exception ex) { Debug.LogException(ex); return(null); } }
public void AddChild(BehaviourNode node) { if (!m_children.Contains(node)) { node.parent = this; m_children.Add(node); } }
public int GetIndex(BehaviourNode node) { for (int i = 0; i < m_children.Count; i++) { if (m_children[i] == node) { return(i); } } return(-1); }
public string Dump(Context context) { System.Text.StringBuilder builder = new System.Text.StringBuilder(); string[] statusColors = { "grey", "yellow", "green", "red" }; NodeStack nodeStack = new NodeStack(); nodeStack.Push(root); while (nodeStack.Count > 0) { BehaviourNode node = nodeStack.Pop(); int depth = 0; BehaviourNode tmpNode = node; while (tmpNode.parent != null) { tmpNode = tmpNode.parent; depth++; } while (depth-- > 0) { builder.Append(" "); } RunningStatus lastRet = (RunningStatus)context.blackboard.GetInt(this.guid, node.guid, "Status"); string color = statusColors[(int)lastRet]; if (!context._travelNodes[this.guid].Contains(node)) { color = statusColors[0]; } builder.Append(string.Format("<color={0}>{1}</color>\n", color, node.GetType().Name)); if (node is Composite) { var childrenList = (node as Composite)._getChildren(); for (int i = childrenList.Count - 1; i >= 0; --i) { nodeStack.Push(childrenList[i]); } } else if (node is Decorator) { nodeStack.Push((node as Decorator).GetChild()); } } return(builder.ToString()); }
public static BehaviourNode CreateNode(Type nodeType) { BehaviourNode node = null; if (nodeType != null && nodeType.IsSubclassOf(typeof(BehaviourNode)) && !nodeType.IsAbstract) { node = Activator.CreateInstance(nodeType) as BehaviourNode; if (node != null) { FieldInfo uniqueIDField = typeof(BehaviourNode).GetField("m_guid", BindingFlags.Instance | BindingFlags.NonPublic); long uniqueID = GenUniqueGUID(); uniqueIDField.SetValue(node, uniqueID); } } return(node); }
public void SetChild(BehaviourNode node) { m_child = node; }
public Decorator(BehaviourNode node) : base() { m_child = node; }