コード例 #1
0
        public static BTData.BehaviorTreeElement CreateBehaviorTreeData(BehaviorTreeDesigner behaviorTree)
        {
            BTData.BehaviorTreeElement data = new BTData.BehaviorTreeElement();
            data.ID = behaviorTree.ID;

            //行为树变量
            for (int i = 0; i < behaviorTree.BehaviorTreeVariableFields.Count; i++)
            {
                VariableFieldDesigner field = behaviorTree.BehaviorTreeVariableFields[i];
                if (field == null)
                {
                    continue;
                }
                data.BehaviorTreeVariables.Add(CreateVariableField(field));
            }

            for (int i = 0; i < behaviorTree.Fields.Count; i++)
            {
                FieldDesigner field = behaviorTree.Fields[i];
                if (field == null)
                {
                    continue;
                }
                data.Fields.Add(CreateField(field));
            }

            NodeDesigner startNode = behaviorTree.GetStartNode();

            if (startNode != null)
            {
                data.StartNode = CreateNode(behaviorTree, startNode);
            }

            return(data);
        }
コード例 #2
0
        private void PasteField()
        {
            try
            {
                FieldListContent content = XmlUtility.StringToObject <FieldListContent>(Clipboard.GetText());

                for (int i = 0; i < content.DataList.Count; i++)
                {
                    FieldDesigner field     = content.DataList[i];
                    string        fieldName = field.FieldName;
                    while (m_EditBehaviorTree.ExistFieldName(fieldName))
                    {
                        fieldName += "_New";
                    }

                    field.FieldName = fieldName;
                    m_EditBehaviorTree.AddField(field);
                }
                Exec("Refresh_Field");
                MainForm.Instance.ShowInfo("您粘贴了" + content.DataList.Count + "个字段!!!");
            }
            catch (Exception ex)
            {
                MainForm.Instance.ShowInfo("无法进行粘贴,错误信息:" + ex.Message);
                MainForm.Instance.ShowMessage("无法进行粘贴,错误信息:" + ex.Message, "警告");
            }
        }
コード例 #3
0
        public static BTData.NodeData CreateNode(BehaviorTreeDesigner behaviorTree, NodeDesigner nodeData)
        {
            BTData.NodeData data = new BTData.NodeData();
            data.ID        = nodeData.ID;
            data.ClassType = nodeData.ClassType;
            data.Label     = nodeData.Label;
            data.X         = (int)nodeData.Rect.x;
            data.Y         = (int)nodeData.Rect.y;

            for (int i = 0; i < nodeData.Fields.Count; i++)
            {
                FieldDesigner field = nodeData.Fields[i];
                if (field == null)
                {
                    continue;
                }
                data.Fields.Add(CreateField(field));
            }

            if (nodeData.Transitions.Count > 0)
            {
                data.Childs = new List <BTData.NodeData>(nodeData.Transitions.Count);
                for (int i = 0; i < nodeData.Transitions.Count; i++)
                {
                    Transition      transition    = nodeData.Transitions[i];
                    NodeDesigner    childNode     = behaviorTree.FindByID(transition.ToNodeID);
                    BTData.NodeData childNodeData = CreateNode(behaviorTree, childNode);
                    data.Childs.Add(childNodeData);
                }
            }

            return(data);
        }
コード例 #4
0
        /// <summary>
        /// 添加字段
        /// </summary>
        /// <param name="field"></param>
        /// <returns></returns>
        public bool AddField(FieldDesigner field)
        {
            FieldDesigner tempField = FindFieldByName(field.FieldName);

            if (tempField == null)
            {
                m_Fields.Add(field);
                return(true);
            }
            return(false);
        }
コード例 #5
0
 /// <summary>
 /// 判断字段名是否已存在
 /// </summary>
 /// <param name="fieldName"></param>
 /// <returns></returns>
 public bool ExistFieldName(string fieldName)
 {
     for (int i = 0; i < m_Fields.Count; i++)
     {
         FieldDesigner temp = m_Fields[i];
         if (temp.FieldName == fieldName)
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #6
0
        private void SwapField(bool up)
        {
            if (listView1.SelectedIndices.Count > 1)
            {
                MainForm.Instance.ShowInfo("请选择一条记录进行交换");
                MainForm.Instance.ShowMessage("请选择一条记录进行交换", "警告");
                return;
            }

            int selectIdx = listView1.SelectedIndices[0];

            if (up)
            {
                //第一个不能往上交换
                if (selectIdx == 0)
                {
                    return;
                }

                int preIdx = selectIdx - 1;

                FieldDesigner preField      = m_EditBehaviorTree.Fields[preIdx];
                FieldDesigner selectedField = m_EditBehaviorTree.Fields[selectIdx];

                m_EditBehaviorTree.Fields[preIdx]    = selectedField;
                m_EditBehaviorTree.Fields[selectIdx] = preField;

                selectIdx = preIdx;
            }
            else
            {
                //最后一个不能往下交换
                if (selectIdx == listView1.Items.Count - 1)
                {
                    return;
                }

                int nextIdx = selectIdx + 1;

                FieldDesigner preField      = m_EditBehaviorTree.Fields[nextIdx];
                FieldDesigner selectedField = m_EditBehaviorTree.Fields[selectIdx];

                m_EditBehaviorTree.Fields[nextIdx]   = selectedField;
                m_EditBehaviorTree.Fields[selectIdx] = preField;

                selectIdx = nextIdx;
            }

            Exec("Refresh_Field");
            MainForm.Instance.ShowInfo("交换成功 时间:" + DateTime.Now);
            listView1.Items[selectIdx].Selected = true;
        }
コード例 #7
0
        /// <summary>
        /// 校验字段是否存在空名字
        /// </summary>
        /// <returns></returns>
        public VerifyInfo VerifyEmptyFieldName()
        {
            //检测是否有空字段
            for (int i = 0; i < m_Fields.Count; i++)
            {
                FieldDesigner field = m_Fields[i];
                if (string.IsNullOrEmpty(field.FieldName))
                {
                    return(new VerifyInfo(string.Format("行为树[{0}]\n存在空字段名", m_TreeID)));
                }
            }

            return(VerifyInfo.DefaultVerifyInfo);
        }
コード例 #8
0
        public override string ToString()
        {
            string content = string.Empty;

            for (int i = 0; i < m_Fields.Count; i++)
            {
                FieldDesigner field = m_Fields[i];
                if (field.Field != null)
                {
                    content += field.Field + (i != m_Fields.Count - 1 ? "," : string.Empty);
                }
            }
            return(content);
        }
コード例 #9
0
        public string ShowContent()
        {
            if (NodeDefine == null)
            {
                NodeDefine = MainForm.Instance.NodeTemplate.FindNode(ClassType);
            }

            if (NodeDefine == null)
            {
                throw new Exception(ClassType + "的" + nameof(NodeDefine) + "为空");
            }

            string content = string.Empty;

            int showCount = 0;

            for (int i = 0; i < m_Fields.Count; i++)
            {
                FieldDesigner field     = m_Fields[i];
                NodeField     nodeField = NodeDefine.Fields[i];
                if (nodeField.Show && field.Field != null)
                {
                    if (showCount == 0)
                    {
                        content += "[";
                    }
                    else
                    {
                        content += ",";
                    }

                    showCount++;
                    content += field.Field;
                }
            }

            if (showCount > 0)
            {
                content += "]";
            }
            else
            {
                content = Describe;
            }

            return(content);
        }
コード例 #10
0
 private void EditField()
 {
     if (listView1.SelectedItems.Count == 1)
     {
         FieldDesigner        field = listView1.SelectedItems[0].Tag as FieldDesigner;
         InputValueDialogForm dlg   = new InputValueDialogForm("编辑字段", listView1.SelectedItems[0].Tag);
         if (dlg.ShowDialog() == DialogResult.OK)
         {
             Exec("Refresh_Field");
             ListViewItem listViewItem = GetListViewItem(listView1, field);
             if (listViewItem != null)
             {
                 listViewItem.Selected = true;
             }
         }
     }
 }
コード例 #11
0
 /// <summary>
 /// 校验是否存在相同字段名字
 /// </summary>
 /// <returns></returns>
 public VerifyInfo VerifySameFieldName()
 {
     //检测字段是否重复
     for (int i = 0; i < m_Fields.Count; i++)
     {
         FieldDesigner field_i = m_Fields[i];
         for (int ii = i + 1; ii < m_Fields.Count; ii++)
         {
             FieldDesigner field_ii = m_Fields[ii];
             if (field_i.FieldName == field_ii.FieldName)
             {
                 return(new VerifyInfo(string.Format("行为树[{0}]\n存在重复字段:{1}", m_TreeID, field_ii.FieldName)));
             }
         }
     }
     return(VerifyInfo.DefaultVerifyInfo);
 }
コード例 #12
0
        /// <summary>
        /// 通过字段名查找字段
        /// </summary>
        /// <param name="fieldName">字段名字</param>
        /// <returns></returns>
        public FieldDesigner FindFieldByName(string fieldName)
        {
            if (string.IsNullOrEmpty(fieldName))
            {
                return(null);
            }

            for (int i = 0; i < m_Fields.Count; i++)
            {
                FieldDesigner field = m_Fields[i];
                if (field.FieldName == fieldName)
                {
                    return(field);
                }
            }

            return(null);
        }
コード例 #13
0
        /// <summary>
        /// 获取字段索引
        /// </summary>
        /// <param name="fieldName">字段名字</param>
        /// <returns></returns>
        public int GetFieldIndex(string fieldName)
        {
            if (string.IsNullOrEmpty(fieldName))
            {
                return(-1);
            }

            for (int i = 0; i < m_Fields.Count; i++)
            {
                FieldDesigner field = m_Fields[i];
                if (field.FieldName == fieldName)
                {
                    return(i);
                }
            }

            return(-1);
        }
コード例 #14
0
        private void NewField()
        {
            FieldDesigner        field = new FieldDesigner();
            InputValueDialogForm form  = new InputValueDialogForm("添加字段", field);

            if (form.ShowDialog() == DialogResult.OK)
            {
                if (m_EditBehaviorTree.AddField(field))
                {
                    Exec("Refresh_Field");
                    ListViewItem listViewItem = GetListViewItem(listView1, field);
                    if (listViewItem != null)
                    {
                        listViewItem.Selected = true;
                    }
                }
            }
        }
コード例 #15
0
 private void BindField()
 {
     listView1.Items.Clear();
     for (int i = 0; i < m_EditBehaviorTree.Fields.Count; i++)
     {
         FieldDesigner field        = m_EditBehaviorTree.Fields[i];
         ListViewItem  listViewItem = listView1.Items.Add(field.FieldName);
         listViewItem.Tag = field;
         listViewItem.SubItems.Add(EditorUtility.GetFieldTypeName(field.FieldType));
         string content = string.Empty;
         if (field.Field != null)
         {
             content += field.Field;
         }
         listViewItem.SubItems.Add(content);
         listViewItem.SubItems.Add(field.Describe);
     }
 }
コード例 #16
0
 public FieldDesigner this[string fieldName]
 {
     get
     {
         for (int i = 0; i < Fields.Count; i++)
         {
             FieldDesigner field = Fields[i];
             if (field == null)
             {
                 continue;
             }
             if (field.FieldName == fieldName)
             {
                 return(field);
             }
         }
         return(null);
     }
 }
コード例 #17
0
        private void BindAgent()
        {
            textBox1.Text = m_EditAgent.AgentID;
            textBox2.Text = m_EditAgent.Describe;

            listView1.Items.Clear();
            for (int i = 0; i < m_EditAgent.Fields.Count; i++)
            {
                FieldDesigner field        = m_EditAgent.Fields[i];
                ListViewItem  listViewItem = listView1.Items.Add(field.FieldName);
                listViewItem.Tag = field;
                listViewItem.SubItems.Add(EditorUtility.GetFieldTypeName(field.FieldType));
                string content = string.Empty;
                if (field.Field != null)
                {
                    content += field.Field;
                }
                listViewItem.SubItems.Add(content);
                listViewItem.SubItems.Add(field.Describe);
            }
        }
コード例 #18
0
        public static BehaviorTreeData.AgentData CreateAgentData(AgentDesigner agentData)
        {
            BehaviorTreeData.AgentData data = new BehaviorTreeData.AgentData();
            data.ID = agentData.AgentID;

            for (int i = 0; i < agentData.Fields.Count; i++)
            {
                FieldDesigner field = agentData.Fields[i];
                if (field == null)
                {
                    continue;
                }
                data.Fields.Add(CreateField(field));
            }

            NodeDesigner startNode = agentData.GetStartNode();

            if (startNode != null)
            {
                data.StartNode = CreateNode(agentData, startNode);
            }

            return(data);
        }
コード例 #19
0
        /// <summary>
        /// 是否存在无效枚举类型
        /// </summary>
        /// <returns></returns>
        public VerifyInfo VerifyEnum()
        {
            //校验枚举类型
            //检测字段是否重复
            for (int i = 0; i < m_Fields.Count; i++)
            {
                FieldDesigner field = m_Fields[i];
                if (field.FieldType == FieldType.EnumField)
                {
                    EnumFieldDesigner enumFieldDesigner = field.Field as EnumFieldDesigner;
                    if (enumFieldDesigner != null)
                    {
                        if (string.IsNullOrEmpty(enumFieldDesigner.EnumType))
                        {
                            return(new VerifyInfo(string.Format("行为树[{0}]的字段[{1}]的枚举类型为空", m_TreeID, field.FieldName)));
                        }

                        CustomEnum customEnum = MainForm.Instance.NodeTemplate.FindEnum(enumFieldDesigner.EnumType);
                        if (customEnum == null)
                        {
                            return(new VerifyInfo(string.Format("行为树[{0}]的字段[{1}]的枚举类型[{2}]不存在", m_TreeID, field.FieldName, enumFieldDesigner.EnumType)));
                        }
                        else
                        {
                            EnumItem enumItem = customEnum.FindEnum(enumFieldDesigner.Value);
                            if (enumItem == null)
                            {
                                return(new VerifyInfo(string.Format("行为树[{0}]的字段[{1}]的枚举类型[{2}]\n不存在选项[{3}]", m_TreeID, field.FieldName, customEnum.EnumType, enumFieldDesigner.Value)));
                            }
                        }
                    }
                }
            }

            return(VerifyInfo.DefaultVerifyInfo);
        }
コード例 #20
0
        public bool AddField(FieldDesigner field)
        {
            if (field == null)
            {
                return(false);
            }

            if (field.FieldType == FieldType.None)
            {
                MainForm.Instance.ShowInfo("字段类型为None,添加失败!!!");
                MainForm.Instance.ShowMessage("字段类型为None,添加失败!!!", "警告");
                return(false);
            }

            if (string.IsNullOrEmpty(field.FieldName))
            {
                MainForm.Instance.ShowInfo("字段名为空,添加失败!!!");
                MainForm.Instance.ShowMessage("字段名为空,添加失败!!!", "警告");
                return(false);
            }

            for (int i = 0; i < m_Fields.Count; i++)
            {
                FieldDesigner temp = m_Fields[i];
                if (temp.FieldName == field.FieldName)
                {
                    MainForm.Instance.ShowInfo(string.Format("字段名字{0}相同,添加失败!!!", temp.FieldName));
                    MainForm.Instance.ShowMessage(string.Format("字段名字{0}相同,添加失败!!!", temp.FieldName), "警告");
                    return(false);
                }
            }

            m_Fields.Add(field);

            return(true);
        }
コード例 #21
0
        public static BTData.BaseField CreateField(FieldDesigner fieldData)
        {
            BTData.BaseField data = null;

            switch (fieldData.FieldType)
            {
            case FieldType.IntField:
                BTData.IntField  intField         = new BTData.IntField();
                IntFieldDesigner intFieldDesigner = fieldData.Field as IntFieldDesigner;
                intField.FieldName = fieldData.FieldName;
                intField.Value     = intFieldDesigner.Value;
                data = intField;
                break;

            case FieldType.LongField:
                BTData.LongField  longField         = new BTData.LongField();
                LongFieldDesigner longFieldDesigner = fieldData.Field as LongFieldDesigner;
                longField.FieldName = fieldData.FieldName;
                longField.Value     = longFieldDesigner.Value;
                data = longField;
                break;

            case FieldType.FloatField:
                BTData.FloatField  floatField         = new BTData.FloatField();
                FloatFieldDesigner floatFieldDesigner = fieldData.Field as FloatFieldDesigner;
                floatField.FieldName = fieldData.FieldName;
                floatField.Value     = floatFieldDesigner.Value;
                data = floatField;
                break;

            case FieldType.DoubleField:
                BTData.DoubleField  doubleField         = new BTData.DoubleField();
                DoubleFieldDesigner doubleFieldDesigner = fieldData.Field as DoubleFieldDesigner;
                doubleField.FieldName = fieldData.FieldName;
                doubleField.Value     = doubleFieldDesigner.Value;
                data = doubleField;
                break;

            case FieldType.StringField:
                BTData.StringField  stringField         = new BTData.StringField();
                StringFieldDesigner stringFieldDesigner = fieldData.Field as StringFieldDesigner;
                stringField.FieldName = fieldData.FieldName;
                stringField.Value     = stringFieldDesigner.Value;
                data = stringField;
                break;

            case FieldType.ColorField:
                BTData.ColorField  colorField         = new BTData.ColorField();
                ColorFieldDesigner colorFieldDesigner = fieldData.Field as ColorFieldDesigner;
                colorField.FieldName = fieldData.FieldName;
                colorField.Value    |= colorFieldDesigner.R << 24;
                colorField.Value    |= colorFieldDesigner.G << 16;
                colorField.Value    |= colorFieldDesigner.B << 8;
                colorField.Value    |= colorFieldDesigner.A;
                data = colorField;
                break;

            case FieldType.Vector2:
                BTData.Vector2Field  vector2Field         = new BTData.Vector2Field();
                Vector2FieldDesigner vector2FieldDesigner = fieldData.Field as Vector2FieldDesigner;
                vector2Field.FieldName = fieldData.FieldName;
                vector2Field.X         = vector2FieldDesigner.X;
                vector2Field.Y         = vector2FieldDesigner.Y;
                data = vector2Field;
                break;

            case FieldType.Vector3:
                BTData.Vector3Field  vector3Field         = new BTData.Vector3Field();
                Vector3FieldDesigner vector3FieldDesigner = fieldData.Field as Vector3FieldDesigner;
                vector3Field.FieldName = fieldData.FieldName;
                vector3Field.X         = vector3FieldDesigner.X;
                vector3Field.Y         = vector3FieldDesigner.Y;
                vector3Field.Z         = vector3FieldDesigner.Z;
                data = vector3Field;
                break;

            case FieldType.EnumField:
                BTData.EnumField  enumField         = new BTData.EnumField();
                EnumFieldDesigner enumFieldDesigner = fieldData.Field as EnumFieldDesigner;
                enumField.FieldName = fieldData.FieldName;
                enumField.Value     = enumFieldDesigner.ValueInt;
                data = enumField;
                break;

            case FieldType.BooleanField:
                BTData.BooleanField  booleanField         = new BTData.BooleanField();
                BooleanFieldDesigner booleanFieldDesigner = fieldData.Field as BooleanFieldDesigner;
                booleanField.FieldName = fieldData.FieldName;
                booleanField.Value     = booleanFieldDesigner.Value;
                data = booleanField;
                break;

            case FieldType.RepeatIntField:
                BTData.RepeatIntField  repeatIntField         = new BTData.RepeatIntField();
                RepeatIntFieldDesigner repeatIntFieldDesigner = fieldData.Field as RepeatIntFieldDesigner;
                repeatIntField.FieldName = fieldData.FieldName;
                if (repeatIntFieldDesigner.Value.Count > 0)
                {
                    repeatIntField.Value = new List <int>();
                    for (int i = 0; i < repeatIntFieldDesigner.Value.Count; i++)
                    {
                        repeatIntField.Value.Add(repeatIntFieldDesigner.Value[i]);
                    }
                }
                data = repeatIntField;
                break;

            case FieldType.RepeatLongField:
                BTData.RepeatLongField  repeatLongField         = new BTData.RepeatLongField();
                RepeatLongFieldDesigner repeatLongFieldDesigner = fieldData.Field as RepeatLongFieldDesigner;
                repeatLongField.FieldName = fieldData.FieldName;
                if (repeatLongFieldDesigner.Value.Count > 0)
                {
                    repeatLongField.Value = new List <long>();
                    for (int i = 0; i < repeatLongFieldDesigner.Value.Count; i++)
                    {
                        repeatLongField.Value.Add(repeatLongFieldDesigner.Value[i]);
                    }
                }

                data = repeatLongField;
                break;

            case FieldType.RepeatFloatField:
                BTData.RepeatFloatField  repeatFloatField         = new BTData.RepeatFloatField();
                RepeatFloatFieldDesigner repeatFloatFieldDesigner = fieldData.Field as RepeatFloatFieldDesigner;
                repeatFloatField.FieldName = fieldData.FieldName;
                if (repeatFloatFieldDesigner.Value.Count > 0)
                {
                    repeatFloatField.Value = new List <float>();
                    for (int i = 0; i < repeatFloatFieldDesigner.Value.Count; i++)
                    {
                        repeatFloatField.Value.Add(repeatFloatFieldDesigner.Value[i]);
                    }
                }
                data = repeatFloatField;
                break;

            case FieldType.RepeatVector2Field:
                BTData.RepeatVector2Field  repeatVector2Field         = new BTData.RepeatVector2Field();
                RepeatVector2FieldDesigner repeatVector2FieldDesigner = fieldData.Field as RepeatVector2FieldDesigner;
                repeatVector2Field.FieldName = fieldData.FieldName;
                if (repeatVector2FieldDesigner.Value.Count > 0)
                {
                    for (int i = 0; i < repeatVector2FieldDesigner.Value.Count; i++)
                    {
                        Vector2        vector2 = repeatVector2FieldDesigner.Value[i];
                        BTData.Vector2 temp    = new BTData.Vector2();
                        temp.X = vector2.X;
                        temp.Y = vector2.Y;
                        repeatVector2Field.Value.Add(temp);
                    }
                }
                data = repeatVector2Field;
                break;

            case FieldType.RepeatVector3Field:
                BTData.RepeatVector3Field  repeatVector3Field         = new BTData.RepeatVector3Field();
                RepeatVector3FieldDesigner repeatVector3FieldDesigner = fieldData.Field as RepeatVector3FieldDesigner;
                repeatVector3Field.FieldName = fieldData.FieldName;
                for (int i = 0; i < repeatVector3FieldDesigner.Value.Count; i++)
                {
                    Vector3        vector3 = repeatVector3FieldDesigner.Value[i];
                    BTData.Vector3 temp    = new BTData.Vector3();
                    temp.X = vector3.X;
                    temp.Y = vector3.Y;
                    temp.Z = vector3.Z;
                    repeatVector3Field.Value.Add(temp);
                }
                data = repeatVector3Field;
                break;

            case FieldType.RepeatStringField:
                BTData.RepeatStringField  repeatStringField         = new BTData.RepeatStringField();
                RepeatStringFieldDesigner repeatStringFieldDesigner = fieldData.Field as RepeatStringFieldDesigner;
                repeatStringField.FieldName = fieldData.FieldName;
                if (repeatStringFieldDesigner.Value.Count > 0)
                {
                    repeatStringField.Value = new List <string>();
                    for (int i = 0; i < repeatStringFieldDesigner.Value.Count; i++)
                    {
                        repeatStringField.Value.Add(repeatStringFieldDesigner.Value[i]);
                    }
                }
                data = repeatStringField;
                break;
            }

            return(data);
        }
コード例 #22
0
        /// <summary>
        /// 通过节点模板创建FieldDesigner
        /// </summary>
        /// <param name="nodeField">节点模板</param>
        /// <returns></returns>
        public static FieldDesigner CreateFieldByNodeField(NodeField nodeField)
        {
            FieldDesigner field = new FieldDesigner();

            field.FieldName = nodeField.FieldName;
            field.Label     = nodeField.Label;
            field.FieldType = nodeField.FieldType;
            field.Describe  = nodeField.Describe;
            switch (nodeField.FieldType)
            {
            case FieldType.IntField:
                IntFieldDesigner intFieldDesigner = field.Field as IntFieldDesigner;
                IntDefaultValue  intDefaultValue  = nodeField.DefaultValue as IntDefaultValue;
                intFieldDesigner.Value = intDefaultValue.DefaultValue;
                break;

            case FieldType.LongField:
                LongFieldDesigner longFieldDesigner = field.Field as LongFieldDesigner;
                LongDefaultValue  longDefaultValue  = nodeField.DefaultValue as LongDefaultValue;
                longFieldDesigner.Value = longDefaultValue.DefaultValue;
                break;

            case FieldType.FloatField:
                FloatFieldDesigner floatFieldDesigner = field.Field as FloatFieldDesigner;
                FloatDefaultValue  floatDefaultValue  = nodeField.DefaultValue as FloatDefaultValue;
                floatFieldDesigner.Value = floatDefaultValue.DefaultValue;
                break;

            case FieldType.DoubleField:
                DoubleFieldDesigner doubleFieldDesigner = field.Field as DoubleFieldDesigner;
                DoubleDefaultValue  doubleDefaultValue  = nodeField.DefaultValue as DoubleDefaultValue;
                doubleFieldDesigner.Value = doubleDefaultValue.DefaultValue;
                break;

            case FieldType.StringField:
                StringFieldDesigner stringFieldDesigner = field.Field as StringFieldDesigner;
                StringDefaultValue  stringDefaultValue  = nodeField.DefaultValue as StringDefaultValue;
                stringFieldDesigner.Value = stringDefaultValue.DefaultValue;
                break;

            case FieldType.ColorField:
                ColorFieldDesigner colorFieldDesigner = field.Field as ColorFieldDesigner;
                ColorDefaultValue  colorDefaultValue  = nodeField.DefaultValue as ColorDefaultValue;
                colorFieldDesigner.R = colorDefaultValue.R;
                colorFieldDesigner.G = colorDefaultValue.G;
                colorFieldDesigner.B = colorDefaultValue.B;
                colorFieldDesigner.A = colorDefaultValue.A;
                break;

            case FieldType.Vector2:
                Vector2FieldDesigner vector2FieldDesigner = field.Field as Vector2FieldDesigner;
                Vector2DefaultValue  vector2DefaultValue  = nodeField.DefaultValue as Vector2DefaultValue;
                vector2FieldDesigner.X = vector2DefaultValue.X;
                vector2FieldDesigner.Y = vector2DefaultValue.Y;
                break;

            case FieldType.Vector3:
                Vector3FieldDesigner vector3FieldDesigner = field.Field as Vector3FieldDesigner;
                Vector3DefaultValue  vector3DefaultValue  = nodeField.DefaultValue as Vector3DefaultValue;
                vector3FieldDesigner.X = vector3DefaultValue.X;
                vector3FieldDesigner.Y = vector3DefaultValue.Y;
                vector3FieldDesigner.Z = vector3DefaultValue.Z;
                break;

            case FieldType.EnumField:
                EnumFieldDesigner enumFieldDesigner = field.Field as EnumFieldDesigner;
                EnumDefaultValue  enumDefaultValue  = nodeField.DefaultValue as EnumDefaultValue;
                enumFieldDesigner.EnumType = enumDefaultValue.EnumType;
                enumFieldDesigner.Value    = enumDefaultValue.DefaultValue;
                break;

            case FieldType.BooleanField:
                BooleanFieldDesigner booleanFieldDesigner = field.Field as BooleanFieldDesigner;
                BooleanDefaultValue  booleanDefaultValue  = nodeField.DefaultValue as BooleanDefaultValue;
                booleanFieldDesigner.Value = booleanDefaultValue.DefaultValue;
                break;

            case FieldType.RepeatIntField:
                break;

            case FieldType.RepeatLongField:
                break;

            case FieldType.RepeatFloatField:
                break;

            case FieldType.RepeatVector2Field:
                break;

            case FieldType.RepeatVector3Field:
                break;

            case FieldType.RepeatStringField:
                break;
            }
            return(field);
        }
コード例 #23
0
        /// <summary>
        /// 添加Agent
        /// </summary>
        private void AddAgent()
        {
            if (WorkSpaceData == null)
            {
                ShowMessage("当前没有工作空间,请新建或者打开工作空间!");
                return;
            }

            if (TreeData == null)
            {
                return;
            }

            string group = string.Empty;

            if (treeView1.SelectedNode != null)
            {
                if (treeView1.SelectedNode.Tag is GroupItem)
                {
                    GroupItem groupItem = treeView1.SelectedNode.Tag as GroupItem;
                    group = groupItem.Group.GroupName;
                }
                else if (treeView1.SelectedNode.Tag is AgentItem)
                {
                    AgentItem agentItem = treeView1.SelectedNode.Tag as AgentItem;
                    if (agentItem.GroupItem != null)
                    {
                        group = agentItem.GroupItem.Group.GroupName;
                    }
                }
            }

            AgentDesigner agent = new AgentDesigner();

            agent.GroupName = group;
            string agentID = "NewAgent_" + DateTime.Now.Ticks;

            do
            {
                agentID = "NewAgent_" + DateTime.Now.Ticks;
            } while (TreeData.ExistAgent(agentID));

            agent.AgentID = agentID;

            //创建开始节点
            NodeDesigner startNode = null;
            NodeClass    nodeClass = NodeClasses.FindNode("Sequence");

            if (nodeClass != null)
            {
                Rect rect = new Rect(EditorUtility.Center.x, EditorUtility.Center.y, EditorUtility.NodeWidth,
                                     EditorUtility.NodeHeight);
                startNode           = new NodeDesigner(nodeClass.Label, nodeClass.ClassType, rect);
                startNode.ID        = agent.GenNodeID();
                startNode.StartNode = true;
                startNode.NodeType  = nodeClass.NodeType;
                startNode.Describe  = nodeClass.Describe;

                //创建字段
                for (int i = 0; i < nodeClass.Fields.Count; i++)
                {
                    NodeField     nodeField = nodeClass.Fields[i];
                    FieldDesigner field     = EditorUtility.CreateFieldByNodeField(nodeField);
                    if (field == null)
                    {
                        continue;
                    }
                    startNode.Fields.Add(field);
                }

                agent.AddNode(startNode);
            }

            //创建空操作节点
            NodeClass noopClass = NodeClasses.FindNode("Noop");

            if (startNode != null && noopClass != null)
            {
                Rect rect = new Rect(EditorUtility.Center.x + 250, EditorUtility.Center.y, EditorUtility.NodeWidth,
                                     EditorUtility.NodeHeight);
                NodeDesigner noopNode = new NodeDesigner(noopClass.Label, noopClass.ClassType, rect);
                noopNode.ID       = agent.GenNodeID();
                noopNode.NodeType = noopClass.NodeType;
                noopNode.Describe = noopClass.Describe;
                agent.AddNode(noopNode);

                startNode.AddChildNode(noopNode);
            }

            TreeViewManager.AddAgent(agent);
        }
コード例 #24
0
        /// <summary>
        /// 修正数据
        /// </summary>
        public bool AjustData()
        {
            bool ajust = false;

            for (int i = 0; i < m_Nodes.Count; i++)
            {
                NodeDesigner node       = m_Nodes[i];
                NodeDefine   nodeDefine = MainForm.Instance.NodeTemplate.FindNode(node.ClassType);

                //修正节点标签
                if (node.Label != nodeDefine.Label)
                {
                    node.Label = nodeDefine.Label;
                    ajust      = true;
                }

                //移除模板中没有的字段
                for (int ii = node.Fields.Count - 1; ii >= 0; ii--)
                {
                    FieldDesigner field = node.Fields[ii];
                    if (!nodeDefine.ExistFieldName(field.FieldName))
                    {
                        ajust = true;
                        node.Fields.RemoveAt(ii);
                    }
                }

                //修正类型不匹配的(节点字段和模板字段类型不匹配)
                for (int ii = 0; ii < node.Fields.Count; ii++)
                {
                    FieldDesigner field     = node.Fields[ii];
                    NodeField     nodeField = nodeDefine.FindField(field.FieldName);
                    if (field.FieldType != nodeField.FieldType)
                    {
                        //重新给默认值
                        node.Fields[ii] = EditorUtility.CreateFieldByNodeField(nodeField);
                        ajust           = true;
                    }
                }

                //添加不存的字段
                for (int ii = nodeDefine.Fields.Count - 1; ii >= 0; ii--)
                {
                    NodeField     nodeField = nodeDefine.Fields[ii];
                    FieldDesigner field     = node.FindFieldByName(nodeField.FieldName);
                    //不存在的字段要添加
                    if (field == null)
                    {
                        FieldDesigner newField = EditorUtility.CreateFieldByNodeField(nodeField);
                        node.AddField(newField);
                        ajust = true;
                    }
                }

                //排序字段(要和模板中一致)
                for (int ii = 0; ii < nodeDefine.Fields.Count; ii++)
                {
                    NodeField nodeField = nodeDefine.Fields[ii];
                    int       index     = node.GetFieldIndex(nodeField.FieldName);
                    if (index != ii)
                    {
                        //交换
                        FieldDesigner tempField_ii = node.Fields[ii];
                        node.Fields[ii]    = node.Fields[index];
                        node.Fields[index] = tempField_ii;
                        ajust = true;
                    }
                }

                //修正Label
                for (int ii = 0; ii < node.Fields.Count; ii++)
                {
                    FieldDesigner field     = node.Fields[ii];
                    NodeField     nodeField = nodeDefine.Fields[ii];
                    if (field.Label != nodeField.Label)
                    {
                        field.Label = nodeField.Label;
                        ajust       = true;
                    }
                }
            }

            return(ajust);
        }
コード例 #25
0
        /// <summary>
        /// 添加行为树
        /// </summary>
        private void AddBehaviorTree()
        {
            if (WorkSpaceData == null)
            {
                ShowMessage("当前没有工作空间,请新建或者打开工作空间!");
                return;
            }

            if (BehaviorTreeData == null)
            {
                return;
            }

            string group = string.Empty;

            if (treeView1.SelectedNode != null)
            {
                if (treeView1.SelectedNode.Tag is GroupItem)
                {
                    GroupItem groupItem = treeView1.SelectedNode.Tag as GroupItem;
                    group = groupItem.Group.GroupName;
                }
                else if (treeView1.SelectedNode.Tag is BehaviorTreeItem)
                {
                    BehaviorTreeItem behaviorTreeItem = treeView1.SelectedNode.Tag as BehaviorTreeItem;
                    if (behaviorTreeItem.GroupItem != null)
                    {
                        group = behaviorTreeItem.GroupItem.Group.GroupName;
                    }
                }
            }

            BehaviorTreeDesigner behaviorTree = new BehaviorTreeDesigner();

            behaviorTree.GroupName = group;
            string behaviorTreeID = "New_" + DateTime.Now.Ticks;

            do
            {
                behaviorTreeID = "New_" + DateTime.Now.Ticks;
            } while (BehaviorTreeData.ExistBehaviorTree(behaviorTreeID));

            behaviorTree.ID = behaviorTreeID;

            //创建开始节点
            NodeDesigner startNode  = null;
            NodeDefine   nodeDefine = NodeTemplate.FindNode("Sequence");

            if (nodeDefine != null)
            {
                Rect rect = new Rect(EditorUtility.Center.x, EditorUtility.Center.y, EditorUtility.NodeWidth,
                                     EditorUtility.NodeHeight);
                startNode           = new NodeDesigner(nodeDefine.Label, nodeDefine.ClassType, rect);
                startNode.ID        = behaviorTree.GenNodeID();
                startNode.StartNode = true;
                startNode.NodeType  = nodeDefine.NodeType;

                //创建字段
                for (int i = 0; i < nodeDefine.Fields.Count; i++)
                {
                    NodeField     nodeField = nodeDefine.Fields[i];
                    FieldDesigner field     = EditorUtility.CreateFieldByNodeField(nodeField);
                    if (field == null)
                    {
                        continue;
                    }
                    startNode.Fields.Add(field);
                }

                behaviorTree.AddNode(startNode);
            }

            //创建空操作节点
            NodeDefine noopDefine = NodeTemplate.FindNode("Noop");

            if (startNode != null && noopDefine != null)
            {
                Rect rect = new Rect(EditorUtility.Center.x + 250, EditorUtility.Center.y, EditorUtility.NodeWidth,
                                     EditorUtility.NodeHeight);
                NodeDesigner noopNode = new NodeDesigner(noopDefine.Label, noopDefine.ClassType, rect);
                noopNode.ID       = behaviorTree.GenNodeID();
                noopNode.NodeType = noopDefine.NodeType;
                noopNode.Describe = noopDefine.Describe;
                behaviorTree.AddNode(noopNode);

                startNode.AddChildNode(noopNode);
            }

            TreeViewManager.AddBehaviorTree(behaviorTree);
        }