public bool AddData(IEntityData data) { // Get collision modes of the attachment List <EntityAttachmentCollisionMode> collisionModes = data.GetAttachmentCollisionModes(); // Initialize collision booleans bool collidesWithSelf = collisionModes.Contains(EntityAttachmentCollisionMode.Self), collidesWithInherited = collisionModes.Contains(EntityAttachmentCollisionMode.Inherited); Type t = data.GetType(); // Check if the new attachment collides with any existing attachments if (collidesWithSelf && _typedData.GetValueOrDefault(t, new List <IEntityData> ()).Count > 0) { return(false); } if (collidesWithInherited && _inheritedTypedData.GetValueOrDefault(t, new List <IEntityData> ()).Count > 0) { return(false); } // Remove from previous entity IEntity previous = data.GetPossessingEntity(); previous.RemoveData(data); // Add and initialize _data.Add(data); _typedData.Initialize(t, new List <IEntityData> ()); _typedData[t].Add(data); Type cur = t; while (cur.BaseType != null) { cur = cur.BaseType; _inheritedTypedData.Initialize(cur, new List <IEntityData> ()); _inheritedTypedData[cur].Add(data); } data.AttachTo(this); return(true); }
public bool RemoveData(IEntityData data) { if (!_data.Contains(data)) { return(false); } _data.Remove(data); Type t = data.GetType(); _typedData.Initialize(t, new List <IEntityData> ()); _typedData[t].Remove(data); while (t.BaseType != null) { t = t.BaseType; _inheritedTypedData.Initialize(t, new List <IEntityData> ()); _inheritedTypedData[t].Remove(data); } return(true); }