/// <summary> /// loading and spawning plant information /// </summary> public void loadPlant() { FileStream fs = null; try { fs = new FileStream(SAVEPLANTLOCATION + SAVE_NAME, FileMode.Open); BinaryFormatter bf = new BinaryFormatter(); PlantSaveData psd = (PlantSaveData)bf.Deserialize(fs); LoadingMoney(psd.money, psd.waterr, psd.crops); planted(psd.isWaterVis, psd.isVisible, psd.isGrowing, psd.growthExp); // spawnPlant(psd.plantPosX, psd.plantPosY, psd.plantPosZ); fs.Close(); print("loaded"); } catch (Exception e) { print(e); } finally { if (fs != null) { fs.Close(); } } }
/// <summary> /// save plant /// </summary> public void savePlant() { money = UI.score; cropAmmount = UI.crops; waterAmmount = UI.water; plants = FindObjectsOfType <FlagForSaving>(); FileStream fs = null; try { setWaterAndVisible(); ///getPlantPosition(); PlantSaveData psd = new PlantSaveData(isWater, isVisible, isGrowing, growthEXP, money, cropAmmount, waterAmmount); fs = new FileStream(SAVEPLANTLOCATION + SAVE_NAME, FileMode.Create); BinaryFormatter bf = new BinaryFormatter(); bf.Serialize(fs, psd); fs.Close(); print("Save"); } catch (Exception e) { print(e); } finally { if (fs != null) { fs.Close(); } } }