public static void PlayOneShot(this SoundDef soundDef, SoundInfo info) { if (!UnityData.IsInMainThread) { return; } if (soundDef == null) { Log.Error("Tried to PlayOneShot with null SoundDef. Info=" + info); return; } DebugSoundEventsLog.Notify_SoundEvent(soundDef, info); if (soundDef == null) { return; } if (soundDef.isUndefined) { if (Prefs.DevMode && Find.WindowStack.IsOpen(typeof(EditWindow_DefEditor))) { DefDatabase <SoundDef> .Clear(); DefDatabase <SoundDef> .AddAllInMods(); SoundDef soundDef2 = SoundDef.Named(soundDef.defName); if (!soundDef2.isUndefined) { soundDef2.PlayOneShot(info); } } return; } if (soundDef.sustain) { Log.Error("Tried to play sustainer SoundDef " + soundDef + " as a one-shot sound."); return; } if (!SoundSlotManager.CanPlayNow(soundDef.slot)) { return; } for (int i = 0; i < soundDef.subSounds.Count; i++) { soundDef.subSounds[i].TryPlay(info); } }
public static Sustainer TrySpawnSustainer(this SoundDef soundDef, SoundInfo info) { DebugSoundEventsLog.Notify_SoundEvent(soundDef, info); Sustainer result; if (soundDef == null) { result = null; } else if (soundDef.isUndefined) { if (Prefs.DevMode && Find.WindowStack.IsOpen(typeof(EditWindow_DefEditor))) { DefDatabase <SoundDef> .Clear(); DefDatabase <SoundDef> .AddAllInMods(); SoundDef soundDef2 = SoundDef.Named(soundDef.defName); if (!soundDef2.isUndefined) { return(soundDef2.TrySpawnSustainer(info)); } } result = null; } else if (!soundDef.sustain) { Log.Error("Tried to spawn a sustainer from non-sustainer sound " + soundDef + ".", false); result = null; } else if (!info.IsOnCamera && info.Maker.Thing != null && info.Maker.Thing.Destroyed) { result = null; } else { if (soundDef.sustainStartSound != null) { soundDef.sustainStartSound.PlayOneShot(info); } result = new Sustainer(soundDef, info); } return(result); }