예제 #1
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);
        }
예제 #2
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);
        }
예제 #3
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);
        }
예제 #4
0
        private DebugNode CreateDebugNode(AgentDesigner agent, NodeDesigner node)
        {
            DebugNode debugNode = null;

            //组合节点
            if (node.NodeType == NodeType.Composite)
            {
                //顺序节点
                if (node.ClassType == "Sequence")
                {
                    Debug__Sequence debug__Sequence = new Debug__Sequence();
                    debugNode = debug__Sequence;
                }
                //并行节点
                else if (node.ClassType == "Parallel")
                {
                    EnumFieldDesigner successPolicy = node.Fields[0].Field as EnumFieldDesigner;
                    EnumFieldDesigner failedPolicy  = node.Fields[0].Field as EnumFieldDesigner;

                    Debug__Parallel debug__Parallel = new Debug__Parallel();
                    debug__Parallel.SuccessPolicy = (Debug__Parallel.SUCCESS_POLICY)successPolicy.ValueInt;
                    debug__Parallel.FailurePolicy = (Debug__Parallel.FAILURE_POLICY)failedPolicy.ValueInt;

                    debugNode = debug__Parallel;
                }
                //随机节点
                else if (node.ClassType == "Random")
                {
                    Debug__Random debug__Random = new Debug__Random();
                    debugNode = debug__Random;
                }
                //随机序列
                else if (node.ClassType == "RandomSequence")
                {
                    Debug__RandomSequence__Node debug__RandomSequence__Node = new Debug__RandomSequence__Node();
                    debugNode = debug__RandomSequence__Node;
                }
                //随机选择节点
                else if (node.ClassType == "RandomSelector")
                {
                    Debug__RandomSelector debug__RandomSelector = new Debug__RandomSelector();
                    debugNode = debug__RandomSelector;
                }
                //ifelse节点
                else if (node.ClassType == "IfElse")
                {
                    Debug__IfElse debug__IfElse = new Debug__IfElse();
                    debugNode = debug__IfElse;
                }
                //选择节点
                else if (node.ClassType == "Selector")
                {
                    Debug__Selector debug__Selector = new Debug__Selector();
                    debugNode = debug__Selector;
                }
                //概率选择
                else if (node.ClassType == "RateSelector")
                {
                    Debug__RateSelector debug__RateSelector = new Debug__RateSelector();
                    debugNode = debug__RateSelector;
                }
                else
                {
                    //统一用默认的组合节点,(顺序节点)
                    Debug__Composite debug__Composite = new Debug__Composite();
                    debugNode = debug__Composite;
                }
            }
            //装饰节点
            else if (node.NodeType == NodeType.Decorator)
            {
                //失败节点
                if (node.ClassType == "Failure")
                {
                    Debug__Failure debug__Failure = new Debug__Failure();
                    debugNode = debug__Failure;
                }
                //成功节点
                else if (node.ClassType == "Success")
                {
                    Debug__Success debug__Success = new Debug__Success();
                    debugNode = debug__Success;
                }
                //执行帧节点
                else if (node.ClassType == "Frames")
                {
                    Debug__Frames debug__Frames = new Debug__Frames();
                    debugNode = debug__Frames;
                }
                //输出log节点
                else if (node.ClassType == "Log")
                {
                    Debug__Log debug__Log = new Debug__Log();
                    debugNode = debug__Log;
                }
                //循环节点
                else if (node.ClassType == "Loop")
                {
                    Debug__Loop debug__Loop = new Debug__Loop();
                    debugNode = debug__Loop;
                }
                //取反节点
                else if (node.ClassType == "Not")
                {
                    Debug__Not debug__Not = new Debug__Not();
                    debugNode = debug__Not;
                }
                //指定时间内运行
                else if (node.ClassType == "Time")
                {
                    Debug__Time debug__Time = new Debug__Time();
                    debugNode = debug__Time;
                }
                //等待直到子节点返回成功
                else if (node.ClassType == "WaitUntil")
                {
                    Debug__WaitUntil debug__WaitUntil = new Debug__WaitUntil();
                    debugNode = debug__WaitUntil;
                }
                else
                {
                    Debug__Decorator debug__Decorator = new Debug__Decorator();
                    debug__Decorator.CanChangeStatus = true;
                    debugNode = debug__Decorator;
                }
            }
            //条件节点
            else if (node.NodeType == NodeType.Condition)
            {
                Debug__Condition debug__Condition = new Debug__Condition();
                debug__Condition.CanChangeStatus = true;
                debugNode = debug__Condition;
            }
            //动作节点
            else if (node.NodeType == NodeType.Action)
            {
                //等待一段时间
                if (node.ClassType == "Wait")
                {
                    Debug__Wait debug__Wait = new Debug__Wait();
                    debugNode = debug__Wait;
                }
                //赋值节点Int
                else if (node.ClassType == "AssignmentInt")
                {
                    Debug__AssignmentInt debug__AssignmentInt = new Debug__AssignmentInt();
                    debugNode = debug__AssignmentInt;
                }
                //赋值节点Float
                else if (node.ClassType == "AssignmentFloat")
                {
                    Debug__AssignmentFloat debug__AssignmentFloat = new Debug__AssignmentFloat();
                    debugNode = debug__AssignmentFloat;
                }
                //赋值节点String
                else if (node.ClassType == "AssignmentString")
                {
                    Debug__AssignmentString debug__AssignmentString = new Debug__AssignmentString();
                    debugNode = debug__AssignmentString;
                }
                //空操作节点
                else if (node.ClassType == "Noop")
                {
                    Debug_Noop debug_Noop = new Debug_Noop();
                    debugNode = debug_Noop;
                }
                else
                {
                    Debug__Action debug__Action = new Debug__Action();
                    debugNode = debug__Action;
                    debugNode.CanChangeStatus = true;
                }
            }

            debugNode.Node = node;
            m_Nodes.Add(debugNode);

            for (int i = 0; i < node.Transitions.Count; i++)
            {
                Transition   transition     = node.Transitions[i];
                NodeDesigner childNode      = agent.FindByID(transition.ToNodeID);
                DebugNode    childDebugNode = CreateDebugNode(agent, childNode);
                childDebugNode.ParentNode = debugNode;
                debugNode.Childs.Add(childDebugNode);
            }

            return(debugNode);
        }
        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            m_EnumStr = null;
            if (context.Instance is EnumDefaultValue)
            {
                EnumDefaultValue enumDeaultValue = context.Instance as EnumDefaultValue;
                if (enumDeaultValue != null)
                {
                    m_EnumStr = enumDeaultValue.DefaultValue;
                    if (string.IsNullOrEmpty(enumDeaultValue.EnumType))
                    {
                        MainForm.Instance.ShowMessage("请先选择枚举类型");
                    }
                    else
                    {
                        m_CustomEnum = MainForm.Instance.NodeTemplate.FindEnum(enumDeaultValue.EnumType);
                        if (m_CustomEnum == null)
                        {
                            MainForm.Instance.ShowMessage(string.Format("不存在枚举类型:{0},请先注册", enumDeaultValue.EnumType));
                        }
                    }
                }
            }
            else if (context.Instance is EnumFieldDesigner)
            {
                EnumFieldDesigner enumFieldDesigner = context.Instance as EnumFieldDesigner;
                if (enumFieldDesigner != null)
                {
                    m_EnumStr = enumFieldDesigner.Value;
                    if (string.IsNullOrEmpty(enumFieldDesigner.EnumType))
                    {
                        MainForm.Instance.ShowMessage("请先选择枚举类型");
                    }
                    else
                    {
                        m_CustomEnum = MainForm.Instance.NodeTemplate.FindEnum(enumFieldDesigner.EnumType);
                        if (m_CustomEnum == null)
                        {
                            MainForm.Instance.ShowMessage(string.Format("不存在枚举类型:{0},请先注册", enumFieldDesigner.EnumType));
                        }
                    }
                }
            }

            if (m_CustomEnum != null)
            {
                //绑定
                m_EnumItemList.Clear();
                if (m_CustomEnum.Enums.Count > 0)
                {
                    int selectedIndex = 0;

                    for (int i = 0; i < m_CustomEnum.Enums.Count; i++)
                    {
                        EnumItem enumItem = m_CustomEnum.Enums[i];
                        m_EnumItemList.Add(enumItem.EnumStr);
                        if (m_EnumStr == enumItem.EnumStr)
                        {
                            selectedIndex = i;
                        }
                    }
                }

                return(new StandardValuesCollection(m_EnumItemList));
            }

            return(base.GetStandardValues(context));
        }