Example #1
0
    public static void Play(this SFXOneShot container, Vector3 position)
    {
        if (container == null)
        {
            return;
        }

        if (container.Clips == null)
        {
            return;
        }

        if ((container.Chance < 0.99f) && (UnityEngine.Random.value > container.Chance))
        {
            return;
        }

        if (container.Interval > 0)
        {
            var t = Time.time;

            if (container.NextPlayTime > t)
            {
                return;
            }
            else
            {
                container.NextPlayTime = t + container.Interval;
            }
        }

        SFXOneShotPool.Play(container, position);
    }
Example #2
0
 public static void Play(this SFXOneShot container, Transform transform)
 {
     if (transform)
     {
         Play(container, transform.position);
     }
 }
Example #3
0
 public static void Play(this SFXOneShot container, GameObject gameObject)
 {
     if (gameObject)
     {
         Play(container, gameObject.transform.position);
     }
 }
Example #4
0
    IEnumerator AttackRoutine(float beforeDelay, float activeDuration, float endDelay,
                              SFXOneShot sfx, GameObject collisionObject, string animationName)
    {
        // start animation before hit, in case there's windup
        _playerAnimator.PlayAnimation(animationName);
        MeleeAttackState = MeleeAttackState.BeforeAttack;
        yield return(new WaitForSeconds(beforeDelay));

        MeleeAttackState = MeleeAttackState.DuringAttack;
        AttackActivated?.Invoke(EquippedWeapon);
        //TODO: check/deal damage here
        CurrentWeaponCollision.SetActive(true);
        //_weaponAnimator.Play(animationName);
        sfx.PlayOneShot(transform.position);
        yield return(new WaitForSeconds(activeDuration));

        CurrentWeaponCollision.SetActive(false);
        AttackDeactivated?.Invoke();

        MeleeAttackState = MeleeAttackState.AfterAttack;
        //_weaponAnimator.Stop();
        //TODO: this could be a window for followup/combo attacks
        yield return(new WaitForSeconds(endDelay));

        MeleeAttackState = MeleeAttackState.NotAttacking;
        AttackCompleted?.Invoke();
    }
Example #5
0
 public static void Play(this SFXOneShot container, Component component)
 {
     if (component)
     {
         Play(container, component.transform.position);
     }
 }
 public static void Play(SFXOneShot oneshot, Vector3 position)
 {
     if (Instance)
     {
         Instance.PlayInstance(oneshot, position);
     }
 }
Example #7
0
    public void BounceAttack(MeleeAttack meleeAttack, SFXOneShot hitSound)
    {
        if (meleeAttack == null)
        {
            return;
        }

        CurrentMeleeAttack     = meleeAttack;
        CurrentWeaponCollision = _bounceAttackCollision;

        if (_attackRoutine != null)
        {
            StopCoroutine(_attackRoutine);
        }
        _attackRoutine = StartCoroutine(AttackRoutine(meleeAttack.StartDelay, meleeAttack.ActiveDuration,
                                                      meleeAttack.EndDelay, hitSound, _bounceAttackCollision, PlayerAnimator.BounceAttackName));
    }
Example #8
0
    public void StandardAttack(MeleeAttack meleeAttack, SFXOneShot hitSound, bool isInitialAttack)
    {
        if (meleeAttack == null)
        {
            return;
        }
        // if it's a combo, progress the counter, if not, start over
        if (isInitialAttack)
        {
            AttackCount = 1;
        }
        else
        {
            AttackCount++;
        }

        CurrentMeleeAttack     = meleeAttack;
        CurrentWeaponCollision = _standardAttackCollision;

        string animationName;

        if (AttackCount == EquippedWeapon.MaxComboCount)
        {
            animationName = PlayerAnimator.GroundFinisherName;
        }
        // otherwise, alternate hit sprites
        else if (AttackCount % 2 == 0)
        {
            animationName = PlayerAnimator.GroundAttack02Name;
        }
        else
        {
            animationName = PlayerAnimator.GroundAttack01Name;
        }
        // do the gameplay sequence
        if (_attackRoutine != null)
        {
            StopCoroutine(_attackRoutine);
        }
        _attackRoutine = StartCoroutine(AttackRoutine(meleeAttack.StartDelay, meleeAttack.ActiveDuration,
                                                      meleeAttack.EndDelay, hitSound, _standardAttackCollision, animationName));
    }
    void PlayInstance(SFXOneShot oneshot, Vector3 position)
    {
        if (_sourceActiveList == null)
        {
            _sourceActiveList = new List <SFXOneShotPoolSource>();
        }

        AudioClip clip;

        if (oneshot.Clips.TryPickRandom(out clip))
        {
            var src = GetSource();

            src.AudioSource.clip                  = clip;
            src.AudioSource.pitch                 = oneshot.Pitch.GetRandom();
            src.AudioSource.volume                = oneshot.Volume;
            src.AudioSource.spatialBlend          = oneshot.SpatialBlend;
            src.AudioSource.outputAudioMixerGroup = oneshot.Output;

            if (oneshot.PlayDelay > 0)
            {
                src.Delay = oneshot.PlayDelay * 1.1f;
                src.AudioSource.PlayDelayed(oneshot.PlayDelay);
            }
            else
            {
                src.Delay = 0;
                src.AudioSource.Play();
            }

            // set position
            src.transform.position = position;

            // add to active list
            _sourceActiveList.Add(src);
        }
    }
Example #10
0
 public static void Play(this SFXOneShot container)
 {
     Play(container, Vector3.zero);
 }