using PashaBibko.Pacore.Attributes; using UnityEngine; using System.IO; using System; namespace Fruitomation.Global { [Serializable] public class PlayerInfoData { public bool CompletedTutorial; public double CurrentMoney; } [CreateInstanceOnStart] public class PlayerInfo : MonoBehaviour { private static string Filepath => Path.Combine(Application.persistentDataPath, "playerinfo.json"); public static PlayerInfoData Data { get; private set; } private static PlayerInfoData CreateDefaultPlayerData() { PlayerInfoData data = new() { CompletedTutorial = false, CurrentMoney = 0d }; return data; } private void Awake() { if (!File.Exists(Filepath)) { Data = CreateDefaultPlayerData(); return; } string json = File.ReadAllText(Filepath); Data = json == "" ? CreateDefaultPlayerData() : JsonUtility.FromJson(json); } private void OnDestroy() { Data.CurrentMoney = MoneyController.CurrentAmount; string json = JsonUtility.ToJson(Data, true); File.WriteAllText(Filepath, json); } } }