/// <summary> /// 根据类型获取AgentData /// </summary> /// <param name="behaviorTreeType">行为树类型</param> /// <param name="id">行为树id</param> /// <returns></returns> public BehaviorTreeElement GetBehaviroTreeData(int behaviorTreeType, string id) { BehaviorTreeData treeData = null; if (!TreeDataDic.TryGetValue(behaviorTreeType, out treeData)) { throw new Exception($"There is no treeData,BehaviorTreeType:{behaviorTreeType}."); } if (treeData == null) { return(null); } for (int i = 0; i < treeData.BehaviorTrees.Count; i++) { BehaviorTreeElement behaviorTreeElement = treeData.BehaviorTrees[i]; if (behaviorTreeElement != null && behaviorTreeElement.ID == id) { return(behaviorTreeElement); } } string msg = $"There is no AgentData,BehaviorTreeType:{behaviorTreeType} id:{id}."; LogError(msg); throw new Exception(msg); }
public static void TestLongField() { BehaviorTreeElement behaviorTree = new BehaviorTreeElement(); behaviorTree.StartNode = new NodeData(); LongField longField = new LongField(); longField.FieldName = "LongField"; longField.Value = 100; behaviorTree.StartNode.Fields.Add(longField); RepeatLongField repeatLongField = new RepeatLongField(); repeatLongField.FieldName = "RepeatLongField"; repeatLongField.Value = new List <long>(); repeatLongField.Value.Add(1); repeatLongField.Value.Add(100); repeatLongField.Value.Add(1000); repeatLongField.Value.Add(10000); behaviorTree.StartNode.Fields.Add(repeatLongField); byte[] bytes = Serializer.Serialize(behaviorTree); BehaviorTreeElement deBehaviorTreeData = Serializer.DeSerialize <BehaviorTreeElement>(bytes); }
public static void TestFloatField() { BehaviorTreeElement behaviorTree = new BehaviorTreeElement(); behaviorTree.StartNode = new NodeData(); FloatField floatField = new FloatField(); floatField.FieldName = "FloatField"; floatField.Value = 100.001f; behaviorTree.StartNode.Fields.Add(floatField); RepeatFloatField repeatFloatField = new RepeatFloatField(); repeatFloatField.FieldName = "RepeatIntField"; repeatFloatField.Value = new List <float>(); repeatFloatField.Value.Add(1.1f); repeatFloatField.Value.Add(100.11f); repeatFloatField.Value.Add(1000.11f); repeatFloatField.Value.Add(10000.1119f); behaviorTree.StartNode.Fields.Add(repeatFloatField); byte[] bytes = Serializer.Serialize(behaviorTree); BehaviorTreeElement deBehaviorTreeData = Serializer.DeSerialize <BehaviorTreeElement>(bytes); }
public static void TestIntField() { BehaviorTreeElement behaviorTree = new BehaviorTreeElement(); behaviorTree.StartNode = new NodeData(); IntField intField = new IntField(); intField.FieldName = "IntField"; intField.Value = 100; behaviorTree.StartNode.Fields.Add(intField); RepeatIntField repeatIntField = new RepeatIntField(); repeatIntField.FieldName = "RepeatIntField"; repeatIntField.Value = new List <int>(); repeatIntField.Value.Add(1); repeatIntField.Value.Add(100); repeatIntField.Value.Add(-1000000); repeatIntField.Value.Add(10000); behaviorTree.StartNode.Fields.Add(repeatIntField); byte[] bytes = Serializer.Serialize(behaviorTree); BehaviorTreeElement deBehaviorTreeData = Serializer.DeSerialize <BehaviorTreeElement>(bytes); }
public static void TestDoubleField() { BehaviorTreeElement behaviorTree = new BehaviorTreeElement(); behaviorTree.StartNode = new NodeData(); DoubleField doubleField = new DoubleField(); doubleField.FieldName = "DoubleField"; doubleField.Value = 100.001d; behaviorTree.StartNode.Fields.Add(doubleField); RepeatDoubleField repeatDoubleField = new RepeatDoubleField(); repeatDoubleField.FieldName = "RepeatDoubleField"; repeatDoubleField.Value = new List <double>(); repeatDoubleField.Value.Add(1.1d); repeatDoubleField.Value.Add(100.11d); repeatDoubleField.Value.Add(1000.11d); repeatDoubleField.Value.Add(10000.1119d); behaviorTree.StartNode.Fields.Add(repeatDoubleField); byte[] bytes = Serializer.Serialize(behaviorTree); BehaviorTreeElement deBehaviorTreeData = Serializer.DeSerialize <BehaviorTreeElement>(bytes); }
public static void TestBooleanField() { BehaviorTreeElement behaviorTree = new BehaviorTreeElement(); behaviorTree.StartNode = new NodeData(); BooleanField booleanField = new BooleanField(); booleanField.FieldName = "BooleanField"; booleanField.Value = true; behaviorTree.StartNode.Fields.Add(booleanField); byte[] bytes = Serializer.Serialize(behaviorTree); BehaviorTreeElement deBehaviorTreeData = Serializer.DeSerialize <BehaviorTreeElement>(bytes); }
public static void TestEnumField() { BehaviorTreeElement behaviorTree = new BehaviorTreeElement(); behaviorTree.StartNode = new NodeData(); EnumField enumField = new EnumField(); enumField.FieldName = "EnumField"; enumField.Value = 100; behaviorTree.StartNode.Fields.Add(enumField); byte[] bytes = Serializer.Serialize(behaviorTree); BehaviorTreeElement deBehaviorTreeData = Serializer.DeSerialize <BehaviorTreeElement>(bytes); }
public BehaviorLogEntry(string loggerName, LogType logType, DateTime timestamp, string message, int behaviorID = -2, BehaviorState newState = BehaviorState.Null, long ticknum = -1, UnityEngine.Object context = null, Exception exception = null, string stackTrace = null, BehaviorTreeElement state = null) { this.LoggerName = loggerName; this.LogType = logType; this.Timestamp = timestamp; this.Message = message; this.BehaviorID = behaviorID; this.NewState = newState; this.TickNumber = ticknum; this.Context = context; this.Exception = exception; this.StackTrace = stackTrace; this.State = state; }
private void OnTypeSelected(object typeName) { var selection = _TreeView.GetSelection(); BehaviorTreeElement parent = (selection.Count == 1 ? _TreeView.treeModel.Find(selection[0]) : null) ?? _TreeView.treeModel.Root; int depth = parent != null ? parent.Depth + 1 : 0; int id = _TreeView.treeModel.GenerateUniqueID(); Type type = typeof(BehaviorTreeElement).Assembly.GetType((string)typeName, true); dynamic element = Activator.CreateInstance(type, type.ToString().Split('.').Last() + " " + id, depth, id); element.ElementType = element.GetType().ToString(); //element.BehaviorTreeManager = parent.BehaviorTreeManager; _TreeView.treeModel.AddElement(element, parent, 0); _TreeView.SetSelection(new[] { id }, TreeViewSelectionOptions.RevealAndFrame); //TODO: Show there are unsaved changes }
/// <summary> /// 从池中产生行为树,如果没有就创建 /// </summary> /// <param name="behaviorTreeType">行为树类型</param> /// <param name="behaviorTreeId">行为树ID</param> /// <returns>行为树</returns> private BehaviorTree Spawn(int behaviorTreeType, string behaviorTreeId) { Queue <BehaviorTree> queue = null; do { Dictionary <string, Queue <BehaviorTree> > typePoolDic = null; if (!m_PoolDic.TryGetValue((int)behaviorTreeType, out typePoolDic)) { break; } if (!typePoolDic.TryGetValue(behaviorTreeId, out queue)) { break; } }while (false); BehaviorTree behaviorTree = null; if (queue != null && queue.Count > 0) { while (behaviorTree == null && queue.Count > 0) { behaviorTree = queue.Dequeue(); } } if (behaviorTree == null) { behaviorTree = new BehaviorTree(); BehaviorTreeElement behaviorTreeElement = GetBehaviroTreeData(behaviorTreeType, behaviorTreeId); behaviorTree.SetData(behaviorTreeElement); behaviorTree.StartNode = CreateNode(behaviorTreeElement.StartNode); behaviorTree.BehaviorTreeType = behaviorTreeType; } return(behaviorTree); }
public static void TestNode() { BehaviorTreeElement behaviorTree = new BehaviorTreeElement(); //添加开始节点 behaviorTree.StartNode = new NodeData(); //开始节点字段 IntField intField = new IntField(); intField.FieldName = "IntField"; intField.Value = 100; behaviorTree.StartNode.Fields.Add(intField); //创建开始节点的第一个子节点 NodeData node1 = new NodeData(); //子节点1的枚举字段 EnumField enumField = new EnumField(); enumField.FieldName = "EnumField"; enumField.Value = 100; node1.Fields.Add(enumField); //创建开始节点的第二个子节点 NodeData node2 = new NodeData(); //子节点2的Long字段 LongField longField = new LongField(); longField.FieldName = "LongField"; longField.Value = 100; node2.Fields.Add(longField); behaviorTree.StartNode.Childs = new List <NodeData>(); behaviorTree.StartNode.Childs.Add(node1); behaviorTree.StartNode.Childs.Add(node2); byte[] bytes = Serializer.Serialize(behaviorTree); BehaviorTreeElement deBehaviorTreeData = Serializer.DeSerialize <BehaviorTreeElement>(bytes); }
public virtual void AddChild(BehaviorTreeElement element) { element.Parent = this; Children.Add(element); }
internal void SetData(BehaviorTreeElement behaviorTreeElement) { BehaviorTreeElement = behaviorTreeElement; BehaviorTreeID = behaviorTreeElement.ID; }
public void SetData(BehaviorTreeElement behaviorTreeElement) { BehaviorTreeElement = behaviorTreeElement; BehaviorTreeId = behaviorTreeElement.Id; }