コード例 #1
0
        /// <summary>
        /// Installs/Registers the application. This does not copy any files, but instead points OpenVR to the current working directory.
        /// </summary>
        /// <param name="cleanInstall">If an existing installation is found, setting cleanInstall to true will remove the old registration first (no files are deleted).</param>
        /// <param name="autoStart">If true, the registered application will start with SteamVR</param>
        public void InstallManifest(bool cleanInstall = false, bool autoStart = true)
        {
            if (File.Exists(_manifestFullPath))
            {
                bool alreadyInstalled = false;
                if (OpenVR.Applications.IsApplicationInstalled(_applicationKey))
                {
                    Console.WriteLine("Found existing installation.");
                    if (cleanInstall)
                    {
                        StringBuilder       buffer   = new StringBuilder(1024);
                        EVRApplicationError appError = new EVRApplicationError();
                        OpenVR.Applications.GetApplicationPropertyString(_applicationKey, EVRApplicationProperty.WorkingDirectory_String, buffer, 1024, ref appError);

                        if (appError == EVRApplicationError.None)
                        {
                            string oldManifestPath = Path.Combine(buffer.ToString(), _manifestFileName);
                            if (!_manifestFullPath.Equals(oldManifestPath))
                            {
                                Console.WriteLine("Clean install: Removing old manifest.");
                                OpenVR.Applications.RemoveApplicationManifest(oldManifestPath);
                                Console.WriteLine(oldManifestPath);
                            }
                            else
                            {
                                alreadyInstalled = true;
                            }
                        }
                    }
                    else
                    {
                        alreadyInstalled = true;
                    }
                }
                else
                {
                    Console.WriteLine("Could not find existing installation. Installing now...");
                }
                EVRApplicationError error = OpenVR.Applications.AddApplicationManifest(_manifestFullPath, false);
                if (error != EVRApplicationError.None)
                {
                    throw new Exception("Could not add application manifest: " + error.ToString());
                }
                else if (autoStart && (!alreadyInstalled || cleanInstall))
                {
                    error = OpenVR.Applications.SetApplicationAutoLaunch(_applicationKey, true);
                    if (error != EVRApplicationError.None)
                    {
                        throw new Exception("Could not set autostart: " + error.ToString());
                    }
                }
            }
            else
            {
                throw new Exception("Could not find application manifest: " + _manifestFullPath);
            }
        }
コード例 #2
0
        private static void IdentifyEditorApplication(bool showLogs = true)
        {
            var    manifestFI   = new FileInfo("unityProject.vrmanifest");
            string manifestPath = manifestFI.FullName;

            EVRApplicationError addManifestErr = OpenVR.Applications.AddApplicationManifest(manifestPath, true);

            if (addManifestErr != EVRApplicationError.None)
            {
                Debug.LogError("<b>[SteamVR]</b> Error adding vr manifest file: " + addManifestErr.ToString());
            }
            else
            {
                if (showLogs)
                {
                    Debug.Log("<b>[SteamVR]</b> Successfully added VR manifest to SteamVR");
                }
            }

            int processId = System.Diagnostics.Process.GetCurrentProcess().Id;
            var appkey    = string.Format("application.generated.unity.{0}.exe", GenerateCleanProductName());
            EVRApplicationError applicationIdentifyErr = OpenVR.Applications.IdentifyApplication((uint)processId, appkey);

            if (applicationIdentifyErr != EVRApplicationError.None)
            {
                Debug.LogError("<b>[SteamVR]</b> Error identifying application: " + applicationIdentifyErr.ToString());
            }
            else
            {
                if (showLogs)
                {
                    Debug.Log(string.Format("<b>[SteamVR]</b> Successfully identified process as editor project to SteamVR ({0})", appkey));
                }
            }
        }
コード例 #3
0
ファイル: SteamVR.cs プロジェクト: eLefrere/Grim
        private static void IdentifyEditorApplication(bool showLogs = true)
        {
            //bool isInstalled = OpenVR.Applications.IsApplicationInstalled(SteamVR_Settings.instance.editorAppKey);

            string manifestPath = GetManifestFile();

            EVRApplicationError addManifestErr = OpenVR.Applications.AddApplicationManifest(manifestPath, true);

            if (addManifestErr != EVRApplicationError.None)
            {
                Debug.LogError("<b>[SteamVR]</b> Error adding vr manifest file: " + addManifestErr.ToString());
            }
            else
            {
                if (showLogs)
                {
                    Debug.Log("<b>[SteamVR]</b> Successfully added VR manifest to SteamVR");
                }
            }

            int processId = System.Diagnostics.Process.GetCurrentProcess().Id;
            EVRApplicationError applicationIdentifyErr = OpenVR.Applications.IdentifyApplication((uint)processId, SteamVR_Settings.instance.editorAppKey);

            if (applicationIdentifyErr != EVRApplicationError.None)
            {
                Debug.LogError("<b>[SteamVR]</b> Error identifying application: " + applicationIdentifyErr.ToString());
            }
            else
            {
                if (showLogs)
                {
                    Debug.Log(string.Format("<b>[SteamVR]</b> Successfully identified process as editor project to SteamVR ({0})", SteamVR_Settings.instance.editorAppKey));
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// Sets the autostart property.
        /// </summary>
        /// <param name="value">If true, the application will start with SteamVR</param>
        public void SetAutoStartEnabled(bool value)
        {
            EVRApplicationError error = OpenVR.Applications.SetApplicationAutoLaunch(_applicationKey, value);

            if (error != EVRApplicationError.None)
            {
                Console.WriteLine("Could not set auto start: " + error.ToString());
            }
        }
コード例 #5
0
        public string GetApplicationsList()
        {
            List <Application> apps = new List <Application>();

            StringBuilder       keyBuffer = new StringBuilder(255);
            EVRApplicationError err       = EVRApplicationError.None;

            for (int i = 0; i < _applicationsInstance.GetApplicationCount(); i++)
            {
                err = _applicationsInstance.GetApplicationKeyByIndex((uint)i, keyBuffer, 255);

                if (err != EVRApplicationError.None)
                {
                    throw new Exception("EVRApplicationError: " + err.ToString());
                }

                Application newApp = new Application(keyBuffer.ToString());
                apps.Add(newApp);
            }

            string ret = JsonConvert.SerializeObject(apps);

            return(ret);
        }
コード例 #6
0
        private static void IdentifyEditorApplication(bool showLogs = true)
        {
            if (string.IsNullOrEmpty(SteamVR_Settings.instance.editorAppKey))
            {
                UnityEngine.Debug.LogError("<b>[SteamVR_Standalone]</b> Critical Error identifying application. EditorAppKey is null or empty. Input may not work.");
                return;
            }
            string manifestFile = SteamVR.GetManifestFile();
            EVRApplicationError evrapplicationError = OpenVR.Applications.AddApplicationManifest(manifestFile, true);

            if (evrapplicationError != EVRApplicationError.None)
            {
                UnityEngine.Debug.LogError("<b>[SteamVR_Standalone]</b> Error adding vr manifest file: " + evrapplicationError.ToString());
            }
            else if (showLogs)
            {
                UnityEngine.Debug.Log("<b>[SteamVR_Standalone]</b> Successfully added VR manifest to SteamVR_Standalone");
            }
            int id = Process.GetCurrentProcess().Id;
            EVRApplicationError evrapplicationError2 = OpenVR.Applications.IdentifyApplication((uint)id, SteamVR_Settings.instance.editorAppKey);

            if (evrapplicationError2 != EVRApplicationError.None)
            {
                UnityEngine.Debug.LogError("<b>[SteamVR_Standalone]</b> Error identifying application: " + evrapplicationError2.ToString());
                return;
            }
            if (showLogs)
            {
                UnityEngine.Debug.Log(string.Format("<b>[SteamVR_Standalone]</b> Successfully identified process as editor project to SteamVR_Standalone ({0})", SteamVR_Settings.instance.editorAppKey));
            }
        }
コード例 #7
0
 private static SteamVR CreateInstance()
 {
     SteamVR.initializedState = SteamVR.InitializedStates.Initializing;
     try
     {
         EVRInitError evrinitError = EVRInitError.None;
         OpenVR.GetGenericInterface("IVRCompositor_022", ref evrinitError);
         OpenVR.Init(ref evrinitError, EVRApplicationType.VRApplication_Scene, "");
         CVRSystem           system              = OpenVR.System;
         string              manifestFile        = SteamVR.GetManifestFile();
         EVRApplicationError evrapplicationError = OpenVR.Applications.AddApplicationManifest(manifestFile, true);
         if (evrapplicationError != EVRApplicationError.None)
         {
             UnityEngine.Debug.LogError("<b>[SteamVR_Standalone]</b> Error adding vr manifest file: " + evrapplicationError.ToString());
         }
         int id = Process.GetCurrentProcess().Id;
         OpenVR.Applications.IdentifyApplication((uint)id, SteamVR_Settings.instance.editorAppKey);
         UnityEngine.Debug.Log("Is HMD here? " + OpenVR.IsHmdPresent().ToString());
         if (evrinitError != EVRInitError.None)
         {
             SteamVR.initializedState = SteamVR.InitializedStates.InitializeFailure;
             SteamVR.ReportError(evrinitError);
             SteamVR.ReportGeneralErrors();
             SteamVR_Events.Initializing.Send(false);
             return(null);
         }
         OpenVR.GetGenericInterface("IVROverlay_021", ref evrinitError);
         if (evrinitError != EVRInitError.None)
         {
             SteamVR.initializedState = SteamVR.InitializedStates.InitializeFailure;
             SteamVR.ReportError(evrinitError);
             SteamVR_Events.Initializing.Send(false);
             return(null);
         }
         OpenVR.GetGenericInterface("IVRInput_007", ref evrinitError);
         if (evrinitError != EVRInitError.None)
         {
             SteamVR.initializedState = SteamVR.InitializedStates.InitializeFailure;
             SteamVR.ReportError(evrinitError);
             SteamVR_Events.Initializing.Send(false);
             return(null);
         }
         SteamVR.settings = SteamVR_Settings.instance;
         if (Application.isEditor)
         {
             SteamVR.IdentifyEditorApplication(true);
         }
         SteamVR_Input.IdentifyActionsFile(true);
         if (SteamVR_Settings.instance.inputUpdateMode != SteamVR_UpdateModes.Nothing || SteamVR_Settings.instance.poseUpdateMode != SteamVR_UpdateModes.Nothing)
         {
             SteamVR_Input.Initialize(false);
         }
     }
     catch (Exception arg)
     {
         UnityEngine.Debug.LogError("<b>[SteamVR_Standalone]</b> " + arg);
         SteamVR_Events.Initializing.Send(false);
         return(null);
     }
     SteamVR._enabled         = true;
     SteamVR.initializedState = SteamVR.InitializedStates.InitializeSuccess;
     SteamVR_Events.Initializing.Send(true);
     return(new SteamVR());
 }
コード例 #8
0
            public string GetPropertyString(EVRApplicationProperty prop)
            {
                EVRApplicationError err            = EVRApplicationError.None;
                StringBuilder       propertyBuffer = new StringBuilder(255);

                OpenVR.Applications.GetApplicationPropertyString(AppKey, prop, propertyBuffer, 255, ref err);

#if DEBUG
                if (err != EVRApplicationError.None)
                {
                    Console.WriteLine("EVRApplicationError on " + AppKey + " property " + prop.ToString() + ": " + err.ToString());
                }
#endif

                //Console.WriteLine(propertyBuffer.ToString());

                return(propertyBuffer.ToString());
            }
コード例 #9
0
 /// <summary>
 /// Uninstalls/Unregisters the application. No files are deleted.
 /// </summary>
 public void RemoveManifest()
 {
     if (File.Exists(_manifestFullPath))
     {
         if (OpenVR.Applications.IsApplicationInstalled(_applicationKey))
         {
             EVRApplicationError error = OpenVR.Applications.RemoveApplicationManifest(_manifestFullPath);
             if (error != EVRApplicationError.None)
             {
                 throw new Exception("Could not remove application manifest: " + error.ToString());
             }
         }
     }
     else
     {
         throw new Exception("Could not find application manifest: " + _manifestFullPath);
     }
 }