Пример #1
0
        public List <T> GetComponents <T>() where T : class
        {
            var components = ListPool <T> .Obtain();

            GetComponents(components);

            return(components);
        }
Пример #2
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(list[i]);
            }

            return(returnList);
        }
Пример #3
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);
        }
Пример #4
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);
        }
Пример #5
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);
        }
Пример #6
0
        /// <summary>
        /// Returns a list of all root entities. Root entities are entities that have no parent.
        /// Disabled entities will be included in the list, but not destroyed entities.
        /// The returned list should be put back into the pool via <see cref="ListPool{T}.Free(List{T})"/>.
        /// </summary>
        /// <returns>A list of scene root entities.</returns>
        public List <Entity> RootEntities()
        {
            var list = ListPool <Entity> .Obtain();

            for (var i = 0; i < _entities.Length; i++)
            {
                var e = _entities.Buffer[i];
                if (!e.IsDestroyed && e.Parent == null)
                {
                    list.Add(e);
                }
            }

            foreach (var e in _entitiesToAdd)
            {
                if (!e.IsDestroyed && e.Parent == null)
                {
                    list.Add(e);
                }
            }

            return(list);
        }