Beispiel #1
0
        private EntityComponent AddEntityComponent(Type type)
        {
            if (IsDestroyed)
            {
                UnityEngine.Debug.LogWarning($"Can't add component {type.Name} to a destroyed entity!");
                return(null);
            }

            EntityComponent component = Activator.CreateInstance(type) as EntityComponent;

            if (component != null)
            {
                _components.Add(component);
                component.Initialize(this);
                component.Enabled();
                AddedComponentEvent?.Invoke(this, component);
            }

            return(component);
        }
Beispiel #2
0
        internal void AddComponent(Entity entity, IComponent component, ComponentType type)
        {
            if (type.Id >= _componentsByType.Capacity)
            {
                _componentsByType.Set(type.Id, null);
            }

            var components = _componentsByType.Get(type.Id);

            if (components == null)
            {
                components = new Bag <IComponent>();
                _componentsByType.Set(type.Id, components);
            }

            components.Set(entity.Id, component);

            entity.AddTypeBit(type.Bit);
            AddedComponentEvent?.Invoke(entity, component);

            _entityWorld.RefreshEntity(entity);
        }
Beispiel #3
0
 private void OnAddedComponentEvent(EntityComponent entityComponent)
 {
     AddedComponentEvent?.Invoke(entityComponent);
 }