Esempio n. 1
0
 private void Cleanup()
 {
     if (this.def.subSounds.Count > 0)
     {
         Find.SoundRoot.sustainerManager.DeregisterSustainer(this);
         for (int i = 0; i < this.subSustainers.Count; i++)
         {
             this.subSustainers[i].Cleanup();
         }
     }
     if (this.def.sustainStopSound != string.Empty)
     {
         if ((Object)this.worldRootObject != (Object)null)
         {
             Map map = this.info.Maker.Map;
             if (map != null)
             {
                 SoundInfo soundInfo = SoundInfo.InMap(new TargetInfo(this.worldRootObject.transform.position.ToIntVec3(), map, false), MaintenanceType.None);
                 SoundDef.Named(this.def.sustainStopSound).PlayOneShot(soundInfo);
             }
         }
         else
         {
             SoundDef.Named(this.def.sustainStopSound).PlayOneShot(SoundInfo.OnCamera(MaintenanceType.None));
         }
     }
     if ((Object)this.worldRootObject != (Object)null)
     {
         Object.Destroy(this.worldRootObject);
     }
     DebugSoundEventsLog.Notify_SustainerEnded(this, this.info);
 }
Esempio n. 2
0
 public static void Notify_SoundEvent(SoundDef def, SoundInfo info)
 {
     if (DebugViewSettings.writeSoundEventsRecord)
     {
         string str  = (def != null) ? ((!def.isUndefined) ? ((!def.sustain) ? "OneShot: " : "SustainerSpawn: ") : "Undefined: ") : "null: ";
         string str2 = (def == null) ? "null" : def.defName;
         string str3 = str + str2 + " - " + info.ToString();
         DebugSoundEventsLog.CreateRecord(str3);
     }
 }
Esempio n. 3
0
        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);
        }
Esempio n. 5
0
        public static void Notify_SustainerEnded(Sustainer sustainer, SoundInfo info)
        {
            string str = "SustainerEnd: " + sustainer.def.defName + " - " + info.ToString();

            DebugSoundEventsLog.CreateRecord(str);
        }