示例#1
0
    /// <summary>
    /// Check if angle of hit point is in range of recoil
    /// </summary>
    /// <param name="hitInfo"></param>
    /// <returns></returns>
    protected virtual bool InRecoilRange(vHitInfo hitInfo)
    {
        var center = new Vector3(transform.position.x, hitInfo.hitPoint.y, transform.position.z);
        var euler  = (Quaternion.LookRotation(hitInfo.hitPoint - center).eulerAngles - transform.eulerAngles).NormalizeAngle();

        return(euler.y <= hitProperties.recoilRange);
    }
示例#2
0
    /// <summary>
    /// Listener of Damage Event
    /// </summary>
    /// <param name="hitInfo"></param>
    public virtual void OnDamageHit(vHitInfo hitInfo)
    {
        vDamage damage = new vDamage(hitInfo.attackObject.damage);

        damage.sender      = transform;
        damage.reaction_id = currentReactionID;
        damage.recoil_id   = currentRecoilID;
        if (this.activeRagdoll)
        {
            damage.activeRagdoll = this.activeRagdoll;
        }
        if (this.attackName != string.Empty)
        {
            damage.attackName = this.attackName;
        }
        if (this.ignoreDefense)
        {
            damage.ignoreDefense = this.ignoreDefense;
        }
        /// Calc damage with multiplier
        /// and Call ApplyDamage of attackObject
        damage.damageValue *= damageMultiplier > 1 ? damageMultiplier : 1;
        hitInfo.attackObject.ApplyDamage(hitInfo.hitBox, hitInfo.targetCollider, damage);
        onDamageHit.Invoke(hitInfo);
    }
示例#3
0
 public void PlayHitEffects(vHitInfo hitInfo)
 {
     if (audioSource != null && hitSounds.Length > 0)
     {
         var clip     = hitSounds[UnityEngine.Random.Range(0, hitSounds.Length)];
         var audioObj = Instantiate(audioSource, transform.position, transform.rotation) as GameObject;
         audioObj.GetComponent <AudioSource>().PlayOneShot(clip);
     }
 }
示例#4
0
 /// <summary>
 /// Listener of Recoil Event
 /// </summary>
 /// <param name="hitInfo"></param>
 public virtual void OnRecoilHit(vHitInfo hitInfo)
 {
     if (hitProperties.useRecoil && InRecoilRange(hitInfo) && !inRecoil)
     {
         inRecoil = true;
         var id = currentRecoilID;
         fighter.OnRecoil(id);
         onRecoilHit.Invoke(hitInfo);
         Invoke("ResetRecoil", 1f);
     }
 }
示例#5
0
 public void PlayRecoilEffects(vHitInfo hitInfo)
 {
     if (audioSource != null && recoilSounds.Length > 0)
     {
         var clip     = recoilSounds[UnityEngine.Random.Range(0, recoilSounds.Length)];
         var audioObj = Instantiate(audioSource, transform.position, transform.rotation) as GameObject;
         audioObj.GetComponent <AudioSource>().PlayOneShot(clip);
     }
     if (recoilParticles.Length > 0)
     {
         var particles   = recoilParticles[UnityEngine.Random.Range(0, recoilParticles.Length)];
         var hitrotation = Quaternion.LookRotation(new Vector3(transform.position.x, hitInfo.hitPoint.y, transform.position.z) - hitInfo.hitPoint);
         if (particles != null)
         {
             Instantiate(particles, hitInfo.hitPoint, hitrotation);
         }
     }
 }
示例#6
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);
                }
            }
        }
    }