Beispiel #1
0
        public static bool SetResonanceAudioSourceMaxDistance(FMOD.Studio.EventInstance eventInstance, float maxDistanceValue)
        {
            if (!eventInstance.isValid() || maxDistanceValue < 0)
            {
                return(false);
            }

            FMOD.RESULT result;

            FMOD.ChannelGroup channelGroup;
            result = eventInstance.getChannelGroup(out channelGroup);
            if (result != FMOD.RESULT.OK)
            {
                Debug.Log(result);
                return(false);
            }

            int dspNumber;

            result = channelGroup.getNumDSPs(out dspNumber);
            if (result != FMOD.RESULT.OK)
            {
                Debug.Log(result);
                return(false);
            }

            for (int i = 0; i < dspNumber; i++)
            {
                FMOD.DSP dsp;
                result = channelGroup.getDSP(i, out dsp);
                if (result != FMOD.RESULT.OK)
                {
                    Debug.Log(result);
                    continue;
                }

                result = dsp.getInfo(out string name, out uint version, out int channels, out int configWidth, out int configHeight);
                if (result != FMOD.RESULT.OK)
                {
                    Debug.Log(result);
                    continue;
                }

                if (name == "Resonance Audio Source")
                {
                    result = dsp.getNumParameters(out int parameterNumber);
                    if (result != FMOD.RESULT.OK)
                    {
                        Debug.Log(result);
                        continue;
                    }

                    for (int j = 0; j < parameterNumber; j++)
                    {
                        result = dsp.getParameterInfo(j, out FMOD.DSP_PARAMETER_DESC description);
                        if (result != FMOD.RESULT.OK)
                        {
                            Debug.Log(result);
                            continue;
                        }

                        string stringName = System.Text.Encoding.UTF8.GetString(description.name);

                        if (String.Equals(stringName, "Max Distance", StringComparison.InvariantCultureIgnoreCase))
                        {
                            result = dsp.setParameterFloat(j, maxDistanceValue);
                            if (result != FMOD.RESULT.OK)
                            {
                                Debug.Log(result);
                                continue;
                            }

                            return(true);
                        }
                    }
                }
            }

            return(false);
        }