Ejemplo n.º 1
0
        private void CheckMenuAvailable()
        {
            IBehaviorItem selected = null;

            if (_TreeView.SelectedItem != null)
            {
                selected = _TreeView.SelectedItem as IBehaviorItem;
            }

            bool canDelete   = true;
            bool canNew      = false;
            bool canMoveUp   = false;
            bool canMoveDown = false;

            if (selected != null)
            {
                if (selected.Data.BehaviorType == Framework.AI.BehaviorType.Composite)
                {
                    CompositeData composite = (CompositeData)selected.Data;
                    if (composite.CompositeType == Framework.AI.CompositeType.State)
                    {
                        canDelete = false;
                    }

                    canNew = true;
                }
                else if (selected.Data.BehaviorType == Framework.AI.BehaviorType.Decorator)
                {
                    DecoratorData decorator = (DecoratorData)selected.Data;
                    canNew = decorator.Count == 0;
                }
                else
                {
                    canNew = false;
                }

                canMoveUp   = selected.CanMoveUp;
                canMoveDown = selected.CanMoveDown;
            }
            else
            {
                canDelete   = false;
                canNew      = false;
                canMoveUp   = false;
                canMoveDown = false;
            }

            _BtnMoveUp.IsEnabled         = canMoveUp;
            _BtnMoveDown.IsEnabled       = canMoveDown;
            _BtnRemoveBehavior.IsEnabled = canDelete;
            //_BtnCopyBehavior.IsEnabled = canDelete;
            _AddBehaviorMenuItem.IsEnabled    = canNew;
            _InsertBehaviorMenuItem.IsEnabled = canNew;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Create view model based on CompositeType
        /// </summary>
        /// <param name="behavior">selector data</param>
        /// <returns>Create view model</returns>
        static CompositeItem CreateCompositeItem(CompositeData composite)
        {
            switch (composite.CompositeType)
            {
            case Skill.Framework.AI.CompositeType.Sequence:
                return(new SequenceSelectorItem((SequenceSelectorData)composite));

            case Skill.Framework.AI.CompositeType.Concurrent:
                return(new ConcurrentSelectorItem((ConcurrentSelectorData)composite));

            case Skill.Framework.AI.CompositeType.Random:
                return(new RandomSelectorItem((RandomSelectorData)composite));

            case Skill.Framework.AI.CompositeType.Priority:
                return(new PrioritySelectorItem((PrioritySelectorData)composite));

            case Skill.Framework.AI.CompositeType.Loop:
                return(new LoopSelectorItem((LoopSelectorData)composite));

            default:
                throw new System.InvalidCastException("Invalid CompositeType");
            }
        }
Ejemplo n.º 3
0
        private static void SearchForBehaviorWarnings()
        {
            foreach (var b in _Behaviors)
            {
                if (b.BehaviorType == Framework.AI.BehaviorType.Composite)
                {
                    CompositeData composite = (CompositeData)b;
                    if (composite.Count == 0)
                    {
                        Debug.LogError(string.Format("Composite node {0} has not any children.", composite.Name));
                        _ErrorFound = true;
                    }
                    if (composite.CompositeType == Framework.AI.CompositeType.Priority || composite.CompositeType == Framework.AI.CompositeType.Concurrent || composite.CompositeType == Framework.AI.CompositeType.State) // check if a Decorator with NeverFaile property is child of PrioritySelector or ConcurrentSelector
                    {
                        foreach (var child in composite)
                        {
                            if (child != null && child.BehaviorType == Framework.AI.BehaviorType.Decorator)
                            {
                                if (((DecoratorData)child).NeverFail)
                                {
                                    if (composite.CompositeType == Framework.AI.CompositeType.Priority || composite.CompositeType == Framework.AI.CompositeType.State)
                                    {
                                        Debug.LogWarning(string.Format("Decorator '{0}' with 'NeverFail' property setted to 'true' is child of PrioritySelector '{1}'. This cause next children unreachable.", child.Name, b.Name));
                                    }
                                    else if (composite.CompositeType == Framework.AI.CompositeType.Concurrent)
                                    {
                                        if (((ConcurrentSelectorData)composite).SuccessPolicy == Framework.AI.SuccessPolicy.SucceedOnOne)
                                        {
                                            Debug.LogWarning(string.Format("Decorator '{0}' with 'NeverFail' property setted to 'true' is child of ConcurrentSelector '{1}' width 'SuccessPolicy' property setted to 'SucceedOnOne' . This cause ConcurrentSelector never fail.", child.Name, b.Name));
                                        }
                                    }
                                }
                            }
                        }
                    }

                    if (composite.CompositeType != Framework.AI.CompositeType.Random)
                    {
                        foreach (var child in composite)
                        {
                            if (child != null && child.BehaviorType == Framework.AI.BehaviorType.ChangeState)
                            {
                                int index = composite.IndexOf(child);
                                if (index < composite.Count - 1)
                                {
                                    Debug.LogWarning(string.Format("There are unreachable behaviors in Composite '{0}', after ChangeState '{1}'", composite.Name, child.Name));
                                }
                            }
                        }
                    }
                }
                else if (b.BehaviorType == Framework.AI.BehaviorType.Decorator)
                {
                    DecoratorData decorator = (DecoratorData)b;
                    if (decorator.Type == Framework.AI.DecoratorType.AccessLimit)
                    {
                        AccessLimitDecoratorData al = (AccessLimitDecoratorData)decorator;

                        if (decorator.Child.BehaviorType == Framework.AI.BehaviorType.ChangeState && al.KeyType == Framework.AI.AccessKeyType.CounterLimit)
                        {
                            Debug.LogWarning(string.Format("AccessLimitDecorator '{0} with CounterLimit accesskey' has a ChangeState child '{1}'. CounterLimit key will be unlocked after change state.", decorator.Name, decorator.Child.Name));
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
 public CompositeItem(CompositeData data)
     : base(data)
 {
 }