Exemple #1
0
        public void Debug(AgentDesigner agent)
        {
            if (agent == null)
            {
                MainForm.Instance.ShowMessage("Agent为空");
                return;
            }

            m_Nodes.Clear();
            VerifyInfo verifyAgent = agent.VerifyAgent();

            if (verifyAgent.HasError)
            {
                MainForm.Instance.ShowMessage("确保行为树编辑正确后才能调试\n" + verifyAgent.Msg);
                return;
            }

            for (int i = 0; i < agent.Nodes.Count; i++)
            {
                NodeDesigner node = agent.Nodes[i];
                if (node.StartNode)
                {
                    m_DebugNode = CreateDebugNode(agent, node);
                    break;
                }
            }

            State = DebugState.Running;
            ContentUserControl.Instance.OnDebugStart();
            MainForm.Instance.ShowInfo("播放成功 时间:" + DateTime.Now);
        }
Exemple #2
0
        /// <summary>
        /// 校验行为树是否合法
        /// </summary>
        /// <returns></returns>
        public VerifyInfo VerifyBehaviorTree()
        {
            //检验ID是否合法
            VerifyInfo verifyBehaviroTreeID = VerifyBehaviorTreeID();

            if (verifyBehaviroTreeID.HasError)
            {
                return(verifyBehaviroTreeID);
            }

            //检验是否存在空字段名
            VerifyInfo verifyEmptyFieldName = VerifyEmptyFieldName();

            if (verifyEmptyFieldName.HasError)
            {
                return(verifyEmptyFieldName);
            }

            //检验是否存在相同名字字段
            VerifyInfo verifySameFieldName = VerifySameFieldName();

            if (verifySameFieldName.HasError)
            {
                return(verifySameFieldName);
            }

            //检验枚举字段
            VerifyInfo verifyEnum = VerifyEnum();

            if (verifyEnum.HasError)
            {
                return(verifyEnum);
            }

            //校验开始节点
            VerifyInfo verifyStartNode = VerifyStartNode();

            if (verifyStartNode.HasError)
            {
                return(verifyStartNode);
            }

            //校验父节点
            VerifyInfo verifyParentNode = VerifyParentNode();

            if (verifyParentNode.HasError)
            {
                return(verifyParentNode);
            }

            //检验子节点
            VerifyInfo verifyChildNode = VerifyChildNode();

            if (verifyChildNode.HasError)
            {
                return(verifyChildNode);
            }

            return(VerifyInfo.DefaultVerifyInfo);
        }
Exemple #3
0
        private void enterBTN_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(textBox1.Text.Trim()))
            {
                MainForm.Instance.ShowMessage("枚举类型为空,请填写枚举类型");
                return;
            }

            if (m_EditCustomEnum.Enums.Count == 0)
            {
                MainForm.Instance.ShowMessage("枚举项为0,请添加至少一个枚举项");
                return;
            }

            m_EditCustomEnum.EnumType = textBox1.Text.Trim();
            m_EditCustomEnum.Describe = textBox2.Text.Trim();

            VerifyInfo verifyEnum = m_EditCustomEnum.VerifyEnum();

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

            string newContent = XmlUtility.ObjectToString(m_EditCustomEnum);

            if (m_OldContent != newContent)
            {
                m_CustomEnum.UpdateEnum(m_EditCustomEnum);
                m_EnumForm.UpdateEnum(m_CustomEnum);
            }

            this.Close();
        }
        public void Debug(BehaviorTreeDesigner behaviorTree)
        {
            if (behaviorTree == null)
            {
                MainForm.Instance.ShowMessage("行为树为空");
                return;
            }

            m_Nodes.Clear();
            VerifyInfo verifyBehaviorTree = behaviorTree.VerifyBehaviorTree();

            if (verifyBehaviorTree.HasError)
            {
                MainForm.Instance.ShowMessage("确保行为树编辑正确后才能调试\n" + verifyBehaviorTree.Msg);
                return;
            }

            for (int i = 0; i < behaviorTree.Nodes.Count; i++)
            {
                NodeDesigner node = behaviorTree.Nodes[i];
                if (node.StartNode)
                {
                    m_DebugNode = CreateDebugNode(behaviorTree, node);
                    break;
                }
            }

            State = DebugState.Running;
            ContentUserControl.Instance.OnDebugStart();
            MainForm.Instance.ShowInfo("播放成功 时间:" + DateTime.Now);
        }
Exemple #5
0
        private void enterBTN_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(textBox1.Text.Trim()))
            {
                MainForm.Instance.ShowMessage("枚举类型为空,请填写枚举类型");
                return;
            }

            if (m_CustomEnum.Enums.Count == 0)
            {
                MainForm.Instance.ShowMessage("枚举项为0,请添加至少一个枚举项");
                return;
            }

            m_CustomEnum.EnumType = textBox1.Text.Trim();
            m_CustomEnum.Describe = textBox2.Text.Trim();

            VerifyInfo verifyEnum = m_CustomEnum.VerifyEnum();

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

            if (!MainForm.Instance.NodeTemplate.AddEnum(m_CustomEnum))
            {
                return;
            }

            m_EnumForm.AddEnum(m_CustomEnum);
            this.Close();
        }
Exemple #6
0
        /// <summary>
        /// 校验行为树数据
        /// </summary>
        /// <returns></returns>
        public VerifyInfo VerifyBehaviorTree()
        {
            VerifyInfo verifyID = VerifyBehaviorTreeID();

            if (verifyID.HasError)
            {
                return(verifyID);
            }

            for (int i = 0; i < m_Groups.Count; i++)
            {
                BehaviorGroupDesigner group = m_Groups[i];

                if (group == null)
                {
                    continue;
                }

                for (int j = 0; j < group.BehaviorTrees.Count; j++)
                {
                    BehaviorTreeDesigner behaviorTree = group.BehaviorTrees[j];
                    if (behaviorTree != null)
                    {
                        VerifyInfo verifyBehaviorTree = behaviorTree.VerifyBehaviorTree();
                        if (verifyBehaviorTree.HasError)
                        {
                            return(verifyBehaviorTree);
                        }
                    }
                }
            }

            for (int i = 0; i < m_BehaviorTrees.Count; i++)
            {
                BehaviorTreeDesigner behaviorTree = m_BehaviorTrees[i];
                if (behaviorTree != null)
                {
                    VerifyInfo verifyBehaviorTree = behaviorTree.VerifyBehaviorTree();
                    if (verifyBehaviorTree.HasError)
                    {
                        return(verifyBehaviorTree);
                    }
                }
            }
            return(VerifyInfo.DefaultVerifyInfo);
        }
        private void enterBTN_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(textBox1.Text.Trim()))
            {
                MainForm.Instance.ShowMessage("BehaviorTreeID不能为空");
                MainForm.Instance.ShowInfo("BehaviorTreeID不能为空");
                return;
            }

            string behaviorTreeId = textBox1.Text.Trim();
            string behaviorName   = textBox3.Text.Trim();

            if (m_BehaviorTree.ID != behaviorTreeId)
            {
                if (MainForm.Instance.BehaviorTreeData.ExistBehaviorTree(behaviorTreeId))
                {
                    MainForm.Instance.ShowMessage(string.Format("已存在BehaviorTreeID:{0}", behaviorTreeId));
                    MainForm.Instance.ShowInfo(string.Format("已存在BehaviorTreeID:{0}", behaviorTreeId));
                    return;
                }
            }

            m_EditBehaviorTree.ID       = behaviorTreeId;
            m_EditBehaviorTree.Describe = textBox2.Text.Trim();
            m_EditBehaviorTree.Name     = textBox3.Text.Trim();

            //检验行为树是否合法
            VerifyInfo verifyBehaviorTree = m_EditBehaviorTree.VerifyBehaviorTree();

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

            string editContent = XmlUtility.ObjectToString(m_EditBehaviorTree);

            if (editContent != m_BehaviorTreeContent)
            {
                m_BehaviorTree.UpdateBehaviorTree(m_EditBehaviorTree);
                MainForm.Instance.ShowInfo(string.Format("更新行为树:{0}成功 时间:{1}", m_EditBehaviorTree.ID, DateTime.Now));
            }

            MainForm.Instance.Exec(OperationType.UpdateBehaviorTree, m_BehaviorTree);
            this.Close();
        }
Exemple #8
0
        /// <summary>
        /// 检验枚举是否合法
        /// </summary>
        /// <returns></returns>
        public VerifyInfo VerifyEnum()
        {
            //检验枚举类型
            VerifyInfo verifyEnumType = VerifyEnumType();

            if (verifyEnumType.HasError)
            {
                return(verifyEnumType);
            }

            //检验枚举个数
            VerifyInfo verifyEnumItemCount = VerifyEnumItemCount();

            if (verifyEnumItemCount.HasError)
            {
                return(verifyEnumItemCount);
            }

            //检验空枚举项名字
            VerifyInfo verifyEmptyEnumStr = VerifyEmptyEnumStr();

            if (verifyEmptyEnumStr.HasError)
            {
                return(verifyEmptyEnumStr);
            }

            //检验是否有相同的枚举选项名
            VerifyInfo verifySameEnumStr = VerifySameEnumStr();

            if (verifySameEnumStr.HasError)
            {
                return(verifySameEnumStr);
            }

            //校验枚举值是否存在相同
            VerifyInfo verifySameEnumValue = VerifySameEnumValue();

            if (verifySameEnumValue.HasError)
            {
                return(verifySameEnumValue);
            }

            return(VerifyInfo.DefaultVerifyInfo);
        }
        private void enterBTN_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(textBox1.Text.Trim()))
            {
                MainForm.Instance.ShowMessage("AgentID不能为空");
                MainForm.Instance.ShowInfo("AgentID不能为空");
                return;
            }

            string agentId = textBox1.Text.Trim();

            if (m_Agent.AgentID != agentId)
            {
                if (MainForm.Instance.TreeData.ExistAgent(agentId))
                {
                    MainForm.Instance.ShowMessage(string.Format("已存在AgentID:{0}", agentId));
                    MainForm.Instance.ShowInfo(string.Format("已存在AgentID:{0}", agentId));
                    return;
                }
            }

            m_EditAgent.AgentID  = agentId;
            m_EditAgent.Describe = textBox2.Text.Trim();

            //检验Agent的是否合法
            VerifyInfo verifyAgent = m_EditAgent.VerifyAgent();

            if (verifyAgent.HasError)
            {
                MainForm.Instance.ShowMessage(verifyAgent.Msg);
                return;
            }

            string editContent = XmlUtility.ObjectToString(m_EditAgent);

            if (editContent != m_AgentContent)
            {
                m_Agent.UpdateAgent(m_EditAgent);
                MainForm.Instance.ShowInfo(string.Format("更新Agent:{0}成功 时间:{1}", m_EditAgent.AgentID, DateTime.Now));
            }

            MainForm.Instance.Exec(OperationType.UpdateAgent, m_Agent);
            this.Close();
        }
Exemple #10
0
        private void enterBTN_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(classTypeTB.Text.Trim()))
            {
                MainForm.Instance.ShowMessage("请填写类名", "提示");
                return;
            }

            if (categoryTB.Text.Trim().Contains(" "))
            {
                MainForm.Instance.ShowMessage("类别不能有空格", "提示");
                return;
            }

            m_EditNodeDefine.ClassType  = classTypeTB.Text.Trim();
            m_EditNodeDefine.NodeType   = (NodeType)(nodeTypeCBB.SelectedIndex + 1);
            m_EditNodeDefine.Label      = labelTB.Text.Trim();
            m_EditNodeDefine.Describe   = describeTB.Text.Trim();
            m_EditNodeDefine.Category   = categoryTB.Text.Trim();
            m_EditNodeDefine.CheckField = CBB_CheckField.Checked;
            m_NodeDefine.NodeIcon       = nodeIconCBB.Text;

            //校验节点类是否合法
            VerifyInfo verifyNodeDefine = m_EditNodeDefine.VerifyNodeDefine();

            if (verifyNodeDefine.HasError)
            {
                MainForm.Instance.ShowMessage(verifyNodeDefine.Msg);
                return;
            }

            string content = XmlUtility.ObjectToString(m_EditNodeDefine);

            if (m_Content != content)
            {
                m_NodeDefine.UpdateNodeDefine(m_EditNodeDefine);
                MainForm.Instance.ShowInfo("修改成功 时间:" + DateTime.Now);
            }

            this.Close();

            m_EditCallback?.Invoke();
        }
        /// <summary>
        /// 校节点类数据
        /// </summary>
        /// <returns></returns>
        public VerifyInfo VerifyNodeClass()
        {
            VerifyInfo verifyClassType = VerifyClassType();

            if (verifyClassType.HasError)
            {
                return(verifyClassType);
            }

            for (int i = 0; i < m_Nodes.Count; i++)
            {
                NodeClass  nodeClass       = m_Nodes[i];
                VerifyInfo verifyNodeClass = nodeClass.VerifyNodeClass();
                if (verifyNodeClass.HasError)
                {
                    return(verifyNodeClass);
                }
            }

            return(VerifyInfo.DefaultVerifyInfo);
        }
Exemple #12
0
        /// <summary>
        /// 校节点类数据
        /// </summary>
        /// <returns></returns>
        public VerifyInfo VerifyNodeTemplate()
        {
            VerifyInfo verifyClassType = VerifyClassType();

            if (verifyClassType.HasError)
            {
                return(verifyClassType);
            }

            for (int i = 0; i < m_Nodes.Count; i++)
            {
                NodeDefine nodeDefine       = m_Nodes[i];
                VerifyInfo verifyNodeDefine = nodeDefine.VerifyNodeDefine();
                if (verifyNodeDefine.HasError)
                {
                    return(verifyNodeDefine);
                }
            }

            return(VerifyInfo.DefaultVerifyInfo);
        }
        private void enterBTN_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(classTypeTB.Text.Trim()))
            {
                MainForm.Instance.ShowMessage("请填写类名", "提示");
                return;
            }

            if (categoryTB.Text.Trim().Contains(" "))
            {
                MainForm.Instance.ShowMessage("类别不能有空格", "提示");
                return;
            }

            m_NodeDefine.ClassType  = classTypeTB.Text.Trim();
            m_NodeDefine.NodeType   = (NodeType)(nodeTypeCBB.SelectedIndex + 1);
            m_NodeDefine.Describe   = describeTB.Text.Trim();
            m_NodeDefine.Category   = categoryTB.Text.Trim();
            m_NodeDefine.CheckField = CBB_CheckField.Checked;
            m_NodeDefine.Label      = labelTB.Text.Trim();
            m_NodeDefine.NodeIcon   = nodeIconCBB.Text;

            //校验节点类是否合法
            VerifyInfo verifyNodeDefine = m_NodeDefine.VerifyNodeDefine();

            if (verifyNodeDefine.HasError)
            {
                MainForm.Instance.ShowMessage(verifyNodeDefine.Msg);
                return;
            }

            if (!MainForm.Instance.NodeTemplate.AddClass(m_NodeDefine))
            {
                return;
            }

            m_NodeTemplateForm.AddNodeDefine(m_NodeDefine);

            this.Close();
        }
        /// <summary>
        /// 校验枚举数据
        /// </summary>
        /// <returns></returns>
        public VerifyInfo VerifyEnum()
        {
            //校验枚举类型
            VerifyInfo verifyEnumType = VerifyEnumType();

            if (verifyEnumType.HasError)
            {
                return(verifyEnumType);
            }

            for (int i = 0; i < m_Enums.Count; i++)
            {
                CustomEnum customEnum = m_Enums[i];
                VerifyInfo verifyEnum = customEnum.VerifyEnum();
                if (verifyEnum.HasError)
                {
                    return(verifyEnum);
                }
            }

            return(VerifyInfo.DefaultVerifyInfo);
        }
        private void enterBTN_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(classTypeTB.Text.Trim()))
            {
                MainForm.Instance.ShowMessage("请填写类名", "提示");
                return;
            }

            if (categoryTB.Text.Trim().Contains(" "))
            {
                MainForm.Instance.ShowMessage("类别不能有空格", "提示");
                return;
            }

            m_NodeClass.ClassType   = classTypeTB.Text.Trim();
            m_NodeClass.NodeType    = (NodeType)(nodeTypeCBB.SelectedIndex + 1);
            m_NodeClass.Describe    = describeTB.Text.Trim();
            m_NodeClass.Category    = categoryTB.Text.Trim();
            m_NodeClass.ShowContent = showContentCB.Checked;
            m_NodeClass.Label       = labelTB.Text.Trim();

            //校验节点类是否合法
            VerifyInfo verifyNodeClass = m_NodeClass.VerifyNodeClass();

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

            if (!MainForm.Instance.NodeClasses.AddClass(m_NodeClass))
            {
                return;
            }

            m_ClassForm.AddClass(m_NodeClass);

            this.Close();
        }
Exemple #16
0
        /// <summary>
        /// 校验行为树数据
        /// </summary>
        /// <returns></returns>
        public VerifyInfo VerifyBehaviorTree()
        {
            VerifyInfo verifyID = VerifyBehaviorTreeID();

            if (verifyID.HasError)
            {
                return(verifyID);
            }

            for (int i = 0; i < m_BehaviorTrees.Count; i++)
            {
                BehaviorTreeDesigner behaviorTree = m_BehaviorTrees[i];
                if (behaviorTree != null)
                {
                    VerifyInfo verifyBehaviorTree = behaviorTree.VerifyBehaviorTree();
                    if (verifyBehaviorTree.HasError)
                    {
                        return(verifyBehaviorTree);
                    }
                }
            }
            return(VerifyInfo.DefaultVerifyInfo);
        }
Exemple #17
0
        /// <summary>
        /// 校验行为树数据
        /// </summary>
        /// <returns></returns>
        public VerifyInfo VerifyBehaviorTree()
        {
            VerifyInfo verifyAgentID = VerifyAgentID();

            if (verifyAgentID.HasError)
            {
                return(verifyAgentID);
            }

            for (int i = 0; i < m_Agents.Count; i++)
            {
                AgentDesigner agent = m_Agents[i];
                if (agent != null)
                {
                    VerifyInfo verifyAgent = agent.VerifyAgent();
                    if (verifyAgent.HasError)
                    {
                        return(verifyAgent);
                    }
                }
            }
            return(VerifyInfo.DefaultVerifyInfo);
        }
        /// <summary>
        /// 检验节点是否合法
        /// </summary>
        /// <returns></returns>
        public VerifyInfo VerifyNodeClass()
        {
            //检验ClassType
            VerifyInfo verifyClassType = VerifyClassType();

            if (verifyClassType.HasError)
            {
                return(verifyClassType);
            }

            //检验字段是否存在空名
            VerifyInfo verifyEmptyFieldName = VerifyEmptyFieldName();

            if (verifyEmptyFieldName.HasError)
            {
                return(verifyEmptyFieldName);
            }

            //校验是否重名
            VerifyInfo verifySameFieldName = VerifySameFieldName();

            if (verifySameFieldName.HasError)
            {
                return(verifySameFieldName);
            }

            //校验枚举
            VerifyInfo verifyEnum = VerifyEnum();

            if (verifyEnum.HasError)
            {
                return(verifyEnum);
            }

            return(VerifyInfo.DefaultVerifyInfo);
        }
        //保存
        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);
        }