Exemplo n.º 1
0
        private static string GetManifestFile()
        {
            string text = Application.dataPath;
            int    num  = text.LastIndexOf('/');

            text = text.Remove(num, text.Length - num);
            string   text2    = Path.Combine(text, "unityProject.vrmanifest");
            FileInfo fileInfo = new FileInfo(SteamVR_Input.GetActionsFilePath(true));

            if (File.Exists(text2))
            {
                SteamVR_Input_ManifestFile steamVR_Input_ManifestFile = JsonConvert.DeserializeObject <SteamVR_Input_ManifestFile>(File.ReadAllText(text2));
                if (steamVR_Input_ManifestFile != null && steamVR_Input_ManifestFile.applications != null && steamVR_Input_ManifestFile.applications.Count > 0 && steamVR_Input_ManifestFile.applications[0].app_key != SteamVR_Settings.instance.editorAppKey)
                {
                    UnityEngine.Debug.Log("<b>[SteamVR_Standalone]</b> Deleting existing VRManifest because it has a different app key.");
                    FileInfo fileInfo2 = new FileInfo(text2);
                    if (fileInfo2.IsReadOnly)
                    {
                        fileInfo2.IsReadOnly = false;
                    }
                    fileInfo2.Delete();
                }
                if (steamVR_Input_ManifestFile != null && steamVR_Input_ManifestFile.applications != null && steamVR_Input_ManifestFile.applications.Count > 0 && steamVR_Input_ManifestFile.applications[0].action_manifest_path != fileInfo.FullName)
                {
                    UnityEngine.Debug.Log("<b>[SteamVR_Standalone]</b> Deleting existing VRManifest because it has a different action manifest path:\nExisting:" + steamVR_Input_ManifestFile.applications[0].action_manifest_path + "\nNew: " + fileInfo.FullName);
                    FileInfo fileInfo3 = new FileInfo(text2);
                    if (fileInfo3.IsReadOnly)
                    {
                        fileInfo3.IsReadOnly = false;
                    }
                    fileInfo3.Delete();
                }
            }
            if (!File.Exists(text2))
            {
                SteamVR_Input_ManifestFile steamVR_Input_ManifestFile2 = new SteamVR_Input_ManifestFile();
                steamVR_Input_ManifestFile2.source = "Unity";
                SteamVR_Input_ManifestFile_Application steamVR_Input_ManifestFile_Application = new SteamVR_Input_ManifestFile_Application();
                steamVR_Input_ManifestFile_Application.app_key = SteamVR_Settings.instance.editorAppKey;
                steamVR_Input_ManifestFile_Application.action_manifest_path = fileInfo.FullName;
                steamVR_Input_ManifestFile_Application.launch_type          = "url";
                steamVR_Input_ManifestFile_Application.url = "steam://launch/";
                steamVR_Input_ManifestFile_Application.strings.Add("en_us", new SteamVR_Input_ManifestFile_ApplicationString
                {
                    name = string.Format("{0} VR", Application.productName)
                });
                steamVR_Input_ManifestFile2.applications = new List <SteamVR_Input_ManifestFile_Application>();
                steamVR_Input_ManifestFile2.applications.Add(steamVR_Input_ManifestFile_Application);
                string contents = JsonConvert.SerializeObject(steamVR_Input_ManifestFile2, Formatting.Indented, new JsonSerializerSettings
                {
                    NullValueHandling = NullValueHandling.Ignore
                });
                File.WriteAllText(text2, contents);
            }
            return(text2);
        }
Exemplo n.º 2
0
        private static string GetManifestFile()
        {
            string currentPath = Application.dataPath;
            int    lastIndex   = currentPath.LastIndexOf('/');

            currentPath = currentPath.Remove(lastIndex, currentPath.Length - lastIndex);

            string fullPath = Path.Combine(currentPath, "unityProject.vrmanifest");

            if (File.Exists(fullPath))
            {
                string jsonText = File.ReadAllText(fullPath);
                SteamVR_Input_ManifestFile existingFile = Valve.Newtonsoft.Json.JsonConvert.DeserializeObject <SteamVR_Input_ManifestFile>(jsonText);
                if (existingFile != null && existingFile.applications != null && existingFile.applications.Count > 0 && existingFile.applications[0].app_key != SteamVR_Settings.instance.appKey)
                {
                    Debug.Log("[SteamVR] Deleting existing VRManifest because it has a different app key.");
                    FileInfo existingInfo = new FileInfo(fullPath);
                    if (existingInfo.IsReadOnly)
                    {
                        existingInfo.IsReadOnly = false;
                    }
                    existingInfo.Delete();
                }
            }

            if (File.Exists(fullPath) == false)
            {
                SteamVR_Input_ManifestFile manifestFile = new SteamVR_Input_ManifestFile();
                manifestFile.source = "Unity";
                SteamVR_Input_ManifestFile_Application manifestApplication = new SteamVR_Input_ManifestFile_Application();
                manifestApplication.app_key = SteamVR_Settings.instance.appKey;
                //manifestApplication.action_manifest_path = SteamVR_Settings.instance.actionsFilePath;
                manifestApplication.launch_type = "url";
                //manifestApplication.binary_path_windows = SteamVR_Utils.ConvertToForwardSlashes(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
                //manifestApplication.binary_path_linux = SteamVR_Utils.ConvertToForwardSlashes(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
                //manifestApplication.binary_path_osx = SteamVR_Utils.ConvertToForwardSlashes(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
                manifestApplication.url = "steam://launch/";
                manifestApplication.strings.Add("en_us", new SteamVR_Input_ManifestFile_ApplicationString()
                {
                    name = string.Format("{0} [Testing]", Application.productName)
                });
                manifestFile.applications = new System.Collections.Generic.List <SteamVR_Input_ManifestFile_Application>();
                manifestFile.applications.Add(manifestApplication);

                string json = Valve.Newtonsoft.Json.JsonConvert.SerializeObject(manifestFile, Valve.Newtonsoft.Json.Formatting.Indented,
                                                                                new Valve.Newtonsoft.Json.JsonSerializerSettings {
                    NullValueHandling = Valve.Newtonsoft.Json.NullValueHandling.Ignore
                });

                File.WriteAllText(fullPath, json);
            }

            return(fullPath);
        }
Exemplo n.º 3
0
        private static string GetManifestFile()
        {
            string currentPath = Application.dataPath;
            int    lastIndex   = currentPath.LastIndexOf('/');

            currentPath = currentPath.Remove(lastIndex, currentPath.Length - lastIndex);

            string fullPath = Path.Combine(currentPath, "unityProject.vrmanifest");

            FileInfo fullManifestPath = new FileInfo(SteamVR_Input.GetActionsFilePath());

            if (File.Exists(fullPath))
            {
                string jsonText = File.ReadAllText(fullPath);
                SteamVR_Input_ManifestFile existingFile = Valve.Newtonsoft.Json.JsonConvert.DeserializeObject <SteamVR_Input_ManifestFile>(jsonText);

                if (existingFile != null && existingFile.applications != null && existingFile.applications.Count > 0 &&
                    existingFile.applications[0].app_key != SteamVR_Settings.instance.editorAppKey)
                {
                    Debug.Log("<b>[SteamVR]</b> Deleting existing VRManifest because it has a different app key.");
                    FileInfo existingInfo = new FileInfo(fullPath);
                    if (existingInfo.IsReadOnly)
                    {
                        existingInfo.IsReadOnly = false;
                    }
                    existingInfo.Delete();
                }

                if (existingFile != null && existingFile.applications != null && existingFile.applications.Count > 0 &&
                    existingFile.applications[0].action_manifest_path != fullManifestPath.FullName)
                {
                    Debug.Log("<b>[SteamVR]</b> Deleting existing VRManifest because it has a different action manifest path:" +
                              "\nExisting:" + existingFile.applications[0].action_manifest_path +
                              "\nNew: " + fullManifestPath.FullName);
                    FileInfo existingInfo = new FileInfo(fullPath);
                    if (existingInfo.IsReadOnly)
                    {
                        existingInfo.IsReadOnly = false;
                    }
                    existingInfo.Delete();
                }
            }

            if (File.Exists(fullPath) == false)
            {
                SteamVR_Input_ManifestFile manifestFile = new SteamVR_Input_ManifestFile();
                manifestFile.source = "Unity";
                SteamVR_Input_ManifestFile_Application manifestApplication = new SteamVR_Input_ManifestFile_Application();
                manifestApplication.app_key = SteamVR_Settings.instance.editorAppKey;
                manifestApplication.action_manifest_path = fullManifestPath.FullName;
                manifestApplication.launch_type          = "url";
                //manifestApplication.binary_path_windows = SteamVR_Utils.ConvertToForwardSlashes(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
                //manifestApplication.binary_path_linux = SteamVR_Utils.ConvertToForwardSlashes(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
                //manifestApplication.binary_path_osx = SteamVR_Utils.ConvertToForwardSlashes(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
                manifestApplication.url = "steam://launch/";
                manifestApplication.strings.Add("en_us", new SteamVR_Input_ManifestFile_ApplicationString()
                {
                    name = string.Format("{0} [Testing]", Application.productName)
                });

                /*
                 * var bindings = new System.Collections.Generic.List<SteamVR_Input_ManifestFile_Application_Binding>();
                 *
                 * SteamVR_Input.InitializeFile();
                 * if (SteamVR_Input.actionFile != null)
                 * {
                 *  string[] bindingFiles = SteamVR_Input.actionFile.GetFilesToCopy(true);
                 *  if (bindingFiles.Length == SteamVR_Input.actionFile.default_bindings.Count)
                 *  {
                 *      for (int bindingIndex = 0; bindingIndex < bindingFiles.Length; bindingIndex++)
                 *      {
                 *          SteamVR_Input_ManifestFile_Application_Binding binding = new SteamVR_Input_ManifestFile_Application_Binding();
                 *          binding.binding_url = bindingFiles[bindingIndex];
                 *          binding.controller_type = SteamVR_Input.actionFile.default_bindings[bindingIndex].controller_type;
                 *          bindings.Add(binding);
                 *      }
                 *      manifestApplication.bindings = bindings;
                 *  }
                 *  else
                 *  {
                 *      Debug.LogError("<b>[SteamVR]</b> Mismatch in available binding files.");
                 *  }
                 * }
                 * else
                 * {
                 *  Debug.LogError("<b>[SteamVR]</b> Could not load actions file.");
                 * }
                 */

                manifestFile.applications = new System.Collections.Generic.List <SteamVR_Input_ManifestFile_Application>();
                manifestFile.applications.Add(manifestApplication);

                string json = Valve.Newtonsoft.Json.JsonConvert.SerializeObject(manifestFile, Valve.Newtonsoft.Json.Formatting.Indented,
                                                                                new Valve.Newtonsoft.Json.JsonSerializerSettings {
                    NullValueHandling = Valve.Newtonsoft.Json.NullValueHandling.Ignore
                });

                File.WriteAllText(fullPath, json);
            }

            return(fullPath);
        }