/// <summary>Check for removed entities to remove them from inventories.</summary> /// <param name="message"></param> public override void OnComponentRemoved(ComponentRemoved message) { base.OnComponentRemoved(message); var item = message.Component as Item; if (item != null) { // Remove items that were equipped inside this item. Do this first, // to keep the hierarchy alive as long as possible (due to this // recursing this will delete bottom up). This is necessary to allow // other systems to check the root node (e.g. thruster effect system). Component slot; while ((slot = Manager.GetComponent(item.Entity, ItemSlot.TypeId)) != null) { Manager.RemoveComponent(slot); } } else { var itemSlot = message.Component as ItemSlot; if (itemSlot != null) { // An equipment was removed, remove its item. This will // also recursively remove the sub tree (as the removed // item will remove its item slots, etc.) var slot = itemSlot; if (slot.Item > 0) { Manager.RemoveEntity(slot.Item); } } } }
public void RemoveComponent(IComponent component) { components.Remove(component); EntityManager.SharedManager.UnregisterComponent(this, component); ComponentRemoved?.Invoke(this, component); }
private void RemoveState() { GameState State = gameStates.Peek(); ComponentRemoved?.Invoke(this, State); gameStates.Pop(); }
public void RemoveComponent <T>() { T component = GetComponent <T>(); components.Remove(component); ComponentRemoved?.Invoke(this); }
public virtual void RemoveComponent(IStudioComponent component) { if (_components.Remove(component)) { component.InputRemoved -= Component_EndpointRemoved; component.OutputRemoved -= Component_EndpointRemoved; var foundConnections = new List <StudioConnection>(); if (component.Inputs != null) { foreach (var input in component.Inputs) { foreach (var connection in _connections.Where(c => c.Input == input).ToList()) { RemoveConnection(connection); } } } if (component.Outputs != null) { foreach (var output in component.Outputs) { foreach (var connection in _connections.Where(c => c.Output == output).ToList()) { RemoveConnection(connection); } } } ComponentRemoved?.Invoke(this, component); } }
/// <summary>Check for removed entities to remove them from inventories.</summary> /// <param name="message"></param> public override void OnComponentRemoved(ComponentRemoved message) { base.OnComponentRemoved(message); if (message.Component is Item) { // An item was removed, remove it from all inventories. foreach (var inventory in Components) { inventory.Remove(inventory.Entity); } } else { var inventory = message.Component as Inventory; if (inventory != null) { // An inventory was removed, remove all items in it. foreach (var item in inventory) { Manager.RemoveEntity(item); } } } }
private void RemoveComponentImmediate(Component component) { if (component == null) { throw new ArgumentNullException(nameof(component)); } if (component.Deleted) { return; } // these two components are required on all entities and cannot be removed. if (component is ITransformComponent || component is IMetaDataComponent) { DebugTools.Assert("Tried to remove a protected component."); return; } component.Running = false; component.OnRemove(); ComponentRemoved?.Invoke(this, new ComponentEventArgs(component)); DeleteComponent(component); }
public void ClearComponents() { foreach (var component in components) { ComponentRemoved?.Invoke(this, component); } components.Clear(); }
protected internal virtual void OnComponentRemoved(ComponentEventArgs args) { if (args.Component == Transform) { Requires.That <ArgumentException>(args.Binding.Equals(typeof(Transform))); Transform = null; } ComponentRemoved?.Invoke(this, args); }
public void OnComponentRemoved(ComponentRemoved message) { var index = message.Component as IIndexable; if (index != null) { // Remove from any indexes the component was part of. RemoveIndex(index, index.IndexId); } }
/// <summary>Called when a component is removed.</summary> /// <param name="message"></param> public override void OnComponentRemoved(ComponentRemoved message) { base.OnComponentRemoved(message); if (message.Component is Item) { // An item was removed, clear its cooldowns. _cooldowns.Remove(message.Component.Entity); } }
public override void OnComponentRemoved(ComponentRemoved message) { base.OnComponentRemoved(message); var shield = message.Component as ShieldEnergyStatusEffect; if (shield != null && shield.Fixture >= 0) { Manager.RemoveComponent(shield.Fixture); } }
public void OnComponentRemoved(ComponentRemoved message) { // Remove from positions list if it was in the index we use to find // entities to interpolate. var component = message.Component; if (component is IIndexable && ((IIndexable)component).IndexId == IndexId) { _entries.Remove(component.Entity); } }
/// <summary> /// Removes a given component /// </summary> /// <param name="component"></param> /// <returns></returns> public Entity RemoveComponent(IComponent component) { if (_components.ContainsKey(component.GetType())) { _components.Remove(component.GetType()); } ComponentRemoved?.Invoke(this, null); return(this); }
/// <summary> /// Remove a given component /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> public Entity RemoveComponent <T>() where T : class, IComponent { if (_components.ContainsKey(typeof(T))) { _components.Remove(typeof(T)); } ComponentRemoved?.Invoke(this, EventArgs.Empty); return(this); }
public void OnComponentRemoved(ComponentRemoved message) { var squad = message.Component as Squad; if (squad != null) { // Remove from squad moving it to its identity squad. RemoveMember(squad.SquadId, squad.Entity); // Remove the component's identity squad. _squadIds.ReleaseId(squad.SquadId); } }
private void OnComponentRemoved(MyEntityComponent obj) { var cast = obj as TComp; if (cast == null) { return; } if (_components.Remove(cast)) { ComponentRemoved?.Invoke(cast); } }
public void RemoveComponent <ComponentType>() where ComponentType : class, IComponent, new() { Type type = typeof(ComponentType); if (components.Remove(type, out IComponent component)) { ComponentRemoved?.Invoke(this, new ComponentEventArgs(component)); } else { throw new ArgumentException("This component does not exist on this entity", nameof(ComponentType)); } }
/// <summary>Called by the manager when a new component was removed.</summary> /// <param name="message"></param> public override void OnComponentRemoved(ComponentRemoved message) { base.OnComponentRemoved(message); // Check if the component is of the right type. var shield = message.Component as Shield; if (shield != null) { var typedComponent = shield; // Take advantage of the fact that the list is sorted. var index = _shields.BinarySearch(typedComponent); Debug.Assert(index >= 0); _shields.RemoveAt(index); } }
public Result <IDisposable> AddComponent(Identity identity, RenderedComponent component) { if (renderedComponents.ContainsKey(identity)) { return(Result.FailWith <IDisposable>(State.Forbidden, $"TargetRenderer already contains component {identity.Id}.")); } renderedComponents.Add(identity, component); ComponentAdded?.Invoke(this, new RenderedComponentEventArgs(identity, component)); return(Result.Ok(Disposable.For(() => { if (renderedComponents.ContainsKey(identity)) { renderedComponents.Remove(identity); ComponentRemoved?.Invoke(this, new RenderedComponentEventArgs(identity, component)); } }))); }
public virtual void OnComponentRemoved(ComponentRemoved message) { Debug.Assert(message.Component.Entity > 0, "component.Entity > 0"); Debug.Assert(message.Component.Id > 0, "component.Id > 0"); // Check if the component is of the right type. if (!(message.Component is TComponent)) { return; } // Take advantage of the fact that the list is sorted. var component = (TComponent)message.Component; var index = Components.BinarySearch(component); Debug.Assert(index >= 0); Components.RemoveAt(index); }
public void Dispose() { if (ComponentAdded != null) { //Remove all Events associated to this control (That haven't been unsubscribed !) foreach (Delegate d in ComponentAdded.GetInvocationList()) { ComponentAdded -= (EventHandler <GameComponentCollectionEventArgs>)d; } } if (ComponentRemoved != null) { //Remove all Events associated to this control (That haven't been unsubscribed !) foreach (Delegate d in ComponentRemoved.GetInvocationList()) { ComponentRemoved -= (EventHandler <GameComponentCollectionEventArgs>)d; } } }
protected virtual void OnComponentRemoved(GameComponentEventArgs <ComponentType> e) { IUpdateable asUpdateable; IDrawable asDrawable; Sprite asSprite; if (!m_IsInitialized) { m_UninitializedComponents.Remove(e.GameComponent); } asUpdateable = e.GameComponent as IUpdateable; if (asUpdateable != null) { m_UpdateableComponents.Remove(asUpdateable); asUpdateable.UpdateOrderChanged -= child_UpdateOrderChanged; } asSprite = e.GameComponent as Sprite; if (asSprite != null) { m_Sprites.Remove(asSprite); asSprite.DrawOrderChanged -= child_DrawOrderChanged; } else { asDrawable = e.GameComponent as IDrawable; if (asDrawable != null) { m_DrawableComponents.Remove(asDrawable); asDrawable.DrawOrderChanged -= child_DrawOrderChanged; } } if (ComponentRemoved != null) { ComponentRemoved.Invoke(this, e); } }
/// <summary> /// When a componenet removed from the game, it will be also removed from the screen. /// </summary> /// <param name="i_Sender">Sender object.</param> /// <param name="i_ArgsHolder">Arguments holder.</param> private void components_ComponentRemoved(object i_Sender, GameComponentCollectionEventArgs i_ArgsHolder) { IGameComponent component = i_ArgsHolder.GameComponent; if (!m_constGameComponentCollection.Contains(component)) { if (m_gameComponentCollection.Contains(component)) { m_gameComponentCollection.Remove(component); } if (m_gameDrawableComponentCollection.Contains(component)) { m_gameDrawableComponentCollection.Remove(component); } if (ComponentRemoved != null) { ComponentRemoved.Invoke(component); } } }
private void RemoveComponentImmediate(Component component) { if (component == null) { throw new ArgumentNullException(nameof(component)); } if (component.Deleted) { return; } if (component.Running) { component.Shutdown(); } component.OnRemove(); ComponentRemoved?.Invoke(this, new ComponentEventArgs(component)); DeleteComponent(component); }
private void RemoveComponentDeferred(Component component) { if (component == null) { throw new ArgumentNullException(nameof(component)); } if (component.Deleted) { return; } _deleteList.Add(component); if (component.Running) { component.Shutdown(); } component.OnRemove(); ComponentRemoved?.Invoke(this, new ComponentEventArgs(component)); }
private void RemoveComponentDeferred(Component component, bool removeProtected) { if (component == null) { throw new ArgumentNullException(nameof(component)); } if (component.Deleted) { return; } #if EXCEPTION_TOLERANCE try { #endif // these two components are required on all entities and cannot be removed normally. if (!removeProtected && (component is ITransformComponent || component is IMetaDataComponent)) { DebugTools.Assert("Tried to remove a protected component."); return; } _deleteList.Add(component); component.Running = false; component.OnRemove(); ComponentRemoved?.Invoke(this, new ComponentEventArgs(component)); #if EXCEPTION_TOLERANCE } catch (Exception e) { _runtimeLog.LogException(e, $"RemoveComponentDeferred, owner={component.Owner}, type={component.GetType()}"); } #endif }
public void RemoveFromContainer() { if (_includeParent) { _hierarchy.ParentChanged -= ParentChanged; ParentChanged(_hierarchy, _hierarchy.Parent, null); _hierarchy = null; } if (_modelAttachment != null) { _modelAttachment.OnEntityAttached -= OnEntityAttached; _modelAttachment.OnEntityDetached -= OnEntityDetached; var h = _container.Get <MyHierarchyComponent>(); if (h != null) { foreach (var e in h.Children) { if (e.Entity != null && _modelAttachment.GetEntityAttachmentPoint(e.Entity) != MyStringHash.NullOrEmpty) { OnEntityDetached(_modelAttachment, e.Entity); } } } _modelAttachment = null; } _container.ComponentAdded -= OnComponentAdded; _container.ComponentRemoved -= OnComponentAdded; foreach (var c in _components) { ComponentRemoved?.Invoke(c); } _components.Clear(); _container = null; }
/// <summary> /// Removes the component from the entity. /// </summary> /// <param name="type">The type of the entity.</param> public void RemoveComponent(Type type) { var cmp = components[type]; if (cmp == null) { return; } if (cmp.GetType().IsSubclassOf(typeof(Behavior))) { var behavior = cmp as Behavior; behaviorManager.RemoveBehavior(behavior); } if (cmp.GetType().IsSubclassOf(typeof(Drawable))) { var drawable = cmp as Drawable; renderManager.RemoveDrawable(drawable); } ComponentRemoved?.Invoke(this, new ComponentEventArgs(cmp)); components.Remove(type); }
private void OnComponentRemoved(ComponentCollectionEventArgs eventArgs) => ComponentRemoved?.Invoke(this, eventArgs);