private void EditField()
        {
            if (listView1.SelectedItems.Count != 1)
            {
                return;
            }

            ListViewItem  listViewItem = listView1.SelectedItems[0];
            FieldDesigner field        = listViewItem.Tag as FieldDesigner;

            if (field == null)
            {
                return;
            }

            if (field.Field == null)
            {
                return;
            }

            InputValueDialogForm dlg = new InputValueDialogForm("编辑", field.Field);

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                BindFields();
                ListViewItem selectedItem = GetListViewItem(field);
                if (selectedItem != null)
                {
                    selectedItem.Selected = true;
                }
            }
        }
        private void CBB_RightParameter_SelectedIndexChanged(object sender, EventArgs e)
        {
            string              value = CBB_RightParameter.Text.Trim();
            FieldDesigner       rightRightParameter      = m_Node.FindFieldByName("RightParameter");
            StringFieldDesigner rightStringFieldDesigner = rightRightParameter.Field as StringFieldDesigner;

            rightStringFieldDesigner.Value = value;
        }
        private void BindNode()
        {
            m_BindState = false;

            CBB_LeftParameterType.Items.Clear();
            CBB_RightParameterType.Items.Clear();

            CBB_RightParameter.Items.Clear();
            CBB_CompareType.Items.Clear();

            CustomEnum variableCustomEnum = MainForm.Instance.NodeTemplate.FindEnum("VariableType");

            for (int i = 0; i < variableCustomEnum.Enums.Count; i++)
            {
                EnumItem enumItem = variableCustomEnum.Enums[i];
                CBB_LeftParameterType.Items.Add(enumItem.EnumStr);
                CBB_RightParameterType.Items.Add(enumItem.EnumStr);
            }

            //绑定左边参数类型
            FieldDesigner     leftFieldDesigner     = m_Node.FindFieldByName("LeftType");
            EnumFieldDesigner leftEnumFieldDesigner = leftFieldDesigner.Field as EnumFieldDesigner;

            CBB_LeftParameterType.SelectedIndex = leftEnumFieldDesigner.ValueIndex;

            //绑定右边参数类型
            FieldDesigner     rightFieldDesigner     = m_Node.FindFieldByName("RightType");
            EnumFieldDesigner rightEnumFieldDesigner = rightFieldDesigner.Field as EnumFieldDesigner;

            CBB_RightParameterType.SelectedIndex = rightEnumFieldDesigner.ValueIndex;

            //绑定左边参数名
            BindLeftParameter(leftEnumFieldDesigner.Value);

            //绑定右边参数
            BindRightParameter(rightEnumFieldDesigner.Value);

            //绑定比较类型
            CustomEnum compareCustomEnum = MainForm.Instance.NodeTemplate.FindEnum("CompareType");

            for (int i = 0; i < compareCustomEnum.Enums.Count; i++)
            {
                EnumItem enumItem = compareCustomEnum.Enums[i];
                CBB_CompareType.Items.Add(enumItem.EnumStr);
            }
            FieldDesigner     compareTypeFieldDesigner = m_Node.FindFieldByName("CompareType");
            EnumFieldDesigner compareEnumFieldDesigner = compareTypeFieldDesigner.Field as EnumFieldDesigner;

            CBB_CompareType.SelectedIndex = compareEnumFieldDesigner.ValueIndex;

            m_BindState = true;
        }
        private void CBB_CompareType_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (!m_BindState)
            {
                return;
            }

            CustomEnum compareCustomEnum = MainForm.Instance.NodeTemplate.FindEnum("CompareType");
            EnumItem   enumItem          = compareCustomEnum.FindEnum(CBB_CompareType.Text.Trim());

            FieldDesigner     compareFieldDesigner     = m_Node.FindFieldByName("CompareType");
            EnumFieldDesigner compareEnumFieldDesigner = compareFieldDesigner.Field as EnumFieldDesigner;

            compareEnumFieldDesigner.Value = enumItem.EnumStr;
        }
        //绑定右边参数名
        private void BindRightParameter(string varType)
        {
            CBB_RightParameter.Items.Clear();

            if (varType == "GlobalVar")
            {
                var variable = MainForm.Instance.BehaviorTreeData.GlobalVariable;
                for (int i = 0; i < variable.VariableFields.Count; i++)
                {
                    VariableFieldDesigner variableFieldDesigner = variable.VariableFields[i];
                    CBB_RightParameter.Items.Add(variableFieldDesigner.VariableFieldName);
                }
            }
            else if (varType == "BehaviorTreeVar")
            {
                BehaviorTreeDesigner behaviorTreeDesigner = MainForm.Instance.SelectedBehaviorTree;
                var variable = behaviorTreeDesigner.BehaviorTreeVariableFields;
                if (variable != null)
                {
                    for (int i = 0; i < variable.Count; i++)
                    {
                        VariableFieldDesigner variableFieldDesigner = variable[i];
                        CBB_RightParameter.Items.Add(variableFieldDesigner.VariableFieldName);
                    }
                }
            }
            else if (varType == "ContextVar")
            {
                var variable = MainForm.Instance.BehaviorTreeData.ContextVariable;
                for (int i = 0; i < variable.VariableFields.Count; i++)
                {
                    VariableFieldDesigner variableFieldDesigner = variable.VariableFields[i];
                    CBB_RightParameter.Items.Add(variableFieldDesigner.VariableFieldName);
                }
            }
            else if (varType == "Const")
            {
                //todo
            }

            FieldDesigner       rightRightParameter      = m_Node.FindFieldByName("RightParameter");
            StringFieldDesigner rightStringFieldDesigner = rightRightParameter.Field as StringFieldDesigner;

            CBB_RightParameter.Text = rightStringFieldDesigner.Value;
        }
        private void CBB_ParameterType_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (!m_BindState)
            {
                return;
            }

            //置空变量名
            FieldDesigner       parameterName = m_Node.FindFieldByName("ParameterName");
            StringFieldDesigner parameterNameStringFieldDesigner = parameterName.Field as StringFieldDesigner;

            parameterNameStringFieldDesigner.Value = null;

            FieldDesigner     parameterType = m_Node.FindFieldByName("ParameterType");
            EnumFieldDesigner parameterTypeEnumFieldDesigner = parameterType.Field as EnumFieldDesigner;

            BindParameter(parameterTypeEnumFieldDesigner.GetEnumItemByIndex(CBB_ParameterType.SelectedIndex).EnumStr);
        }
        private void BindNode()
        {
            m_BindState = false;

            //绑定参数类型
            FieldDesigner     parameterType = m_Node.FindFieldByName("ParameterType");
            EnumFieldDesigner parameterTypeEnumFieldDesigner = parameterType.Field as EnumFieldDesigner;

            CBB_ParameterType.SelectedIndex = parameterTypeEnumFieldDesigner.ValueIndex;

            //绑定参数名
            BindParameter(parameterTypeEnumFieldDesigner.GetEnumItemByIndex(CBB_ParameterType.SelectedIndex).EnumStr);

            //绑定参数值
            BindParameterValue();

            m_BindState = true;
        }
        private void CheckError()
        {
            //现在找到参数类型(作用域)
            FieldDesigner     parameterType = m_Node.FindFieldByName("ParameterType");
            EnumFieldDesigner parameterTypeEnumFieldDesigner = parameterType.Field as EnumFieldDesigner;
            string            varType = parameterTypeEnumFieldDesigner.GetEnumItemByIndex(CBB_ParameterType.SelectedIndex).EnumStr;

            //找到参数名
            FieldDesigner       parameterName = m_Node.FindFieldByName("ParameterName");
            StringFieldDesigner parameterNameStringFieldDesigner = parameterName.Field as StringFieldDesigner;

            CBB_ParameterName.Text = parameterNameStringFieldDesigner.Value;

            if (string.IsNullOrEmpty(parameterNameStringFieldDesigner.Value))
            {
                errorProvider1.SetError(CBB_ParameterName, "请选择参数名称");
                return;
            }
        }
        private void BindFields()
        {
            listView1.Items.Clear();

            if (m_Node == null)
            {
                return;
            }

            for (int i = 0; i < m_Node.Fields.Count; i++)
            {
                FieldDesigner field        = m_Node.Fields[i];
                ListViewItem  listViewItem = listView1.Items.Add(field.Title);
                listViewItem.Tag = field;
                listViewItem.SubItems.Add(EditorUtility.GetFieldTypeName(field.FieldType));
                string content = field.Field != null?field.Field.ToString() : string.Empty;

                listViewItem.SubItems.Add(content);
                listViewItem.SubItems.Add(field.Describe);
            }
        }
        private void BindParameterValue()
        {
            //绑定参数值
            FieldDesigner     parameterValue = m_Node.FindFieldByName("ParameterValue");
            BaseFieldDesigner parameterValueBaseFieldDesigner = parameterValue.Field;

            string value = null;

            if (parameterValueBaseFieldDesigner is IntFieldDesigner)
            {
                value = (parameterValueBaseFieldDesigner as IntFieldDesigner).Value.ToString();
            }
            else if (parameterValueBaseFieldDesigner is LongFieldDesigner)
            {
                value = (parameterValueBaseFieldDesigner as LongFieldDesigner).Value.ToString();
            }
            else if (parameterValueBaseFieldDesigner is FloatFieldDesigner)
            {
                value = (parameterValueBaseFieldDesigner as FloatFieldDesigner).Value.ToString();
            }
            else if (parameterValueBaseFieldDesigner is DoubleFieldDesigner)
            {
                value = (parameterValueBaseFieldDesigner as DoubleFieldDesigner).Value.ToString();
            }
            else if (parameterValueBaseFieldDesigner is StringFieldDesigner)
            {
                value = (parameterValueBaseFieldDesigner as StringFieldDesigner).Value;
            }
            else if (parameterValueBaseFieldDesigner is BooleanFieldDesigner)
            {
                value = (parameterValueBaseFieldDesigner as BooleanFieldDesigner).Value.ToString();
            }
            else
            {
                //todo...
            }

            TB_ParameterValue.Text = value;
        }
Beispiel #11
0
        private void OnClickNodeItem(object sender, EventArgs e)
        {
            ToolStripDropDownItem toolStripDropDownItem = (ToolStripDropDownItem)sender;

            if (toolStripDropDownItem == null)
            {
                return;
            }

            NodeClass nodeClass = (NodeClass)toolStripDropDownItem.Tag;

            if (nodeClass == null)
            {
                return;
            }

            Rect         rect = new Rect(m_MouseWorldPoint.x, m_MouseWorldPoint.y, EditorUtility.NodeWidth, EditorUtility.NodeHeight);
            NodeDesigner node = new NodeDesigner(nodeClass.Label, nodeClass.ClassType, rect);

            node.ID        = Agent.GenNodeID();
            node.Label     = nodeClass.Label;
            node.NodeType  = nodeClass.NodeType;
            node.ClassType = nodeClass.ClassType;
            node.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;
                }
                node.Fields.Add(field);
            }

            Agent.AddNode(node);
        }
        //改变左边参数类型
        private void CBB_LeftParameterType_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (!m_BindState)
            {
                return;
            }

            FieldDesigner     leftFieldDesigner     = m_Node.FindFieldByName("LeftType");
            EnumFieldDesigner leftEnumFieldDesigner = leftFieldDesigner.Field as EnumFieldDesigner;

            CustomEnum leftNodeType = MainForm.Instance.NodeTemplate.FindEnum("VariableType");
            EnumItem   enumItem     = leftNodeType.FindEnum(CBB_LeftParameterType.Text.Trim());

            leftEnumFieldDesigner.Value = enumItem.EnumStr;

            //重置参数名
            FieldDesigner       leftLeftParameter       = m_Node.FindFieldByName("LeftParameter");
            StringFieldDesigner leftStringFieldDesigner = leftLeftParameter.Field as StringFieldDesigner;

            leftStringFieldDesigner.Value = null;

            BindLeftParameter(leftEnumFieldDesigner.Value);
        }