public static SampleSustainer TryMakeAndPlay(SubSustainer subSus, AudioClip clip, float scheduledEndTime) { SampleSustainer sampleSustainer = new SampleSustainer(subSus.subDef); sampleSustainer.subSustainer = subSus; sampleSustainer.scheduledEndTime = scheduledEndTime; GameObject gameObject = new GameObject(string.Concat(new object[] { "SampleSource_", sampleSustainer.subDef.name, "_", sampleSustainer.startRealTime })); GameObject gameObject2 = (!subSus.subDef.onCamera) ? subSus.parent.worldRootObject : Find.Camera.gameObject; gameObject.transform.parent = gameObject2.transform; gameObject.transform.localPosition = Vector3.zero; sampleSustainer.source = AudioSourceMaker.NewAudioSourceOn(gameObject); SampleSustainer result; if (sampleSustainer.source == null) { if (gameObject != null) { UnityEngine.Object.Destroy(gameObject); } result = null; } else { sampleSustainer.source.clip = clip; sampleSustainer.source.volume = sampleSustainer.SanitizedVolume; sampleSustainer.source.pitch = sampleSustainer.SanitizedPitch; sampleSustainer.source.minDistance = sampleSustainer.subDef.distRange.TrueMin; sampleSustainer.source.maxDistance = sampleSustainer.subDef.distRange.TrueMax; sampleSustainer.source.spatialBlend = 1f; List <SoundFilter> filters = sampleSustainer.subDef.filters; for (int i = 0; i < filters.Count; i++) { filters[i].SetupOn(sampleSustainer.source); } if (sampleSustainer.subDef.sustainLoop) { sampleSustainer.source.loop = true; } sampleSustainer.Update(); sampleSustainer.source.Play(); sampleSustainer.source.Play(); result = sampleSustainer; } return(result); }
public AudioSourcePoolWorld() { GameObject gameObject = new GameObject("OneShotSourcesWorldContainer"); gameObject.transform.position = Vector3.zero; for (int i = 0; i < 32; i++) { GameObject gameObject2 = new GameObject("OneShotSource_" + i.ToString()); gameObject2.transform.parent = gameObject.transform; gameObject2.transform.localPosition = Vector3.zero; sourcesWorld.Add(AudioSourceMaker.NewAudioSourceOn(gameObject2)); } }
public AudioSourcePoolCamera() { cameraSourcesContainer = new GameObject("OneShotSourcesCameraContainer"); cameraSourcesContainer.transform.parent = Find.Camera.transform; cameraSourcesContainer.transform.localPosition = Vector3.zero; for (int i = 0; i < 16; i++) { GameObject gameObject = new GameObject("OneShotSourceCamera_" + i); gameObject.transform.parent = cameraSourcesContainer.transform; gameObject.transform.localPosition = Vector3.zero; AudioSource audioSource = AudioSourceMaker.NewAudioSourceOn(gameObject); audioSource.bypassReverbZones = true; sourcesCamera.Add(audioSource); } }
public AudioSourcePoolCamera() { this.cameraSourcesContainer = new GameObject("OneShotSourcesCameraContainer"); this.cameraSourcesContainer.transform.parent = Find.Camera.transform; this.cameraSourcesContainer.transform.localPosition = Vector3.zero; for (int i = 0; i < 16; i++) { AudioSource audioSource = AudioSourceMaker.NewAudioSourceOn(new GameObject("OneShotSourceCamera_" + i.ToString()) { transform = { parent = this.cameraSourcesContainer.transform, localPosition = Vector3.zero } }); audioSource.bypassReverbZones = true; this.sourcesCamera.Add(audioSource); } }
public AudioSourcePoolWorld() { GameObject gameObject = new GameObject("OneShotSourcesWorldContainer") { transform = { position = Vector3.zero } }; for (int i = 0; i < 32; i++) { GameObject go = new GameObject("OneShotSource_" + i.ToString()) { transform = { parent = gameObject.transform, localPosition = Vector3.zero } }; this.sourcesWorld.Add(AudioSourceMaker.NewAudioSourceOn(go)); } }