public void Save() { BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Create(Application.persistentDataPath + "/apiaryData.nut"); ApiaryData data = new ApiaryData(); //<<<-------------SAVING DATA--------------->>> Dictionary <string, int> burs = new Dictionary <string, int>(); foreach (GameObject obj in bees) { Bee bee = obj.GetComponentInChildren <Bee>(); burs.Add(bee.type, bee.quantity); } data.beeQuants = burs; data.slotOne = beeSlotOne.GetComponentInChildren <RawImage>().texture.name; data.slotTwo = beeSlotTwo.GetComponentInChildren <RawImage>().texture.name; if (resultOne == null) { data.resOne = "HOCUSPOCUS"; } else { if (justFinished == false || resultOne.enabled == false || resultTwo.enabled == false || resultThree.enabled == false)//should fix it but still isnt perfect { data.resOne = "HOCUSPOCUS"; } else { data.resOne = resultOne.GetComponentInChildren <RawImage>().texture.name; data.resTwo = resultTwo.GetComponentInChildren <RawImage>().texture.name; data.resThree = resultThree.GetComponentInChildren <RawImage>().texture.name; data.honeyRes = breed.honeyNumberResult; } } if (breedTimer > 0) { data.turns = breedTimer; } else { data.turns = 0; } //<<<-------------END OF SAVING DATA--------------->>> //need a different file for each data bf.Serialize(file, data); file.Close(); }
public void Load(int loadedFrom, int currentLoad) { if (File.Exists(Application.persistentDataPath + "/apiaryData.nut")) { BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(Application.persistentDataPath + "/apiaryData.nut", FileMode.Open); ApiaryData data = (ApiaryData)bf.Deserialize(file); //<<<-------------LOADING DATA--------------->>> GameObject beeOne = null, beeTwo = null; foreach (GameObject obj in bees) { Bee bee = obj.GetComponentInChildren <Bee>(); bee.quantity = data.beeQuants[bee.name]; if (bee.updateVisuals()) { DisplayBee(obj, bee); } else { obj.SetActive(false); } //MAYBE: save all data that is needed: on load hard reset everything... THEN load the results //should work regardless as name will be 'blueflower' if no bees if (bee.name == data.slotOne) { beeSlotOne.texture = obj.GetComponentInChildren <RawImage>().texture; beeSlotOne.enabled = true; beeOne = obj; } if (bee.name == data.slotTwo) { beeSlotTwo.texture = obj.GetComponentInChildren <RawImage>().texture; beeSlotTwo.enabled = true; beeTwo = obj; } if (data.resOne != "HOCUSPOCUS") { //WE WOULD HAVE TO CHECK: turns for that recipe, how many turns inbetween, what the turns was when they were loaded //need some funky setImageCode in here; if (bee.name == data.resOne) { resultOne.enabled = true; resultOneButton.enabled = true; resultOne.texture = obj.GetComponentInChildren <RawImage>().texture; beeResultOne = obj; } if (bee.name == data.resTwo) { resultTwo.enabled = true; resultTwoButton.enabled = true; resultTwo.texture = obj.GetComponentInChildren <RawImage>().texture; beeResultTwo = obj; } if (bee.name == data.resThree) { resultThree.enabled = true; resultThreeButton.enabled = true; resultThree.texture = obj.GetComponentInChildren <RawImage>().texture; beeResultThree = obj; } } } if (data.turns > 0) { //HERE DO THE FUNKY BUSINESS. Null check here is unnecessary as this will not run unless they are not null (i think) breed.startBreeding(beeOne, beeTwo); //then hardcode turns remaining as a fix breedTimer = data.turns; breedText.text = "Days: " + breedTimer.ToString(); beeSlotOne.GetComponentInChildren <Button>().enabled = false; beeSlotTwo.GetComponentInChildren <Button>().enabled = false; //DISABLE BUTTON } else { breedTimerText(-100); beeSlotOne.texture = beeSlotOne.GetComponentInChildren <BeeSlotScript>().defaultTexture; beeSlotOne.enabled = false; beeSlotTwo.texture = beeSlotOne.GetComponentInChildren <BeeSlotScript>().defaultTexture; beeSlotTwo.enabled = false; } if (data.resOne != "HOCUSPOCUS") //if NOT: we only want to do these ONCE after the bees have been looped through { enableHoney(); honeyResultText.GetComponentInChildren <Text>().text = data.honeyRes.ToString(); } else { disableHoney(); resultOne.enabled = false; resultOneButton.enabled = false; resultTwo.enabled = false; resultTwoButton.enabled = false; resultThree.enabled = false; resultThreeButton.enabled = false; } //<<<-------------END OF LOADING DATA--------------->>> file.Close(); } }