Пример #1
0
        protected virtual void ToggleSDKVisibility()
        {
            VRTK_SDKSetup sdkType = VRTK_SDKManager.GetLoadedSDKSetup();

            if (sdkType != null)
            {
                VRTK_ControllerReference leftController  = VRTK_ControllerReference.GetControllerReference(VRTK_DeviceFinder.GetControllerLeftHand(true));
                VRTK_ControllerReference rightController = VRTK_ControllerReference.GetControllerReference(VRTK_DeviceFinder.GetControllerRightHand(true));
                switch (sdkType.name)
                {
                case "SteamVR":
                    ToggleControllerRenderer(leftController.actual, "Model");
                    ToggleControllerRenderer(rightController.actual, "Model");
                    break;

                case "Oculus":
                    ToggleControllerRenderer(leftController.model);
                    ToggleControllerRenderer(rightController.model);
                    break;

                case "WindowsMR":
                    ToggleControllerRenderer(leftController.model, "glTFController");
                    ToggleControllerRenderer(rightController.model, "glTFController");
                    break;
                }
            }
        }
Пример #2
0
 /// <summary>
 /// Observable Unloaded event
 /// </summary>
 /// <param name="events"></param>
 /// <returns></returns>
 public static IObservable <VRTK_SDKSetup> UnloadedAsObservable(this VRTK_SDKSetup events)
 {
     return(Observable.FromEvent <VRTK_SDKSetup.LoadEventHandler, VRTK_SDKSetup>(
                h => (s, e) => h(e),
                h => events.Unloaded += h,
                h => events.Unloaded -= h));
 }
Пример #3
0
        private void LoadedSetupChanged(VRTK_SDKManager sender, VRTK_SDKManager.LoadedSetupChangeEventArgs e)
        {
            VRTK_SDKSetup loadedSetup = sdkManager.loadedSetup;

            if (loadedSetup == null)
            {
                return;
            }

            trackerTransform           = loadedSetup.actualBoundaries.transform;
            headSensor.sensorTransform = loadedSetup.actualHeadset.transform;

            VrtkHand.ControllerType controllerType = VrtkHand.ControllerType.None;
            if (loadedSetup.controllerSDK.GetType() == typeof(SDK_SteamVRController))
            {
                controllerType = VrtkHand.ControllerType.SteamVRController;
            }
            else if (loadedSetup.controllerSDK.GetType() == typeof(SDK_OculusController))
            {
                controllerType = VrtkHand.ControllerType.OculusTouch;
            }

            humanoid.leftHandTarget.vrtk.SetSensorTransform(loadedSetup.actualLeftController.transform, controllerType);
            humanoid.rightHandTarget.vrtk.SetSensorTransform(loadedSetup.actualRightController.transform, controllerType);
        }
Пример #4
0
    private void SDK_Loaded(VRTK_SDKManager sender, VRTK_SDKManager.LoadedSetupChangeEventArgs e)
    {
        VRTK_SDKSetup setup = e.currentSetup;

        // When switching scenes, we can get a non-existent SDK for some reason
        if (setup == null)
        {
            return;
        }

        m_headsetObject = setup.actualHeadset.transform;
    }
Пример #5
0
        protected virtual void FixOculus()
        {
#if VRTK_DEFINE_SDK_OCULUS
            string        oculusPath    = "[VRTK_SDKManager]/[VRTK_SDKSetups]/Oculus";
            GameObject    oculusSDK     = GameObject.Find(oculusPath);
            GameObject    currentRig    = GameObject.Find(oculusPath + "/OVRCameraRig");
            GameObject    currentAvatar = GameObject.Find(oculusPath + "/LocalAvatar");
            VRTK_SDKSetup oculusSetup   = oculusSDK.GetComponent <VRTK_SDKSetup>();

            if (currentRig != null)
            {
                DestroyImmediate(currentRig);
            }
            if (currentAvatar != null)
            {
                DestroyImmediate(currentAvatar);
            }

            GameObject ovrCameraRig = PrefabUtility.InstantiatePrefab((GameObject)AssetDatabase.LoadAssetAtPath("Assets/Oculus/VR/Prefabs/OVRCameraRig.prefab", typeof(GameObject))) as GameObject;
            if (ovrCameraRig != null)
            {
                ovrCameraRig.transform.SetParent(oculusSDK.transform);
                ovrCameraRig.SetActive(false);
                oculusSetup.actualBoundaries      = ovrCameraRig;
                oculusSetup.actualHeadset         = GameObject.Find(oculusPath + "/OVRCameraRig/TrackingSpace/CenterEyeAnchor");
                oculusSetup.actualLeftController  = GameObject.Find(oculusPath + "/OVRCameraRig/TrackingSpace/LeftHandAnchor");
                oculusSetup.actualRightController = GameObject.Find(oculusPath + "/OVRCameraRig/TrackingSpace/RightHandAnchor");
                OVRManager ovrManager = ovrCameraRig.GetComponent <OVRManager>();
                ovrManager.trackingOriginType = OVRManager.TrackingOrigin.FloorLevel;
                Debug.Log("Successfully repaired Oculus OVRCameraRig prefab");
            }

            GameObject ovrAvatar = PrefabUtility.InstantiatePrefab((GameObject)AssetDatabase.LoadAssetAtPath("Assets/Oculus/Avatar/Content/Prefabs/LocalAvatar.prefab", typeof(GameObject))) as GameObject;
            if (ovrAvatar == null)
            {
                //legacy location
                ovrAvatar = PrefabUtility.InstantiatePrefab((GameObject)AssetDatabase.LoadAssetAtPath("Assets/OvrAvatar/Content/Prefabs/LocalAvatar.prefab", typeof(GameObject))) as GameObject;
            }
            if (ovrAvatar != null)
            {
                ovrAvatar.transform.SetParent(oculusSDK.transform);
                ovrAvatar.SetActive(false);
                oculusSetup.modelAliasLeftController  = GameObject.Find(oculusPath + "/LocalAvatar/controller_left");
                oculusSetup.modelAliasRightController = GameObject.Find(oculusPath + "/LocalAvatar/controller_right");
                GameObject.Find(oculusPath + "/LocalAvatar/hand_left").SetActive(false);
                GameObject.Find(oculusPath + "/LocalAvatar/hand_right").SetActive(false);
                VRTK_TransformFollow transformFollow = ovrAvatar.AddComponent <VRTK_TransformFollow>();
                transformFollow.gameObjectToFollow = ovrCameraRig;
                Debug.Log("Successfully repaired Oculus LocalAvatar prefab");
            }
#endif
        }
Пример #6
0
        public override void OnInspectorGUI()
        {
            // Read any updates on the serialized object
            serializedObject.Update();

            // Prompt the user for the SDK selection
            sdkIndex.intValue = EditorGUILayout.Popup(sdkIndex.intValue, sdkNameList.ToArray());

            VRTK_SDKSetup selectedSDK  = sdkArray[sdkIndex.intValue];
            List <string> trackerNames = new List <string>();

            // Turn the tracker list into an array of string names
            foreach (GameObject currentTracker in selectedSDK.actualTrackers)
            {
                trackerNames.Add(currentTracker.name);
            }

            // Prompt user for the tracker selection
            trackerIndex.intValue = EditorGUILayout.Popup(trackerIndex.intValue, trackerNames.ToArray());

            // Save changes made to the serialized object
            serializedObject.ApplyModifiedProperties();
        }
Пример #7
0
    // Use this for initialization
    void Start()
    {
        //mainMenu = GameObject.Find("MainMenu").GetComponent<Canvas>();
        playVR  = GameObject.Find("playVR").GetComponent <Button>();
        playFPS = GameObject.Find("playFPS").GetComponent <Button>();
        credits = GameObject.Find("credits").GetComponent <Button>();
        exitBtn = GameObject.Find("exitBtn").GetComponent <Button>();
        version = GameObject.Find("version").GetComponent <Text>();


        playVR.onClick.AddListener(onPlayVRClicked);
        playFPS.onClick.AddListener(onPlayFPSButtonClicked);
        credits.onClick.AddListener(onCreditsButtonClicked);
        exitBtn.onClick.AddListener(onExitButtonClicked);

        sdk  = GameObject.Find("VRTKSDK").GetComponentInChildren <VRTK_SDKSetup>();
        menu = gameObject.GetComponent <Canvas>();
        cam  = GameObject.Find("fallbackCam");

        version.text = Application.version;
        setupMenu(new Scene(), LoadSceneMode.Single);
        SceneManager.sceneLoaded += setupMenu;
    }
Пример #8
0
    private void SDK_Loaded(VRTK_SDKManager sender, VRTK_SDKManager.LoadedSetupChangeEventArgs e)
    {
        VRTK_SDKSetup setup = e.currentSetup;

        // When switching scenes, we can get a non-existent SDK for some reason
        if (setup == null)
        {
            return;
        }

        // TODO: Obtain actual controller references somehow (VRTK_ControllerReference.GetControllerReference does not get the actual reference)
        leftController  = setup.modelAliasLeftController;
        rightController = setup.modelAliasRightController;

        InputManager.AddUserController(setup.modelAliasLeftController);
        InputManager.AddUserController(setup.modelAliasRightController);

        VRTK_ControllerEvents[] events = new VRTK_ControllerEvents[] { leftControllerEvent, rightControllerEvent };

        foreach (VRTK_ControllerEvents controllerEvents in events)
        {
            controllerEvents.ButtonTwoReleased += OnMenuRelease;
            controllerEvents.ButtonTwoPressed  += OnMenuPress;

            controllerEvents.TouchpadPressed  += OnTouchpadPress;
            controllerEvents.TouchpadReleased += OnTouchpadRelease;

            controllerEvents.GripClicked   += OnGripPress;
            controllerEvents.GripUnclicked += OnGripRelease;

            controllerEvents.TriggerAxisChanged += OnTriggerChange;

            controllerEvents.TriggerPressed  += OnTriggerPressed;
            controllerEvents.TriggerReleased += OnTriggerReleased;
        }
    }
        protected virtual void FixOculus()
        {
#if VRTK_DEFINE_SDK_OCULUS
            string     oculusPath = "[VRTK_SDKManager]/[VRTK_SDKSetups]/Oculus";
            GameObject oculusSDK  = GameObject.Find(oculusPath);

            if (oculusSDK == null || oculusSDK.GetComponentInChildren <OVRManager>() != null)
            {
                Debug.Log("No Oculus Repaired Required");
                return;
            }

            GameObject    currentRig    = GameObject.Find(oculusPath + "/OVRCameraRig");
            GameObject    currentAvatar = GameObject.Find(oculusPath + "/LocalAvatar");
            VRTK_SDKSetup oculusSetup   = oculusSDK.GetComponent <VRTK_SDKSetup>();

            if (currentRig != null)
            {
                DestroyImmediate(currentRig);
            }
            if (currentAvatar != null)
            {
                DestroyImmediate(currentAvatar);
            }

            GameObject ovrCameraRig = null;
            GameObject ovrCameraRigToInstantiate = (GameObject)AssetDatabase.LoadAssetAtPath("Assets/Oculus/VR/Prefabs/OVRCameraRig.prefab", typeof(GameObject));
            if (ovrCameraRigToInstantiate != null)
            {
                ovrCameraRig = Instantiate(ovrCameraRigToInstantiate) as GameObject;
            }
            if (ovrCameraRig != null)
            {
                ovrCameraRig.name = ovrCameraRig.name.Replace("(Clone)", "");
                ovrCameraRig.transform.SetParent(oculusSDK.transform);
                ovrCameraRig.SetActive(true);
                oculusSetup.actualBoundaries      = ovrCameraRig;
                oculusSetup.actualHeadset         = GameObject.Find(oculusPath + "/OVRCameraRig/TrackingSpace/CenterEyeAnchor");
                oculusSetup.actualLeftController  = GameObject.Find(oculusPath + "/OVRCameraRig/TrackingSpace/LeftHandAnchor");
                oculusSetup.actualRightController = GameObject.Find(oculusPath + "/OVRCameraRig/TrackingSpace/RightHandAnchor");
                Debug.Log("Successfully repaired Oculus OVRCameraRig prefab");
            }

            GameObject ovrAvatar = null;
            GameObject ovrAvatarToInstantiate = (GameObject)AssetDatabase.LoadAssetAtPath("Assets/Oculus/Avatar/Content/Prefabs/LocalAvatar.prefab", typeof(GameObject));
            if (ovrAvatarToInstantiate != null)
            {
                ovrAvatar = Instantiate(ovrAvatarToInstantiate) as GameObject;
            }

            if (ovrAvatar == null)
            {
                //legacy location
                ovrAvatarToInstantiate = (GameObject)AssetDatabase.LoadAssetAtPath("Assets/OvrAvatar/Content/Prefabs/LocalAvatar.prefab", typeof(GameObject));
                if (ovrAvatarToInstantiate != null)
                {
                    ovrAvatar = Instantiate(ovrAvatarToInstantiate) as GameObject;
                }
            }
            if (ovrAvatar != null)
            {
                OvrAvatar avatarScript = ovrAvatar.GetComponent <OvrAvatar>();
                avatarScript.StartWithControllers = true;
                ovrAvatar.name = ovrAvatar.name.Replace("(Clone)", "");
                ovrAvatar.transform.SetParent(oculusSDK.transform);
                ovrAvatar.SetActive(true);
                oculusSetup.modelAliasLeftController  = GameObject.Find(oculusPath + "/LocalAvatar/controller_left");
                oculusSetup.modelAliasRightController = GameObject.Find(oculusPath + "/LocalAvatar/controller_right");
                GameObject.Find(oculusPath + "/LocalAvatar/hand_left").SetActive(false);
                GameObject.Find(oculusPath + "/LocalAvatar/hand_right").SetActive(false);
                VRTK_TransformFollow transformFollow = ovrAvatar.AddComponent <VRTK_TransformFollow>();
                transformFollow.gameObjectToFollow = ovrCameraRig;
                Debug.Log("Successfully repaired Oculus LocalAvatar prefab");
            }
#endif
        }