Exemple #1
0
        /// <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)
        {
            DisplayConfig foundConfig = null;

            if (displays == null)
            {
                ParseDisplayProfiles();
            }

            foreach (DisplayConfig config in displays)
            {
                if (name.Equals(config.Name))
                {
                    foundConfig = config;
                    break;
                }
            }

            if (foundConfig == null)
            {
                Debug.LogWarning("Could not find VR Display Configuration '" + name + "'");
            }

            return(foundConfig);
        }
        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);
        }
Exemple #3
0
        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 an 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 List <DisplayConfig>();
            string logTxt = "";

            foreach (string configTxt in displayConfigs)
            {
                try
                {
                    string        configTxtTrim = "{" + configTxt + "}";
                    DisplayConfig config        = DisplayConfig.FromJson(configTxtTrim);
                    if (config != null)
                    {
                        displays.Add(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);
        }