/// <summary> /// Retrieves a specific display configuration based on the name. /// </summary> /// <param name="name">the configuration name to look for</param> /// <returns>the configuration or <c>null</c> if the configuration doesn't exist</returns> /// public DisplayConfig GetConfig(string name) { if (displays == null) { ParseDisplayProfiles(); } DisplayConfig config = displays[SimplifyConfigName(name)]; if (config == null) { Debug.LogWarning("Could not find VR Display Configuration '" + name + "'"); } return(config); }
public static DisplayConfig FromJson(string jsonTxt) { // read base config first to get type DisplayConfig config = JsonUtility.FromJson <DisplayConfig>(jsonTxt); // now create specific type switch (config.Type) { case DisplayType.Screen: config = JsonUtility.FromJson <ScreenConfig>(jsonTxt); break; case DisplayType.HMD: config = JsonUtility.FromJson <HMD_Config>(jsonTxt); break; default: break; // just return base type } return(config); }
private void ParseDisplayProfiles() { // JSON file cannot directly be read because of polymorphism > split manually // remove tabs and linefeeds string txtConfig = ConfigFile.text.Replace("\t", "").Replace("\n", ""); // cut beginning and end txtConfig = Regex.Replace(txtConfig, "^\\s*{\\s*\"Displays\":\\[\\s*{", ""); txtConfig = Regex.Replace(txtConfig, "}\\s*\\]\\s*}\\s*$", ""); // split string[] displayConfigs = Regex.Split(txtConfig, "}\\s*,\\s*{"); displays = new Dictionary <string, DisplayConfig>(); string logTxt = ""; foreach (string configTxt in displayConfigs) { try { string configTxtTrim = "{" + configTxt + "}"; DisplayConfig config = DisplayConfig.FromJson(configTxtTrim); if (config != null) { displays.Add(SimplifyConfigName(config.Name), config); logTxt += ((logTxt.Length > 0) ? ", " : "") + config.Name; } } catch (System.Exception e) { Debug.LogWarning("Could not parse VR Display Device Configuration entry " + "'" + configTxt + "'" + " - Reason: " + e.Message); } } Debug.Log("Loaded Display Configurations: " + logTxt); }