public GroupItem AddGroup(BehaviorGroupDesigner group)
        {
            if (string.IsNullOrEmpty(group.GroupName) || GroupDic.ContainsKey(group.GroupName))
            {
                return(null);
            }

            m_Groups.Add(group);

            GroupItem groupItem = new GroupItem();

            groupItem.Group = group;
            GroupDic.Add(group.GroupName, groupItem);

            TreeNode treeNode = m_TreeView.Nodes.Insert(m_Groups.Count - 1, GetGroupTreeNodeName(group));

            treeNode.Tag       = groupItem;
            groupItem.TreeNode = treeNode;

            m_TreeView.SelectedNode = treeNode;

            for (int i = 0; i < group.BehaviorTrees.Count; i++)
            {
                BehaviorTreeDesigner behaviorTree     = group.BehaviorTrees[i];
                TreeNode             tempTreeNode     = treeNode.Nodes.Add(behaviorTree.ID);
                BehaviorTreeItem     behaviorTreeItem = new BehaviorTreeItem();
                behaviorTreeItem.BehaviorTree = behaviorTree;
                behaviorTreeItem.GroupItem    = groupItem;
                behaviorTreeItem.TreeNode     = tempTreeNode;
                tempTreeNode.Tag = behaviorTreeItem;
            }

            return(groupItem);
        }
Exemple #2
0
        /// <summary>
        /// 删除行为树分组
        /// </summary>
        /// <param name="behaviorGroup"></param>
        public bool RemoveGroup(BehaviorGroupDesigner behaviorGroup)
        {
            if (behaviorGroup == null)
            {
                throw new ArgumentException("BehaviorTreeDataDesigner.RemoveGroup() error: behaviorGroup = null.");
            }

            if (!ExistBehaviorGroup(behaviorGroup.GroupName))
            {
                return(false);
            }

            for (int i = 0; i < m_Groups.Count; i++)
            {
                BehaviorGroupDesigner temp = m_Groups[i];
                if (temp == null)
                {
                    continue;
                }

                if (string.IsNullOrEmpty(temp.GroupName))
                {
                    continue;
                }

                if (temp.GroupName == behaviorGroup.GroupName)
                {
                    m_Groups.RemoveAt(i);
                    return(true);
                }
            }

            return(false);
        }
Exemple #3
0
        /// <summary>
        /// 修正数据(和模板保持一致)
        /// </summary>
        public void AjustData()
        {
            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)
                    {
                        behaviorTree.AjustData();
                    }
                }
            }

            for (int i = 0; i < m_BehaviorTrees.Count; i++)
            {
                BehaviorTreeDesigner behaviorTree = m_BehaviorTrees[i];
                if (behaviorTree != null)
                {
                    behaviorTree.AjustData();
                }
            }
        }
        public void BindGroup(BehaviorGroupDesigner group)
        {
            if (string.IsNullOrEmpty(group.GroupName) || GroupDic.ContainsKey(group.GroupName))
            {
                return;
            }

            GroupItem groupItem = new GroupItem();

            groupItem.Group           = group;
            groupItem.Group.GroupName = group.GroupName;
            GroupDic.Add(group.GroupName, groupItem);

            TreeNode treeNode = m_TreeView.Nodes.Add(GetGroupTreeNodeName(group));

            treeNode.Tag       = groupItem;
            groupItem.TreeNode = treeNode;

            for (int i = 0; i < group.BehaviorTrees.Count; i++)
            {
                BehaviorTreeDesigner behaviorTree     = group.BehaviorTrees[i];
                TreeNode             tempTreeNode     = treeNode.Nodes.Add(GetTreeNodeName(behaviorTree));
                BehaviorTreeItem     behaviorTreeItem = new BehaviorTreeItem();
                behaviorTreeItem.BehaviorTree = behaviorTree;
                behaviorTreeItem.GroupItem    = groupItem;
                behaviorTreeItem.TreeNode     = tempTreeNode;
                tempTreeNode.Tag = behaviorTreeItem;
            }
        }
        private void addGroupBTN_Click(object sender, EventArgs e)
        {
            string groupName = textBox1.Text.Trim();
            string describe  = textBox2.Text.Trim();

            if (string.IsNullOrEmpty(groupName))
            {
                MainForm.Instance.ShowMessage("组名不能为空");
                return;
            }

            if (MainForm.Instance.TreeViewManager.ExistGroup(groupName))
            {
                MainForm.Instance.ShowMessage(string.Format("该组{0},已存在", groupName));
                return;
            }

            BehaviorGroupDesigner group = new BehaviorGroupDesigner();

            group.GroupName = groupName;
            group.Describe  = describe;

            MainForm.Instance.TreeViewManager.AddGroup(group);
            this.Close();
        }
Exemple #6
0
        public EditGroupForm(BehaviorGroupDesigner group)
        {
            m_Group      = group;
            m_OldContent = XmlUtility.ObjectToString(m_Group);
            m_EditGroup  = XmlUtility.StringToObject <BehaviorGroupDesigner>(m_OldContent);

            InitializeComponent();
        }
        public GroupItem AddGroup(string groupName)
        {
            if (string.IsNullOrEmpty(groupName) || GroupDic.ContainsKey(groupName))
            {
                return(null);
            }

            BehaviorGroupDesigner group = new BehaviorGroupDesigner(groupName);

            return(AddGroup(group));
        }
 public bool ExistGroup(string groupName)
 {
     for (int i = 0; i < m_Groups.Count; i++)
     {
         BehaviorGroupDesigner group = m_Groups[i];
         if (group.GroupName == groupName)
         {
             return(true);
         }
     }
     return(false);
 }
        public void UpdateGroup(BehaviorGroupDesigner original, BehaviorGroupDesigner group)
        {
            original.GroupName = group.GroupName;
            original.Describe  = group.Describe;

            foreach (var kv in GroupDic)
            {
                if (kv.Value.Group == original)
                {
                    kv.Value.TreeNode.Text = GetGroupTreeNodeName(original);
                }
            }
        }
Exemple #10
0
        public static BTData.GroupData CreateBehaviorGroupData(BehaviorGroupDesigner group)
        {
            BTData.GroupData data = new BTData.GroupData();
            data.GroupName = group.GroupName;

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

            return(data);
        }
Exemple #11
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);
        }
        public void DeleteGroup(BehaviorGroupDesigner group)
        {
            foreach (var kv in GroupDic)
            {
                if (kv.Value.Group == group)
                {
                    kv.Value.TreeNode.Remove();
                }
            }

            if (GroupDic.ContainsKey(group.GroupName))
            {
                GroupDic.Remove(group.GroupName);
            }

            m_Groups.Remove(group);
        }
        public void BindBehaviorTrees()
        {
            m_TreeView.Nodes.Clear();
            GroupDic.Clear();

            //分组优先
            for (int i = 0; i < m_Groups.Count; i++)
            {
                BehaviorGroupDesigner group = m_Groups[i];
                BindGroup(group);
            }

            for (int i = 0; i < m_BehaviorTrees.Count; i++)
            {
                BehaviorTreeDesigner behaviorTree = m_BehaviorTrees[i];
                BindBehaviorTreeItem(behaviorTree);
            }
        }
Exemple #14
0
        /// <summary>
        /// 添加行为树分组
        /// </summary>
        /// <param name="behaviorGroup"></param>
        public void AddGroup(BehaviorGroupDesigner behaviorGroup)
        {
            if (behaviorGroup == null)
            {
                throw new ArgumentException("BehaviorTreeDataDesigner.AddGroup() error: behaviorGroup = null.");
            }

            if (ExistBehaviorGroup(behaviorGroup.GroupName))
            {
                return;
            }

            if (m_Groups.Contains(behaviorGroup))
            {
                throw new Exception(string.Format("BehaviorTreeDataDesigner.AddGroup() error: m_Groups aready contains behaviorGroup:{0}.", behaviorGroup.GroupName));
            }

            m_Groups.Add(behaviorGroup);
        }
Exemple #15
0
        public static BTData.TreeDatas CreateTreeData(TreeDatasDesigner treeData)
        {
            BTData.TreeDatas data = new BTData.TreeDatas();

            //全局变量
            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));
            }

            for (int i = 0; i < treeData.Groups.Count; i++)
            {
                BehaviorGroupDesigner group = treeData.Groups[i];
                if (group == null)
                {
                    continue;
                }
                data.Groups.Add(CreateBehaviorGroupData(group));
            }

            return(data);
        }
Exemple #16
0
        /// <summary>
        /// 判断分组是否存在
        /// </summary>
        /// <param name="groupName">分组名称</param>
        /// <returns>true:存在</returns>
        public bool ExistBehaviorGroup(string groupName)
        {
            if (string.IsNullOrEmpty(groupName))
            {
                throw new ArgumentException("BehaviorTreeDataDesigner.ExistBehaviorGroup() error: groupName = null");
            }

            for (int i = 0; i < m_Groups.Count; i++)
            {
                BehaviorGroupDesigner behaviorGroup = m_Groups[i];
                if (behaviorGroup == null)
                {
                    continue;
                }
                if (behaviorGroup.GroupName == groupName)
                {
                    return(true);
                }
            }

            return(false);
        }
 public string GetGroupTreeNodeName(BehaviorGroupDesigner behaviorGroup)
 {
     return(string.IsNullOrEmpty(behaviorGroup.Describe) ? behaviorGroup.GroupName : string.Format("{0} ({1})", behaviorGroup.GroupName, behaviorGroup.Describe));
 }