public static ArtContainer Load(string path) { var serializer = new XmlSerializer(typeof(ArtContainer)); ArtContainer deserialized = null; string path2; #if WINDOWS_UWP path2 = Path.GetFullPath(Path.Combine(Application.persistentDataPath + "/" + "data.xml")); try { using (FileStream reader = File.Open(path2, FileMode.Open)) { return(serializer.Deserialize(reader) as ArtContainer); } } catch (System.Exception e) { Debug.LogWarningFormat("Error loading animation : {0}", e.Message); return(deserialized); } #else using (var stream = new FileStream(path, FileMode.Open)) { return(serializer.Deserialize(stream) as ArtContainer); } #endif }
void PopulateArt() { var ArtCollection = ArtContainer.Load(Path.Combine(Application.dataPath, "Resources/data.xml")); foreach (Art art in ArtCollection.Arts) { GameObject myArt = Instantiate(artPrefab, new Vector3(0, 0, 0), Quaternion.identity); //create new art instant myArt.transform.parent = arts.transform; //make this child to Artifacts in hierarchy //populate it with data from ArtCollection //add title myArt.transform.Find("Interface").Find("title").GetComponent <TextMeshPro>().text = art.title; //add description myArt.transform.Find("Interface").Find("description").GetComponent <TextMeshPro>().text = art.decription; //add art number myArt.transform.GetComponent <ArtController>().number = art.number; myArt.name = "Art" + art.number; //add category myArt.transform.GetComponent <ArtController>().category = art.category; //add image string ImageName = art.image + "Back"; MeshRenderer mr = myArt.transform.Find("Sphere").GetComponent <MeshRenderer>(); mr.material = Resources.Load(ImageName, typeof(Material)) as Material; myArt.gameObject.SetActive(false); } }