コード例 #1
0
        // Initialization function.
        public AndroidNativeKeyboardProvider()
        {
#if UNITY_ANDROID && !UNITY_EDITOR
            // Running on Android device.
            AndroidJavaObject activity = GvrActivityHelper.GetActivity();
            if (activity == null)
            {
                Debug.Log("Failed to get activity for keyboard.");
                return;
            }

            AndroidJavaObject context = GvrActivityHelper.GetApplicationContext(activity);
            if (context == null)
            {
                Debug.Log("Failed to get context for keyboard.");
                return;
            }

            AndroidJavaObject plugin = new AndroidJavaObject(KEYBOARD_JAVA_CLASS);
            if (plugin != null)
            {
                plugin.Call("initializeKeyboard", context);
                isValid = true;
            }
#endif // UNITY_ANDROID && !UNITY_EDITOR
            renderEventFunction = GetKeyboardRenderEventFunc();
        }
コード例 #2
0
        // Returns true if the VrInputMethod APK is at least as high as MIN_VERSION_VRINPUTMETHOD.
        private bool IsVrInputMethodAppMinVersion(GvrKeyboard.KeyboardCallback keyboardEvent)
        {
#if UNITY_ANDROID && !UNITY_EDITOR
            // Running on Android device.
            AndroidJavaObject activity = GvrActivityHelper.GetActivity();
            if (activity == null)
            {
                Debug.Log("Failed to get activity for keyboard.");
                return(false);
            }
            AndroidJavaObject packageManager = activity.Call <AndroidJavaObject>(METHOD_NAME_GET_PACKAGE_MANAGER);
            if (packageManager == null)
            {
                Debug.Log("Failed to get activity package manager");
                return(false);
            }

            AndroidJavaObject info = packageManager.Call <AndroidJavaObject>(METHOD_NAME_GET_PACKAGE_INFO, PACKAGE_NAME_VRINPUTMETHOD, 0);
            if (info == null)
            {
                Debug.Log("Failed to get package info for com.google.android.apps.vr.inputmethod");
                return(false);
            }

            int versionCode = info.Get <int>(FIELD_NAME_VERSION_CODE);
            if (versionCode < MIN_VERSION_VRINPUTMETHOD)
            {
                keyboardEvent(IntPtr.Zero, GvrKeyboardEvent.GVR_KEYBOARD_ERROR_SDK_LOAD_FAILED);
                return(false);
            }
            return(true);
#else
            return(true);
#endif  // UNITY_ANDROID && !UNITY_EDITOR
        }
コード例 #3
0
    // Running on an Android device.
    private static bool IsDeviceDaydreamReady()
    {
        // Check API level.
        using (var version = new AndroidJavaClass(PACKAGE_BUILD_VERSION)) {
            if (version.GetStatic <int>(FIELD_SDK_INT) < ANDROID_MIN_DAYDREAM_API)
            {
                return(false);
            }
        }
        // API level > 24, check whether the device is Daydream-ready..
        AndroidJavaObject androidActivity = null;

        try {
            androidActivity = GvrActivityHelper.GetActivity();
        } catch (AndroidJavaException e) {
            Debug.LogError("Exception while connecting to the Activity: " + e);
            return(false);
        }
        AndroidJavaClass daydreamApiClass = new AndroidJavaClass(PACKAGE_DAYDREAM_API_CLASS);

        if (daydreamApiClass == null || androidActivity == null)
        {
            return(false);
        }
        return(daydreamApiClass.CallStatic <bool>(METHOD_IS_DAYDREAM_READY, androidActivity));
    }
コード例 #4
0
        // Initialization function.
        public AndroidNativeKeyboardProvider()
        {
#if UNITY_HAS_GOOGLEVR && UNITY_ANDROID && !UNITY_EDITOR
            AndroidJavaObject activity = GvrActivityHelper.GetActivity();
            if (activity == null)
            {
                Debug.Log("Failed to get activity for keyboard.");
                return;
            }

            AndroidJavaObject context = GvrActivityHelper.GetApplicationContext(activity);
            if (context == null)
            {
                Debug.Log("Failed to get context for keyboard.");
                return;
            }

            AndroidJavaObject plugin = new AndroidJavaObject(KEYBOARD_JAVA_CLASS);
            if (plugin != null)
            {
                plugin.Call("initializeKeyboard", context);
                isValid = true;
            }
#endif // UNITY_HAS_GOOGLEVR && UNITY_ANDROID && !UNITY_EDITOR
       // Prevent compilation errors on 5.3.3 and lower.
#if UNITY_HAS_GOOGLEVR
            UnityEngine.XR.InputTracking.disablePositionalTracking = true;
#endif  // UNITY_HAS_GOOGLEVR
            renderEventFunction = GetKeyboardRenderEventFunc();
        }
コード例 #5
0
        internal AndroidNativeControllerProvider()
        {
#if !UNITY_EDITOR
            Debug.Log("Initializing Daydream controller API.");

            int options = gvr_controller_get_default_options();
            options |= GVR_CONTROLLER_ENABLE_ACCEL;
            options |= GVR_CONTROLLER_ENABLE_GYRO;

            statePtr = gvr_controller_state_create();
            // Get a hold of the activity, context and class loader.
            AndroidJavaObject activity = GvrActivityHelper.GetActivity();
            if (activity == null)
            {
                error        = true;
                errorDetails = "Failed to get Activity from Unity Player.";
                return;
            }
            androidContext = GvrActivityHelper.GetApplicationContext(activity);
            if (androidContext == null)
            {
                error        = true;
                errorDetails = "Failed to get Android application context from Activity.";
                return;
            }
            classLoader = GetClassLoaderFromActivity(activity);
            if (classLoader == null)
            {
                error        = true;
                errorDetails = "Failed to get class loader from Activity.";
                return;
            }

            // Use IntPtr instead of GetRawObject() so that Unity can shut down gracefully on
            // Application.Quit(). Note that GetRawObject() is not pinned by the receiver so it's not
            // cleaned up appropriately on shutdown, which is a known bug in Unity.
            IntPtr androidContextPtr = AndroidJNI.NewLocalRef(androidContext.GetRawObject());
            IntPtr classLoaderPtr    = AndroidJNI.NewLocalRef(classLoader.GetRawObject());
            Debug.Log("Creating and initializing GVR API controller object.");
            api = gvr_controller_create_and_init_android(IntPtr.Zero, androidContextPtr, classLoaderPtr,
                                                         options, IntPtr.Zero);
            AndroidJNI.DeleteLocalRef(androidContextPtr);
            AndroidJNI.DeleteLocalRef(classLoaderPtr);
            if (IntPtr.Zero == api)
            {
                Debug.LogError("Error creating/initializing Daydream controller API.");
                error        = true;
                errorDetails = "Failed to initialize Daydream controller API.";
                return;
            }

            Debug.Log("GVR API successfully initialized. Now resuming it.");
            gvr_controller_resume(api);
            Debug.Log("GVR API resumed.");
#endif
        }
コード例 #6
0
ファイル: GvrIntent.cs プロジェクト: Cinth010/LabPhysics
    private static AndroidJavaObject GetIntent()
    {
        AndroidJavaObject androidActivity = null;

        try {
            androidActivity = GvrActivityHelper.GetActivity();
        } catch (AndroidJavaException e) {
            Debug.LogError("Exception while connecting to the Activity: " + e);
            return(null);
        }
        return(androidActivity.Call <AndroidJavaObject>(METHOD_GET_INTENT));
    }
コード例 #7
0
    /// Asynchronously instantiates a GvrDayreamApi.
    ///
    /// The provided callback will be called with a bool argument indicating
    /// whether instance creation was successful.
    public static void CreateAsync(Action <bool> callback)
    {
        if (m_instance == null)
        {
            m_instance = new GvrDaydreamApi();
        }
#if UNITY_ANDROID && !UNITY_EDITOR
        if (m_instance.m_daydreamApiObject != null)
        {
            return;
        }

        if (m_instance.m_daydreamApiClass == null)
        {
            Debug.LogErrorFormat("Failed to get DaydreamApi class, {0}", PACKAGE_DAYDREAM_API);
            return;
        }

        AndroidJavaObject activity = GvrActivityHelper.GetActivity();
        if (activity == null)
        {
            Debug.LogError("DaydreamApi.Create failed to get acitivty");
            return;
        }

        AndroidJavaObject context = GvrActivityHelper.GetApplicationContext(activity);
        if (context == null)
        {
            Debug.LogError("DaydreamApi.Create failed to get application context from activity");
            return;
        }

        activity.Call(METHOD_RUN_ON_UI_THREAD, new AndroidJavaRunnable(() =>
        {
            m_instance.m_daydreamApiObject =
                m_instance.m_daydreamApiClass.CallStatic <AndroidJavaObject>(METHOD_CREATE, context);
            bool success = m_instance.m_daydreamApiObject != null;
            if (!success)
            {
                Debug.LogErrorFormat("DaydreamApi.Create call to {0} failed to instantiate object",
                                     METHOD_CREATE);
            }

            if (callback != null)
            {
                callback(success);
            }
        }));
#endif  // UNITY_ANDROID && !UNITY_EDITOR
    }
コード例 #8
0
    /// <summary>
    /// Initializes the fragment via JNI.
    /// </summary>
    /// <returns>True if fragment was initialized.</returns>
    protected bool InitializeFragment()
    {
#if !UNITY_ANDROID || UNITY_EDITOR
        Debug.LogWarning("GvrPermissionsRequester requires the Android runtime environment");
        return(false);
#else
        AndroidJavaClass ajc = new AndroidJavaClass(FRAGMENT_CLASSNAME);

        if (ajc != null)
        {
            // Get the PermissionsRequesterFragment object
            permissionsFragment = ajc.CallStatic <AndroidJavaObject>("getInstance",
                                                                     GvrActivityHelper.GetActivity());
        }

        return(permissionsFragment != null &&
               permissionsFragment.GetRawObject() != IntPtr.Zero);
#endif  // !UNITY_ANDROID || UNITY_EDITOR
    }
コード例 #9
0
    /// <summary>
    /// Initializes the fragment via JNI.
    /// </summary>
    /// <returns>True if fragment was initialized.</returns>
    protected bool InitializeFragment()
    {
#if UNITY_EDITOR
        Debug.LogWarning("GvrKeyboardIntent requires the Android runtime environment");
        return(false);
#elif UNITY_ANDROID
        AndroidJavaClass ajc = new AndroidJavaClass(FRAGMENT_CLASSNAME);

        if (ajc != null)
        {
            // Get the KeyboardFragment object
            keyboardFragment = ajc.CallStatic <AndroidJavaObject>("getInstance",
                                                                  GvrActivityHelper.GetActivity());
        }

        return(keyboardFragment != null &&
               keyboardFragment.GetRawObject() != IntPtr.Zero);
#endif
    }
コード例 #10
0
    /// #endcond

    /// Instantiates a GvrDayreamApi.
    public static void Create()
    {
        if (m_instance == null)
        {
            m_instance = new GvrDaydreamApi();
        }
#if !UNITY_EDITOR && UNITY_HAS_GOOGLEVR && UNITY_ANDROID
        if (m_instance.m_daydreamApiObject != null)
        {
            return;
        }

        if (m_instance.m_daydreamApiClass == null)
        {
            Debug.LogErrorFormat("Failed to get DaydreamApi class, {0}", PACKAGE_DAYDREAM_API);
            return;
        }

        AndroidJavaObject activity = GvrActivityHelper.GetActivity();
        if (activity == null)
        {
            return;
        }

        AndroidJavaObject context = GvrActivityHelper.GetApplicationContext(activity);
        if (context == null)
        {
            return;
        }

        activity.Call(METHOD_RUN_ON_UI_THREAD, new AndroidJavaRunnable(() => {
            m_instance.m_daydreamApiObject =
                m_instance.m_daydreamApiClass.CallStatic <AndroidJavaObject>(METHOD_CREATE, context);
            if (m_instance.m_daydreamApiObject == null)
            {
                Debug.LogError("DaydreamApi.Create failed to instantiate object");
            }
        })
                      );
#endif  // !UNITY_EDITOR && UNITY_HAS_GOOGLEVR && UNITY_ANDROID
    }
コード例 #11
0
        internal AndroidNativeControllerProvider()
        {
            // Debug.Log("Initializing Daydream controller API.");

            int options = gvr_controller_get_default_options();

            options |= GVR_CONTROLLER_ENABLE_ACCEL;
            options |= GVR_CONTROLLER_ENABLE_GYRO;
            options |= GVR_CONTROLLER_ENABLE_POSITION;

            statePtr = gvr_controller_state_create();
            // Get a hold of the activity, context and class loader.
            AndroidJavaObject activity = GvrActivityHelper.GetActivity();

            if (activity == null)
            {
                error        = true;
                errorDetails = "Failed to get Activity from Unity Player.";
                return;
            }
            androidContext = GvrActivityHelper.GetApplicationContext(activity);
            if (androidContext == null)
            {
                error        = true;
                errorDetails = "Failed to get Android application context from Activity.";
                return;
            }
            classLoader = GetClassLoaderFromActivity(activity);
            if (classLoader == null)
            {
                error        = true;
                errorDetails = "Failed to get class loader from Activity.";
                return;
            }

            // Use IntPtr instead of GetRawObject() so that Unity can shut down gracefully on
            // Application.Quit(). Note that GetRawObject() is not pinned by the receiver so it's not
            // cleaned up appropriately on shutdown, which is a known bug in Unity.
            IntPtr androidContextPtr = AndroidJNI.NewLocalRef(androidContext.GetRawObject());
            IntPtr classLoaderPtr    = AndroidJNI.NewLocalRef(classLoader.GetRawObject());

            Debug.Log("Creating and initializing GVR API controller object.");
            api = gvr_controller_create_and_init_android(IntPtr.Zero, androidContextPtr, classLoaderPtr,
                                                         options, IntPtr.Zero);
            AndroidJNI.DeleteLocalRef(androidContextPtr);
            AndroidJNI.DeleteLocalRef(classLoaderPtr);
            if (IntPtr.Zero == api)
            {
                Debug.LogError("Error creating/initializing Daydream controller API.");
                error        = true;
                errorDetails = "Failed to initialize Daydream controller API.";
                return;
            }

            try {
                gvr_controller_state_get_battery_charging(statePtr);
                gvr_controller_state_get_battery_level(statePtr);
                hasBatteryMethods = true;
            } catch (EntryPointNotFoundException) {
                // Older VrCore version. Does not support battery indicator.
                // Note that controller API is not dynamically loaded as of June 2017 (b/35662043),
                // so we'll need to support this case indefinitely...
            }

            // Debug.Log("GVR API successfully initialized. Now resuming it.");
            gvr_controller_resume(api);
            // Debug.Log("GVR API resumed.");
        }