Exemplo n.º 1
0
        public void RemoveBehaviour <T>() where T : IEntityBehaviour
        {
            IEntityBehaviour behaviour = EntityBehaviours.FirstOrDefault(b => b.GetType() == typeof(T));

            if (behaviour != null)
            {
                EntityBehaviours.Remove(behaviour);
            }
        }
Exemplo n.º 2
0
        public virtual void ReturnToPool()
        {
            ID              = 0;
            BackingEntity   = null;
            EntityBehaviour = null;

            SpriteRenderer.color = Color.white;
            SpriteRenderer.transform.localPosition = Vector3.zero;
            PlayAnimation(null);

            OnEndOfUpdate.ClearCallback();
            OnEntityFinishedAnimation.ClearCallback();

            gameObject.SetActive(false);
            MyObjectPool?.ReturnObjectToPool(this);
        }
Exemplo n.º 3
0
    public bool AddBehaviour(IEntityBehaviour behaviour)
    {
        // Get collision modes of the attachment
        List <EntityAttachmentCollisionMode> collisionModes = behaviour.GetAttachmentCollisionModes();
        // Initialize collision booleans
        bool collidesWithSelf      = collisionModes.Contains(EntityAttachmentCollisionMode.Self),
             collidesWithInherited = collisionModes.Contains(EntityAttachmentCollisionMode.Inherited);

        Type t = behaviour.GetType();

        // Check if the new attachment collides with any existing attachments
        if (collidesWithSelf && _typedBehaviours.GetValueOrDefault(t, new List <IEntityBehaviour> ()).Count > 0)
        {
            return(false);
        }
        if (collidesWithInherited && _inheritedTypedBehaviours.GetValueOrDefault(t, new List <IEntityBehaviour> ()).Count > 0)
        {
            return(false);
        }

        // Remove from previous entity
        IEntity previous = behaviour.GetPossessingEntity();

        previous.RemoveBehaviour(behaviour);

        // Add and initialize
        _behaviours.Add(behaviour);
        _typedBehaviours.Initialize(t, new List <IEntityBehaviour> ());
        _typedBehaviours[t].Add(behaviour);
        Type cur = t;

        while (cur.BaseType != null)
        {
            cur = cur.BaseType;
            _inheritedTypedBehaviours.Initialize(cur, new List <IEntityBehaviour> ());
            _inheritedTypedBehaviours[cur].Add(behaviour);
        }

        behaviour.AttachTo(this);

        return(true);
    }
Exemplo n.º 4
0
    public bool RemoveBehaviour(IEntityBehaviour behaviour)
    {
        if (!_behaviours.Contains(behaviour))
        {
            return(false);
        }

        _behaviours.Remove(behaviour);

        Type t = behaviour.GetType();

        _typedBehaviours.Initialize(t, new List <IEntityBehaviour> ());
        _typedBehaviours[t].Remove(behaviour);

        while (t.BaseType != null)
        {
            t = t.BaseType;
            _inheritedTypedBehaviours.Initialize(t, new List <IEntityBehaviour> ());
            _inheritedTypedBehaviours[t].Remove(behaviour);
        }

        return(true);
    }
Exemplo n.º 5
0
 public static IEntityFactory RegisterBehaviour(this IEntityFactory factory, EntityTypeEnum type, GameEntityBehaviourEnum behaviour, IEntityBehaviour instance)
 {
     return(factory.RegisterBehaviour((short)type, (short)behaviour, instance));
 }
Exemplo n.º 6
0
 public void AddBehaviour(IEntityBehaviour behaviour)
 {
     EntityBehaviours.Add(behaviour);
     m_behavioursCount++;
 }
Exemplo n.º 7
0
 public bool PossessesBehaviour(IEntityBehaviour behaviour)
 {
     return(_behaviours.Contains(behaviour));
 }