Exemple #1
0
    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);
    }