private void OrganiseGroceryList(JB_PlayerData data) { GameObject groceryManagerObj = GameObject.FindGameObjectWithTag("GroceryManager"); GameObject[] groceryItems = GameObject.FindGameObjectsWithTag("Item"); //List<bool> itemsPickedUp = new List<bool>(); for (int i = 0; i < data.itemsPickedUp.Count; ++i) { //itemsPickedUp.Add(data.itemsPickedUp[i]); if (data.itemsPickedUp[i]) { groceryManagerObj.GetComponent <JB_GroceryManager>().itemPickedUp[i] = false; groceryManagerObj.GetComponent <JB_GroceryManager>().SwapGreenTick((GroceryList)i); foreach (GameObject grocery in groceryItems) { if ((GroceryList)i == grocery.GetComponent <JB_GroceryItem>().groceryType) { Destroy(grocery); } } } } }
public static void SavePlayer(JB_PlayerUnit player) { BinaryFormatter formatter = new BinaryFormatter(); // finds a directory on any operating system the game is running on string path = Application.persistentDataPath + "/player.dat"; FileStream stream = new FileStream(path, FileMode.Create); JB_PlayerData data = new JB_PlayerData(player); // writing data to our file formatter.Serialize(stream, data); stream.Close(); }
public void LoadPlayer() { JB_PlayerData data = JB_SaveSystem.LoadPlayer(); OrganiseGroceryList(data); List <bool> leverArray = new List <bool>(); List <bool> waterMoveArray = new List <bool>(); List <bool> waterToggleArray = new List <bool>(); foreach (bool item in data.levers) { leverArray.Add(item); } foreach (bool item in data.waterMovables) { waterMoveArray.Add(item); } foreach (bool item in data.waterToggles) { waterToggleArray.Add(item); } playerUnit.GetComponent <JB_PlayerUnit>().LoadSceneItems(leverArray, waterMoveArray, waterToggleArray); playerUnit.GetComponent <JB_PlayerUnit>().canMove = data.movable; CheckPlayerType(data.heroType); Vector2 position; position.x = data.position[0]; position.y = data.position[1]; playerUnit.transform.position = position; for (int i = 0; i < data.itemsPickedUp.Count; ++i) { playerUnit.GetComponent <JB_PlayerUnit>().itemsPickedUp[i] = data.itemsPickedUp[i]; } }
public static JB_PlayerData LoadPlayer() { // finds a directory on any operating system the game is running on string path = Application.persistentDataPath + "/player.dat"; if (File.Exists(path)) { BinaryFormatter formatter = new BinaryFormatter(); FileStream stream = new FileStream(path, FileMode.Open); JB_PlayerData data = formatter.Deserialize(stream) as JB_PlayerData; stream.Close(); return(data); } else { Debug.LogError("Save file not found in " + path); return(null); } }