Пример #1
0
        public override bool InitAllControllers()
        {
            // SteamVR only works in windows.
            if (Application.platform != RuntimePlatform.WindowsEditor &&
                Application.platform != RuntimePlatform.WindowsPlayer
                )
            {
                return(false);
            }
#if STEAM_VR_SDK
            //
            bool ret = base.InitAllControllers();
            if (ret)
            {
                if (!OpenVRInterop.IsRuntimeInstalled() ||
                    !OpenVRInterop.IsHmdPresent())
                {
                    ret = false;
                }
                if (ret)
                {
                    if (inputTransforms.Length == 0)
                    {
                        inputTransforms = new InputTransform[1] {
                            null
                        };
                    }
                    controllers = new SteamVRController[maxControllers];
                    for (int i = 0; i < maxControllers; ++i)
                    {
                        controllers[i] = new SteamVRController(
                            string.Format(controllerFormat, i), i,
                            inputTransforms.Length == 1?inputTransforms[0]:inputTransforms[i]
                            );
                    }
                }
            }
            return(ret);
#else
            Log.d("SteamVRControllerManager", "Not Support!!!If you want to enable this feature,please follow these steps:\n" +
                  "    1) You need HTC Vive or other devices which can be developed by OpenVR,and remember SteamVR only works in pc.\n" +
                  "    2) Import \"SteamVR Plugin.unitypackage\"(you can download it from \"https://www.assetstore.unity3d.com/en/#!/content/32647\").\n" +
                  "    3) Add \"STEAM_VR_SDK\" to [Scripting Define Symbols] in [Player Settings](menu:Edit>Project Settings>Player).\n");
            return(false);
#endif
        }
Пример #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            EVRInitError error = EVRInitError.None;
            var          sys   = OpenVR.Init(ref error);

            // var i = OpenVRInterop.InitInternal(ref error, EVRApplicationType.VRApplication_Utility);
            try
            {
                Console.WriteLine($"Error: {error}");
                Console.WriteLine($"PResent: {sys.IsTrackedDeviceConnected(0)}");
                Console.WriteLine($"PResent: {OpenVRInterop.IsHmdPresent()}");
            }
            finally
            {
                OpenVR.Shutdown();
                // OpenVRInterop.ShutdownInternal();
            }
        }
Пример #3
0
        /// <inheritdoc />
        protected override CheckResult OnCheck()
        {
            var isApiReady   = false;
            var isHmdPresent = false;

            try
            {
                isHmdPresent = OpenVRInterop.IsHmdPresent();
                isApiReady   = true;
            }
            catch (Exception e)
            {
                Logger.GetInstance(typeof(DefaultOpenVRManager)).Error(e.ToString());
            }

            return(new CheckResult
            {
                IsApiReady = isApiReady,
                IsHmdPresent = isHmdPresent,
                IsRuntimeInstalled = Runtime.IsSteamVRInstalled(),
                IsRuntimeRunning = Runtime.IsSteamVRRunning()
            });
        }
        /// <summary>
        /// Uses OpenVR to query the installation path of SteamVR, to then build the path to the OpenXR manifest file
        /// </summary>
        /// <returns>True upon success. </returns>
        private bool ProbeForSteamVRInstallationPath()
        {
            StringBuilder pathBuilder = new StringBuilder(256);
            uint          bufferSize  = 256;

            try
            {
                if (OpenVRInterop.GetRuntimePath(pathBuilder, bufferSize, ref bufferSize))
                {
                    string pathToSteamVR = pathBuilder.ToString();
                    Debug.Print($"Found a SteamVR installation at {pathToSteamVR}");
                    string pathToSteamVRManifest = Path.Combine(pathBuilder.ToString(), "steamxr_win64.json");
                    WellKnwonOpenXRRuntimeManifestPaths.Add(pathToSteamVRManifest);
                    return(true);
                }
                return(false);
            }
            catch (DllNotFoundException e)
            {
                Debug.Print("Missing openvr_api.dll?!");
                Debug.Print(e.Message);
                return(false);
            }
        }