private void replaceComponent(int index, IComponent replacement) { // TODO VD PERFORMANCE // _toStringCache = null; var previousComponent = _components[index]; if (replacement != previousComponent) { _components[index] = replacement; _componentsCache = null; if (replacement != null) { OnComponentReplaced?.Invoke(this, index, previousComponent, replacement); } else { _componentIndicesCache = null; // TODO VD PERFORMANCE _toStringCache = null; OnComponentRemoved?.Invoke(this, index, previousComponent); } GetComponentPool(index).Push(previousComponent); } else { OnComponentReplaced?.Invoke(this, index, previousComponent, replacement); } }
public TComponent RemoveComponent <TComponent>(int entity, TComponent component) where TComponent : IEcsComponent { Type type = component.GetType(); var componentsOfType = components[type]; IEcsComponent existingComponent; if (componentsOfType.TryGetValue(entity, out existingComponent)) { if (existingComponent.Equals(component)) { componentsOfType.Remove(entity); Console.WriteLine("Removed " + type + " from " + entity); OnComponentRemoved?.Invoke(entity, component); return(component); } else { throw new ExistingComponentException(entity + " has a different " + component.GetType() + " component"); } } else { throw new MissingComponentException(entity + " does not have a " + component.GetType() + " component"); } }
public void RemoveComponent <TComponent>(TComponent component) where TComponent : class, IComponent, new() { if (componentsMap.Remove(component.GetType())) { context.RecycleComponent(component); OnComponentRemoved?.Invoke(this, component); } }
public void SharedComponentDispose(string id) { if (disposableComponents.TryGetValue(id, out ISharedComponent sharedComponent)) { sharedComponent?.Dispose(); disposableComponents.Remove(id); OnComponentRemoved?.Invoke(sharedComponent); } }
internal void RemoveAllComponents() { foreach (var comp in componentsMap) { context.RecycleComponent(comp.Value); OnComponentRemoved?.Invoke(this, comp.Value); } componentsMap.Clear(); }
public void RemoveComponent(ECSComponent component) { bool removed = components.Remove(component); if (removed) { OnComponentRemoved?.Invoke(component); } }
public void DestroyComponent(ComponentEcs component) { component.OnDestroy(); OnComponentRemoved?.Invoke(component); _componentPools[component.ComponentType].Remove(component); _componentsById.Remove(component.Id); ComponentCache.Instance.Release(component); CurrentHash = Guid.NewGuid(); }
public void Remove <T>() where T : class { for (int i = list.Count - 1; i >= 0; --i) { if (i >= list.Count) { continue; } Component component = list[i]; if (component is T) { list.RemoveAt(i); OnComponentRemoved?.Invoke(gameObject, component); } } }
public TComponent RemoveComponent <TComponent>(int entity) where TComponent : IEcsComponent { var type = typeof(TComponent); var componentsOfType = components[type]; IEcsComponent component; if (componentsOfType.TryGetValue(entity, out component)) { componentsOfType.Remove(entity); Console.WriteLine("Removed " + type + " from " + entity); OnComponentRemoved?.Invoke(entity, component); return((TComponent)component); } else { throw new MissingComponentException(entity + " does not have a " + typeof(TComponent) + " component"); } }
private Entity <T> ReplaceInstance(Type type, T component) { if (!_isEnabled) { throw new EntityIsNotEnabledException <T>("Cannot replace component '" + component + "' on " + this + "!"); } if (Has(type)) { var previousComponent = _components[type]; if (component != previousComponent) { _components[type] = component; _componentsCache = null; if (component != null) { OnComponentReplaced?.Invoke(this, type, previousComponent, component); } else { _componentTypesCache = null; OnComponentRemoved?.Invoke(this, type, previousComponent); } GetComponentPool(type).Push(previousComponent); } else { OnComponentReplaced?.Invoke(this, type, previousComponent, component); } } else if (component != null) { AddInstance(component); } return(this); }
/// <summary> /// Unlink the entity and component /// </summary> /// <typeparam name="E">type extending Entity</typeparam> /// <typeparam name="C">type implementing IComponent</typeparam> /// <param name="entity">The entity that the component will be removed from</param> /// <param name="component">The component being removed</param> public void RemoveComponent <E, C>(E entity, C component) where E : Entity where C : IComponent { if (entity.Parent.Id != Id) { throw new ArgumentException(nameof(entity)); } if (entity == null) { throw new ArgumentNullException(nameof(entity)); } if (component == null) { throw new ArgumentNullException(nameof(component)); } if (entityComponentMap.ContainsKey(entity.Id)) { if (entityComponentMap[entity.Id].Item2.Contains(component)) { entityComponentMap[entity.Id].Item2.Remove(component); OnComponentRemoved?.Invoke(this, new ComponentRemovedEventArgs(entity, component)); } } }
internal void OnComponentRemovedInternal(BaseComponent component) { ComponentRemoved(component.SourceEntity, component); OnComponentRemoved?.Invoke(component.SourceEntity, component); }
internal void ComponentRemoved(Component component) { OnComponentRemoved?.Invoke(component); }
public void RemoveComponent(IPlayerComponent i_ComponentToRemove) { m_PlayListComponents.Remove(i_ComponentToRemove); OnComponentRemoved.Invoke(i_ComponentToRemove); }
private void RemoveRecycleComponent(IComponent component) { _components.Remove(component.GetType()); OnComponentRemoved?.Invoke(this, component); _componentFactory.Recycle(component); }