static AGSAchievementsClient(){ #if UNITY_ANDROID && !UNITY_EDITOR JavaObject = new AmazonJavaWrapper(); using( var PluginClass = new AndroidJavaClass( PROXY_CLASS_NAME ) ){ if (PluginClass.GetRawClass() == IntPtr.Zero) { AGSClient.LogGameCircleWarning(string.Format("No java class {0} present, can't use AGSAchievementsClient",PROXY_CLASS_NAME )); return; } JavaObject.setAndroidJavaObject(PluginClass.CallStatic<AndroidJavaObject>( "getInstance" )); } #endif }
static AGSPlayerClient(){ #if UNITY_ANDROID && !UNITY_EDITOR // find the plugin instance JavaObject = new AmazonJavaWrapper(); using( var PluginClass = new AndroidJavaClass( PROXY_CLASS_NAME ) ){ if (PluginClass.GetRawClass() == IntPtr.Zero) { AGSClient.LogGameCircleWarning("No java class " + PROXY_CLASS_NAME + " present, can't use AGSPlayerClient" ); return; } JavaObject.setAndroidJavaObject(PluginClass.CallStatic<AndroidJavaObject>( "getInstance" )); } #endif }
/// <summary> /// Awake this instance. /// </summary> void Awake() { #if (!UNITY_ANDROID || UNITY_EDITOR) //// -- UnityAndroid // create the distortion camera component and camera (only on PC) if (this.enabled) { if (GetComponent<OVRDistortionCamera>() == null) { gameObject.AddComponent<OVRDistortionCamera>(); } } //// -- UnityAndroid #endif // Get the cameras OVRCamera[] ovrcameras = gameObject.GetComponentsInChildren<OVRCamera>( true ); for (int i = 0; i < ovrcameras.Length; i++) { // assign the right and left cameras, check the camera name for outdated prefabs if(ovrcameras[i].RightEye || ( string.Compare( ovrcameras[i].name, "cameraright", true ) == 0 ) ) { ovrcameras[i].RightEye = true; SetCameras(CameraLeft, ovrcameras[i].camera); } else { SetCameras(ovrcameras[i].camera, CameraRight); } if ( ( ovrcameras[i].camera.clearFlags == CameraClearFlags.Skybox ) && ( ( ovrcameras[i].gameObject.GetComponent<Skybox>() != null ) || ( RenderSettings.skybox != null ) ) ) { HasSkybox = true; Debug.Log ( "Skybox Clear Required" ); } } if ((CameraLeft == null) || (CameraRight == null)) Debug.LogWarning("WARNING: Unity Cameras in OVRCameraController not found!"); #if (UNITY_ANDROID && !UNITY_EDITOR) // Disable screen dimming Screen.sleepTimeout = SleepTimeout.NeverSleep; Application.targetFrameRate = 60; // don't allow the app to run in the background Application.runInBackground = false; // don't enable gyro, it is not used and triggers expensive display calls if ( Input.gyro.enabled ) { Debug.LogError( "*** Auto-disabling Gyroscope ***" ); Input.gyro.enabled = false; } // don't enable antiAliasing on the main window display, it may cause // bad behavior with various tiling controls. if ( QualitySettings.antiAliasing > 1 ) { Debug.LogError( "*** Main Display should have 0 samples ***" ); } // Only perform this check when the CameraController is enabled // to allow for toggling stereo / non-stero camers for testing. if ( this.enabled ) { // Make sure there isn't an OVRDistortion camera on Android // this is done primarly to clean up old camera controller prefabs Camera[] cameras = gameObject.GetComponentsInChildren<Camera>(); for (int i = 0; i < cameras.Length; i++) { if ( (cameras[i] != CameraLeft) && ( cameras[i] != CameraRight ) ) { Debug.LogWarning("WARNING: Extra camera on OVRCameraController found!"); cameras[i].cullingMask = 0; // cull everything cameras[i].clearFlags = CameraClearFlags.Nothing; Destroy( cameras[i] ); } } } CameraLeft.depth = (int)RenderEventType.LeftEyeEndFrame; CameraRight.depth = (int)RenderEventType.RightEyeEndFrame; // When rendering monoscopic, we will use the left camera render // for both eyes. if ( Monoscopic ) { //CameraRight.enabled = false; CameraRight.cullingMask = 0; // cull everything CameraRight.clearFlags = CameraClearFlags.Nothing; } if ( !androidJavaInit ) { AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity"); javaVrActivityClass = new AndroidJavaClass("com.oculusvr.vrlib.VrActivity"); // Prepare for the RenderThreadInit() OVR_SetInitVariables( activity.GetRawObject(), javaVrActivityClass.GetRawClass() ); androidJavaInit = true; } InitVolumeController(); #endif }
// Must be launched from the game thread (otherwise the classloader cannot locate the unity // java classes we require). private void LaunchBridgeIntent(IntPtr bridgedIntent) { object[] objectArray = new object[2]; jvalue[] jArgs = AndroidJNIHelper.CreateJNIArgArray(objectArray); try { using (var bridgeClass = new AndroidJavaClass(BridgeActivityClass)) { using (var currentActivity = GetActivity()) { // Unity no longer supports constructing an AndroidJavaObject using an IntPtr, // so I have to manually munge with JNI here. IntPtr methodId = AndroidJNI.GetStaticMethodID(bridgeClass.GetRawClass(), LaunchBridgeMethod, LaunchBridgeSignature); jArgs[0].l = currentActivity.GetRawObject(); jArgs[1].l = bridgedIntent; AndroidJNI.CallStaticVoidMethod(bridgeClass.GetRawClass(), methodId, jArgs); } } } finally { AndroidJNIHelper.DeleteJNIArgArray(objectArray, jArgs); } }
private static bool IsAndroidJavaClassNull(AndroidJavaClass androidJavaClass) { return androidJavaClass == null || androidJavaClass.GetRawClass().ToInt32() == 0; }
private void Awake() { // Only allow one instance at runtime. if (instance != null) { enabled = false; DestroyImmediate(this); return; } instance = this; #if !UNITY_ANDROID || UNITY_EDITOR if (!ovrIsInitialized) { OVR_Initialize(); OVRPluginEvent.Issue(RenderEventType.Initialize); ovrIsInitialized = true; } var netVersion = new System.Version(Ovr.Hmd.OVR_VERSION_STRING); var ovrVersion = new System.Version(Ovr.Hmd.GetVersionString()); if (netVersion > ovrVersion) Debug.LogWarning("Using an older version of LibOVR."); #endif // Detect whether this platform is a supported platform RuntimePlatform currPlatform = Application.platform; isSupportedPlatform |= currPlatform == RuntimePlatform.Android; isSupportedPlatform |= currPlatform == RuntimePlatform.LinuxPlayer; isSupportedPlatform |= currPlatform == RuntimePlatform.OSXEditor; isSupportedPlatform |= currPlatform == RuntimePlatform.OSXPlayer; isSupportedPlatform |= currPlatform == RuntimePlatform.WindowsEditor; isSupportedPlatform |= currPlatform == RuntimePlatform.WindowsPlayer; if (!isSupportedPlatform) { Debug.LogWarning("This platform is unsupported"); return; } #if UNITY_ANDROID && !UNITY_EDITOR // don't allow the application to run if orientation is not landscape left. if (Screen.orientation != ScreenOrientation.LandscapeLeft) { Debug.LogError("********************************************************************************\n"); Debug.LogError("***** Default screen orientation must be set to landscape left for VR.\n" + "***** Stopping application.\n"); Debug.LogError("********************************************************************************\n"); Debug.Break(); Application.Quit(); } // don't enable gyro, it is not used and triggers expensive display calls if (Input.gyro.enabled) { Debug.LogError("*** Auto-disabling Gyroscope ***"); Input.gyro.enabled = false; } // NOTE: On Adreno Lollipop, it is an error to have antiAliasing set on the // main window surface with front buffer rendering enabled. The view will // render black. // On Adreno KitKat, some tiling control modes will cause the view to render // black. if (QualitySettings.antiAliasing > 1) { Debug.LogError("*** Antialiasing must be disabled for Gear VR ***"); } // we sync in the TimeWarp, so we don't want unity // syncing elsewhere QualitySettings.vSyncCount = 0; // try to render at 60fps Application.targetFrameRate = 60; // don't allow the app to run in the background Application.runInBackground = false; // Disable screen dimming Screen.sleepTimeout = SleepTimeout.NeverSleep; if (!androidJavaInit) { AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity"); javaVrActivityClass = new AndroidJavaClass("com.oculusvr.vrlib.VrActivity"); // Prepare for the RenderThreadInit() SetInitVariables(activity.GetRawObject(), javaVrActivityClass.GetRawClass()); #if !INHIBIT_ENTITLEMENT_CHECK AndroidJavaObject entitlementChecker = new AndroidJavaObject("com.oculus.svclib.OVREntitlementChecker"); entitlementChecker.CallStatic("doAutomatedCheck", activity); #else Debug.Log( "Inhibiting Entitlement Check!" ); #endif androidJavaInit = true; } // We want to set up our touchpad messaging system OVRTouchpad.Create(); InitVolumeController(); #else SetEditorPlay(Application.isEditor); #endif prevEyeTextureAntiAliasing = OVRManager.instance.eyeTextureAntiAliasing; prevEyeTextureDepth = OVRManager.instance.eyeTextureDepth; prevEyeTextureFormat = OVRManager.instance.eyeTextureFormat; prevNativeTextureScale = OVRManager.instance.nativeTextureScale; prevVirtualTextureScale = OVRManager.instance.virtualTextureScale; prevMonoscopic = OVRManager.instance.monoscopic; prevHdr = OVRManager.instance.hdr; if (display == null) display = new OVRDisplay(); if (tracker == null) tracker = new OVRTracker(); if (resetTrackerOnLoad) display.RecenterPose(); #if !UNITY_ANDROID || UNITY_EDITOR // Except for D3D9, SDK rendering forces vsync unless you pass ovrHmdCap_NoVSync to Hmd.SetEnabledCaps(). if (timeWarp) { bool useUnityVSync = SystemInfo.graphicsDeviceVersion.Contains("Direct3D 9"); QualitySettings.vSyncCount = useUnityVSync ? 1 : 0; } #endif #if (UNITY_STANDALONE_WIN && (UNITY_4_6 || UNITY_4_5)) bool unity_4_6 = false; bool unity_4_5_2 = false; bool unity_4_5_3 = false; bool unity_4_5_4 = false; bool unity_4_5_5 = false; #if (UNITY_4_6) unity_4_6 = true; #elif (UNITY_4_5_2) unity_4_5_2 = true; #elif (UNITY_4_5_3) unity_4_5_3 = true; #elif (UNITY_4_5_4) unity_4_5_4 = true; #elif (UNITY_4_5_5) unity_4_5_5 = true; #endif // Detect correct Unity releases which contain the fix for D3D11 exclusive mode. string version = Application.unityVersion; int releaseNumber; bool releaseNumberFound = Int32.TryParse(Regex.Match(version, @"\d+$").Value, out releaseNumber); // Exclusive mode was broken for D3D9 in Unity 4.5.2p2 - 4.5.4 and 4.6 builds prior to beta 21 bool unsupportedExclusiveModeD3D9 = (unity_4_6 && version.Last(char.IsLetter) == 'b' && releaseNumberFound && releaseNumber < 21) || (unity_4_5_2 && version.Last(char.IsLetter) == 'p' && releaseNumberFound && releaseNumber >= 2) || (unity_4_5_3) || (unity_4_5_4); // Exclusive mode was broken for D3D11 in Unity 4.5.2p2 - 4.5.5p2 and 4.6 builds prior to f1 bool unsupportedExclusiveModeD3D11 = (unity_4_6 && version.Last(char.IsLetter) == 'b') || (unity_4_5_2 && version.Last(char.IsLetter) == 'p' && releaseNumberFound && releaseNumber >= 2) || (unity_4_5_3) || (unity_4_5_4) || (unity_4_5_5 && version.Last(char.IsLetter) == 'f') || (unity_4_5_5 && version.Last(char.IsLetter) == 'p' && releaseNumberFound && releaseNumber < 3); if (unsupportedExclusiveModeD3D9 && !display.isDirectMode && SystemInfo.graphicsDeviceVersion.Contains("Direct3D 9")) { MessageBox(0, "Direct3D 9 extended mode is not supported in this configuration. " + "Please use direct display mode, a different graphics API, or rebuild the application with a newer Unity version." , "VR Configuration Warning", 0); } if (unsupportedExclusiveModeD3D11 && !display.isDirectMode && SystemInfo.graphicsDeviceVersion.Contains("Direct3D 11")) { MessageBox(0, "Direct3D 11 extended mode is not supported in this configuration. " + "Please use direct display mode, a different graphics API, or rebuild the application with a newer Unity version." , "VR Configuration Warning", 0); } #endif }
private void Awake() { // Only allow one instance at runtime. if (instance != null) { enabled = false; DestroyImmediate(this); return; } instance = this; #if !UNITY_ANDROID || UNITY_EDITOR var netVersion = new System.Version(Ovr.Hmd.OVR_VERSION_STRING); var ovrVersion = new System.Version(Ovr.Hmd.GetVersionString()); if (netVersion > ovrVersion) Debug.LogWarning("Using an older version of LibOVR."); #endif // Detect whether this platform is a supported platform RuntimePlatform currPlatform = Application.platform; isSupportedPlatform |= currPlatform == RuntimePlatform.Android; isSupportedPlatform |= currPlatform == RuntimePlatform.LinuxPlayer; isSupportedPlatform |= currPlatform == RuntimePlatform.OSXEditor; isSupportedPlatform |= currPlatform == RuntimePlatform.OSXPlayer; isSupportedPlatform |= currPlatform == RuntimePlatform.WindowsEditor; isSupportedPlatform |= currPlatform == RuntimePlatform.WindowsPlayer; if (!isSupportedPlatform) { Debug.LogWarning("This platform is unsupported"); return; } #if UNITY_ANDROID && !UNITY_EDITOR Application.targetFrameRate = 60; // don't allow the app to run in the background Application.runInBackground = false; // Disable screen dimming Screen.sleepTimeout = SleepTimeout.NeverSleep; if (!androidJavaInit) { AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity"); javaVrActivityClass = new AndroidJavaClass("com.oculusvr.vrlib.VrActivity"); // Prepare for the RenderThreadInit() SetInitVariables(activity.GetRawObject(), javaVrActivityClass.GetRawClass()); androidJavaInit = true; } // We want to set up our touchpad messaging system OVRTouchpad.Create(); // This will trigger the init on the render thread InitRenderThread(); #else SetEditorPlay(Application.isEditor); #endif if (display == null) display = new OVRDisplay(); if (tracker == null) tracker = new OVRTracker(); tracker.isEnabled = false; usePositionTracking = false; if (resetTrackerOnLoad) display.RecenterPose(); // Except for D3D9, SDK rendering forces vsync unless you pass ovrHmdCap_NoVSync to Hmd.SetEnabledCaps(). if (timeWarp) { bool useUnityVSync = SystemInfo.graphicsDeviceVersion.Contains("Direct3D 9"); QualitySettings.vSyncCount = useUnityVSync ? 1 : 0; } #if (UNITY_STANDALONE_WIN && (UNITY_4_6 || UNITY_4_5)) bool unity_4_6 = false; bool unity_4_5_2 = false; bool unity_4_5_3 = false; bool unity_4_5_4 = false; bool unity_4_5_5 = false; #if (UNITY_4_6) unity_4_6 = true; #elif (UNITY_4_5_2) unity_4_5_2 = true; #elif (UNITY_4_5_3) unity_4_5_3 = true; #elif (UNITY_4_5_4) unity_4_5_4 = true; #elif (UNITY_4_5_5) unity_4_5_5 = true; #endif // Detect correct Unity releases which contain the fix for D3D11 exclusive mode. string version = Application.unityVersion; int releaseNumber; bool releaseNumberFound = Int32.TryParse(Regex.Match(version, @"\d+$").Value, out releaseNumber); // Exclusive mode was broken for D3D9 in Unity 4.5.2p2 - 4.5.4 and 4.6 builds prior to beta 21 bool unsupportedExclusiveModeD3D9 = (unity_4_6 && version.Last(char.IsLetter) == 'b' && releaseNumberFound && releaseNumber < 21) || (unity_4_5_2 && version.Last(char.IsLetter) == 'p' && releaseNumberFound && releaseNumber >= 2) || (unity_4_5_3) || (unity_4_5_4); // Exclusive mode was broken for D3D11 in Unity 4.5.2p2 - 4.5.5p2 and 4.6 builds prior to f1 bool unsupportedExclusiveModeD3D11 = (unity_4_6 && version.Last(char.IsLetter) == 'b') || (unity_4_5_2 && version.Last(char.IsLetter) == 'p' && releaseNumberFound && releaseNumber >= 2) || (unity_4_5_3) || (unity_4_5_4) || (unity_4_5_5 && version.Last(char.IsLetter) == 'f') || (unity_4_5_5 && version.Last(char.IsLetter) == 'p' && releaseNumberFound && releaseNumber < 3); if (unsupportedExclusiveModeD3D9 && !display.isDirectMode && SystemInfo.graphicsDeviceVersion.Contains("Direct3D 9")) { MessageBox(0, "Direct3D 9 extended mode is not supported in this configuration. " + "Please use direct display mode, a different graphics API, or rebuild the application with a newer Unity version." , "VR Configuration Warning", 0); } if (unsupportedExclusiveModeD3D11 && !display.isDirectMode && SystemInfo.graphicsDeviceVersion.Contains("Direct3D 11")) { MessageBox(0, "Direct3D 11 extended mode is not supported in this configuration. " + "Please use direct display mode, a different graphics API, or rebuild the application with a newer Unity version." , "VR Configuration Warning", 0); } #endif }
private void Awake() { // Only allow one instance at runtime. if (instance != null) { enabled = false; DestroyImmediate(this); return; } instance = this; #if !UNITY_ANDROID || UNITY_EDITOR if (!ovrIsInitialized) { OVR_Initialize(); OVRPluginEvent.Issue(RenderEventType.Initialize); ovrIsInitialized = true; } var netVersion = new System.Version(Ovr.Hmd.OVR_VERSION_STRING); System.Version ovrVersion = new System.Version("0.0.0"); var versionString = Ovr.Hmd.GetVersionString(); var success = false; try { ovrVersion = new System.Version(versionString); success = true; } catch (Exception e) { Debug.Log("Failed to parse Oculus version string \"" + versionString + "\" with message \"" + e.Message + "\"."); } if (!success || netVersion > ovrVersion) Debug.LogWarning("Version check failed. Please make sure you are using Oculus runtime " + Ovr.Hmd.OVR_VERSION_STRING + " or newer."); #endif // Detect whether this platform is a supported platform RuntimePlatform currPlatform = Application.platform; isSupportedPlatform |= currPlatform == RuntimePlatform.Android; isSupportedPlatform |= currPlatform == RuntimePlatform.LinuxPlayer; isSupportedPlatform |= currPlatform == RuntimePlatform.OSXEditor; isSupportedPlatform |= currPlatform == RuntimePlatform.OSXPlayer; isSupportedPlatform |= currPlatform == RuntimePlatform.WindowsEditor; isSupportedPlatform |= currPlatform == RuntimePlatform.WindowsPlayer; if (!isSupportedPlatform) { Debug.LogWarning("This platform is unsupported"); return; } #if UNITY_ANDROID && !UNITY_EDITOR // log the unity version Debug.Log( "Unity Version: " + Application.unityVersion ); // don't allow the application to run if orientation is not landscape left. if (Screen.orientation != ScreenOrientation.LandscapeLeft) { Debug.LogError("********************************************************************************\n"); Debug.LogError("***** Default screen orientation must be set to landscape left for VR.\n" + "***** Stopping application.\n"); Debug.LogError("********************************************************************************\n"); Debug.Break(); Application.Quit(); } // don't enable gyro, it is not used and triggers expensive display calls if (Input.gyro.enabled) { Debug.LogError("*** Auto-disabling Gyroscope ***"); Input.gyro.enabled = false; } // NOTE: On Adreno Lollipop, it is an error to have antiAliasing set on the // main window surface with front buffer rendering enabled. The view will // render black. // On Adreno KitKat, some tiling control modes will cause the view to render // black. if (QualitySettings.antiAliasing > 1) { Debug.LogError("*** Antialiasing must be disabled for Gear VR ***"); } // we sync in the TimeWarp, so we don't want unity // syncing elsewhere QualitySettings.vSyncCount = 0; // try to render at 60fps Application.targetFrameRate = 60; // don't allow the app to run in the background Application.runInBackground = false; // Disable screen dimming Screen.sleepTimeout = SleepTimeout.NeverSleep; if (!androidJavaInit) { AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity"); javaVrActivityClass = new AndroidJavaClass("com.oculusvr.vrlib.VrActivity"); // Prepare for the RenderThreadInit() SetInitVariables(activity.GetRawObject(), javaVrActivityClass.GetRawClass()); #if USE_ENTITLEMENT_CHECK AndroidJavaObject entitlementChecker = new AndroidJavaObject("com.oculus.svclib.OVREntitlementChecker"); entitlementChecker.CallStatic("doAutomatedCheck", activity); #else Debug.Log( "Inhibiting Entitlement Check!" ); #endif androidJavaInit = true; } // We want to set up our touchpad messaging system OVRTouchpad.Create(); InitVolumeController(); #else SetEditorPlay(Application.isEditor); #endif prevEyeTextureAntiAliasing = OVRManager.instance.eyeTextureAntiAliasing; prevEyeTextureDepth = OVRManager.instance.eyeTextureDepth; prevEyeTextureFormat = OVRManager.instance.eyeTextureFormat; prevNativeTextureScale = OVRManager.instance.nativeTextureScale; prevVirtualTextureScale = OVRManager.instance.virtualTextureScale; prevMonoscopic = OVRManager.instance.monoscopic; prevHdr = OVRManager.instance.hdr; if (display == null) display = new OVRDisplay(); if (tracker == null) tracker = new OVRTracker(); if (resetTrackerOnLoad) display.RecenterPose(); #if !UNITY_ANDROID || UNITY_EDITOR // Except for D3D9, SDK rendering forces vsync unless you pass ovrHmdCap_NoVSync to Hmd.SetEnabledCaps(). if (timeWarp) { bool useUnityVSync = SystemInfo.graphicsDeviceVersion.Contains("Direct3D 9"); QualitySettings.vSyncCount = useUnityVSync ? 1 : 0; } #endif #if UNITY_STANDALONE_WIN if (!OVRUnityVersionChecker.hasD3D9ExclusiveModeSupport && !display.isDirectMode && SystemInfo.graphicsDeviceVersion.Contains("Direct3D 9")) { MessageBox(0, "Direct3D 9 extended mode is not supported in this configuration. " + "Please use direct display mode, a different graphics API, or rebuild the application with a newer Unity version." , "VR Configuration Warning", 0); } if (!OVRUnityVersionChecker.hasD3D11ExclusiveModeSupport && !display.isDirectMode && SystemInfo.graphicsDeviceVersion.Contains("Direct3D 11")) { MessageBox(0, "Direct3D 11 extended mode is not supported in this configuration. " + "Please use direct display mode, a different graphics API, or rebuild the application with a newer Unity version." , "VR Configuration Warning", 0); } #endif }
/// <summary> /// 连接安卓 /// </summary> public void ConnectToAndriod() { try { UnityEngine.AndroidJavaClass unityPlayer = new UnityEngine.AndroidJavaClass("com.unity3d.player.UnityPlayer"); activity = unityPlayer.GetStatic <UnityEngine.AndroidJavaObject>("currentActivity"); javaVrActivityClass = new UnityEngine.AndroidJavaClass("com.picovr.picovrlib.VrActivity"); SetInitActivity(activity.GetRawObject(), javaVrActivityClass.GetRawClass()); canConnecttoActivity = true; CanConnecttoActivity = canConnecttoActivity; PicoVRManager.SDK.inPicovr = true; Headweartype = (int)PicoVRManager.SDK.DeviceType; SetPupillaryPoint(PupillaryPoint); model = javaVrActivityClass.CallStatic <string>("getBuildModel"); Debug.Log("model = " + model); if (model == "Pico Neo DK") { model = "Falcon"; } Debug.Log("SDK Version = " + GetSDKVersion() + ",UnityVersion=" + UnityVersion); Async = GetAsyncFlag(); useHMD = GetSensorExternal(); if (useHMD) { usePhoneSensor = false; } Debug.Log("ConnectToAndroid: useHMD = " + useHMD + ", usePhoneSensor = " + usePhoneSensor); if (model == "Falcon") { usePhoneSensor = false; useHMD = true; isFalcon = true; Debug.Log("ConnectToAndroid: useHMD = " + useHMD + ", usePhoneSensor = " + usePhoneSensor + ", isFalcon = " + isFalcon); Headweartype = (int)PicoVRConfigProfile.DeviceTypes.PicoNeo; Debug.Log("Falcon : " + Headweartype.ToString()); CallStaticMethod(javaVrActivityClass, "initFalconDevice", activity); } else { int deviceType = 0; CallStaticMethod <int>(ref deviceType, javaVrActivityClass, "readDeviceTypeFromWing", activity); Debug.Log("wingDeviceType = " + deviceType); if (deviceType != 0) { Headweartype = deviceType; } } double[] parameters = new double[5]; CallStaticMethod(ref parameters, javaVrActivityClass, "getDPIParameters", activity); ModifyScreenParameters(model, (int)parameters[0], (int)parameters[1], parameters[2], parameters[3], parameters[4]); ChangeHeadwear(Headweartype); SetAsyncModel(Async); Debug.Log("Async:" + Async.ToString() + " Headweartype: " + Headweartype.ToString()); startLarkConnectService(); } catch (AndroidJavaException e) { Debug.LogError("ConnectToAndriod------------------------catch" + e.Message); } }
public PlatformAndroid(string version, int capacity, int trim, string gesture) { pluginClass = new AndroidJavaClass(PluginClassName); pluginClassRaw = pluginClass.GetRawClass(); IntPtr methodInit = GetStaticMethod(pluginClassRaw, "init", "(Ljava.lang.String;IILjava.lang.String;)V"); CallStaticVoidMethod(methodInit, new jvalue[] { jval(version), jval(capacity), jval(trim), jval(gesture) }); methodLogMessage = GetStaticMethod(pluginClassRaw, "logMessage", "(Ljava.lang.String;Ljava.lang.String;I)V"); methodShowConsole = GetStaticMethod(pluginClassRaw, "show", "()V"); methodHideConsole = GetStaticMethod(pluginClassRaw, "hide", "()V"); }
// Must be launched from the game thread (otherwise the classloader cannot locate the unity // java classes we require). private static void LaunchBridgeIntent(IntPtr bridgedIntent) { object[] objectArray = new object[2]; jvalue[] jArgs = AndroidJNIHelper.CreateJNIArgArray(objectArray); try { using (var bridgeClass = new AndroidJavaClass(BridgeActivityClass)) { using (var currentActivity = AndroidTokenClient.GetActivity()) { // Unity no longer supports constructing an AndroidJavaObject using an IntPtr, // so I have to manually munge with JNI here. IntPtr methodId = AndroidJNI.GetStaticMethodID(bridgeClass.GetRawClass(), LaunchBridgeMethod, LaunchBridgeSignature); jArgs[0].l = currentActivity.GetRawObject(); jArgs[1].l = bridgedIntent; AndroidJNI.CallStaticVoidMethod(bridgeClass.GetRawClass(), methodId, jArgs); } } } catch (Exception e) { GooglePlayGames.OurUtils.Logger.e("Exception launching bridge intent: " + e.Message); GooglePlayGames.OurUtils.Logger.e(e.ToString()); } finally { AndroidJNIHelper.DeleteJNIArgArray(objectArray, jArgs); } }
private void Awake() { // Only allow one instance at runtime. if (instance != null) { enabled = false; DestroyImmediate(this); return; } instance = this; #if !UNITY_ANDROID || UNITY_EDITOR var netVersion = new System.Version(Ovr.Hmd.OVR_VERSION_STRING); var ovrVersion = new System.Version(Ovr.Hmd.GetVersionString()); if (netVersion > ovrVersion) Debug.LogWarning("Using an older version of LibOVR."); #endif // Detect whether this platform is a supported platform RuntimePlatform currPlatform = Application.platform; isSupportedPlatform |= currPlatform == RuntimePlatform.Android; isSupportedPlatform |= currPlatform == RuntimePlatform.LinuxPlayer; isSupportedPlatform |= currPlatform == RuntimePlatform.OSXEditor; isSupportedPlatform |= currPlatform == RuntimePlatform.OSXPlayer; isSupportedPlatform |= currPlatform == RuntimePlatform.WindowsEditor; isSupportedPlatform |= currPlatform == RuntimePlatform.WindowsPlayer; if (!isSupportedPlatform) { Debug.LogWarning("This platform is unsupported"); return; } #if UNITY_ANDROID && !UNITY_EDITOR Application.targetFrameRate = 60; // don't allow the app to run in the background Application.runInBackground = false; // Disable screen dimming Screen.sleepTimeout = SleepTimeout.NeverSleep; if (!androidJavaInit) { AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity"); javaVrActivityClass = new AndroidJavaClass("com.oculusvr.vrlib.VrActivity"); // Prepare for the RenderThreadInit() SetInitVariables(activity.GetRawObject(), javaVrActivityClass.GetRawClass()); androidJavaInit = true; } // We want to set up our touchpad messaging system OVRTouchpad.Create(); // This will trigger the init on the render thread InitRenderThread(); #else SetEditorPlay(Application.isEditor); #endif display = new OVRDisplay(); tracker = new OVRTracker(); // Except for D3D9, SDK rendering forces vsync unless you pass ovrHmdCap_NoVSync to Hmd.SetEnabledCaps(). if (timeWarp) { bool useUnityVSync = SystemInfo.graphicsDeviceVersion.Contains("Direct3D 9"); QualitySettings.vSyncCount = useUnityVSync ? 1 : 0; } }