public static SampleOneShot TryMakeAndPlay(SubSoundDef def, AudioClip clip, SoundInfo info) { SampleOneShot result; if ((double)info.pitchFactor <= 0.0001) { Log.ErrorOnce(string.Concat(new object[] { "Played sound with pitchFactor ", info.pitchFactor, ": ", def, ", ", info }), 632321, false); result = null; } else { SampleOneShot sampleOneShot = new SampleOneShot(def); sampleOneShot.info = info; sampleOneShot.source = Find.SoundRoot.sourcePool.GetSource(def.onCamera); if (sampleOneShot.source == null) { result = null; } else { sampleOneShot.source.clip = clip; sampleOneShot.source.volume = sampleOneShot.SanitizedVolume; sampleOneShot.source.pitch = sampleOneShot.SanitizedPitch; sampleOneShot.source.minDistance = sampleOneShot.subDef.distRange.TrueMin; sampleOneShot.source.maxDistance = sampleOneShot.subDef.distRange.TrueMax; if (!def.onCamera) { sampleOneShot.source.gameObject.transform.position = info.Maker.Cell.ToVector3ShiftedWithAltitude(0f); sampleOneShot.source.minDistance = def.distRange.TrueMin; sampleOneShot.source.maxDistance = def.distRange.TrueMax; sampleOneShot.source.spatialBlend = 1f; } else { sampleOneShot.source.spatialBlend = 0f; } for (int i = 0; i < def.filters.Count; i++) { def.filters[i].SetupOn(sampleOneShot.source); } foreach (KeyValuePair <string, float> keyValuePair in info.DefinedParameters) { sampleOneShot.externalParams[keyValuePair.Key] = keyValuePair.Value; } sampleOneShot.Update(); sampleOneShot.source.Play(); Find.SoundRoot.oneShotManager.TryAddPlayingOneShot(sampleOneShot); result = sampleOneShot; } } return(result); }
public Sample(SubSoundDef def) { subDef = def; resolvedVolume = def.RandomizedVolume(); resolvedPitch = def.pitchRange.RandomInRange; startRealTime = Time.realtimeSinceStartup; if (Current.ProgramState == ProgramState.Playing) { startTick = Find.TickManager.TicksGame; } else { startTick = 0; } foreach (SoundParamTarget_Volume item in subDef.paramMappings.Select((SoundParameterMapping m) => m.outParam).OfType <SoundParamTarget_Volume>()) { volumeInMappings.Add(item, 0f); } }
public Sample(SubSoundDef def) { this.subDef = def; this.resolvedVolume = def.RandomizedVolume(); this.resolvedPitch = def.pitchRange.RandomInRange; this.startRealTime = Time.realtimeSinceStartup; if (Current.ProgramState == ProgramState.Playing) { this.startTick = Find.TickManager.TicksGame; } else { this.startTick = 0; } foreach (SoundParamTarget_Volume key in (from m in this.subDef.paramMappings select m.outParam).OfType <SoundParamTarget_Volume>()) { this.volumeInMappings.Add(key, 0f); } }
public SubSustainer(Sustainer parent, SubSoundDef subSoundDef) { this.parent = parent; this.subDef = subSoundDef; LongEventHandler.ExecuteWhenFinished(delegate { this.creationFrame = Time.frameCount; this.creationRealTime = Time.realtimeSinceStartup; if (Current.ProgramState == ProgramState.Playing) { this.creationTick = Find.TickManager.TicksGame; } if (this.subDef.startDelayRange.TrueMax < 0.001f) { this.StartSample(); } else { this.nextSampleStartTime = Time.realtimeSinceStartup + this.subDef.startDelayRange.RandomInRange; } }); }
private SampleOneShot(SubSoundDef def) : base(def) { }
private SampleSustainer(SubSoundDef def) : base(def) { }