示例#1
0
    /// <summary>
    /// Call Back of hitboxes
    /// </summary>
    /// <param name="hitBox">vHitBox object</param>
    /// <param name="other">target Collider</param>
    public virtual void OnHit(vHitBox hitBox, Collider other)
    {
        //Check  first contition for hit
        if (canApplyDamage && !targetColliders[hitBox].Contains(other.gameObject) && (meleeManager != null && other.gameObject != meleeManager.gameObject))
        {
            var inDamage = false;
            var inRecoil = false;
            if (meleeManager == null)
            {
                meleeManager = GetComponentInParent <vMeleeManager>();
            }
            //check if meleeManager exist and apply  his hitProperties  to this
            HitProperties _hitProperties = meleeManager.hitProperties;

            /// Damage Conditions
            if (((hitBox.triggerType & vHitBoxType.Damage) != 0) && _hitProperties.hitDamageTags == null || _hitProperties.hitDamageTags.Count == 0)
            {
                inDamage = true;
            }
            else if (((hitBox.triggerType & vHitBoxType.Damage) != 0) && _hitProperties.hitDamageTags.Contains(other.tag))
            {
                inDamage = true;
            }
            else   ///Recoil Conditions
            if (((hitBox.triggerType & vHitBoxType.Recoil) != 0) && (_hitProperties.hitRecoilLayer == (_hitProperties.hitRecoilLayer | (1 << other.gameObject.layer))))
            {
                inRecoil = true;
            }
            if (inDamage || inRecoil)
            {
                ///add target collider in list to control frequency of hit him
                targetColliders[hitBox].Add(other.gameObject);
                vHitInfo hitInfo = new vHitInfo(this, hitBox, other, hitBox.transform.position);
                if (inDamage == true)
                {
                    /// If meleeManager
                    /// call onDamageHit to control damage values
                    /// and  meleemanager will call the ApplyDamage after to filter the damage
                    /// if meleeManager is null
                    /// The damage will be  directly applied
                    /// Finally the OnDamageHit event is called
                    if (meleeManager)
                    {
                        meleeManager.OnDamageHit(hitInfo);
                    }
                    else
                    {
                        damage.sender = transform;
                        ApplyDamage(hitBox, other, damage);
                    }
                    onDamageHit.Invoke(hitInfo);
                }
                /// Recoil just work with OnRecoilHit event and meleeManger
                if (inRecoil == true)
                {
                    if (meleeManager)
                    {
                        meleeManager.OnRecoilHit(hitInfo);
                    }
                    onRecoilHit.Invoke(hitInfo);
                }
            }
        }
    }