Ejemplo n.º 1
0
    /// <summary>
    /// Creates a new <see cref="TimerDecoratorNode"/> in the behaviour tree
    /// </summary>
    /// <param name="name">The name of the node</param>
    /// <param name="child">The child of the node</param>
    /// <param name="time">The time it will take to execute the child node, in seconds</param>
    /// <returns></returns>
    public TimerDecoratorNode CreateTimerNode(string name, TreeNode child, float time)
    {
        if (!states.ContainsKey(name))
        {
            TimerDecoratorNode timerNode = new TimerDecoratorNode(name, child, time, this);
            BTnodes.Add(timerNode);
            states.Add(name, timerNode.StateNode);

            return(timerNode);
        }
        else
        {
            throw new DuplicateWaitObjectException(name, "The node already exists in the behaviour tree");
        }
    }
Ejemplo n.º 2
0
    private void CreateBehaviourTree()
    {
        behaviourTree = new BehaviourTreeEngine(false);

        LeafNode           throwRod       = behaviourTree.CreateLeafNode("Throw rod", ThrowRod, RodThrown);
        LeafNode           catchSomething = behaviourTree.CreateLeafNode("Catch something", Catch, SomethingCatched);
        LeafNode           returnToWater  = behaviourTree.CreateLeafNode("Return to water", () => Invoke("ReturnToWater", 2), ReturnedToWater);
        LeafNode           storeInBasket  = behaviourTree.CreateLeafNode("Store in the basket", () => Invoke("StoreBasket", 2), StoredInBasket);
        TimerDecoratorNode timerNode      = behaviourTree.CreateTimerNode("Timer node", catchSomething, 3);
        SelectorNode       selectorNode   = behaviourTree.CreateSelectorNode("Selector node");

        selectorNode.AddChild(returnToWater);
        selectorNode.AddChild(storeInBasket);
        SequenceNode sequenceNode = behaviourTree.CreateSequenceNode("Sequence node", false);

        sequenceNode.AddChild(throwRod);
        sequenceNode.AddChild(timerNode);
        sequenceNode.AddChild(selectorNode);
        LoopDecoratorNode rootNode = behaviourTree.CreateLoopNode("Root node", sequenceNode);

        behaviourTree.SetRootNode(rootNode);
    }