public static bool PlayOneShot(SoundDef soundDef, SoundInfo info) { if (UnityData.IsInMainThread) { return(true); } if (soundDef == null) { Log.Error("Tried to PlayOneShot with null SoundDef. Info=" + info, false); return(false); } DebugSoundEventsLog.Notify_SoundEvent(soundDef, info); if (soundDef == null) { return(false); } if (soundDef.isUndefined) { return(false); } if (soundDef.sustain) { Log.Error("Tried to play sustainer SoundDef " + soundDef + " as a one-shot sound.", false); return(false); } for (int i = 0; i < soundDef.subSounds.Count; i++) { RimThreaded.PlayOneShot.Enqueue(new Tuple <SoundDef, SoundInfo>(soundDef, info)); } // Don't know why but if this is set to false, threads will hang and timeout. return(true); }
public static bool Cleanup(Sustainer __instance) { if (__instance.def.subSounds.Count > 0) { Find.SoundRoot.sustainerManager.DeregisterSustainer(__instance); lock (subSustainers(__instance)) { for (int index = 0; index < subSustainers(__instance).Count; ++index) { subSustainers(__instance)[index].Cleanup(); } } } if (__instance.def.sustainStopSound != null) { lock (worldRootObject(__instance)) { if (worldRootObject(__instance) != null) { Map map = __instance.info.Maker.Map; if (map != null) { __instance.def.sustainStopSound.PlayOneShot(SoundInfo.InMap(new TargetInfo(worldRootObject(__instance).transform.position.ToIntVec3(), map, false), MaintenanceType.None)); } } else { __instance.def.sustainStopSound.PlayOneShot(SoundInfo.OnCamera(MaintenanceType.None)); } } if (worldRootObject(__instance) != null) { UnityEngine.Object.Destroy(worldRootObject(__instance)); } } DebugSoundEventsLog.Notify_SustainerEnded(__instance, __instance.info); return(false); }