Beispiel #1
0
 public static void Recycle <TComponent>(IList <TComponent> list) where TComponent : class, IComponentBase
 {
     for (int i = 0; i < list.Count; ++i)
     {
         PoolComponents.Recycle(list[i], list[i].GetType());
     }
     list.Clear();
 }
Beispiel #2
0
 public static void Recycle <TComponent>(HashSet <TComponent> list) where TComponent : class, IComponentBase
 {
     foreach (var item in list)
     {
         PoolComponents.Recycle(item);
     }
     list.Clear();
 }
Beispiel #3
0
 public static void Recycle <TComponent>(ref TComponent[] list) where TComponent : class, IComponentBase
 {
     for (int i = 0; i < list.Length; ++i)
     {
         PoolComponents.Recycle(list[i]);
     }
     PoolArray <TComponent> .Recycle(ref list);
 }
Beispiel #4
0
 public static void Recycle <TComponent>(ME.ECS.Collections.ListCopyable <TComponent> list) where TComponent : class, IComponentBase
 {
     for (int i = 0; i < list.Count; ++i)
     {
         PoolComponents.Recycle(list[i], list[i].GetType());
     }
     list.Clear();
 }
Beispiel #5
0
        /// <summary>
        /// Add component for current entity only (create component data)
        /// </summary>
        /// <param name="entity"></param>
        /// <typeparam name="TEntity"></typeparam>
        /// <typeparam name="TComponent"></typeparam>
        /// <typeparam name="TComponentType"></typeparam>
        public TComponent AddComponent <TComponent, TComponentType>(Entity entity) where TComponentType : class, IComponent where TComponent : class, TComponentType, IComponent, new()
        {
            TComponent data;

            data = PoolComponents.Spawn <TComponent>();

            return((TComponent)this.AddComponent <TComponentType>(entity, data));
        }
Beispiel #6
0
        public void RemoveAll(Entity entity)
        {
            List <IComponent <TState, TEntity> > list;

            if (this.dic.TryGetValue(entity.id, out list) == true)
            {
                PoolComponents.Recycle(list);
                list.Clear();
            }
        }
Beispiel #7
0
        public static T Spawn <T>() where T : class, IComponentBase, new()
        {
            var key = WorldUtilities.GetKey <T>();
            var obj = (T)PoolComponents.Spawn_INTERNAL(key);

            if (obj != null)
            {
                return(obj);
            }

            return(PoolInternalBase.Create <T>());
        }
Beispiel #8
0
        void IPoolableRecycle.OnRecycle()
        {
            foreach (var item in this.dic)
            {
                PoolComponents.Recycle(item.Value);
                PoolList <IComponent <TState, TEntity> > .Recycle(item.Value);
            }
            PoolDictionary <EntityId, List <IComponent <TState, TEntity> > > .Recycle(ref this.dic);

            this.freeze   = false;
            this.capacity = 0;
        }
Beispiel #9
0
        public static object Spawn(System.Type type)
        {
            var key      = WorldUtilities.GetKey(type);
            var instance = PoolComponents.Spawn_INTERNAL(type, key, out var pool);

            if (instance == null)
            {
                instance = (IComponent)System.Activator.CreateInstance(type);
                PoolInternalBase.CallOnSpawn(instance, pool);
            }

            return(instance);
        }
Beispiel #10
0
 public void RemoveAll <TComponent>() where TComponent : class, IComponentBase
 {
     foreach (var item in this.dic)
     {
         var list = item.Value;
         for (int i = 0; i < list.Count; ++i)
         {
             var listItem = list[i];
             if (listItem is TComponent listItemComponent)
             {
                 PoolComponents.Recycle(listItemComponent);
                 list.RemoveAt(i);
                 --i;
             }
         }
     }
 }
Beispiel #11
0
        public static void Recycle <T>(T system, System.Type type) where T : class, IComponentBase
        {
            var key = WorldUtilities.GetKey(type);

            PoolComponents.Recycle_INTERNAL(key, system);
        }
Beispiel #12
0
        public static void Recycle(object system)
        {
            var key = WorldUtilities.GetKey(system.GetType());

            PoolComponents.Recycle_INTERNAL(key, system);
        }
Beispiel #13
0
 public static void Recycle <T>(ref T system) where T : class, IComponentBase
 {
     PoolComponents.Recycle(system);
     system = null;
 }
Beispiel #14
0
        public static object Spawn(System.Type type)
        {
            var key = WorldUtilities.GetKey(type);

            return(PoolComponents.Spawn_INTERNAL(key));
        }
Beispiel #15
0
        public static void Recycle <T>(T system) where T : class, IComponentBase
        {
            var key = WorldUtilities.GetKey <T>();

            PoolComponents.Recycle_INTERNAL(typeof(T), key, system);
        }