private void Awake() { if (instance != null) { Destroy(this); return; } if (!CriAtomPlugin.IsLibraryInitialized()) { Debug.LogError("[CRIWARE] Atom library is not initialized. Cannot setup CriAtomExOutputDeviceObserver."); Destroy(this); return; } instance = this; #if CRIWAREPLUGIN_SUPPORT_OUTPUTDEVICE_OBSERVER #if !UNITY_EDITOR && UNITY_IOS bool isStarted = UnsafeNativeMethods.criAtomUnity_StartOutputDeviceObserver_IOS(); if (!isStarted) { Debug.LogError("[CRIWARE] CriAtomOutputDeviceObserver cannot start while Atom library is not initialized."); } #elif !UNITY_EDITOR && UNITY_ANDROID UnityEngine.AndroidJavaClass jc = new UnityEngine.AndroidJavaClass("com.unity3d.player.UnityPlayer"); UnityEngine.AndroidJavaObject activity = jc.GetStatic <UnityEngine.AndroidJavaObject>("currentActivity"); if (checker == null) { checker = new UnityEngine.AndroidJavaObject("com.crimw.crijavaclasses.CriOutputDeviceObserver", activity, this.gameObject.name, "CallbackFromObserver_ANDROID"); } if (checker == null) { Debug.LogError("[CRIWARE] Cannot load CriOutputDeviceObserver class in library."); } checker.Call("Start", activity); CheckOutputDevice_ANDROID(); #endif isConnected = lastIsConnected = IsDeviceConnected; deviceType = lastDeviceType = DeviceType; if (_onDeviceConnectionChanged != null) { _onDeviceConnectionChanged(isConnected, deviceType); } #elif !UNITY_EDITOR Debug.Log("[CRIWARE] CriAtomOutputDeviceObserver is not supported on this platform."); #endif if (this.dontDestroyOnLoad) { GameObject.DontDestroyOnLoad(this.gameObject); } }
private void OnDestroy() { if (instance != this) { return; } instance = null; #if CRIWAREPLUGIN_SUPPORT_OUTPUTDEVICE_OBSERVER #if !UNITY_EDITOR && UNITY_IOS UnsafeNativeMethods.criAtomUnity_StopOutputDeviceObserver_IOS(); #elif !UNITY_EDITOR && UNITY_ANDROID UnityEngine.AndroidJavaClass jc = new UnityEngine.AndroidJavaClass("com.unity3d.player.UnityPlayer"); UnityEngine.AndroidJavaObject activity = jc.GetStatic <UnityEngine.AndroidJavaObject>("currentActivity"); if (activity != null && checker != null) { checker.Call("Stop", activity); } checker = null; #endif #endif }