diff --git a/Assets/Scripts/PetData.cs b/Assets/Scripts/PetData.cs new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/Assets/Scripts/PetData.cs.meta b/Assets/Scripts/PetData.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..9c45bed2c59e9584adc04be3b09894dccb69cf1a --- /dev/null +++ b/Assets/Scripts/PetData.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1592109dfcbf6d944b8edad5e086dbb7 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Player/PlayerData.cs b/Assets/Scripts/Player/PlayerData.cs new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/Assets/Scripts/Player/PlayerData.cs.meta b/Assets/Scripts/Player/PlayerData.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..f758d6fde1d61453d5c99a74cceff51cda6bfa26 --- /dev/null +++ b/Assets/Scripts/Player/PlayerData.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9a00aafbb5f305f4a825d692b6dec5db +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/SaveData.cs b/Assets/Scripts/SaveData.cs index 4b8ff919f6c91359c926b8e23c5500d2256db4d8..28fec9f17157c6856f4daf6f4e722e51b9f741f9 100644 --- a/Assets/Scripts/SaveData.cs +++ b/Assets/Scripts/SaveData.cs @@ -2,12 +2,61 @@ using static UnityEditor.Progress; using System.Collections.Generic; using System; using System.Numerics; +using UnityEngine; [Serializable] -public class SaveData +public class SaveData : MonoBehaviour { - public Vector3 playerPosition; - public int playerHealth; - public List<Item> inventoryItems; - // ... other game data -} \ No newline at end of file + public PlayerData playerData = new PlayerData(); + + public void SaveToJson() + { + string savePlayerData = JsonUtility.ToJson(playerData); + string filePath = Application.persistentDataPath + "/savePlayerData.json"; + Debug.Log(filePath); + System.IO.File.WriteAllText(filePath, savePlayerData); + Debug.Log("save successful"); + } + + public void LoadFromJson() + { + string filePath = Application.persistentDataPath + "/savePlayerData.json"; + string savePlayerData = System.IO.File.ReadAllText(filePath); + + playerData = JsonUtility.FromJson<PlayerData>(savePlayerData); + Debug.Log("load successful"); + } +} + +[System.Serializable] +public class PlayerData +{ + public int currentLevel; + + // from PlayerHealth.cs + public int currentHealth; + public bool godMode; + + // from PlayerMovement.cs + public float speed; + public bool isDoubleSpeed; + + // from PlayerShooting.cs + public int damagePerShot; + public bool isOneHitKill; + + // from PlayerGold.cs + public int currentGold; + public bool isMotherlode; + + public List<PetData> pet = new List<PetData>(); +} + +[System.Serializable] +public class PetData +{ + public string type; + public int currentHealth; + public int damagePerShot; + public float speed; +}