예제 #1
0
 private void CheckTriggers(IColliderEntity thisEntity, IGameObject otherObject)
 {
     foreach (ITrigger trigger in thisEntity.GetTriggers())
     {
         if (trigger.IsInsideTrigger(otherObject))
         {
             if (!triggers[thisEntity][trigger.GetTag()].ContainsKey(otherObject))
             {
                 thisEntity.OnEnterTrigger(trigger.GetTag(), otherObject);
             }
             triggers[thisEntity][trigger.GetTag()][otherObject] = true;
         }
     }
 }
예제 #2
0
        public void Update(IColliderEntity thisEntity = null)
        {
            if (changedObjects.Count == 0 && (entities.Count == 0 || toCheckAgainst.Count == 0))
            {
                return;
            }

            HandleChangedObjects();


            if (!thisEntity.CollisionsEnabled && thisEntity.GetTriggers().Count == 0)
            {
                return;
            }

            foreach (IColliderEntity otherEntity in toCheckAgainst)
            {
                if (thisEntity.Equals(otherEntity))
                {
                    continue;
                }

                if (thisEntity.GetTriggers().Count > 0 && otherEntity.CanFireTriggers)
                {
                    CheckTriggers(thisEntity, otherEntity);
                }

                if (otherEntity.GetTags().Count == 0 || !otherEntity.CollisionsEnabled)
                {
                    continue;
                }

                bool possibleCollision = false;
                bool allowOverlap      = false;
                foreach (string tag in otherEntity.GetTags())
                {
                    if (thisEntity.GetCollidesAgainst().ContainsKey(tag))
                    {
                        possibleCollision = true;
                        allowOverlap      = thisEntity.GetCollidesAgainst()[tag];
                        break;
                    }
                }

                if (!possibleCollision)
                {
                    continue;
                }

                if (thisEntity.GetCollisionComponent() != null && otherEntity.GetCollisionComponent() != null)
                {
                    CheckCollision(thisEntity, otherEntity, allowOverlap);
                }

                /*if (thisEntity.CheckGridCollisions)
                 * {
                 *  CheckGridCollisions(thisEntity);
                 * }*/
            }

            InactivateCollisionsAndTriggers(thisEntity);
        }