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); }
public void Play() { var s = AudioSourcePool.GetSource(); Play(s, false); AudioSourcePool.ReturnSourceWhenDone(s); }
protected override void Awake() { base.Awake(); audioSourcePool = new Queue <AudioSource>(); instance = this; AllocPool(); }
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; } }
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(); } }
private void Awake() { if (instance == null) { instance = this; PrepareAudioSources(); } else { Destroy(gameObject); } }
void Awake() { if (Instance == null) { Instance = this; DontDestroyOnLoad(this); } else { DestroyImmediate(this); } }
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); }
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); }
public void Play() { if (audioSourcePool == null) { audioSourcePool = FindObjectOfType <AudioSourcePool>(); } AudioSource source = audioSourcePool.GetSource(); source.transform.position = Vector3.zero; source.spatialBlend = 0; Play(source); }
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); }
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); } }
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); } }
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); }
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); } }
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; }
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); } } } }
private void Awake() { Instance = this; }
// Use this for initialization void Awake() { _instance = this; InitSources(); }
public SoundRoot() { this.sourcePool = new AudioSourcePool(); this.sustainerManager = new SustainerManager(); this.oneShotManager = new SampleOneShotManager(); }
private void Awake() { _audioSourcePool = GetComponent <AudioSourcePool>(); _musicPlayer = GetComponent <BackgroundMusicPlayer>(); }
void Start() { _pool = new AudioSourcePool(prefab.GetComponent <AudioSource>()); }
private void OnEnable() { timeStamp = -Cooldown; audioSourcePool = FindObjectOfType <AudioSourcePool>(); }
private void Awake() { current = this; }
private void Awake() { Instance = this; audioSources = new List <AudioSource>(); }
void Start() { prefab = new GameObject(); prefab.AddComponent <AudioSource>(); _pool = new AudioSourcePool(prefab.GetComponent <AudioSource>()); }
public void CloseDoor() { //TODO Make Close sound AudioSourcePool.PlayAtPoint(doorSounds.DoorClose, transform.position); AnimateDoors("Open", false); }