void _UpdateDisplay()
        {
            var lineNumbers = xmlLayout.GetElementById <InputField>("lineNumbers");

            lineNumbers.text = String.Join("\r\n", Enumerable.Range(1, 100).Select(i => i.ToString().PadLeft(2, '0')).ToArray());

            var outputField          = xmlLayout.GetElementById("output");
            var outputFieldXmlLayout = outputField.gameObject.GetComponent <XmlLayout>() ?? outputField.gameObject.AddComponent <XmlLayout>();

            outputField.ApplyAttributes(GetOutputFieldAttributes());
            outputFieldXmlLayout.gameObject.SetActive(true);

            outputFieldXmlLayout.Hide(() =>
            {
                outputFieldXmlLayout.gameObject.SetActive(true);
                outputFieldXmlLayout.Xml = this.Xml;
                try
                {
                    // We're using a custom log handler here so that any log/error messsages can be displayed in our message dialog
                    var oldHandler = Debug.unityLogger.logHandler;
                    Debug.unityLogger.logHandler = new TestLogHandler(MessageDialog, oldHandler);

                    outputFieldXmlLayout.RebuildLayout(false, true);

                    Debug.unityLogger.logHandler = oldHandler;
                }
                catch (Exception e)
                {
                    MessageDialog.Show("Xml Parse Error", e.Message);
                }

                outputField.ApplyAttributes(GetOutputFieldAttributes());
                outputFieldXmlLayout.Show();
            });
        }
Exemple #2
0
        void SubmitForm()
        {
            // xmlLayout.GetFormData() returns the values of all form objects in the layout with an 'id' set (as a Dictionary<string, string>)
            var formValues = xmlLayout.GetFormData();

            // As this is only an example, we're not going to actually use these values - instead, we'll just format them into a human-readable string and show the user
            // (with the exception of the Quality setting)
            string formattedFormValues = "<b>Form Values</b>:\n----------------------------------------\n";

            foreach (var formValue in formValues)
            {
                formattedFormValues += String.Format("<b>{0}</b>: <i>{1}</i>\n", FormatFieldName(formValue.Key), formValue.Value);
            }

            formattedFormValues += "\n\n";
            formattedFormValues += "For the purposes of this example, only the <i>Quality</i> setting will take effect.";

            // Show the formatted values in a message dialog (which is also an XmlLayout)
            MessageDialog.Show("Form Submitted", formattedFormValues);

            // Retrieve the index of the selected quality level from QualitySettings.names and set the new value
            var qualitySetting = QualitySettings.names.ToList().IndexOf(formValues["quality"]);

            QualitySettings.SetQualityLevel(qualitySetting);

            // The changes have now been 'applied', so we can clear the highlight
            ClearApplyButtonHighlight();
        }
        public void LogFormat(LogType logType, UnityEngine.Object context, string format, params object[] args)
        {
            if (!m_MessageDialog.gameObject.activeInHierarchy)
            {
                m_MessageDialog.Show(logType.ToString(), String.Format(format, args));
            }
            else
            {
                m_MessageDialog.AppendText(String.Format(format, args));
            }

            // Pass on the message to the original logger so that it can be displayed on the console as well
            m_OriginalLogger.LogFormat(logType, context, format, args);
        }
        /// <summary>
        /// This is a regular XmlLayout event which has been set up to be called
        /// whenever the 'Apply' button is clicked
        /// </summary>
        void Apply()
        {
            // All of the view model properties in this example use two-way binding, which means that the ViewModel itself is updated
            // whenever any of their values change; as such, we can utilize the 'viewModel' object to see the new values
            MessageDialog.Show("Updated ViewModel Values",
                               String.Format(@"
Resolution    : {0}
Quality       : {1}
Master Volume : {2}
Music Volume  : {3}
Sfx Volume    : {4}
Enable Hints  : {5}
", viewModel.resolution, viewModel.quality, viewModel.masterVolume, viewModel.musicVolume, viewModel.sfxVolume, viewModel.enableHints));

            // disable the apply button again
            applyButton.element.interactable = false;
        }