public void Load() { #if UNITY_EDITOR string path = StandaloneFileBrowser.OpenFilePanel("Open a map file", Environment.GetFolderPath(Environment.SpecialFolder.Desktop), new ExtensionFilter[] { new ExtensionFilter("Map files", "clhier") }, false).FirstOrDefault(); #else string path = FindObjectOfType <InputField>().text; #endif if (path == null) { return; } foreach (AssetRepresentation i in FindObjectsOfType <AssetRepresentation>()) { Destroy(i.gameObject); } try { HierarchyNode node = HierarchyNode.FromFile(path); Deserialize(node); } catch (Exception ex) { Debug.Log(ex); } }
/// <summary> /// Loads the given file path and initializes the setup controls with its contents /// </summary> /// <param name="path">Path to the file to load</param> public void LoadFile(string path) { try { /* * Read preset file */ HierarchyNode node; try { node = HierarchyNode.FromFile(path); } catch (Exception) { MessageBox.Show("The specified file was not found or could not be openend!", "Open file error!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //Preset is of type: to-time if (node["PresetType"].String == "toTime") { //Navigate to to-time screen tabs.SelectedIndex = 0; //Load advanced-mode switch chkAdv.Checked = node["EnableExtendedSelector"].Boolean; //Load date values if (node["EnableExtendedSelector"].Boolean) { numYear.Value = node["Target;Date;Year"].Int; knbMonth.Value = node["Target;Date;Month"].Int; knbDay.Value = node["Target;Date;Day"].Int; knbSec.Value = node["Target;Time;Second"].Int; } //Load time values knbHour.Value = node["Target;Time;Hour"].Int; knbMin.Value = node["Target;Time;Minute"].Int; } //Preset is of type: duration else if (node["PresetType"].String == "duration") { //Navigate to duration screen tabs.SelectedIndex = 1; //Load time values knbDurHour.Value = node["Target;Hours"].Int; knbDurMin.Value = node["Target;Minutes"].Int; knbDurSec.Value = node["Target;Seconds"].Int; } //The preset did not have a valid header else { throw new ArgumentOutOfRangeException("Invalid preset type!"); } //Load the color scheme cboxColors.SelectedIndex = node["ColorScheme"]?.Int ?? 0; } catch (Exception ex) { MessageBox.Show("Something went wrong while loading this file:\r\n" + ex.Message, "Open file error!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } }