Пример #1
0
        private void CreateBlendByIndex(AnimNodeBlendByIndexData node)
        {
            // create action variable
            CreateProperty("Skill.Framework.Animation.AnimNodeBlendByIndex", node);

            // new action inside CreateTree method
            _CreateTreeMethodBody.AppendLine(string.Format("this.{0} = new Skill.Framework.Animation.AnimNodeBlendByIndex({1});", Variable.GetName(node.Name), node.Inputs.Length));

            if (node.NodeType != AnimNodeType.Sequence && node.BlendTime != 0.3f) // default is 0.3f
            {
                SetProperty(node, "BlendTime", node.BlendTime.ToString() + "f");
            }

            if (!string.IsNullOrEmpty(node.Enum))
            {
                EnumClass enumClass = new EnumClass(node.Enum)
                {
                    Modifier = Modifiers.Public
                };
                for (int i = 0; i < node.Inputs.Length; i++)
                {
                    enumClass.Add(node.Inputs[i].Name, i);
                }
                this.Add(enumClass);
            }
            // set parameters
            SetSharedParameters(node);
        }
Пример #2
0
        /// <summary>
        /// Create a BehaviorTreeClass
        /// </summary>
        /// <param name="tree">BehaviorTree model</param>
        public BehaviorTreeClass(BehaviorTreeData tree)
            : base(tree.Name)
        {
            this._Tree                 = tree;
            this._Behaviors            = new List <BehaviorData>();
            this._CreateTreeMethodBody = new StringBuilder();
            CreateBehaviorList();
            ProcessNodes();
            AddInherit("Skill.Framework.AI.BehaviorTree");

            // states class
            BehaviorTreeStateNamesClass states = new BehaviorTreeStateNamesClass(tree);

            Add(states);

            if (!_Tree.ExpandMethods)
            {
                ClassModifier = ClassModifiers.Abstract;

                EnumClass actions = new EnumClass("Actions")
                {
                    Modifier = Modifiers.Protected
                };
                EnumClass conditions = new EnumClass("Conditions")
                {
                    Modifier = Modifiers.Protected
                };
                EnumClass decorators = new EnumClass("Decorators")
                {
                    Modifier = Modifiers.Protected
                };

                foreach (var b in _Behaviors)
                {
                    switch (b.BehaviorType)
                    {
                    case BehaviorType.Action:
                        actions.Add(b.Name);
                        break;

                    case BehaviorType.Condition:
                        conditions.Add(b.Name);
                        break;

                    case BehaviorType.Decorator:
                        decorators.Add(b.Name);
                        break;
                    }
                }

                if (actions.Count > 0)
                {
                    Add(actions);
                    Add(new Method("Skill.Framework.AI.BehaviorResult", "OnAction", "", "Actions action", "object sender", "Skill.Framework.AI.BehaviorParameterCollection parameters")
                    {
                        SubMethod = SubMethod.Abstract, Modifier = Modifiers.Protected
                    });
                    Add(new Method("void", "OnActionReset", "", "Actions action")
                    {
                        SubMethod = SubMethod.Abstract, Modifier = Modifiers.Protected
                    });
                }
                if (conditions.Count > 0)
                {
                    Add(conditions);
                    Add(new Method("bool", "OnCondition", "", "Conditions condition", "object sender", "Skill.Framework.AI.BehaviorParameterCollection parameters")
                    {
                        SubMethod = SubMethod.Abstract, Modifier = Modifiers.Protected
                    });
                }
                if (decorators.Count > 0)
                {
                    Add(decorators);
                    Add(new Method("bool", "OnDecorator", "", "Decorators decorator", "object sender", "Skill.Framework.AI.BehaviorParameterCollection parameters")
                    {
                        SubMethod = SubMethod.Abstract, Modifier = Modifiers.Protected
                    });
                }

                IsPartial = false;
            }

            // add DefaultState property

            Property defaultState = new Property("string", "DefaultState", string.Format("\"{0}\"", _Tree.DefaultState), false)
            {
                Modifier = Modifiers.Public, SubMethod = SubMethod.Override
            };

            Add(defaultState);

            //Method constructor = new Method("", Name, "", "");
            //constructor.Modifier = Modifiers.Public;
            //Add(constructor);

            Method createTree = new Method("Skill.Framework.AI.BehaviorTreeState[]", "CreateTree", this._CreateTreeMethodBody.ToString());

            createTree.IsPartial = false;
            createTree.SubMethod = SubMethod.Override;
            createTree.Modifier  = Modifiers.Protected;
            Add(createTree);
        }