Made money save to file
This commit is contained in:
@@ -9854,6 +9854,7 @@ RectTransform:
|
||||
- {fileID: 1512838242}
|
||||
- {fileID: 1377362335}
|
||||
- {fileID: 120641731}
|
||||
- {fileID: 1719094753}
|
||||
m_Father: {fileID: 0}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0, y: 0}
|
||||
@@ -10315,6 +10316,81 @@ RectTransform:
|
||||
m_AnchoredPosition: {x: 0, y: 100}
|
||||
m_SizeDelta: {x: 100, y: 100}
|
||||
m_Pivot: {x: 0.5, y: 0.5}
|
||||
--- !u!1 &1719094752
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 1719094753}
|
||||
- component: {fileID: 1719094755}
|
||||
- component: {fileID: 1719094754}
|
||||
m_Layer: 5
|
||||
m_Name: BigUpgradeInfoBoard
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!224 &1719094753
|
||||
RectTransform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1719094752}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 1601651585}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0.5, y: 0.5}
|
||||
m_AnchorMax: {x: 0.5, y: 0.5}
|
||||
m_AnchoredPosition: {x: 0, y: 0}
|
||||
m_SizeDelta: {x: 3840, y: 2160}
|
||||
m_Pivot: {x: 0.5, y: 0.5}
|
||||
--- !u!114 &1719094754
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1719094752}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier: UnityEngine.UI::UnityEngine.UI.Image
|
||||
m_Material: {fileID: 0}
|
||||
m_Color: {r: 0.23529412, g: 0.23529412, b: 0.23529412, a: 0.5882353}
|
||||
m_RaycastTarget: 1
|
||||
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
|
||||
m_Maskable: 1
|
||||
m_OnCullStateChanged:
|
||||
m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_Sprite: {fileID: 0}
|
||||
m_Type: 0
|
||||
m_PreserveAspect: 0
|
||||
m_FillCenter: 1
|
||||
m_FillMethod: 4
|
||||
m_FillAmount: 1
|
||||
m_FillClockwise: 1
|
||||
m_FillOrigin: 0
|
||||
m_UseSpriteMesh: 0
|
||||
m_PixelsPerUnitMultiplier: 1
|
||||
--- !u!222 &1719094755
|
||||
CanvasRenderer:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1719094752}
|
||||
m_CullTransparentMesh: 1
|
||||
--- !u!1 &1721077920
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
@@ -9,8 +9,8 @@ namespace Fruitomation.Global
|
||||
private static MoneyController Instance;
|
||||
|
||||
[SerializeField, InspectorReadOnly("Current Money")]
|
||||
private double InternalCurrentMoney = new();
|
||||
public static double Current => Instance.InternalCurrentMoney;
|
||||
private double InternalCurrentMoney;
|
||||
public static double CurrentAmount => Instance.InternalCurrentMoney;
|
||||
|
||||
public static void Add(double amount)
|
||||
{
|
||||
@@ -39,5 +39,10 @@ namespace Fruitomation.Global
|
||||
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
InternalCurrentMoney = PlayerInfo.Data.CurrentMoney;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
52
Assets/Scripts/Global/PlayerInfo.cs
Normal file
52
Assets/Scripts/Global/PlayerInfo.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
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<PlayerInfoData>(json);
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
Data.CurrentMoney = MoneyController.CurrentAmount;
|
||||
|
||||
string json = JsonUtility.ToJson(Data, true);
|
||||
File.WriteAllText(Filepath, json);
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Global/PlayerInfo.cs.meta
Normal file
2
Assets/Scripts/Global/PlayerInfo.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8846c38a3d06a3249ad538d59638d5a5
|
||||
@@ -9,6 +9,6 @@ namespace Fruitomation.UI
|
||||
[SerializeField] private Text MoneyText;
|
||||
|
||||
private void Update() =>
|
||||
MoneyText.text = $"Current Money: {MoneyController.Current:F1}";
|
||||
MoneyText.text = $"Current Money: {MoneyController.CurrentAmount:F1}";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user