obtain() public static method

pops an item off the stack if available creating a new item as necessary
public static obtain ( ) : List
return List
Beispiel #1
0
        public List <Collider> getColliders()
        {
            var list = ListPool <Collider> .obtain();

            getColliders(list);
            return(list);
        }
Beispiel #2
0
        public List <T> getComponents <T>() where T : class
        {
            var components = ListPool <T> .obtain();

            getComponents(components);

            return(components);
        }
        /// <summary>
        /// returns a list of all entities with tag. If no entities have the tag an empty list is returned. The returned List can be put back in the pool via ListPool.free.
        /// </summary>
        /// <returns>The with tag.</returns>
        /// <param name="tag">Tag.</param>
        public List <Entity> entitiesWithTag(int tag)
        {
            var list = getTagList(tag);

            var returnList = ListPool <Entity> .obtain();

            returnList.AddRange(list);

            return(returnList);
        }
Beispiel #4
0
        public List <Entity> getList()
        {
            var list = ListPool <Entity> .obtain();

            for (var i = 0; i < _entities.length; i++)
            {
                list.Add(_entities.buffer[i]);
            }
            return(list);
        }
Beispiel #5
0
        /// <summary>
        /// returns a list of all entities with tag. If no entities have the tag an empty list is returned. The returned List can be put back in the pool via ListPool.free.
        /// </summary>
        /// <returns>The with tag.</returns>
        /// <param name="tag">Tag.</param>
        public List <Entity> entitiesWithTag(int tag)
        {
            var list = getTagList(tag);

            var returnList = ListPool <Entity> .obtain();

            returnList.Capacity = _entities.length;
            for (var i = 0; i < list.length; i++)
            {
                returnList.Add(_entities.buffer[i]);
            }

            return(returnList);
        }
Beispiel #6
0
        /// <summary>
        /// gets random items from the list. Does not empty check the list or verify that list count is greater than item count! The returned List can be put back in the pool via ListPool.free.
        /// </summary>
        /// <returns>The item.</returns>
        /// <param name="list">List.</param>
        /// <param name="itemCount">The number of random items to return from the list.</param>
        /// <typeparam name="T">The 1st type parameter.</typeparam>
        public static List <T> randomItems <T>(this IList <T> list, int itemCount)
        {
            var set = new HashSet <T>();

            while (set.Count != itemCount)
            {
                var item = list.randomItem();
                if (!set.Contains(item))
                {
                    set.Add(item);
                }
            }

            var items = ListPool <T> .obtain();

            items.AddRange(set);
            return(items);
        }
Beispiel #7
0
        /// <summary>
        /// returns all Components found in the Scene of type T. The returned List can be put back in the pool via ListPool.free.
        /// </summary>
        /// <returns>The components of type.</returns>
        /// <typeparam name="T">The 1st type parameter.</typeparam>
        public List <T> findComponentsOfType <T>() where T : Component
        {
            var comps = ListPool <T> .obtain();

            for (var i = 0; i < _entities.length; i++)
            {
                if (_entities.buffer[i].enabled)
                {
                    _entities.buffer[i].getComponents <T>(comps);
                }
            }

            foreach (var entity in _entitiesToAdd)
            {
                if (entity.enabled)
                {
                    entity.getComponents <T>(comps);
                }
            }

            return(comps);
        }
Beispiel #8
0
        /// <summary>
        /// returns a List of all Entities of type T. The returned List can be put back in the pool via ListPool.free.
        /// </summary>
        /// <returns>The of type.</returns>
        /// <typeparam name="T">The 1st type parameter.</typeparam>
        public List <Entity> entitiesOfType <T>() where T : Entity
        {
            var list = ListPool <Entity> .obtain();

            for (var i = 0; i < _entities.length; i++)
            {
                if (_entities.buffer[i] is T)
                {
                    list.Add(_entities.buffer[i]);
                }
            }

            foreach (var entity in _entitiesToAdd)
            {
                if (entity is T)
                {
                    list.Add(entity);
                }
            }

            return(list);
        }
        /// <summary>
        /// returns all Components found in the Scene of type T. The returned List can be put back in the pool via ListPool.free.
        /// </summary>
        /// <returns>The components of type.</returns>
        /// <typeparam name="T">The 1st type parameter.</typeparam>
        public List <T> findComponentsOfType <T>() where T : Component
        {
            var comps = ListPool <T> .obtain();

            for (var i = 0; i < _entities.length; i++)
            {
                if (_entities.buffer[i].enabled)
                {
                    _entities.buffer[i].getComponents <T>(comps);
                }
            }

            // in case an entity is added and searched for in the same frame we check the toAdd list
            for (var i = 0; i < _entitiesToAdd.Count; i++)
            {
                if (_entitiesToAdd[i].enabled)
                {
                    _entitiesToAdd[i].getComponents <T>(comps);
                }
            }

            return(comps);
        }
        /// <summary>
        /// returns a List of all Entities of type T. The returned List can be put back in the pool via ListPool.free.
        /// </summary>
        /// <returns>The of type.</returns>
        /// <typeparam name="T">The 1st type parameter.</typeparam>
        public List <Entity> entitiesOfType <T>() where T : Entity
        {
            var list = ListPool <Entity> .obtain();

            for (var i = 0; i < _entities.length; i++)
            {
                if (_entities.buffer[i] is T)
                {
                    list.Add(_entities.buffer[i]);
                }
            }

            // in case an entity is added and searched for in the same frame we check the toAdd list
            for (var i = 0; i < _entitiesToAdd.Count; i++)
            {
                if (_entitiesToAdd[i] is T)
                {
                    list.Add(_entitiesToAdd[i]);
                }
            }

            return(list);
        }
Beispiel #11
0
        /// <summary>
        /// returns a List of all Entities with a matching name. The returned List can be put back in the pool via ListPool.free.
        /// </summary>
        /// <returns>The of type.</returns>
        /// <typeparam name="T">The 1st type parameter.</typeparam>
        public List <Entity> entitiesWithName(string name)
        {
            var list = ListPool <Entity> .obtain();

            for (var i = 0; i < _entities.length; i++)
            {
                if (_entities.buffer[i].name == name)
                {
                    list.Add(_entities.buffer[i]);
                }
            }

            // in case an entity is added and searched for in the same frame we check the toAdd list
            foreach (var entityToAdd in _entitiesToAdd)
            {
                if (entityToAdd.name == name)
                {
                    list.Add(entityToAdd);
                }
            }

            return(list);
        }