//READING / SAVING XML FILE public void ReadXMLTiles() { var tileContainer = TileCollection.Load(Path.Combine(Application.dataPath, "Tiles.xml")); // var xmlData = @"<TileCollection><tiles><Tiles name=""a""><model_path></model_path>x<material_path>y</material_path></Tiles></tiles></TileCollection>"; // var tileContainer = TileCollection.LoadFromText(xmlData); // Debug.Log("Number of tiles in database: " + tileContainer.tiles.Length); // Debug.Log(tileContainer.tiles[0].model_path); // AddButton(tileContainer.tiles.Length); //ADD BUTTONS TO UI var parentDatabase = new GameObject(); parentDatabase.name = "Tile_Database"; parentDatabase.layer = 10; for (int c = 0; c < tileContainer.tiles.Length; c++) { FilePath = tileContainer.tiles[c].model_path; Debug.Log(tileContainer.tiles[c].model_path); // FilePath = "Models/Tiles/Floors/nukeguard/mesh1"; GameObject model = Resources.Load <GameObject>(FilePath); GameObject obj = (GameObject)Instantiate(model); // obj.AddComponent(typeof(LODGroup)); foreach (Transform child in obj.transform) { child.gameObject.layer = 10; } // obj.SetActive(false); obj.transform.SetParent(parentDatabase.transform); // obj.name = tileContainer.tiles[c].Name; obj.name = c.ToString(); newButton = Instantiate(Button); but = newButton.GetComponent <SelectTileButton>(); but.TileID = c; newButton.GetComponentInChildren <Text>().text = tileContainer.tiles[c].Name; newButton.transform.SetParent(BuildingMenu.transform); // TO REMOVE WHEN ALL TILES IS UNIFIED if (obj.transform.Find("Camera") != null) { obj.transform.Find("Camera").GetComponent <Camera>().enabled = false; } // END REMOVE //obj.GetComponent<LODGroup>(). // /* if (obj.transform.Find("model") != null) { group = obj.AddComponent <LODGroup>(); // Add 4 LOD levels LOD[] lods = new LOD[4]; for (int i = 0; i < 4; i++) { GameObject primType = obj.transform.Find("model").gameObject; switch (i) { case 1: primType = obj.transform.Find("lod1").gameObject; break; case 2: primType = obj.transform.Find("lod2").gameObject; break; case 3: primType = obj.transform.Find("lod3").gameObject; break; } Renderer[] renderers = new Renderer[1]; renderers[0] = primType.GetComponentInChildren <Renderer>(); lods[i] = new LOD(1.0F / (i + 1.2f), renderers); } group.SetLODs(lods); group.RecalculateBounds(); } } }
public void SaveXMLTiles() { var tileContainer = TileCollection.Load(Path.Combine(Application.dataPath, "Tiles.xml")); tileContainer.Save(Path.Combine(Application.persistentDataPath, "Tiles.xml")); }