Exemple #1
0
    public bool PlayRMS(AudioChannel channel, Vector3 pos, float rms, float pitch)
    {
        float num  = rms;
        float num2 = pitch;

        rms *= volumeAdjust;
        rms  = ((rndVolumeMin != rndVolumeMax) ? (rms * Random.Range(rndVolumeMin, rndVolumeMax)) : (rms * rndVolumeMin));
        if (!CanPlay(rms))
        {
            return(false);
        }
        pitch = ((rndPitchMin != rndPitchMax) ? (pitch * Random.Range(rndPitchMin, rndPitchMax)) : (pitch * rndPitchMin));
        int         num3        = Random.Range(0, clips.Length);
        AudioClip   audioClip   = clips[num3];
        float       volumeScale = rms / clipsRms[num3];
        AudioSource audioSource = AudioSourcePool.Allocate(poolId, null, pos);

        audioSource.pitch = pitch;
        audioSource.outputAudioMixerGroup = AudioRouting.GetChannel(channel);
        audioSource.volume = 1f;
        audioSource.PlayOneShot(audioClip, volumeScale);
        float time = Time.time;

        if (blockTime > 0f)
        {
            blockUntil = Mathf.Max(blockUntil, time + blockTime);
        }
        if (maxVoices > 0)
        {
            polyphonyBlockUntil.Add(time + audioClip.length);
            playingLoudness.Add(rms);
        }
        return(true);
    }
Exemple #2
0
    public void Play()
    {
        var s = AudioSourcePool.GetSource();

        Play(s, false);
        AudioSourcePool.ReturnSourceWhenDone(s);
    }
Exemple #3
0
 protected override void Awake()
 {
     base.Awake();
     audioSourcePool = new Queue <AudioSource>();
     instance        = this;
     AllocPool();
 }
Exemple #4
0
    void Awake()
    {
        if (instance == null)
        {
            instance = this;
        }
        else
        {
            Destroy(gameObject);
            return;
        }
        DontDestroyOnLoad(gameObject);

        foreach (AudioClipGroup audioClipGroup in Sounds)
        {
            audioClipGroup.AudioSource      = gameObject.AddComponent <AudioSource>();
            audioClipGroup.AudioSource.clip = audioClipGroup.Clip;

            audioClipGroup.Duration = audioClipGroup.AudioSource.clip.samples / audioClipGroup.AudioSource.clip.frequency;

            audioClipGroup.AudioSource.volume = audioClipGroup.Volume;
            audioClipGroup.AudioSource.pitch  = audioClipGroup.Pitch;
            audioClipGroup.AudioSource.loop   = audioClipGroup.Loop;
        }
    }
Exemple #5
0
    public void Play2D(float pan = 0)
    {
        var s = AudioSourcePool.GetSource();

        s.spatialBlend = 0;
        Play(s, false, pan);
        AudioSourcePool.ReturnSourceWhenDone(s);
    }
 public void Play()
 {
     if (_pool == null)
     {
         _pool = FindObjectOfType <AudioSourcePool>();
     }
     Play(_pool.GetSource());
 }
 //Create Singleton
 private void Awake()
 {
     if (instance == null)
     {
         instance = this;
     }
     else if (instance != null)
     {
         Destroy(gameObject);
     }
 }
 private void Awake()
 {
     channelsSFX   = new AudioSourcePool(gameObject, groupSFX, channelCountSFX);
     channelsMusic = new AudioSourcePool(gameObject, groupMusic, channelCountMusic,
                                         true, 0.0f);
     groupsMusic = new MusicGroup[groupCountMusic];
     for (int i = 0; i < groupCountMusic; ++i)
     {
         groupsMusic[i] = new MusicGroup();
     }
 }
Exemple #9
0
 private void Awake()
 {
     if (instance == null)
     {
         instance = this;
         PrepareAudioSources();
     }
     else
     {
         Destroy(gameObject);
     }
 }
Exemple #10
0
 void Awake()
 {
     if (Instance == null)
     {
         Instance = this;
         DontDestroyOnLoad(this);
     }
     else
     {
         DestroyImmediate(this);
     }
 }
Exemple #11
0
    public void Play(Vector3 location)
    {
        if (!audioSourcePool)
        {
            audioSourcePool = FindObjectOfType <AudioSourcePool>();
        }
        AudioSource source = audioSourcePool.GetSource();

        source.transform.position = location;
        source.transform.SetParent(null);
        source.spatialBlend = 1;
        Play(source);
    }
Exemple #12
0
    private void LoadSources(Transform parent, string path)
    {
        AudioSource[] array = Resources.LoadAll <AudioSource>(path);

        foreach (var source in array)
        {
            var pool = new AudioSourcePool();
            pool.Init(source, max, parent);

            sources.Add(source.name, pool);
        }
        //Debug.Log(sources.Count);
    }
Exemple #13
0
    public void Play()
    {
        if (audioSourcePool == null)
        {
            audioSourcePool = FindObjectOfType <AudioSourcePool>();
        }

        AudioSource source = audioSourcePool.GetSource();

        source.transform.position = Vector3.zero;
        source.spatialBlend       = 0;
        Play(source);
    }
Exemple #14
0
    public void Play(Transform transform)
    {
        if (!audioSourcePool)
        {
            audioSourcePool = FindObjectOfType <AudioSourcePool>();
        }
        AudioSource source = audioSourcePool.GetSource();

        source.transform.position = Vector3.zero;
        source.transform.SetParent(transform);
        source.spatialBlend = 1;

        Play(source);
    }
Exemple #15
0
 public virtual void OpenDoor(int KeyValue)
 {
     if (!IsLocked || (IsLocked && KeyValue == keyValue))
     {
         //TODO Make success sound
         AudioSourcePool.PlayAtPoint(doorSounds.KeyInsert, transform.position);
         AudioSourcePool.PlayAtPoint(doorSounds.DoorUnlock, transform.position);
         OpenDoor();
     }
     else
     {
         //TODO Make failure Sound
         AudioSourcePool.PlayAtPoint(doorSounds.DoorLocked, transform.position);
     }
 }
Exemple #16
0
 public void PickDoor(int lockpickValue)
 {
     updateTimer = 0;
     if (lockpickValues.Length > 0)
     {
         if (tumblerPos == lockpickValues.Length)
         {
             //TODO Make unlock sound
             AudioSourcePool.PlayAtPoint(doorSounds.DoorUnlock, transform.position);
             OpenDoor();
             tumblerPos = 0;
             oldTimer   = lockPicktimer = 0;
         }
         else if (lockpickValue == lockpickValues[tumblerPos])
         {
             lockPicktimer += Time.deltaTime;
             if (lockPicktimer > timeToLockpick)
             {
                 //TODO Make success sound
                 AudioSourcePool.PlayAtPoint(doorSounds.KeyInsert, transform.position);
                 tumblerPos++;
                 lockPicktimer = 0;
             }
             else
             {
                 //TODO Make lockpicking sound
                 AudioSourcePool.PlayAtPoint(doorSounds.LockPicking, transform.position);
             }
         }
         else
         {
             lockPicktimer = 0;
             //TODO Make failure Sound
         }
     }
     else if (!IsLocked)
     {
         OpenDoor();
     }
     else
     {
         //TODO Make failure Sound
         AudioSourcePool.PlayAtPoint(doorSounds.KeyRemove, transform.position);
     }
 }
Exemple #17
0
    void Awake()
    {
        if (I != null)
        {
            Destroy(gameObject);
            return;
        }
        I = this;

        audioSourcePool = new AudioSourcePool(64);

        foreach (var snd in soundLib.sounds)
        {
            soundDict.Add(snd.name, snd);
        }

        DontDestroyOnLoad(gameObject);
    }
Exemple #18
0
 void Start()
 {
     if (!instance)
     {
         instance = this;
     }
     else
     {
         Destroy(this);
     }
     _sources = new Queue <AudioSource>();
     for (int i = 0; i < capacity; i++)
     {
         var source = Instantiate(sourcePrefab).GetComponent <AudioSource>();
         source.volume           = sourceVolume;
         source.transform.parent = transform;
         _sources.Enqueue(source);
     }
 }
Exemple #19
0
    private void Update()
    {
        if (tumblerPos != 0 || (System.Math.Abs(oldTimer) > 0 && System.Math.Abs(oldTimer - lockPicktimer) < 0.01))
        {
            updateTimer += Time.deltaTime;
            if (updateTimer > 1.3f)
            {
                lockPicktimer = 0;
                //TODO Make failure Sound
                AudioSourcePool.PlayAtPoint(doorSounds.KeyRemove, transform.position);
                tumblerPos = 0;
            }
        }
        else
        {
            updateTimer = 0;
        }

        oldTimer = lockPicktimer;
    }
Exemple #20
0
 public void PlaySound(bool state, string name, bool loop, AudioClip clip, Vector3 pos)
 {
     if (_globalSoundsState)
     {
         if (state)
         {
             AudioSource source;
             if (_lib.ContainsKey(name))
             {
                 source = _lib[name];
                 if (!source.gameObject.active)
                 {
                     _lib.Remove(name);
                     PlaySound(state, name, loop, clip, pos);
                     return;
                 }
             }
             else
             {
                 source = AudioSourcePool.GetInstance().GetAudioSource();
                 source.transform.position = pos;
                 _lib.Add(name, source);
             }
             source.clip = clip;
             source.loop = loop;
             source.Play(0);
         }
         else
         {
             if (_lib.ContainsKey(name))
             {
                 AudioSource source = _lib[name];
                 source.Stop();
                 AudioSourcePool.GetInstance().DestroyAudioSource(source);
                 _lib.Remove(name);
             }
         }
     }
 }
Exemple #21
0
 private void Awake()
 {
     Instance = this;
 }
 // Use this for initialization
 void Awake()
 {
     _instance = this;
     InitSources();
 }
Exemple #23
0
 public SoundRoot()
 {
     this.sourcePool       = new AudioSourcePool();
     this.sustainerManager = new SustainerManager();
     this.oneShotManager   = new SampleOneShotManager();
 }
Exemple #24
0
 private void Awake()
 {
     _audioSourcePool = GetComponent <AudioSourcePool>();
     _musicPlayer     = GetComponent <BackgroundMusicPlayer>();
 }
Exemple #25
0
 void Start()
 {
     _pool = new AudioSourcePool(prefab.GetComponent <AudioSource>());
 }
Exemple #26
0
 private void OnEnable()
 {
     timeStamp       = -Cooldown;
     audioSourcePool = FindObjectOfType <AudioSourcePool>();
 }
Exemple #27
0
 private void Awake()
 {
     current = this;
 }
Exemple #28
0
 private void Awake()
 {
     Instance     = this;
     audioSources = new List <AudioSource>();
 }
Exemple #29
0
 void Start()
 {
     prefab = new GameObject();
     prefab.AddComponent <AudioSource>();
     _pool = new AudioSourcePool(prefab.GetComponent <AudioSource>());
 }
Exemple #30
0
 public void CloseDoor()
 {
     //TODO Make Close sound
     AudioSourcePool.PlayAtPoint(doorSounds.DoorClose, transform.position);
     AnimateDoors("Open", false);
 }