Esempio n. 1
0
        private void CreateAction(Skill.Editor.AI.ActionData action)
        {
            // create action variable
            Add(new Variable("Skill.Framework.AI.Action", action.Name, "null"));
            // new action inside CreateTree method
            _CreateTreeMethodBody.AppendLine(string.Format("this.{0} = new Skill.Framework.AI.Action(\"{1}\", {2}, Skill.Framework.Posture.{3});", Variable.GetName(action.Name), action.Name, GetActionHandlerName(action.Name), action.ChangePosture));
            // set weight
            SetBehaviorParameters(action);


            Method m = new Method("Skill.Framework.AI.BehaviorResult", GetActionHandlerName(action.Name), string.Empty, ActionHandlerParams)
            {
                IsPartial = _Tree.ExpandMethods
            };

            if (_Tree.ExpandMethods)
            {
                m.Body = CreateMethodBody(action, "return Skill.Framework.AI.BehaviorResult.Failure;");
            }
            else
            {
                m.Body = string.Format("return OnAction( Actions.{0} , sender ,  parameters);", action.Name);
            }
            Add(m);

            // create reset event handler and assign it to Reset event
            if (action.ResetEvent)
            {
                string resetName   = action.Name + "_Reset";
                Method resetMethod = new Method("void", resetName,
                                                _Tree.ExpandMethods ? "" : string.Format("return OnActionReset( Actions.{0} );", action.Name),
                                                ActionResetEventHandlerParams)
                {
                    IsPartial = _Tree.ExpandMethods
                };
                Add(resetMethod);
                _CreateTreeMethodBody.AppendLine(string.Format("this.{0}.Reset += new ActionResetEventHandler({1});", Variable.GetName(action.Name)
                                                               , resetName));
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Detect Behavior data from Given XmlElement  and load it
        /// </summary>
        /// <param name="behavior">XmlElement contains Behavior data</param>
        /// <returns>Loaded Behavior</returns>
        public static BehaviorData CreateBehaviorFrom(XmlElement behavior)
        {
            BehaviorData result = null;

            Skill.Framework.AI.BehaviorType behaviorType = Skill.Framework.AI.BehaviorType.Action;
            bool isCorrect = false;

            try
            {
                behaviorType = behavior.GetAttributeValueAsEnum <Skill.Framework.AI.BehaviorType>("BehaviorType", Skill.Framework.AI.BehaviorType.Condition);
                isCorrect    = true;
            }
            catch (Exception)
            {
                isCorrect = false;
            }
            if (isCorrect)
            {
                switch (behaviorType)
                {
                case Skill.Framework.AI.BehaviorType.Action:
                    result = new ActionData();
                    break;

                case Skill.Framework.AI.BehaviorType.Condition:
                    result = new ConditionData();
                    break;

                case Skill.Framework.AI.BehaviorType.Decorator:
                    Skill.Framework.AI.DecoratorType decoratorType = behavior.GetAttributeValueAsEnum <Skill.Framework.AI.DecoratorType>("DecoratorType", Skill.Framework.AI.DecoratorType.Default);
                    switch (decoratorType)
                    {
                    case Skill.Framework.AI.DecoratorType.Default:
                        result = new DecoratorData();
                        break;

                    case Skill.Framework.AI.DecoratorType.AccessLimit:
                        result = new AccessLimitDecoratorData();
                        break;

                    default:
                        break;
                    }

                    break;

                case Skill.Framework.AI.BehaviorType.Composite:
                    Skill.Framework.AI.CompositeType selectorType = behavior.GetAttributeValueAsEnum <Skill.Framework.AI.CompositeType>("CompositeType", Skill.Framework.AI.CompositeType.Sequence);
                    switch (selectorType)
                    {
                    case Skill.Framework.AI.CompositeType.Sequence:
                        result = new SequenceSelectorData();
                        break;

                    case Skill.Framework.AI.CompositeType.Concurrent:
                        result = new ConcurrentSelectorData();
                        break;

                    case Skill.Framework.AI.CompositeType.Random:
                        result = new RandomSelectorData();
                        break;

                    case Skill.Framework.AI.CompositeType.Priority:
                        result = new PrioritySelectorData();
                        break;

                    case Skill.Framework.AI.CompositeType.Loop:
                        result = new LoopSelectorData();
                        break;

                    case Skill.Framework.AI.CompositeType.State:
                        result = new BehaviorTreeStateData();
                        break;
                    }
                    break;

                case Skill.Framework.AI.BehaviorType.ChangeState:
                    result = new ChangeStateData();
                    break;
                }
            }
            return(result);
        }
Esempio n. 3
0
        void AddMenuItem_Click(object sender, System.EventArgs e)
        {
            if (_TreeView.SelectedItem == null)
            {
                return;
            }
            if (!(_TreeView.SelectedItem is TreeViewFolder))
            {
                return;
            }


            Skill.Editor.UI.MenuItem item     = (Skill.Editor.UI.MenuItem)sender;
            BehaviorData             behavior = null;

            if (string.IsNullOrEmpty(item.Tag))
            {
                Skill.Framework.AI.BehaviorType type = (Framework.AI.BehaviorType)item.UserData;
                switch (type)
                {
                case Skill.Framework.AI.BehaviorType.Action:
                    behavior = new ActionData()
                    {
                        Name = _Editor.GetUniqueName("NewAction")
                    };
                    break;

                case Skill.Framework.AI.BehaviorType.Condition:
                    behavior = new ConditionData()
                    {
                        Name = _Editor.GetUniqueName("NewCondition")
                    };
                    break;

                default:
                    behavior = null;
                    break;
                }
            }
            else if (item.Tag == "Decorator")
            {
                Skill.Framework.AI.DecoratorType type = (Framework.AI.DecoratorType)item.UserData;
                switch (type)
                {
                case Skill.Framework.AI.DecoratorType.Default:
                    behavior = new DecoratorData()
                    {
                        Name = _Editor.GetUniqueName("NewDecorator")
                    };
                    break;

                case Skill.Framework.AI.DecoratorType.AccessLimit:
                    behavior = new AccessLimitDecoratorData()
                    {
                        Name = _Editor.GetUniqueName("NewAccessDecorator")
                    };
                    break;

                default:
                    behavior = null;
                    break;
                }
            }
            else if (item.Tag == "Composite")
            {
                Skill.Framework.AI.CompositeType type = (Framework.AI.CompositeType)item.UserData;
                switch (type)
                {
                case Skill.Framework.AI.CompositeType.Sequence:
                    behavior = new SequenceSelectorData()
                    {
                        Name = _Editor.GetUniqueName("NewSequence")
                    };
                    break;

                case Skill.Framework.AI.CompositeType.Concurrent:
                    behavior = new ConcurrentSelectorData()
                    {
                        Name = _Editor.GetUniqueName("NewConcurrent")
                    };
                    break;

                case Skill.Framework.AI.CompositeType.Random:
                    behavior = new RandomSelectorData()
                    {
                        Name = _Editor.GetUniqueName("NewRandom")
                    };
                    break;

                case Skill.Framework.AI.CompositeType.Priority:
                    behavior = new PrioritySelectorData()
                    {
                        Name = _Editor.GetUniqueName("NewPriority")
                    };
                    break;

                case Skill.Framework.AI.CompositeType.Loop:
                    behavior = new LoopSelectorData()
                    {
                        Name = _Editor.GetUniqueName("NewLoop")
                    };
                    break;

                default:
                    behavior = null;
                    break;
                }
            }

            if (behavior != null)
            {
                TreeViewFolder tvf = (TreeViewFolder)_TreeView.SelectedItem;
                tvf.Foldout.IsOpen = true;
                tvf.AddBehavior(behavior);
                _Editor.AddToList(behavior);
                _Editor.RefreshTree();
                SelectItem(tvf, behavior);
            }
        }
Esempio n. 4
0
 public ActionItem(ActionData data)
     : base(data)
 {
 }