Beispiel #1
0
    private void Init()
    {
        UnityUtil.Log("FMOD_StudioSystem: Initialize");
        if (this.isInitialized)
        {
            return;
        }
        UnityEngine.Object.DontDestroyOnLoad(base.gameObject);
        this.LiveUpdateEnabled = false;
        string[] commandLineArgs = Environment.GetCommandLineArgs();
        for (int i = 0; i < commandLineArgs.Length; i++)
        {
            string a = commandLineArgs[i];
            if (a == "-FMODLiveUpdate")
            {
                this.LiveUpdateEnabled = true;
                break;
            }
        }
        UnityUtil.Log("FMOD_StudioSystem: System_Create");
        FMOD_StudioSystem.ERRCHECK(FMOD.Studio.System.create(out this.system));
        FMOD.Studio.INITFLAGS iNITFLAGS        = FMOD.Studio.INITFLAGS.NORMAL;
        FMOD.ADVANCEDSETTINGS aDVANCEDSETTINGS = default(FMOD.ADVANCEDSETTINGS);
        if (this.LiveUpdateEnabled)
        {
            iNITFLAGS |= FMOD.Studio.INITFLAGS.LIVEUPDATE;
            if (Application.unityVersion.StartsWith("5"))
            {
                UnityUtil.LogWarning("FMOD_StudioSystem: detected Unity 5, running on port 9265");
                aDVANCEDSETTINGS.profilePort = 9265;
            }
        }
        int @int = PlayerPrefs.GetInt("VoiceCount", 128);

        FMOD.System system;
        FMOD_StudioSystem.ERRCHECK(this.system.getLowLevelSystem(out system));
        FMOD_StudioSystem.ERRCHECK(system.setSoftwareChannels(@int));
        aDVANCEDSETTINGS.maxVorbisCodecs = @int;
        FMOD_StudioSystem.ERRCHECK(system.setAdvancedSettings(ref aDVANCEDSETTINGS));
        int           num  = 48000;
        StringBuilder name = new StringBuilder();
        Guid          guid;
        SPEAKERMODE   sPEAKERMODE;
        int           num2;

        FMOD_StudioSystem.ERRCHECK(system.getDriverInfo(0, name, 0, out guid, out num, out sPEAKERMODE, out num2));
        if (num > 48000)
        {
            uint bufferlength = 0u;
            int  num3         = 0;
            FMOD_StudioSystem.ERRCHECK(system.getDSPBufferSize(out bufferlength, out num3));
            FMOD_StudioSystem.ERRCHECK(system.setDSPBufferSize(bufferlength, num3 * 2));
        }
        num = Math.Min(num, 48000);
        FMOD_StudioSystem.ERRCHECK(system.setSoftwareFormat(num, SPEAKERMODE._5POINT1, 0));
        UnityUtil.Log("FMOD_StudioSystem: system.init");
        RESULT rESULT = this.system.initialize(1024, iNITFLAGS, FMOD.INITFLAGS.NORMAL, IntPtr.Zero);

        if (rESULT == RESULT.ERR_NET_SOCKET_ERROR)
        {
            UnityUtil.LogError("Unable to initalize with LiveUpdate: socket is already in use");
        }
        else if (rESULT == RESULT.ERR_HEADER_MISMATCH)
        {
            UnityUtil.LogError("Version mismatch between C# script and FMOD binary, restart Unity and reimport the integration package to resolve this issue.");
        }
        else
        {
            FMOD_StudioSystem.ERRCHECK(rESULT);
        }
        this.isInitialized = true;
    }