Ejemplo n.º 1
0
 public void MusicUpdate()
 {
     if (!gameObjectCreated)
     {
         gameObjectCreated = true;
         GameObject gameObject = new GameObject("MusicAudioSourceDummy");
         gameObject.transform.parent = Find.Root.soundRoot.sourcePool.sourcePoolCamera.cameraSourcesContainer.transform;
         audioSource = gameObject.AddComponent <AudioSource>();
         audioSource.bypassEffects         = true;
         audioSource.bypassListenerEffects = true;
         audioSource.bypassReverbZones     = true;
         audioSource.priority = 0;
     }
     UpdateSubtleAmbienceSoundVolumeMultiplier();
     if (!disabled)
     {
         if (songWasForced)
         {
             state         = MusicManagerState.Normal;
             fadeoutFactor = 1f;
         }
         if (audioSource.isPlaying && !songWasForced && ((DangerMusicMode && !lastStartedSong.tense) || (!DangerMusicMode && lastStartedSong.tense)))
         {
             state = MusicManagerState.Fadeout;
         }
         audioSource.volume = CurSanitizedVolume;
         if (audioSource.isPlaying)
         {
             if (state == MusicManagerState.Fadeout)
             {
                 fadeoutFactor -= Time.deltaTime / 10f;
                 if (fadeoutFactor <= 0f)
                 {
                     audioSource.Stop();
                     state         = MusicManagerState.Normal;
                     fadeoutFactor = 1f;
                 }
             }
         }
         else
         {
             if (DangerMusicMode)
             {
                 float      num                 = nextSongStartTime;
                 float      curTime             = CurTime;
                 FloatRange songIntervalTension = SongIntervalTension;
                 if (num > curTime + songIntervalTension.max)
                 {
                     nextSongStartTime = CurTime + SongIntervalTension.RandomInRange;
                 }
             }
             if (nextSongStartTime < CurTime - 5f)
             {
                 float num2 = (!DangerMusicMode) ? SongIntervalRelax.RandomInRange : SongIntervalTension.RandomInRange;
                 nextSongStartTime = CurTime + num2;
             }
             if (CurTime >= nextSongStartTime)
             {
                 ignorePrefsVolumeThisSong = false;
                 StartNewSong();
             }
         }
     }
 }
Ejemplo n.º 2
0
 public void MusicUpdate()
 {
     if (!gameObjectCreated)
     {
         gameObjectCreated = true;
         GameObject gameObject = new GameObject("MusicAudioSourceDummy");
         gameObject.transform.parent = Find.Root.soundRoot.sourcePool.sourcePoolCamera.cameraSourcesContainer.transform;
         audioSource = gameObject.AddComponent <AudioSource>();
         audioSource.bypassEffects         = true;
         audioSource.bypassListenerEffects = true;
         audioSource.bypassReverbZones     = true;
         audioSource.priority = 0;
     }
     UpdateSubtleAmbienceSoundVolumeMultiplier();
     if (disabled)
     {
         return;
     }
     if (songWasForced)
     {
         state         = MusicManagerState.Normal;
         fadeoutFactor = 1f;
     }
     if (audioSource.isPlaying && !songWasForced && ((DangerMusicMode && !lastStartedSong.tense) || (!DangerMusicMode && lastStartedSong.tense)))
     {
         state = MusicManagerState.Fadeout;
     }
     audioSource.volume = CurSanitizedVolume;
     if (audioSource.isPlaying)
     {
         if (state == MusicManagerState.Fadeout)
         {
             fadeoutFactor -= Time.deltaTime / 10f;
             if (fadeoutFactor <= 0f)
             {
                 audioSource.Stop();
                 state         = MusicManagerState.Normal;
                 fadeoutFactor = 1f;
             }
         }
         Map currentMap = Find.CurrentMap;
         if (currentMap != null && !WorldRendererUtility.WorldRenderedNow)
         {
             float        num    = 1f;
             Camera       camera = Find.Camera;
             List <Thing> list   = currentMap.listerThings.ThingsInGroup(ThingRequestGroup.MusicalInstrument);
             for (int i = 0; i < list.Count; i++)
             {
                 Building_MusicalInstrument building_MusicalInstrument = (Building_MusicalInstrument)list[i];
                 if (building_MusicalInstrument.IsBeingPlayed)
                 {
                     Vector3 vector = camera.transform.position - building_MusicalInstrument.Position.ToVector3Shifted();
                     vector.y  = Mathf.Max(vector.y - 15f, 0f);
                     vector.y *= 3.5f;
                     float      magnitude  = vector.magnitude;
                     FloatRange soundRange = building_MusicalInstrument.SoundRange;
                     float      num2       = Mathf.Min(Mathf.Max(magnitude - soundRange.min, 0f) / (soundRange.max - soundRange.min), 1f);
                     if (num2 < num)
                     {
                         num = num2;
                     }
                 }
             }
             instrumentProximityFadeFactor = num;
         }
         else
         {
             instrumentProximityFadeFactor = 1f;
         }
     }
     else
     {
         if (DangerMusicMode && nextSongStartTime > CurTime + SongIntervalTension.max)
         {
             nextSongStartTime = CurTime + SongIntervalTension.RandomInRange;
         }
         if (nextSongStartTime < CurTime - 5f)
         {
             float num3 = (!DangerMusicMode) ? SongIntervalRelax.RandomInRange : SongIntervalTension.RandomInRange;
             nextSongStartTime = CurTime + num3;
         }
         if (CurTime >= nextSongStartTime)
         {
             ignorePrefsVolumeThisSong = false;
             StartNewSong();
         }
     }
 }
Ejemplo n.º 3
0
        public void MusicUpdate()
        {
            if (!this.gameObjectCreated)
            {
                this.gameObjectCreated = true;
                GameObject gameObject = new GameObject("MusicAudioSourceDummy");
                gameObject.transform.parent            = Find.Root.soundRoot.sourcePool.sourcePoolCamera.cameraSourcesContainer.transform;
                this.audioSource                       = gameObject.AddComponent <AudioSource>();
                this.audioSource.bypassEffects         = true;
                this.audioSource.bypassListenerEffects = true;
                this.audioSource.bypassReverbZones     = true;
                this.audioSource.priority              = 0;
            }
            this.UpdateSubtleAmbienceSoundVolumeMultiplier();
            if (!this.disabled)
            {
                if (this.songWasForced)
                {
                    this.state         = MusicManagerState.Normal;
                    this.fadeoutFactor = 1f;
                }
                if (this.audioSource.isPlaying && !this.songWasForced)
                {
                    if (this.DangerMusicMode && !this.lastStartedSong.tense)
                    {
                        goto IL_0102;
                    }
                    if (!this.DangerMusicMode && this.lastStartedSong.tense)
                    {
                        goto IL_0102;
                    }
                }
                goto IL_0109;
            }
            return;

IL_0109:
            this.audioSource.volume = this.CurSanitizedVolume;
            if (this.audioSource.isPlaying)
            {
                if (this.state == MusicManagerState.Fadeout)
                {
                    this.fadeoutFactor -= (float)(Time.deltaTime / 10.0);
                    if (this.fadeoutFactor <= 0.0)
                    {
                        this.audioSource.Stop();
                        this.state         = MusicManagerState.Normal;
                        this.fadeoutFactor = 1f;
                    }
                }
            }
            else
            {
                if (this.DangerMusicMode)
                {
                    float      num                 = this.nextSongStartTime;
                    float      curTime             = this.CurTime;
                    FloatRange songIntervalTension = MusicManagerPlay.SongIntervalTension;
                    if (num > curTime + songIntervalTension.max)
                    {
                        this.nextSongStartTime = this.CurTime + MusicManagerPlay.SongIntervalTension.RandomInRange;
                    }
                }
                if (this.nextSongStartTime < this.CurTime - 5.0)
                {
                    float num2 = (!this.DangerMusicMode) ? MusicManagerPlay.SongIntervalRelax.RandomInRange : MusicManagerPlay.SongIntervalTension.RandomInRange;
                    this.nextSongStartTime = this.CurTime + num2;
                }
                if (this.CurTime >= this.nextSongStartTime)
                {
                    this.ignorePrefsVolumeThisSong = false;
                    this.StartNewSong();
                }
            }
            return;

IL_0102:
            this.state = MusicManagerState.Fadeout;
            goto IL_0109;
        }