static public void DebugLog(string debugLogStr)
    {
        bool log = false;
        Q3DAudioGlobalSettings globalSettings = Q3DAudioGlobalSettings.GetQ3DAudioGlobalSettings();

        if (globalSettings)
        {
#if UNITY_ANDROID
            log = globalSettings.mLogOnAndroid;
#elif UNITY_EDITOR
            log = globalSettings.mLogOnWin64CSharp;
#elif UNITY_STANDALONE_WIN
            if (IntPtr.Size == 8)
            {
                log = globalSettings.mLogOnWin64CSharp;
            }
            else if (IntPtr.Size == 4)
            {
                log = globalSettings.mLogOnWin32;
            }
#endif
        }

        if (log)
        {
            DebugLogAlways(debugLogStr);
        }
    }
    void Update()
    {
        Q3DAudioGlobalSettings globalSettings = Q3DAudioGlobalSettings.GetQ3DAudioGlobalSettings();

        if (globalSettings && globalSettings.mOnUpdateSpatializeMonoAudioSources)
        {
            SpatializeMonoAudioSources(globalSettings.mLogSpatializeMonoAudioSources);
        }
    }
    void OnSceneLoaded(Scene scene, LoadSceneMode mode)
    {
        Q3DAudioGlobalSettings globalSettings = Q3DAudioGlobalSettings.GetQ3DAudioGlobalSettings();

        if (globalSettings && globalSettings.mOnSceneLoadedSpatializeMonoAudioSources)
        {
            SpatializeMonoAudioSources(globalSettings.mLogSpatializeMonoAudioSources);
        }
    }
    void Start()
    {
        SceneManager.sceneLoaded += OnSceneLoaded;

        Q3DAudioGlobalSettings globalSettings = Q3DAudioGlobalSettings.GetQ3DAudioGlobalSettings();

        if (globalSettings && globalSettings.mOnStartSpatializeMonoAudioSources)
        {
            SpatializeMonoAudioSources(globalSettings.mLogSpatializeMonoAudioSources);
        }
    }
Пример #5
0
    static Q3DAudioGlobalSettings smQ3DAudioGlobalSettings;///note that this value will remain resident even if the underlying GameObject is destroyed, so the last set global settings will persist forever

    void Awake()
    {
        if (Q3DAudioManager.DisableIfUnsupportedPlatform(this))
        {
            return;
        }

        /*  setup the global settings even if the user has disabled Q3DAudio on this supported platform; this allows the rest of Q3DAudio to disable
         *  with minimal startup processing */
        if (smQ3DAudioGlobalSettings)
        {
            Q3DAudioManager.DebugLog("There is already another Q3DAudioGlobalSettings; this Q3DAudioGlobalSettings replaces and destroys it.  Multiple Q3DAudioGlobalSetting's in one scene is not recommended practice, since " +
                                     "this original Q3DAudioGlobalSettings will not be restored, even if this Q3DAudioGlobalSettings is destroyed.  We recommend you " +
                                     "instantiate one Q3DAudioGlobalSettings at startup; it will remain resident for the entire lifetime of the application, even if its " +
                                     "GameObject is destroyed when a new scene is loaded.  If you place one Q3DAudioGlobalSettings object in each scene, then each time " +
                                     "a new scene is loaded the latest Q3DAudioGlobalSettings will replace the previous one without emitting this message.");
            GameObject.Destroy(smQ3DAudioGlobalSettings.gameObject);
        }
        smQ3DAudioGlobalSettings = this;
    }
    static public bool DisableIfQ3DNotActive(Behaviour behaviour)
    {
        //special-case unsupported platforms to minimize wasted startup processing
        bool disabledUnsupportedPlatform = DisableIfUnsupportedPlatform(behaviour);

        if (disabledUnsupportedPlatform)
        {
            return(disabledUnsupportedPlatform);
        }

        bool supportedPlatformDisabled        = false;
        Q3DAudioGlobalSettings globalSettings = Q3DAudioGlobalSettings.GetQ3DAudioGlobalSettings();

        if (globalSettings)
        {
#if UNITY_ANDROID
            supportedPlatformDisabled = globalSettings.mDisableOnAndroid;
#elif UNITY_EDITOR_WIN
            supportedPlatformDisabled = globalSettings.mDisableOnWin64Editor;
#elif UNITY_STANDALONE_WIN
            if (IntPtr.Size == 8)
            {
                supportedPlatformDisabled = globalSettings.mDisableOnWin64;
            }
            else if (IntPtr.Size == 4)
            {
                supportedPlatformDisabled = globalSettings.mDisableOnWin32;
            }
#endif
        }

        if (supportedPlatformDisabled)
        {
            behaviour.enabled = false;
            return(true);
        }

        return(false);
    }
    public override void OnInspectorGUI()
    {
        Q3DAudioGlobalSettings q3dAudioGlobalSettings = (Q3DAudioGlobalSettings)target;
        string spatializeMonoAudioSourcesTooltipString = 
                "all AudioSources are gathered, and any AudioSource that has a mono(1 channel) clip and does not have a " +
                "Q3DAudioSource and Spatialized=true will get both, thereby turning that AudioSource into a Q3DAudio sound object.  If " +
                "LogSpatializeMonoAudioSources is checked, a log message is emitted with the name of the mono clip that was transformed into a sound object.  " +
                "Depending on the complexity of the scene, this might be an expensive operation, so you might want to use this checkbox as a conversion " +
                "tool to discover which AudioSources should be set this way, set them yourself and then uncheck this checkbox.";
        string negligibleProcessingTimeTooltipString = 
            "If checked, all Q3DAudio scripts and plugin effects will consume negligible processing time on startup and shutdown, and even more " +
            "negligible processing time on a typical frame on the ";
        string logTooltipString = 
            "Enables Q3DAudio logging, which is very slow and will often cause audio dropouts, but gives much insight into what Q3DAudio is doing";

        if(Application.isPlaying)
        {
            GUI.enabled = false;
        }

        string androidReverbProcessorTooltipString = 
            "On Android platforms running on some Snapdragon hardware, reverb processing can be offloaded to separate processors for better performance and/or battery usage.  If neither the first nor second choice is available, then reverb will run on the ARM CPU.  ARM_CPU is guaranteed to be available";
        mAndroidReverbProcessorFirstChoiceSerializedProperty.enumValueIndex = 
            (int)(Q3DAudioGlobalSettings.vr_audio_shoebox_mode)EditorGUILayout.EnumPopup(
                new GUIContent
                (
                    "1st Choice Reverb Processor (Android,Snapdragon)",
                    androidReverbProcessorTooltipString
                ), 
                q3dAudioGlobalSettings.mAndroidReverbProcessorFirstChoice
        );
        mAndroidReverbProcessorSecondChoiceSerializedProperty.enumValueIndex = 
            (int)(Q3DAudioGlobalSettings.vr_audio_shoebox_mode)EditorGUILayout.EnumPopup(
                new GUIContent
                (
                    "2nd Choice Reverb Processor (Android,Snapdragon)",
                    androidReverbProcessorTooltipString
                ),
                q3dAudioGlobalSettings.mAndroidReverbProcessorSecondChoice
        );

        EditorGUILayout.Separator();

        bool logOnWin32OldValue = mLogOnWin32SerializedProperty.boolValue;
        mLogOnWin32SerializedProperty.boolValue = EditorGUILayout.Toggle(
            new GUIContent
            (
                "Log on Win32",
                logTooltipString
            ),
            q3dAudioGlobalSettings.mLogOnWin32
        );
        if(logOnWin32OldValue != mLogOnWin32SerializedProperty.boolValue)
        {
            SetLogOnWin32(mLogOnWin32SerializedProperty.boolValue);
        }

        mLogOnWin64CSharpSerializedProperty.boolValue = EditorGUILayout.Toggle(
            new GUIContent
            (
                "Log on Win64 (C# only)",
                logTooltipString + ".  " + LogOnWin64Note
            ),
            q3dAudioGlobalSettings.mLogOnWin64CSharp
        );

        bool oldGUIEnabled = GUI.enabled;
        GUI.enabled = false;
        EditorGUILayout.Toggle(
            new GUIContent
            (
                "Log on Win64 (C++)",
                logTooltipString + ".  " + LogOnWin64Note
            ),
            mLogOnWin64Cpp
        );
        GUI.enabled = oldGUIEnabled;

        bool logOnAndroidOldValue = mLogOnAndroidSerializedProperty.boolValue;
        mLogOnAndroidSerializedProperty.boolValue = EditorGUILayout.Toggle(
            new GUIContent
            (
                "Log on Android",
                logTooltipString
            ),
            q3dAudioGlobalSettings.mLogOnAndroid
        );
        if (logOnAndroidOldValue != mLogOnAndroidSerializedProperty.boolValue)
        {
            SetLogOnAndroid(mLogOnAndroidSerializedProperty.boolValue);
        }

        EditorGUILayout.Separator();

        mDisableOnWin32SerializedProperty.boolValue = EditorGUILayout.Toggle(
            new GUIContent
            (
                "Disable on Win32",
                negligibleProcessingTimeTooltipString + "Win32 (x86) platform."
            ),
            q3dAudioGlobalSettings.mDisableOnWin32
        );
        mDisableOnWin64SerializedProperty.boolValue = EditorGUILayout.Toggle(
            new GUIContent
            (
                "Disable on Win64",
                negligibleProcessingTimeTooltipString + "Win64 (x64) platform."
            ),
            q3dAudioGlobalSettings.mDisableOnWin64
        );
        mDisableOnWin64EditorSerializedProperty.boolValue = EditorGUILayout.Toggle(
            new GUIContent
            (
                "Disable on Win64 Editor",
                negligibleProcessingTimeTooltipString + "Win64 (x64) Editor platform.  Note that if you disable Q3DAudio in the Editor but have played the game in the Editor with one more Q3DAudio mixer effects, those effects will continue to use more-than-minimal per-frame processing resources until the Editor is restarted"
            ),
            q3dAudioGlobalSettings.mDisableOnWin64Editor
        );
        mDisableOnAndroidSerializedProperty.boolValue = EditorGUILayout.Toggle(
            new GUIContent
            (
                "Disable on Android",
                negligibleProcessingTimeTooltipString + "Android platform."
            ),
            q3dAudioGlobalSettings.mDisableOnAndroid
        );
        if (Application.isPlaying)
        {
            GUI.enabled = true;
        }

        EditorGUILayout.Separator();

        mOnUpdateSpatializeMonoAudioSourcesSerializedProperty.boolValue = EditorGUILayout.Toggle(
            new GUIContent
            (
                "OnUpdateSpatializeMonoAudioSources",
                "If checked, once every frame " + spatializeMonoAudioSourcesTooltipString
            ),
            q3dAudioGlobalSettings.mOnUpdateSpatializeMonoAudioSources
        );
        mOnSceneLoadedSpatializeMonoAudioSourcesSerializedProperty.boolValue = EditorGUILayout.Toggle(
            new GUIContent
            (
                "OnSceneLoadedSpatializeMonoAudioSources",
                "If checked, once every wave of OnSceneLoaded() calls " + spatializeMonoAudioSourcesTooltipString
            ),
            q3dAudioGlobalSettings.mOnSceneLoadedSpatializeMonoAudioSources
        );
        mOnStartSpatializeMonoAudioSourcesSerializedProperty.boolValue = EditorGUILayout.Toggle(
            new GUIContent
            (
                "OnStartSpatializeMonoAudioSources",
                "If checked, once every wave of OnStart() calls " + spatializeMonoAudioSourcesTooltipString
            ),
            q3dAudioGlobalSettings.mOnStartSpatializeMonoAudioSources
        );

        bool allowDebugLoggingForSpatializedMonoAudioSources =
            mOnUpdateSpatializeMonoAudioSourcesSerializedProperty.boolValue ||
            mOnSceneLoadedSpatializeMonoAudioSourcesSerializedProperty.boolValue ||
            mOnStartSpatializeMonoAudioSourcesSerializedProperty.boolValue;
        if(!allowDebugLoggingForSpatializedMonoAudioSources)
        {
            GUI.enabled = false;
        }
        mLogSpatializeMonoAudioSourcesSerializedProperty.boolValue = EditorGUILayout.Toggle(
            new GUIContent
            (
                "LogSpatializeMonoAudioSources",
                "If checked, every time one of the above 'SpatializeMonoAudioSources' checkboxes transforms an AudioSource into a sound object, a log " + 
                "with the name of the AudioSource's mono clip is emitted."
            ),
            q3dAudioGlobalSettings.mLogSpatializeMonoAudioSources
        );
        if (!allowDebugLoggingForSpatializedMonoAudioSources)
        {
            GUI.enabled = true;
        }

        serializedObject.ApplyModifiedProperties();
    }
    void Awake()
    {
        //Q3DAudioManager should never be constructed by Q3DAudioListener if we are running a platform Q3DAudio does not support or the user has disabled
        //allow C++ plugin can emit to Unity's debug logs -- call as soon as possible!
        DebugLogCallbackDelegate callbackDelegate = new DebugLogCallbackDelegate(DebugLogCallBackFunction);

        System.IntPtr intptrDelegate = Marshal.GetFunctionPointerForDelegate(callbackDelegate); //convert callback_delegate into a function pointer that can be used in unmanaged code
        SetDebugLogCallback(intptrDelegate);                                                    // Call the API passing along the function pointer

        Q3DAudioGlobalSettings.vr_audio_shoebox_mode firstChoiceReverbProcessor  = Q3DAudioGlobalSettings.vr_audio_shoebox_mode.COMPUTE_DSP;
        Q3DAudioGlobalSettings.vr_audio_shoebox_mode secondChoiceReverbProcessor = Q3DAudioGlobalSettings.vr_audio_shoebox_mode.HEXAGON_ADSP;
        Q3DAudioGlobalSettings globalSettings = Q3DAudioGlobalSettings.GetQ3DAudioGlobalSettings();

        if (globalSettings)
        {
            firstChoiceReverbProcessor  = globalSettings.mAndroidReverbProcessorFirstChoice;
            secondChoiceReverbProcessor = globalSettings.mAndroidReverbProcessorSecondChoice;
        }

        /*  * command line arguments (Windows) and intents (Android) override global settings
         * command line arguments are case-insensitive and are expected to be formatted: NAME_OF_EXE Q3DAudio1stChoiceReverbProcessor=COMPUTE_DSP
         * the equivalent Android intent has a case-sensitive key (due to Android's requirements) and a case-insensitive value:
         *    adb shell am start -n NAME_OF_PACKAGE/com.unity3d.player.UnityPlayerActivity -e Q3DAudio1stChoiceReverbProcessor COMPUTE_CPU
         */
        string firstChoiceReverbProcessorString  = "1stChoiceReverbProcessor";
        string secondChoiceReverbProcessorString = "2ndChoiceReverbProcessor";
        string q3dAudioString = "Q3DAudio";

#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
        //Windows is case-insensitive for convenience, because (unlike some other platforms) we can make it so
        q3dAudioString = q3dAudioString.ToLower();
        firstChoiceReverbProcessorString  = firstChoiceReverbProcessorString.ToLower();
        secondChoiceReverbProcessorString = secondChoiceReverbProcessorString.ToLower();

        string[] commandLineArgs = Environment.GetCommandLineArgs();
        foreach (string c in commandLineArgs)
        {
            string commandLineArg = c.ToLower();
            if (StringIsInString(q3dAudioString, commandLineArg))
            {
                if (StringIsInString(firstChoiceReverbProcessorString, commandLineArg))
                {
                    ParseAndroidReverbProcessorIfItExists(ref firstChoiceReverbProcessor, commandLineArg);
                }
                else if (StringIsInString(secondChoiceReverbProcessorString, commandLineArg))
                {
                    ParseAndroidReverbProcessorIfItExists(ref secondChoiceReverbProcessor, commandLineArg);
                }
            }
        }
#elif UNITY_ANDROID
        AndroidJavaClass  UnityPlayer     = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
        AndroidJavaObject currentActivity = UnityPlayer.GetStatic <AndroidJavaObject>("currentActivity");

        AndroidJavaObject intent = currentActivity.Call <AndroidJavaObject>("getIntent");
        ParseAndroidReverbProcessorIfItExists(ref firstChoiceReverbProcessor, q3dAudioString + firstChoiceReverbProcessorString, intent);
        ParseAndroidReverbProcessorIfItExists(ref secondChoiceReverbProcessor, q3dAudioString + secondChoiceReverbProcessorString, intent);
#endif//#if UNITY_STANDALONE_WIN #elif UNITY_ANDROID

        Q3DAudioManager.DebugLog("Reverb: 1stChoiceProcessor=" + firstChoiceReverbProcessor + ";2ndChoiceProcessor=" + secondChoiceReverbProcessor);
        SetReverbProcessorPreferences((int)firstChoiceReverbProcessor, (int)secondChoiceReverbProcessor);

        //point C++ plugin to the directory where q3d_audio dll's are deployed
        Q3DAudioManager.SetApplicationDataPath(Application.dataPath, InEditor());

        //the user is not allowed to set the default parameters on the mixer effect at runtime, so this can be done here once
        int roomMatWalls, roomMatCeiling, roomMatFloor;
        GetDefaultReverb(
            out mQ3DAudioRoomSettingsDefault.gainAdjust,
            out mQ3DAudioRoomSettingsDefault.brightAdjust,
            out mQ3DAudioRoomSettingsDefault.timeAdjust,
            out mQ3DAudioRoomSettingsDefault.wetMix,
            out mQ3DAudioRoomSettingsDefault.roomDimensionsX_meters,
            out mQ3DAudioRoomSettingsDefault.roomDimensionsY_meters,
            out mQ3DAudioRoomSettingsDefault.roomDimensionsZ_meters,
            out roomMatWalls,
            out roomMatCeiling,
            out roomMatFloor);
        mQ3DAudioRoomSettingsDefault.roomMaterialWalls   = (Q3DAudioRoom.vr_audio_room_material_type)roomMatWalls;
        mQ3DAudioRoomSettingsDefault.roomMaterialCeiling = (Q3DAudioRoom.vr_audio_room_material_type)roomMatCeiling;
        mQ3DAudioRoomSettingsDefault.roomMaterialFloor   = (Q3DAudioRoom.vr_audio_room_material_type)roomMatFloor;

#if UNITY_EDITOR
        //after the first "play", the editor doesn't recreate the mixer effects, so the default settings are not necessarily what q3d_audio is using
        SetAudioRoomSettings(mQ3DAudioRoomSettingsDefault);//q3d_audio uses default settings
#else
        //for standalone players, the default settings are by definition what is set immediately after creating the mixer effects
        mQ3DAudioRoomSettingsLast = mQ3DAudioRoomSettingsDefault;
#endif//#if UNITY_EDITOR

        DontDestroyOnLoad(this);//persist until the game is shut down

        //BEG_CONFIG

        /*  as of Unity 2017.1.0f3 this cannot be done.  Executing the code below appears to cause Unity to destroy all
         *  mixer effects, and the spatializer effect and ambisonic decoder effect (correct), and then recreate all of
         *  these except for the ambisonic decoder effect (wrong) and then proceeds to play silence on Android (wrong) */

        ///@todo: warn if overriding values
        //AudioConfiguration audioConfiguration = AudioSettings.GetConfiguration();
        //audioConfiguration.dspBufferSize = 192;
        ////audioConfiguration.sampleRate = 48000;
        ////audioConfiguration.speakerMode = AudioSpeakerMode.Stereo;
        ////AudioSettings.Reset(audioConfiguration);///@todo: if false, then log epic failure
        //END_CONFIG
    }