示例#1
0
 private void configureEntity(ECSEntity entity, ECSEntityPool pool, bool isNew)
 {
     if (entity == null)
     {
         throw new ArgumentNullException("entity");
     }
     if (isNew)
     {
         var components = entity.GetComponents();
         for (int i = 0; i < components.Length; ++i)
         {
             components[i].Entity = entity;
         }
         entity.Id   = _entities.Count;
         entity.Pool = pool;
         _entities.Add(entity);
     }
     else
     {
         entity.Id = reverseEntityId(entity.Id);
     }
     this.debugVerifyEntityId(entity);
     if (_isIterating)
     {
         _entitiesCreatedDuringIteration.Add(entity);
     }
     else
     {
         this.insertComponentsOfEntity(entity);
     }
     entity.gameObject.SendMessage("Acquire", null, SendMessageOptions.DontRequireReceiver);
 }
示例#2
0
        private void insertComponentsOfEntity(ECSEntity entity)
        {
            var components = entity.GetComponents();

            for (int i = 0; i < components.Length; ++i)
            {
                this.insertComponent(components[i]);
            }
#if UNITY_EDITOR
            this.debugAssertInvariants();
#endif
        }
示例#3
0
 public void Release(ECSEntity entity)
 {
     if (entity == null)
     {
         throw new ArgumentNullException("entity");
     }
     this.debugVerifyEntityId(entity);
     entity.gameObject.SendMessage("Release", null, SendMessageOptions.DontRequireReceiver);
     ECSBaseComponent[] components = entity.GetComponents();
     for (int i = 0; i < components.Length; ++i)
     {
         this.deleteComponent(components[i]);
     }
     if (entity.Pool == null)
     {
         GameObject.Destroy(entity.gameObject);
         _entities[entity.Id] = null;
     }
     else
     {
         entity.Pool.Release(entity.gameObject);
         entity.Id = reverseEntityId(entity.Id);
     }
 }