예제 #1
0
    public void OnTriggerEnter(Collider collider)
    {
        IHealthEntity healthEntity = Utils.GetBehaviorWithInterface <IHealthEntity>(collider.gameObject);

        if (healthEntity != null)
        {
            IHealthEntity parent = healthEntity.GetParent();

            IHealthEntity entityToReferTo = parent == null ? healthEntity : parent;

            if (entitiesInsideCount.ContainsKey(entityToReferTo))
            {
                //already inside
                uint prevCount = entitiesInsideCount[entityToReferTo];
                entitiesInsideCount[entityToReferTo] = prevCount + 1;
            }
            else
            {
                entitiesInsideCount.Add(entityToReferTo, 1);

                if (continuousDamage)
                {
                    nextDamageTimes.Add(entityToReferTo, Time.time + continuousDamagePeriod);
                }
            }

            if (initialDamage)
            {
                healthEntity.Damage(team, damageSource, damageAmount);


                DealKnockback(collider.attachedRigidbody);
            }
        }
    }
예제 #2
0
    public void OnTriggerExit(Collider collider)
    {
        IHealthEntity healthEntity = Utils.GetBehaviorWithInterface <IHealthEntity>(collider.gameObject);

        if (healthEntity != null)
        {
            IHealthEntity parent = healthEntity.GetParent();

            IHealthEntity entityToReferTo = parent == null ? healthEntity : parent;

            if (entitiesInsideCount.ContainsKey(entityToReferTo))
            {
                //already inside
                uint prevCount = entitiesInsideCount[entityToReferTo];
                prevCount -= 1;
                if (prevCount == 0)
                {
                    //all of the parts of the entity are out of the area, remove them.
                    entitiesInsideCount.Remove(entityToReferTo);
                    nextDamageTimes.Remove(entityToReferTo);
                }
                else
                {
                    entitiesInsideCount[entityToReferTo] = prevCount;
                }
            }
        }
    }