コード例 #1
0
 public static void PlayOneShotOnCamera(this SoundDef soundDef, Map onlyThisMap = null)
 {
     if (UnityData.IsInMainThread)
     {
         if (onlyThisMap != null)
         {
             if (Find.VisibleMap != onlyThisMap)
             {
                 return;
             }
             if (WorldRendererUtility.WorldRenderedNow)
             {
                 return;
             }
         }
         if (soundDef != null)
         {
             if (soundDef.subSounds.Count > 0)
             {
                 bool flag = false;
                 int  num  = 0;
                 while (num < soundDef.subSounds.Count)
                 {
                     if (!soundDef.subSounds[num].onCamera)
                     {
                         num++;
                         continue;
                     }
                     flag = true;
                     break;
                 }
                 if (!flag)
                 {
                     Log.Error("Tried to play " + soundDef + " on camera but it has no on-camera subSounds.");
                 }
             }
             soundDef.PlayOneShot(SoundInfo.OnCamera(MaintenanceType.None));
         }
     }
 }
コード例 #2
0
 public Sustainer(SoundDef def, SoundInfo info)
 {
     this.def  = def;
     this.info = info;
     if (def.subSounds.Count > 0)
     {
         foreach (KeyValuePair <string, float> keyValuePair in info.DefinedParameters)
         {
             this.externalParams[keyValuePair.Key] = keyValuePair.Value;
         }
         if (def.HasSubSoundsInWorld)
         {
             if (info.IsOnCamera)
             {
                 Log.Error("Playing sound " + def.ToString() + " on camera, but it has sub-sounds in the world.", false);
             }
             this.worldRootObject = new GameObject("SustainerRootObject_" + def.defName);
             this.UpdateRootObjectPosition();
         }
         else if (!info.IsOnCamera)
         {
             info = SoundInfo.OnCamera(info.Maintenance);
         }
         Find.SoundRoot.sustainerManager.RegisterSustainer(this);
         if (!info.IsOnCamera)
         {
             Find.SoundRoot.sustainerManager.UpdateAllSustainerScopes();
         }
         for (int i = 0; i < def.subSounds.Count; i++)
         {
             this.subSustainers.Add(new SubSustainer(this, def.subSounds[i]));
         }
     }
     LongEventHandler.ExecuteWhenFinished(delegate
     {
         this.lastMaintainTick  = Find.TickManager.TicksGame;
         this.lastMaintainFrame = Time.frameCount;
     });
 }
コード例 #3
0
ファイル: SubSoundDef.cs プロジェクト: potsh/RimWorld
 public virtual void TryPlay(SoundInfo info)
 {
     if (resolvedGrains.Count == 0)
     {
         Log.Error("Cannot play " + parentDef + " (subSound " + this + "_: No resolved grains.");
     }
     else if (Find.SoundRoot.oneShotManager.CanAddPlayingOneShot(parentDef, info))
     {
         ResolvedGrain      resolvedGrain      = RandomizedResolvedGrain();
         ResolvedGrain_Clip resolvedGrain_Clip = resolvedGrain as ResolvedGrain_Clip;
         if (resolvedGrain_Clip != null)
         {
             SampleOneShot sampleOneShot = SampleOneShot.TryMakeAndPlay(this, resolvedGrain_Clip.clip, info);
             if (sampleOneShot == null)
             {
                 return;
             }
             SoundSlotManager.Notify_Played(parentDef.slot, resolvedGrain_Clip.clip.length);
         }
         if (distinctResolvedGrainsCount > 1)
         {
             if (repeatMode == RepeatSelectMode.NeverLastHalf)
             {
                 while (recentlyPlayedResolvedGrains.Count >= numToAvoid)
                 {
                     recentlyPlayedResolvedGrains.Dequeue();
                 }
                 if (recentlyPlayedResolvedGrains.Count < numToAvoid)
                 {
                     recentlyPlayedResolvedGrains.Enqueue(resolvedGrain);
                 }
             }
             else if (repeatMode == RepeatSelectMode.NeverTwice)
             {
                 lastPlayedResolvedGrain = resolvedGrain;
             }
         }
     }
 }
コード例 #4
0
 public static void Notify_SoundEvent(SoundDef def, SoundInfo info)
 {
     if (DebugViewSettings.writeSoundEventsRecord)
     {
         string str;
         if (def == null)
         {
             str = "null: ";
         }
         else if (def.isUndefined)
         {
             str = "Undefined: ";
         }
         else
         {
             str = ((!def.sustain) ? "OneShot: " : "SustainerSpawn: ");
         }
         string str2 = (def == null) ? "null" : def.defName;
         string str3 = str + str2 + " - " + info.ToString();
         DebugSoundEventsLog.CreateRecord(str3);
     }
 }
コード例 #5
0
        public static Sustainer TrySpawnSustainer(this SoundDef soundDef, SoundInfo info)
        {
            DebugSoundEventsLog.Notify_SoundEvent(soundDef, info);
            if (soundDef == null)
            {
                return(null);
            }
            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));
                    }
                }
                return(null);
            }
            if (!soundDef.sustain)
            {
                Log.Error("Tried to spawn a sustainer from non-sustainer sound " + soundDef + ".");
                return(null);
            }
            if (!info.IsOnCamera && info.Maker.Thing != null && info.Maker.Thing.Destroyed)
            {
                return(null);
            }
            if (!soundDef.sustainStartSound.NullOrEmpty())
            {
                SoundDef.Named(soundDef.sustainStartSound).PlayOneShot(info);
            }
            return(new Sustainer(soundDef, info));
        }
コード例 #6
0
ファイル: SoundStarter.cs プロジェクト: potsh/RimWorld
 public static void PlayOneShotOnCamera(this SoundDef soundDef, Map onlyThisMap = null)
 {
     if (UnityData.IsInMainThread && (onlyThisMap == null || (Find.CurrentMap == onlyThisMap && !WorldRendererUtility.WorldRenderedNow)) && soundDef != null)
     {
         if (soundDef.subSounds.Count > 0)
         {
             bool flag = false;
             for (int i = 0; i < soundDef.subSounds.Count; i++)
             {
                 if (soundDef.subSounds[i].onCamera)
                 {
                     flag = true;
                     break;
                 }
             }
             if (!flag)
             {
                 Log.Error("Tried to play " + soundDef + " on camera but it has no on-camera subSounds.");
             }
         }
         soundDef.PlayOneShot(SoundInfo.OnCamera());
     }
 }
コード例 #7
0
 public static void PlayOneShotOnCamera(this SoundDef soundDef, Map onlyThisMap = null)
 {
     if (!UnityData.IsInMainThread || (onlyThisMap != null && (Find.CurrentMap != onlyThisMap || WorldRendererUtility.WorldRenderedNow)) || soundDef == null)
     {
         return;
     }
     if (soundDef.subSounds.Count > 0)
     {
         bool flag = false;
         for (int i = 0; i < soundDef.subSounds.Count; i++)
         {
             if (soundDef.subSounds[i].onCamera)
             {
                 flag = true;
                 break;
             }
         }
         if (!flag)
         {
             Log.Error(string.Concat("Tried to play ", soundDef, " on camera but it has no on-camera subSounds."));
         }
     }
     soundDef.PlayOneShot(SoundInfo.OnCamera());
 }
コード例 #8
0
        public static Sustainer AggregateOrSpawnSustainerFor(ISizeReporter reporter, SoundDef def, SoundInfo info)
        {
            Sustainer sustainer = null;

            foreach (Sustainer sustainer2 in Find.SoundRoot.sustainerManager.AllSustainers)
            {
                if (sustainer2.def == def && sustainer2.info.Maker.Map == info.Maker.Map && sustainer2.info.Maker.Cell.InHorDistOf(info.Maker.Cell, SustainerAggregatorUtility.AggregateRadius))
                {
                    sustainer = sustainer2;
                    break;
                }
            }
            if (sustainer == null)
            {
                sustainer = def.TrySpawnSustainer(info);
            }
            else
            {
                sustainer.Maintain();
            }
            if (sustainer.externalParams.sizeAggregator == null)
            {
                sustainer.externalParams.sizeAggregator = new SoundSizeAggregator();
            }
            sustainer.externalParams.sizeAggregator.RegisterReporter(reporter);
            return(sustainer);
        }
コード例 #9
0
        public static void Notify_SustainerEnded(Sustainer sustainer, SoundInfo info)
        {
            string str = "SustainerEnd: " + sustainer.def.defName + " - " + info.ToString();

            DebugSoundEventsLog.CreateRecord(str);
        }
コード例 #10
0
 private float CameraDistanceSquaredOf(SoundInfo info)
 {
     return((float)(Find.CameraDriver.MapPosition - info.Maker.Cell).LengthHorizontalSquared);
 }
コード例 #11
0
 public static void Notify_SustainerEnded(Sustainer sustainer, SoundInfo info)
 {
     CreateRecord("SustainerEnd: " + sustainer.def.defName + " - " + info.ToString());
 }