Ejemplo n.º 1
0
        public void RenderEveryTick(float dt)
        {
            SoundCuller soundCuller = CameraController.Instance.soundCuller;

            if (shouldPauseOnGamePause && Time.timeScale == 0f)
            {
                sound.setPaused(true);
                return;
            }

            bool audible = !enableCulling || (enableCameraScaling && soundCuller.IsAudible(transform.position, falloffDistanceSq)) || soundCuller.IsAudibleNoCameraScaling(transform.position, falloffDistanceSq);

            if (!audible)
            {
                sound.setPaused(true);
                return;
            }

            sound.setPaused(false);

            Vector3 soundPos = transform.position;

            soundPos.z = 0;

            float velocityScale = TuningData <LoopingSoundManager.Tuning> .Get().velocityScale;

            VECTOR scaledSoundPos = SoundEvent.GetCameraScaledPosition(soundPos, false).ToFMODVector();
            VECTOR scaledSoundVel = (velocity * velocityScale).ToFMODVector();

            sound.set3DAttributes(ref scaledSoundPos, ref scaledSoundVel);
        }
Ejemplo n.º 2
0
    public override void PlaySound(AnimEventManager.EventPlayerData behaviour)
    {
        Vector3 pos = behaviour.GetComponent <Transform>().GetPosition();
        KBatchedAnimController component = behaviour.GetComponent <KBatchedAnimController>();

        if ((Object)component != (Object)null)
        {
            pos = component.GetPivotSymbolPosition();
        }
        int    num           = Grid.PosToCell(pos);
        int    cell          = Grid.CellBelow(num);
        string audioCategory = GetAudioCategory(cell);
        string name          = StringFormatter.Combine(audioCategory, "_", base.name);
        string sound         = GlobalAssets.GetSound(name, true);

        if (sound == null)
        {
            name  = StringFormatter.Combine("Rock_", base.name);
            sound = GlobalAssets.GetSound(name, true);
            if (sound == null)
            {
                name  = base.name;
                sound = GlobalAssets.GetSound(name, true);
            }
        }
        if (!SoundEvent.IsLowPrioritySound(sound))
        {
            pos = SoundEvent.GetCameraScaledPosition(pos);
            if (Grid.Element != null)
            {
                bool  isLiquid = Grid.Element[num].IsLiquid;
                float num2     = 0f;
                if (isLiquid)
                {
                    num2 = SoundUtil.GetLiquidDepth(num);
                    string sound2 = GlobalAssets.GetSound("Liquid_footstep", true);
                    if (sound2 != null)
                    {
                        FMOD.Studio.EventInstance instance = SoundEvent.BeginOneShot(sound2, pos);
                        if (num2 > 0f)
                        {
                            instance.setParameterValue("liquidDepth", num2);
                        }
                        SoundEvent.EndOneShot(instance);
                    }
                }
                if (sound != null)
                {
                    FMOD.Studio.EventInstance instance2 = SoundEvent.BeginOneShot(sound, pos);
                    if (instance2.isValid())
                    {
                        if (num2 > 0f)
                        {
                            instance2.setParameterValue("liquidDepth", num2);
                        }
                        if (behaviour.currentAnimFile != null && behaviour.currentAnimFile.Contains("anim_loco_walk"))
                        {
                            instance2.setVolume(IDLE_WALKING_VOLUME_REDUCTION);
                        }
                        SoundEvent.EndOneShot(instance2);
                    }
                }
            }
        }
    }
Ejemplo n.º 3
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();
    }