示例#1
0
        public static bool GetAllThingsRecursively(IThingHolder holder, List <Thing> outThings, bool allowUnreal = true, Predicate <IThingHolder> passCheck = null)
        {
            outThings.Clear();
            if (passCheck != null && !passCheck(holder))
            {
                return(false);
            }
            Stack <IThingHolder> tmpStack = new Stack <IThingHolder>();

            tmpStack.Push(holder);
            while (tmpStack.Count != 0)
            {
                IThingHolder thingHolder = tmpStack.Pop();
                if (allowUnreal || ThingOwnerUtility.AreImmediateContentsReal(thingHolder))
                {
                    ThingOwner directlyHeldThings = thingHolder.GetDirectlyHeldThings();
                    if (directlyHeldThings != null)
                    {
                        outThings.AddRange(directlyHeldThings);
                    }
                }
                List <IThingHolder> tmpHolders = new List <IThingHolder>();
                thingHolder.GetChildHolders(tmpHolders);
                for (int i = 0; i < tmpHolders.Count; i++)
                {
                    if (passCheck == null || passCheck(tmpHolders[i]))
                    {
                        tmpStack.Push(tmpHolders[i]);
                    }
                }
            }
            //tmpStack.Clear();
            //tmpHolders.Clear();
            return(false);
        }