Exemplo n.º 1
0
        public static IEnumerable <T> Cache <T>(this IEnumerable <T> self)
        {
            using (InstanceScope <List <T> > .Create(() => new List <T>(), out var items))
            {
                try
                {
                    items.AddRange(self);

                    foreach (var item in items)
                    {
                        yield return(item);
                    }
                }
                finally
                {
                    items.Clear();
                }
            }
        }
Exemplo n.º 2
0
        public static IEnumerable <T> GetComponentsInParentEnumerable <T>(this GameObject self, bool includeInactive = false)
            where T : class
        {
            using (InstanceScope <List <T> > .Create(() => new List <T>(), out var components))
            {
                try
                {
                    self.GetComponentsInParent(includeInactive, components);

                    foreach (var component in components)
                    {
                        yield return(component);
                    }
                }
                finally
                {
                    components.Clear();
                }
            }
        }
Exemplo n.º 3
0
        public static IEnumerable <T> GetComponentsEnumerable <T>(this GameObject self)
            where T : class
        {
            using (InstanceScope <List <T> > .Create(() => new List <T>(), out var components))
            {
                try
                {
                    self.GetComponents(components);

                    foreach (var component in components)
                    {
                        yield return(component);
                    }
                }
                finally
                {
                    components.Clear();
                }
            }
        }
Exemplo n.º 4
0
        public static IEnumerable <GameObject> GetRootGameObjectsEnumerable(this Scene self)
        {
            if (self.rootCount < 1)
            {
                yield break;
            }

            using (InstanceScope <List <GameObject> > .Create(() => new List <GameObject>(), out var gameObjects))
            {
                try
                {
                    self.GetRootGameObjects(gameObjects);

                    foreach (var gameObject in gameObjects)
                    {
                        yield return(gameObject);
                    }
                }
                finally
                {
                    gameObjects.Clear();
                }
            }
        }