示例#1
0
        public static BTData.BehaviorTreeData CreateTreeData(BehaviorTreeDataDesigner treeData)
        {
            BTData.BehaviorTreeData data = new BTData.BehaviorTreeData();

            //全局变量
            for (int i = 0; i < treeData.GlobalVariable.VariableFields.Count; i++)
            {
                VariableFieldDesigner variableField     = treeData.GlobalVariable.VariableFields[i];
                BTData.BaseField      variableFieldData = CreateVariableField(variableField);
                data.GlobalVariable.VariableFields.Add(variableFieldData);
            }

            //Context变量
            for (int i = 0; i < treeData.ContextVariable.VariableFields.Count; i++)
            {
                VariableFieldDesigner variableField     = treeData.ContextVariable.VariableFields[i];
                BTData.BaseField      variableFieldData = CreateVariableField(variableField);
                data.ContextVariable.VariableFields.Add(variableFieldData);
            }

            for (int i = 0; i < treeData.BehaviorTrees.Count; i++)
            {
                BehaviorTreeDesigner behaviorTree = treeData.BehaviorTrees[i];
                if (behaviorTree == null)
                {
                    continue;
                }
                data.BehaviorTrees.Add(CreateBehaviorTreeData(behaviorTree));
            }

            return(data);
        }
示例#2
0
 //重置数据
 private void Reset()
 {
     EditorUtility.NodeDefineDic.Clear();
     treeView1.Nodes.Clear();
     NodeTemplate = new NodeTemplate();
     NodeTemplate.ResetEnums();
     NodeTemplate.ResetNodes();
     BehaviorTreeData = new BehaviorTreeDataDesigner();
     CreateTreeViewManager();
     SetSelectedBehaviorTree(null);
 }
示例#3
0
        public void LoadBehaviorTreeData()
        {
            //读取行为树数据
            BehaviorTreeData = XmlUtility.Read <BehaviorTreeDataDesigner>(GetBehaviorTreeDataPath());
            if (BehaviorTreeData == null)
            {
                BehaviorTreeData = new BehaviorTreeDataDesigner();
                XmlUtility.Save(GetBehaviorTreeDataPath(), BehaviorTreeData);
            }

            BehaviorTreeDataStringContent = XmlUtility.ObjectToString(BehaviorTreeData);

            if (BehaviorTreeData.BehaviorTrees.Count > 0)
            {
                for (int i = 0; i < BehaviorTreeData.BehaviorTrees.Count; i++)
                {
                    BehaviorTreeDesigner behaviorTree = BehaviorTreeData.BehaviorTrees[i];
                    if (behaviorTree != null)
                    {
                        if (behaviorTree.Nodes.Count > 0)
                        {
                            for (int ii = 0; ii < behaviorTree.Nodes.Count; ii++)
                            {
                                NodeDesigner node = behaviorTree.Nodes[ii];
                                if (node.Transitions.Count > 0)
                                {
                                    for (int iii = 0; iii < node.Transitions.Count; iii++)
                                    {
                                        Transition   transition = node.Transitions[iii];
                                        NodeDesigner fromNode   = behaviorTree.FindNodeByID(transition.FromNodeID);
                                        NodeDesigner toNode     = behaviorTree.FindNodeByID(transition.ToNodeID);
                                        transition.Set(toNode, fromNode);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }