public void Start(Vector3 emitter_position)
 {
     if (!isRunning)
     {
         if (oneShotSound != null)
         {
             EventInstance eventInstance = KFMOD.CreateInstance(oneShotSound);
             if (!eventInstance.isValid())
             {
                 Debug.LogWarning("Could not find event: " + oneShotSound);
             }
             else
             {
                 Vector3       pos        = new Vector3(emitter_position.x, emitter_position.y, 0f);
                 ATTRIBUTES_3D attributes = pos.To3DAttributes();
                 eventInstance.set3DAttributes(attributes);
                 eventInstance.setVolume(tilePercentage * 2f);
                 eventInstance.start();
                 eventInstance.release();
             }
         }
         else
         {
             soundEvent = KFMOD.CreateInstance(sound);
             if (soundEvent.isValid())
             {
                 soundEvent.start();
             }
             isRunning = true;
         }
     }
 }
Example #2
0
 protected override void OnSpawn()
 {
     base.OnSpawn();
     techViewSound        = KFMOD.CreateInstance(techViewSoundPath);
     techViewSoundPlaying = false;
     Shader.SetGlobalVector("_OverlayParams", Vector4.zero);
     RegisterModes();
     currentModeInfo = modeInfos[OverlayModes.None.ID];
 }
 public EventInstance Start(string snapshot)
 {
     if (!activeSnapshots.TryGetValue(snapshot, out EventInstance value))
     {
         if (RuntimeManager.IsInitialized)
         {
             value = KFMOD.CreateInstance(snapshot);
             activeSnapshots[snapshot] = value;
             value.start();
             value.setParameterValue("snapshotActive", 1f);
         }
         else
         {
             value = default(EventInstance);
         }
     }
     instance.Log("Start Snapshot: " + snapshot);
     return(value);
 }
Example #4
0
 public void PlaySong(string song_name, bool canWait = false)
 {
     Log("Play: " + song_name);
     if (AudioDebug.Get().musicEnabled)
     {
         SongInfo value = null;
         if (!songMap.TryGetValue(song_name, out value))
         {
             DebugUtil.LogErrorArgs("Unknown song:", song_name);
         }
         else if (activeSongs.ContainsKey(song_name))
         {
             DebugUtil.LogWarningArgs("Trying to play duplicate song:", song_name);
         }
         else if (activeSongs.Count == 0)
         {
             value.ev = KFMOD.CreateInstance(value.fmodEvent);
             if (!value.ev.isValid())
             {
                 DebugUtil.LogWarningArgs("Failed to find FMOD event [" + value.fmodEvent + "]");
             }
             int num = (value.numberOfVariations <= 0) ? (-1) : UnityEngine.Random.Range(1, value.numberOfVariations + 1);
             if (num != -1)
             {
                 value.ev.setParameterValue("variation", (float)num);
             }
             value.ev.start();
             activeSongs[song_name] = value;
             if (value.dynamic)
             {
                 activeDynamicSong = value;
             }
         }
         else
         {
             List <string> list = new List <string>(activeSongs.Keys);
             if (value.interruptsActiveMusic)
             {
                 for (int i = 0; i < list.Count; i++)
                 {
                     if (!activeSongs[list[i]].interruptsActiveMusic)
                     {
                         SongInfo songInfo = activeSongs[list[i]];
                         songInfo.ev.setParameterValue("interrupted_dimmed", 1f);
                         Log("Dimming: " + Assets.GetSimpleSoundEventName(songInfo.fmodEvent));
                         value.songsOnHold.Add(list[i]);
                     }
                 }
                 value.ev = KFMOD.CreateInstance(value.fmodEvent);
                 if (!value.ev.isValid())
                 {
                     DebugUtil.LogWarningArgs("Failed to find FMOD event [" + value.fmodEvent + "]");
                 }
                 value.ev.start();
                 value.ev.release();
                 activeSongs[song_name] = value;
             }
             else
             {
                 int num2 = 0;
                 foreach (string key in activeSongs.Keys)
                 {
                     SongInfo songInfo2 = activeSongs[key];
                     if (!songInfo2.interruptsActiveMusic && songInfo2.priority > num2)
                     {
                         num2 = songInfo2.priority;
                     }
                 }
                 if (value.priority >= num2)
                 {
                     for (int j = 0; j < list.Count; j++)
                     {
                         SongInfo songInfo3           = activeSongs[list[j]];
                         FMOD.Studio.EventInstance ev = songInfo3.ev;
                         if (!songInfo3.interruptsActiveMusic)
                         {
                             ev.setParameterValue("interrupted_dimmed", 1f);
                             ev.stop(STOP_MODE.ALLOWFADEOUT);
                             activeSongs.Remove(list[j]);
                             list.Remove(list[j]);
                         }
                     }
                     value.ev = KFMOD.CreateInstance(value.fmodEvent);
                     if (!value.ev.isValid())
                     {
                         DebugUtil.LogWarningArgs("Failed to find FMOD event [" + value.fmodEvent + "]");
                     }
                     int num3 = (value.numberOfVariations <= 0) ? (-1) : UnityEngine.Random.Range(1, value.numberOfVariations + 1);
                     if (num3 != -1)
                     {
                         value.ev.setParameterValue("variation", (float)num3);
                     }
                     value.ev.start();
                     activeSongs[song_name] = value;
                 }
             }
         }
     }
 }
Example #5
0
    public void RenderEveryTick(float dt)
    {
        ListPool <Sound, LoopingSoundManager> .PooledList pooledList = ListPool <Sound, LoopingSoundManager> .Allocate();

        ListPool <int, LoopingSoundManager> .PooledList pooledList2 = ListPool <int, LoopingSoundManager> .Allocate();

        ListPool <int, LoopingSoundManager> .PooledList pooledList3 = ListPool <int, LoopingSoundManager> .Allocate();

        List <Sound> dataList    = sounds.GetDataList();
        bool         flag        = Time.timeScale == 0f;
        SoundCuller  soundCuller = CameraController.Instance.soundCuller;

        for (int i = 0; i < dataList.Count; i++)
        {
            Sound sound = dataList[i];
            if ((UnityEngine.Object)sound.transform != (UnityEngine.Object)null)
            {
                sound.pos = sound.transform.GetPosition();
                if ((UnityEngine.Object)sound.animController != (UnityEngine.Object)null)
                {
                    Vector3 offset = sound.animController.Offset;
                    sound.pos.x += offset.x;
                    sound.pos.y += offset.y;
                }
            }
            bool flag2     = !sound.IsCullingEnabled || (sound.ShouldCameraScalePosition && soundCuller.IsAudible(sound.pos, sound.falloffDistanceSq)) || soundCuller.IsAudibleNoCameraScaling(sound.pos, sound.falloffDistanceSq);
            bool isPlaying = sound.IsPlaying;
            if (flag2)
            {
                pooledList.Add(sound);
                if (!isPlaying)
                {
                    SoundDescription soundDescription = GetSoundDescription(sound.path);
                    sound.ev    = KFMOD.CreateInstance(soundDescription.path);
                    dataList[i] = sound;
                    pooledList2.Add(i);
                }
            }
            else if (isPlaying)
            {
                pooledList3.Add(i);
            }
        }
        LoopingSoundParameterUpdater.Sound sound2;
        foreach (int item in pooledList2)
        {
            Sound            value             = dataList[item];
            SoundDescription soundDescription2 = GetSoundDescription(value.path);
            value.ev.setPaused(flag && value.ShouldPauseOnGamePaused);
            Vector2 v = value.pos;
            if (value.ShouldCameraScalePosition)
            {
                v = SoundEvent.GetCameraScaledPosition(v);
            }
            value.ev.set3DAttributes(RuntimeUtils.To3DAttributes(v));
            value.ev.start();
            value.flags |= Sound.Flags.PLAYING;
            if (value.firstParameter != HashedString.Invalid)
            {
                value.ev.setParameterValueByIndex(soundDescription2.GetParameterIdx(value.firstParameter), value.firstParameterValue);
            }
            if (value.secondParameter != HashedString.Invalid)
            {
                value.ev.setParameterValueByIndex(soundDescription2.GetParameterIdx(value.secondParameter), value.secondParameterValue);
            }
            sound2             = default(LoopingSoundParameterUpdater.Sound);
            sound2.ev          = value.ev;
            sound2.path        = value.path;
            sound2.description = soundDescription2;
            sound2.transform   = value.transform;
            LoopingSoundParameterUpdater.Sound sound3     = sound2;
            SoundDescription.Parameter[]       parameters = soundDescription2.parameters;
            for (int j = 0; j < parameters.Length; j++)
            {
                SoundDescription.Parameter   parameter = parameters[j];
                LoopingSoundParameterUpdater value2    = null;
                if (parameterUpdaters.TryGetValue(parameter.name, out value2))
                {
                    value2.Add(sound3);
                }
            }
            dataList[item] = value;
        }
        pooledList2.Recycle();
        foreach (int item2 in pooledList3)
        {
            Sound            value3            = dataList[item2];
            SoundDescription soundDescription3 = GetSoundDescription(value3.path);
            sound2             = default(LoopingSoundParameterUpdater.Sound);
            sound2.ev          = value3.ev;
            sound2.path        = value3.path;
            sound2.description = soundDescription3;
            sound2.transform   = value3.transform;
            LoopingSoundParameterUpdater.Sound sound4      = sound2;
            SoundDescription.Parameter[]       parameters2 = soundDescription3.parameters;
            for (int k = 0; k < parameters2.Length; k++)
            {
                SoundDescription.Parameter   parameter2 = parameters2[k];
                LoopingSoundParameterUpdater value4     = null;
                if (parameterUpdaters.TryGetValue(parameter2.name, out value4))
                {
                    value4.Remove(sound4);
                }
            }
            if (value3.ShouldCameraScalePosition)
            {
                value3.ev.stop(STOP_MODE.IMMEDIATE);
            }
            else
            {
                value3.ev.stop(STOP_MODE.ALLOWFADEOUT);
            }
            value3.flags &= ~Sound.Flags.PLAYING;
            value3.ev.release();
            dataList[item2] = value3;
        }
        pooledList3.Recycle();
        float velocityScale = TuningData <Tuning> .Get().velocityScale;

        foreach (Sound item3 in pooledList)
        {
            Sound         current3   = item3;
            ATTRIBUTES_3D attributes = SoundEvent.GetCameraScaledPosition(current3.pos).To3DAttributes();
            attributes.velocity = (current3.velocity * velocityScale).ToFMODVector();
            current3.ev.set3DAttributes(attributes);
        }
        foreach (KeyValuePair <HashedString, LoopingSoundParameterUpdater> parameterUpdater in parameterUpdaters)
        {
            parameterUpdater.Value.Update(dt);
        }
        pooledList.Recycle();
    }