Beispiel #1
0
    /// <summary>
    /// Deletes the <paramref name="node"/> and its children
    /// </summary>
    /// <param name="node"></param>
    public void DeleteNode(BehaviourNode node, bool deleteTransitions = true)
    {
        if (nodes.Remove(node))
        {
            if (deleteTransitions)
            {
                foreach (TransitionGUI transition in transitions.FindAll(t => node.Equals(t.fromNode)))
                {
                    DeleteConnection(transition);
                    DeleteNode((BehaviourNode)transition.toNode);
                }
                foreach (TransitionGUI transition in transitions.FindAll(t => node.Equals(t.toNode)))
                {
                    DeleteConnection(transition);
                }
            }

            if (node.subElem == null)
            {
                elementNamer.RemoveName(node.identificator);
            }
            else
            {
                elementNamer.RemoveName(node.subElem.identificator);
            }
        }
    }
Beispiel #2
0
    /// <summary>
    /// Checks wether <paramref name="start"/> could ever reach <paramref name="end"/> in the <see cref="BehaviourTree"/> execution
    /// </summary>
    /// <param name="start"></param>
    /// <param name="end"></param>
    /// <returns></returns>
    public bool ConnectedCheck(BehaviourNode start, BehaviourNode end)
    {
        foreach (TransitionGUI transition in transitions.FindAll(t => !t.isExit && start.Equals(t.fromNode)))
        {
            if (end.Equals((BehaviourNode)transition.toNode))
            {
                return(true);
            }
            if (ConnectedCheck((BehaviourNode)transition.toNode, end))
            {
                return(true);
            }
        }

        return(false);
    }
Beispiel #3
0
    /// <summary>
    /// Returns all children <paramref name="node"/> has
    /// </summary>
    /// <param name="node"></param>
    /// <param name="deepCount"> True if it should count children of its children recursively to infinity </param>
    /// <returns>The number of children <paramref name="node"/> has</returns>
    public List <BehaviourNode> ChildrenGet(BehaviourNode node, bool deepCount = false)
    {
        List <BehaviourNode> children = new List <BehaviourNode>();

        foreach (TransitionGUI transition in transitions.FindAll(t => !t.isExit && node.Equals(t.fromNode)))
        {
            children.Add((BehaviourNode)transition.toNode);

            if (deepCount)
            {
                children.AddRange(ChildrenGet((BehaviourNode)transition.toNode, true));
            }
        }

        return(children);
    }
Beispiel #4
0
    /// <summary>
    /// Returns how many children <paramref name="node"/> has
    /// </summary>
    /// <param name="node"></param>
    /// <param name="deepCount"> True if it should count children of its children recursively to infinity </param>
    /// <returns>The number of children <paramref name="node"/> has</returns>
    public int ChildrenCount(BehaviourNode node, bool deepCount = false)
    {
        int res = 0;

        foreach (TransitionGUI transition in transitions.FindAll(t => !t.isExit && node.Equals(t.fromNode)))
        {
            res += 1;

            if (deepCount)
            {
                res += ChildrenCount((BehaviourNode)transition.toNode, true);
            }
        }

        return(res);
    }