Inheritance: MonoBehaviour
Example #1
0
    void Awake()
    {
        if (instance != null)
        {
            Debug.LogError("More than one GvrController instance was found in your scene. "
                           + "Ensure that there is only one GvrController.");
            this.enabled = false;
            return;
        }
        instance = this;
        if (controllerProvider == null)
        {
            controllerProvider = ControllerProviderFactory.CreateControllerProvider(this);
        }

        // Keep screen on here, in case there isn't a GvrViewerMain prefab in the scene.
        // This ensures the behaviour for:
        //   (a) Cardboard apps on pre-integration Unity versions - they must have GvrViewerMain in a scene.
        //   (b) Daydream apps - these must be on GVR-integrated Unity versions, and must have GvrControllerMain.
        // Cardboard-only apps on the native integration are likely to have GvrViewerMain in their scene; otherwise,
        // the line below can be added to any script of the developer's choice.
        Screen.sleepTimeout = SleepTimeout.NeverSleep;

#if OVERRIDE_GVR_WITH_OPENVR
        gameObject.AddComponent <SteamVR_TrackedControllerExtended>();
        gameObject.AddComponent <SteamVR_TrackedObjectExtended>();
        openVRController = gameObject.AddComponent <GvrOpenVRController>();
#endif
    }
Example #2
0
    // The event handler to call to toggle Cardboard mode.
    public void ChangeCardboardMode()
    {
        GvrController head = mainCamera.GetComponent <GvrController>();

        head.transform.localRotation = Quaternion.identity;

        PlayerPrefs.SetInt("VREnabled", 1);
        PlayerPrefs.Save();
    }
Example #3
0
    public void Start()
    {
        // Save a flag in the local player preferences to initialize VR mode
        // This way when the app is restarted, it is in the mode that was last used.
        int           doVR = PlayerPrefs.GetInt("VREnabled");
        GvrController head = mainCamera.GetComponent <GvrController>();

        head.enabled = true;
    }
Example #4
0
    void OnDestroy()
    {
        // Unregister the controller update listener.
        GvrController controller = GetComponent <GvrController>();

        controller.OnControllerUpdate -= OnControllerUpdate;

        // Reset the singleton instance.
        instance = null;
    }
 /// Provides a concrete implementation of IControllerProvider appropriate for the current
 /// platform. This method never returns null. In the worst case, it might return a dummy
 /// provider if the platform is not supported.
 internal static IControllerProvider CreateControllerProvider(GvrController owner)
 {
     #if UNITY_EDITOR || UNITY_STANDALONE
       // Use the Controller Emulator.
       return new EmulatorControllerProvider(owner.emulatorConnectionMode, true, true);
     #elif UNITY_ANDROID
       // Use the GVR C API.
       return new AndroidNativeControllerProvider(owner.enableGyro, owner.enableAccel);
     #else
       // Platform not supported.
       Debug.LogWarning("No controller support on this platform.");
       return new DummyControllerProvider();
     #endif
 }
Example #6
0
        /// Provides a concrete implementation of IControllerProvider appropriate for the current
        /// platform. This method never returns null. In the worst case, it might return a dummy
        /// provider if the platform is not supported.
        static internal IControllerProvider CreateControllerProvider(GvrController owner)
        {
#if UNITY_EDITOR || UNITY_STANDALONE
            // Use the Controller Emulator.
            return(new EmulatorControllerProvider(owner.emulatorConnectionMode));
#elif UNITY_ANDROID
            // Use the GVR C API.
            return(new AndroidNativeControllerProvider());
#else
            // Platform not supported.
            Debug.LogWarning("No controller support on this platform.");
            return(new DummyControllerProvider());
#endif  // UNITY_EDITOR || UNITY_STANDALONE
        }
    void Start()
    {
        // Obtain the Gvr controller from the scene.
        GvrController controller = GetComponent <GvrController>();

        UpdateHandedness();

        // Register the controller update listener.
        controller.OnControllerUpdate += OnControllerUpdate;

        // Reset other relevant state.
        firstUpdate = true;
        elbowOffset = Vector3.zero;
        zeroAccel.Set(0, GRAVITY_FORCE, 0);
    }
Example #8
0
 void Awake()
 {
     if (instance != null)
     {
         Debug.LogError("More than one GvrController instance was found in your scene. "
                        + "Ensure that there is only one GvrController.");
         this.enabled = false;
         return;
     }
     instance = this;
     if (controllerProvider == null)
     {
         controllerProvider = ControllerProviderFactory.CreateControllerProvider(this);
     }
 }
    /// Creates a new EmulatorControllerProvider with the specified settings.
    internal EmulatorControllerProvider(GvrController.EmulatorConnectionMode connectionMode) {
      if (connectionMode == GvrController.EmulatorConnectionMode.USB) {
        EmulatorConfig.Instance.PHONE_EVENT_MODE = EmulatorConfig.Mode.USB;
      } else if (connectionMode == GvrController.EmulatorConnectionMode.WIFI) {
        EmulatorConfig.Instance.PHONE_EVENT_MODE = EmulatorConfig.Mode.WIFI;
      } else {
        EmulatorConfig.Instance.PHONE_EVENT_MODE = EmulatorConfig.Mode.OFF;
      }

      EmulatorManager.Instance.touchEventListeners += HandleTouchEvent;
      EmulatorManager.Instance.orientationEventListeners += HandleOrientationEvent;
      EmulatorManager.Instance.buttonEventListeners += HandleButtonEvent;
      EmulatorManager.Instance.gyroEventListeners += HandleGyroEvent;
      EmulatorManager.Instance.accelEventListeners += HandleAccelEvent;
    }
    /// Provides a concrete implementation of IControllerProvider appropriate for the current
    /// platform. This method never returns null. In the worst case, it might return a dummy
    /// provider if the platform is not supported.
    static internal IControllerProvider CreateControllerProvider(GvrController owner) {
#if UNITY_EDITOR || UNITY_STANDALONE
      // SystemInfo.graphicsDeviceID is zero for Unity 5.3.3.
      if (SystemInfo.graphicsDeviceID == 0) {
        // Running headless.  Use the dummy provider.
        Debug.Log("No controller support when running headless.");
        return new DummyControllerProvider();
      }
      // Use the Controller Emulator.
      return new EmulatorControllerProvider(owner.emulatorConnectionMode);
#elif UNITY_ANDROID
      // Use the GVR C API.
      return new AndroidNativeControllerProvider();
#else
      // Platform not supported.
      Debug.LogWarning("No controller support on this platform.");
      return new DummyControllerProvider();
#endif  // UNITY_EDITOR || UNITY_STANDALONE
    }
    void Awake()
    {
        if (instance != null)
        {
            Debug.LogError("More than one GvrController instance was found in your scene. "
                           + "Ensure that there is only one GvrController.");
            this.enabled = false;
            return;
        }
        instance = this;
        if (controllerProvider == null)
        {
            controllerProvider = ControllerProviderFactory.CreateControllerProvider(this);
        }

        // Keep screen on here, since GvrController must be in any GVR scene in order to enable
        // controller capabilities.
        Screen.sleepTimeout = SleepTimeout.NeverSleep;
    }
Example #12
0
        /// Provides a concrete implementation of IControllerProvider appropriate for the current
        /// platform. This method never returns null. In the worst case, it might return a dummy
        /// provider if the platform is not supported.
        static internal IControllerProvider CreateControllerProvider(GvrController owner)
        {
#if UNITY_EDITOR || UNITY_STANDALONE
            // SystemInfo.graphicsDeviceID is zero for Unity 5.3.3.
            if (SystemInfo.graphicsDeviceID == 0)
            {
                // Running headless.  Use the dummy provider.
                Debug.Log("No controller support when running headless.");
                return(new DummyControllerProvider());
            }
            // Use the Controller Emulator.
            return(new EmulatorControllerProvider(owner.emulatorConnectionMode));
#elif UNITY_ANDROID
            // Use the GVR C API.
            return(new AndroidNativeControllerProvider());
#else
            // Platform not supported.
            Debug.LogWarning("No controller support on this platform.");
            return(new DummyControllerProvider());
#endif  // UNITY_EDITOR || UNITY_STANDALONE
        }
Example #13
0
 void OnDestroy()
 {
     instance = null;
 }
 void OnDestroy()
 {
     instance = null;
 }
    void Awake()
    {
        if (instance != null) {
          Debug.LogError("More than one GvrController instance was found in your scene. "
          + "Ensure that there is only one GvrController.");
          this.enabled = false;
          return;
        }
        instance = this;
        if (controllerProvider == null) {
          controllerProvider = ControllerProviderFactory.CreateControllerProvider(this);
        }

        // Keep screen on here, in case there isn't a GvrViewerMain prefab in the scene.
        // This ensures the behaviour for:
        //   (a) Cardboard apps on pre-integration Unity versions - they must have GvrViewerMain in a scene.
        //   (b) Daydream apps - these must be on GVR-integrated Unity versions, and must have GvrControllerMain.
        // Cardboard-only apps on the native integration are likely to have GvrViewerMain in their scene; otherwise,
        // the line below can be added to any script of the developer's choice.
        Screen.sleepTimeout = SleepTimeout.NeverSleep;

        #if OVERRIDE_GVR_WITH_OPENVR
        gameObject.AddComponent<SteamVR_TrackedControllerExtended>();
        gameObject.AddComponent<SteamVR_TrackedObjectExtended>();
        openVRController = gameObject.AddComponent<GvrOpenVRController>();
        #endif
    }
Example #16
0
 void Awake() {
   if (instance != null) {
     Debug.LogError("More than one GvrController instance was found in your scene. "
         + "Ensure that there is only one GvrController.");
     this.enabled = false;
     return;
   }
   instance = this;
   if (controllerProvider == null) {
     controllerProvider = ControllerProviderFactory.CreateControllerProvider(this);
   }
 }