Exemplo n.º 1
0
 public DecoratorTickUntilSuccess(BehaviorTree.Composite child) : base(child)
 {
 }
Exemplo n.º 2
0
 public DecoratorTick(BehaviorTree.Composite child) : base(child)
 {
 }
Exemplo n.º 3
0
 public DecoratorNegation(BehaviorTree.Composite child) : base(child)
 {
 }
Exemplo n.º 4
0
        public static BehaviorTree.Composite ParserComposite(TreeNode tree, BehaviorTree.Composite parent)
        {
            Composite current = null;


            //Debug.Log(string.Format("NODE:{0} TYPE:{1}",tree.Name,tree.GetType()));

            #region decoratorNode
            if (tree is DecoratorNode)
            {
                var child = ParserComposite(tree.Children[0], null);
                current = new Decorator(child);
            }

            if (tree is DecoratorNegationNode)
            {
                var child = ParserComposite(tree.Children[0], null);
                current = new DecoratorNegation(child);
            }

            if (tree is DecoratorRunUnitlFailureNode)
            {
                var child = ParserComposite(tree.Children[0], null);
                current = new DecoratorRunUnitlFailure(child);
            }

            if (tree is DecoratorRunUntilSuccessNode)
            {
                var child = ParserComposite(tree.Children[0], null);
                current = new DecoratorRunUntilSuccess(child);
            }

            if (tree is DecoratorTickNode)
            {
                var child = ParserComposite(tree.Children[0], null);
                current = new DecoratorTick(child)
                {
                    TickTime = (tree as DecoratorTickNode).TickTime
                };
            }

            if (tree is DecoratorTickUntilSuccessNode)
            {
                var child = ParserComposite(tree.Children[0], null);
                current = new DecoratorTickUntilSuccess(child)
                {
                    TickTime = (tree as DecoratorTickUntilSuccessNode).TickTime / 1000f
                };
            }

            if (tree is WaitForSecondsNode)
            {
                current = new BWaitForSeconds()
                {
                    Seconds = (tree as WaitForSecondsNode).Milseconds / 1000f
                };
            }
            #endregion

            #region Liner
            if (tree is LinerNode)
            {
                List <Composite> childs = new List <Composite>();
                foreach (var i in tree.Children)
                {
                    childs.Add(ParserComposite(i, null));
                }

                if (tree is ParallelPrioritySelectorNode)
                {
                    current = new ParallelPrioritySelector(childs.ToArray());
                }
                else if (tree is ParallelSequenceNode)
                {
                    current = new ParallelSequence(childs.ToArray());
                }
                else if (tree is SequenceNode)
                {
                    current = new Sequence(childs.ToArray());
                }
                else if (tree is PrioritySelectorNode)
                {
                    current = new PrioritySelector(childs.ToArray());
                }
            }
            #endregion

            #region ProbabilitySelectorNode
            if (tree is ProbabilitySelectorNode)
            {
                List <ProbabilitySelection> randomChilds = new List <ProbabilitySelection>();
                foreach (var i in tree.Children)
                {
                    var item = i as ProbabilitySelectorItemNode;
                    if (item == null)
                    {
                        throw new Exception("ProbabilitySelectorNode's child is not ProbabilitySelectorItemNode");
                    }
                    var pChild = ParserComposite(item.Children[0], null);
                    randomChilds.Add(new ProbabilitySelection(pChild, (int)item.Probability));
                }
                current = new ProbabilitySelector(randomChilds.ToArray());
            }
            if (tree is ProbabilitySelectorItemNode)
            {
                throw new Exception("ProbabilitySelectorItemNode can't be parsed with out parent!");
            }
            #endregion

            #region Action
            Type type;

            if (tree is ActionNode)
            {
                if (_ALL_PARSER.TryGetValue(tree.GetType(), out type))
                {
                    var item = System.Activator.CreateInstance(type);
                    current = (Composite)item;
                    if (current != null)
                    {
                        (current as INodeParser).Parser(tree);
                    }
                    else
                    {
                        Debug.LogError(string.Format("ITEM:{0} current:{1} TYPE:{2}", item, tree, type));
                    }
                }
                else
                {
                    Debug.Log(string.Format("Action {0} No Paser!!!", tree.GetType()));
                }
            }
            #endregion

            if (current != null)
            {
                current.Name = tree.Name;
                //Debug.Log(tree.Name);
            }
            else
            {
                Debug.Log(string.Format("Action {0} No Paser!!!", tree.GetType()));
            }
            //下面解析动作,条件
            if (parent == null)
            {
                parent = current;
            }
            return(parent);
        }
Exemplo n.º 5
0
 public static Composite FindCompositByGuid(Composite c, string guid)
 {
     return(c.FindGuid(guid));
 }