private void SetLoadedTiles() { //Wipe all current tiles for (int i = -15; i < 15; i++) { for (int j = -25; j < 25; j++) { if (GameObject.Find("Tile(" + j + ", " + i + ")").GetComponent <Tile_Scripts>().baseTile) { Tile_Scripts tile_Script = GameObject.Find("Tile(" + j + ", " + i + ")").GetComponent <Tile_Scripts>(); if (tile_Script.buildingID != -1) { tile_Script.childStructure.GetComponent <StructureHP>().TakeDamage(999); } } } } //Set tiles to what is loaded for (int i = 0; i < gameTilesInfoList.Count; i++) { GameTilesInfo gTI = gameTilesInfoList[i]; GameObject tile = GameObject.Find(gTI.tileName); tile.GetComponent <Tile_Scripts>().Load(gTI); } }
public void Load(GameTilesInfo _gTI) { buildingID = _gTI.buildingID; buildingHP = _gTI.buildingHP; buildingLevel = _gTI.buildingLevel; isLoading = true; GameObject structure = SpawnBuilding(_gTI.buildingTypeID, _gTI.buildingID); structure.GetComponent <BaseStructureScript>().loadedBuilding = true; structure.GetComponent <BaseStructureScript>().buildingLevel = buildingLevel; //Debug.Log(childStructure.GetComponent<BaseStructureScript>().buildingLevel); structure.GetComponent <BaseStructureScript>().BuildingLevelAnalysis(); }
public GameTilesInfo Save() { Debug.Log("Tile_Scripts -- Save"); GameTilesInfo gTI = new GameTilesInfo(); gTI.tileName = gameObject.name; gTI.buildingID = buildingID; gTI.buildingTypeID = buildingTypeID; gTI.buildingHP = childStructure.GetComponent <StructureHP>().Health; gTI.buildingLevel = childStructure.GetComponent <BaseStructureScript>().buildingLevel; return(gTI); }
//called from GameManagerScript public void SaveGame() { GameObject townHall_GO = GameObject.Find("TownHallTile(Clone)"); if (townHall_GO.GetComponent <TownHallScript>().Enemiesleft > 0) { Debug.Log("SaveLoadGame -- SaveGame: The wave is still in progress!"); return; } //If the Directory doesn't exist, then create the folder if (!Directory.Exists(Application.persistentDataPath + gameSavesDirectoryPath)) { Directory.CreateDirectory(Application.persistentDataPath + gameSavesDirectoryPath); } //Ga through and save tiles gameTilesInfoList = new List <GameTilesInfo>(); for (int i = -15; i < 15; i++) { for (int j = -25; j < 25; j++) { if (GameObject.Find("Tile(" + j + ", " + i + ")").GetComponent <Tile_Scripts>().baseTile) { //add to the list GameObject tile_GO = GameObject.Find("Tile(" + j + ", " + i + ")"); if (tile_GO.GetComponent <Tile_Scripts>().buildingID != -1) { Debug.Log(tile_GO); GameTilesInfo gTI = tile_GO.GetComponent <Tile_Scripts>().Save(); gameTilesInfoList.Add(gTI); } } } } SaveTiles(); //Save the Game Manager gameManagerInfo = GameObject.Find("GameManager").GetComponent <GameManagerScript>().SaveGameManager(); SaveGameManager(); }