public static BehaviorTreeData.TreeData CreateTreeData(TreeData treeData)
        {
            BehaviorTreeData.TreeData data = new BehaviorTreeData.TreeData();

            for (int i = 0; i < treeData.Agents.Count; i++)
            {
                AgentDesigner agent = treeData.Agents[i];
                if (agent == null)
                {
                    continue;
                }
                data.Agents.Add(CreateAgentData(agent));
            }

            return(data);
        }
Esempio n. 2
0
        //保存
        public void Save()
        {
            if (WorkSpaceData == null)
            {
                ShowMessage("当前没有工作空间,请新建或者打开工作空间!");
                return;
            }

            if (NodeClasses == null || TreeData == null)
            {
                return;
            }

            //节点类移除未定义的枚举字段
            NodeClasses.RemoveUnDefineEnumField();

            //移除未定义的节点
            TreeData.RemoveUnDefineNode();

            //修正数据,和模板的保持一致
            TreeData.AjustData();

            //检验枚举
            VerifyInfo verifyEnum = NodeClasses.VerifyEnum();

            if (verifyEnum.HasError)
            {
                ShowMessage(verifyEnum.Msg);
                ShowInfo(verifyEnum.Msg);
                return;
            }

            //检验节点类
            VerifyInfo verifyNodeClass = NodeClasses.VerifyNodeClass();

            if (verifyNodeClass.HasError)
            {
                ShowMessage(verifyNodeClass.Msg);
                ShowInfo(verifyNodeClass.Msg);
                return;
            }

            //校验行为树
            VerifyInfo verifyBehaviorTree = TreeData.VerifyBehaviorTree();

            if (verifyBehaviorTree.HasError)
            {
                ShowMessage(verifyBehaviorTree.Msg);
                ShowInfo(verifyBehaviorTree.Msg);
                return;
            }

            if (XmlUtility.Save(GetNodeClassPath(), NodeClasses))
            {
                NodeClassesStringContent = XmlUtility.ObjectToString(NodeClasses);
            }


            if (XmlUtility.Save(GetBehaviorTreeDataPath(), TreeData))
            {
                BehaviorTreeDataStringContent = XmlUtility.ObjectToString(TreeData);
            }

            //序列化成二进制
            BehaviorTreeData.TreeData treeData = EditorUtility.CreateTreeData(TreeData);
            if (treeData != null)
            {
                string savePath = GetNodeDataSavePath();
                if (File.Exists(savePath))
                {
                    File.Delete(savePath);
                }
                BehaviorTreeData.Serializer.SerializeToFile(treeData, savePath);
            }

            ShowInfo("保存成功 时间:" + DateTime.Now);
        }