Example #1
0
        private bool CanCollideWith(CollisionAbility other)
        {
            if (!HasInit || other == null)
            {
                return(false);
            }

            bool passTypeTest = UseTypeTest ?
                                GamePlay.instance.collisionManager.CanPassTypeTest(this, other) : true;

            if (passTypeTest)
            {
                bool passExclusiveTest = UseExclusiveTest ?
                                         GamePlay.instance.collisionManager.CanPassExclusiveTest(this, other) : true;

                if (passExclusiveTest)
                {
                    return(true);
                }
                else
                {
                    ZLog.log(owner.name, "fails Exclusive Test with:", other.owner.name);
                }
            }
            else
            {
                ZLog.log(owner.name, "fails Type Test with type:", other.Type);
            }
            return(false);
        }
        /// <summary>
        /// c1 and c2 must be in same pair or not recorded at all to return a valid collison
        /// </summary>
        public bool CanPassExclusiveTest(CollisionAbility me, CollisionAbility other)
        {
            //illegal
            if (me == null || other == null /*|| c1.abilityOwner == null || c2.abilityOwner == null*/)
            {
                return(false);
            }

            //same pair
            foreach (var pairInfo in _beInCollisionCache)
            {
                if (pairInfo.isEqual(me, other))
                {
                    return(true);
                }
            }

            //maybe new pair. examine CanCollideMoreInCollision
            if (me.CanReceiveMoreCollision && other.CanReceiveMoreCollision)
            {
                //ZLog.verbose("add", c1.abilityOwner.name, ",", c2.abilityOwner.name);
                _beInCollisionCache.Add(new CollisionPairInfo(me, other));
                return(true);
            }

            return(false);
        }
Example #3
0
 private void ProcessCollisionExit(CollisionAbility other)
 {
     if (CanCollideWith(other))
     {
         OnGameCollisionExit?.Invoke(other);
     }
 }
 public bool isEqual(CollisionAbility c1, CollisionAbility c2)
 {
     if ((_c1 == c1 && _c2 == c2) || (_c1 == c2 && _c2 == c1))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Example #5
0
        private void OnCollisionEnter(Collision other)
        {
            if (!HasInit || other == null)
            {
                return;
            }
            if (Is2DMode)
            {
                return;
            }

            CollisionAbility ca = other.gameObject.GetComponent <CollisionAbility>();

            ProcessCollisionEnter(ca);
        }
        public bool CanPassTypeTest(CollisionAbility me, CollisionAbility other)
        {
            if (me == null || other == null)
            {
                return(false);
            }

            if (_collisionConfig != null)
            {
                return(_collisionConfig[(int)me.Type, (int)other.Type]);
            }
            else
            {
                ZLog.warn("no collison config file attached.");
                return(true);
            }
        }
Example #7
0
        private void OnTriggerExit2D(Collider2D other)
        {
            if (!HasInit || other == null)
            {
                return;
            }
            if (!Is2DMode)
            {
                return;
            }

            if (CanReceiveBothCollisionAndTrigger)
            {
                CollisionAbility ca = other.gameObject.GetComponent <CollisionAbility>();
                ProcessCollisionExit(ca);
            }
        }
 public bool has(CollisionAbility c)
 {
     return(_c1 == c || _c2 == c);
 }
 public CollisionPairInfo(CollisionAbility c1, CollisionAbility c2)
 {
     _c1 = c1;
     _c2 = c2;
 }