예제 #1
0
        private static void walkBreadthFirst(IScriptAction start, Action <IScriptAction> action, bool isFind)
        {
            Queue <IScriptAction> queue = new Queue <IScriptAction>();

            queue.Enqueue(start);
            while (queue.Count > 0)
            {
                IScriptAction obj = queue.Dequeue();
                if (obj == null)
                {
                    continue;
                }

                action(obj);
                obj.ForAllChildren(delegate(IScriptAction s) { queue.Enqueue(s); return(false); }, isFind);
            }
        }
예제 #2
0
        /// <summary>
        /// Search action in the tree
        /// </summary>
        /// <param name="start">Node where to start</param>
        /// <param name="func">Predicate to execute</param>
        /// <returns>Found action or null</returns>
        static public IScriptAction FindTree(IScriptAction start, Predicate <IScriptAction> func)
        {
            Queue <IScriptAction> queue = new Queue <IScriptAction>();

            queue.Enqueue(start);
            while (queue.Count > 0)
            {
                IScriptAction obj = queue.Dequeue();
                if (obj != null)
                {
                    if (func(obj))
                    {
                        return(obj);
                    }

                    obj.ForAllChildren(delegate(IScriptAction s)
                    {
                        queue.Enqueue(s);
                        return(false);
                    }, true);
                }
            }
            return(null);
        }