public bool OnCollision(Collider2D _collider)
    {
        var _shouldDecay = true;

        if ((LayerHelper.Exist(penetrationForced, _collider)))
        {
            _shouldDecay        = false;
            m_IsPenetrating     = true;
            m_IsPenetratingTemp = true;
            m_PenetrationTimer  = 0.1f;
            m_PenetratingObject = _collider.gameObject.GetInstanceID();

            if (effectPenetratePrf)
            {
                var _effect = (GameObject)Instantiate(effectPenetratePrf, transform.position, transform.rotation);
                _effect.transform.Translate(effectPenetrateOffset);
            }
        }
        else if (LayerHelper.Exist(reflectionMask, _collider))
        {
            _shouldDecay = reflectionCount == 0;
        }

        return(_shouldDecay);
    }
Example #2
0
    void OnTriggerEnter2D(Collider2D _collision)
    {
        if (LayerHelper.Exist(layerMask, _collision))
        {
            if (postDetect == null)
            {
                Debug.LogError(gameObject.name + " does not set terrain detector!");
                return;
            }

            postDetect(_collision);
        }
    }
Example #3
0
    void OnTriggerEnter2D(Collider2D _collider)
    {
        if (!enabled)
        {
            return;
        }

        if (LayerHelper.Exist(targetMask, _collider))
        {
            var detector = _collider.GetComponent <DamageDetector>();
            if (detector)
            {
                detector.Damage(attackData);
            }
        }
    }
    public bool OnCollision(Collider2D _collider)
    {
        bool _shouldDecay = false;

        if ((LayerHelper.Exist(penetrationForced, _collider)
             //				|| (penetration > _collider.hardness)
             ))
        {
            m_IsPenetrating     = true;
            m_IsPenetratingTemp = true;
            m_PenetrationTimer  = 0.1f;
            m_PenetratingObject = _collider.gameObject.GetInstanceID();
            _shouldDecay        = true;

            // todo: server
            if (effectPenetratePrf)
            {
                var _effect = GameObject.Instantiate(effectPenetratePrf, transform.position, transform.rotation) as GameObject;
                _effect.transform.Translate(effectPenetrateOffset);
            }
        }
        else if (reflectionCount > 0 &&
                 (LayerHelper.Exist(reflectionMask, _collider)
                  //		        || _collider.reflectable)
                 ))
        {
            --reflectionCount;
            Reflect(_collider);
            _shouldDecay = true;

            // todo: server
            if (effectReflectPrf)
            {
                var _effect = GameObject.Instantiate(effectReflectPrf, transform.position, transform.rotation) as GameObject;
                _effect.transform.Translate(effectReflectOffset);
            }
        }

        return(_shouldDecay);
    }
    void OnCollision(Collider2D _collider)
    {
        if (!activated)
        {
            return;
        }
        if (decaying)
        {
            return;
        }

        if (LayerHelper.Exist(collisionIgnores, _collider))
        {
            return;
        }

        if (m_Ricochet && !m_Ricochet.ShouldCollide(_collider))
        {
            return;
        }

        if (m_Ricochet)
        {
            if (!m_Ricochet.OnCollision(_collider))
            {
                StartDecay();
            }
        }
        else
        {
            StartDecay();
        }

        if (LayerHelper.Exist(collisionTargets, _collider))
        {
            var _damageDetector = _collider.GetComponentInChildren <DamageDetector>();

            if (!isHitOwner &&
                (_damageDetector.GetInstanceID() == ownerDetecterID))
            {
                return;
            }

            if (_damageDetector != null &&
                _damageDetector.enabled)
            {
                attackData.velocity = rigidbody2D.velocity;
                _damageDetector.Damage(attackData);
            }

            if (postHit != null)
            {
                postHit(this, _collider);
            }

            // todo: server를 통해서 이루어져야합니다.
            if (effectHitPrf)
            {
                var _effectHit = GameObject.Instantiate(effectHitPrf, transform.position, transform.rotation) as GameObject;
                _effectHit.transform.Translate(effectHitOffset);
            }
        }
        else if (LayerHelper.Exist(collisionTargets, _collider.gameObject))
        {
            if (postBumped != null)
            {
                postBumped(this, _collider);
            }
        }

        if (postCollide != null)
        {
            postCollide(this, _collider);
        }
    }