Example #1
0
    public AudioSourceController Play()
    {
        AudioSourceController controller = AudioPoolManager.Instance.GetController();

        controller.SetSourceProperties(GetClip(), volume, pitch, loop, spacialBlend);
        controller.Category = Category;
        controller.Play();

        return(controller);
    }
Example #2
0
    public AudioSourceController Play(Vector3 position)
    {
        controller = AudioPoolManager.Instance.GetController();
        float volGen   = AudioUtils.DecibelToLinear(Volume + Random.Range(RandomVolume, 0));
        float pitchVar = (RandomPitch / 2);
        float pitchGen = AudioUtils.St2pitch(Random.Range(Pitch - pitchVar, Pitch + pitchVar));

        controller.SetSourceProperties(GetClip(), volGen, pitchGen, Loop, SpatialBlend);
        controller.SetPosition(position);
        controller.Play();
        return(controller);
    }
Example #3
0
    // Returns length of random clip just played
    private float PlayRandomClip(SFXScriptableObject sfxSO, Vector3 pos)
    {
        asc = GetController();
        var audioClipArraySize = sfxSO.audioClips.Length;

        if (audioClipArraySize == 0)
        {
            Debug.LogError("Please set audio clip(s) on " + sfxSO.name + " scriptable object.");
            return(0);
        }

        AudioClip clip = sfxSO.audioClips[Random.Range(0, audioClipArraySize)];

        if (asc != null)
        {
            asc.SetPosition(pos);
            asc.SetSourceProperties(clip, sfxSO.volume, sfxSO.pitch, sfxSO.loop);
            asc.Play();
        }
        return(clip.length);
    }