/** * Deserializes the xml file ("Path") into the WalkableGraph Object "Graph". */ private void DeserializeXml() { if (Config.URLUSED) { StartCoroutine(DeserializeXmlFromURL()); return; } // Load the file from StreamingAssets as a String. var fileAsStr = GetFileData(Path); // XML deserialize into the WalkableGraph object "graph". var memStream = new MemoryStream(Encoding.UTF8.GetBytes(fileAsStr)); var serializer = new XmlSerializer(typeof(WalkableGraph)); Graph = (WalkableGraph)serializer.Deserialize(memStream); }
/** * Deserializes the xml file from the URL given in the Config into the WalkableGraph Object "Graph" */ private IEnumerator DeserializeXmlFromURL() { using (UnityWebRequest www = UnityWebRequest.Get(Config.URL + Config.XMLNAME)) { yield return(www.SendWebRequest()); // XML deserialize into the WalkableGraph object "graph". var memStream = new MemoryStream(www.downloadHandler.data); var serializer = new XmlSerializer(typeof(WalkableGraph)); Graph = (WalkableGraph)serializer.Deserialize(memStream); // Compute the right Distances from pov to groupd and from group to their respective nodes. ComputeDistances(); // Load global value from Config. Distance = Config.POV_GROUP_DISTANCE; // Pass the PaperInfo/SciGraph data to the InfoPanel/ImageHolder. InfoPanel.GetComponent <IInfoPanel>().Paper = Graph.PaperInfo.Paper; InfoPanel.SetActive(true); InfoPanel.GetComponent <IInfoPanel>().createContent(); InfoPanel.SetActive(false); // If the sciGraph file does not exist, or is even null, hide the button. if (string.IsNullOrEmpty(Graph.PaperInfo.Paper.SciGraph)) { transform.Find("Menu/SciGraph").gameObject.SetActive(false); } else { ImageHolder.SetActive(true); ImageHolder.GetComponent <IImageHolder>().SciGraph = Graph.PaperInfo.Paper.SciGraph; StartCoroutine(ImageHolder.GetComponent <IImageHolder>().createContentFromURL()); } deserializationIsDone = true; } }