Added basic upgrade menu
This commit is contained in:
2579
Assets/Scenes/UpgradesScene.unity
Normal file
2579
Assets/Scenes/UpgradesScene.unity
Normal file
File diff suppressed because it is too large
Load Diff
7
Assets/Scenes/UpgradesScene.unity.meta
Normal file
7
Assets/Scenes/UpgradesScene.unity.meta
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 4d80f82202f8e9e4a904349507d7458c
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
128
Assets/Scripts/Game/UpgradeManager.cs
Normal file
128
Assets/Scripts/Game/UpgradeManager.cs
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Fruitomation.Game
|
||||||
|
{
|
||||||
|
[Serializable] public enum BasicUpgrade
|
||||||
|
{
|
||||||
|
Grapes,
|
||||||
|
Bananas,
|
||||||
|
Kiwi,
|
||||||
|
Mangoes,
|
||||||
|
Durian,
|
||||||
|
BuddhasHand,
|
||||||
|
Pitayas,
|
||||||
|
|
||||||
|
AppleSlices,
|
||||||
|
DriedAppleSlices,
|
||||||
|
AppleJuice,
|
||||||
|
GrapeJuice,
|
||||||
|
Wine,
|
||||||
|
Raisins,
|
||||||
|
DriedFruitSelection,
|
||||||
|
BananaSlices,
|
||||||
|
DriedBananaSlices,
|
||||||
|
BananaBacon,
|
||||||
|
BananaPeeler,
|
||||||
|
KiwiPresser,
|
||||||
|
KiwiSeedOil,
|
||||||
|
KiwiVinegar,
|
||||||
|
AppleMangoJuice,
|
||||||
|
SlicedKiwi,
|
||||||
|
BananaIceCream,
|
||||||
|
MangoJuice,
|
||||||
|
MangoSlices,
|
||||||
|
SpicedBananaIceCream,
|
||||||
|
DurianPowder,
|
||||||
|
DurianSlices,
|
||||||
|
ExoticFruitSelection,
|
||||||
|
BuddhasHandSlices,
|
||||||
|
PitayaPeeler,
|
||||||
|
PitayaFoodDye,
|
||||||
|
PitayaIceCream,
|
||||||
|
SpicedPitayaIceCream,
|
||||||
|
}
|
||||||
|
|
||||||
|
public class UnlockedUpgrades
|
||||||
|
{
|
||||||
|
[Serializable] public class Serialized
|
||||||
|
{
|
||||||
|
[SerializeField] private BasicUpgrade[] BasicUpgrades;
|
||||||
|
|
||||||
|
private Serialized()
|
||||||
|
{
|
||||||
|
// All logic done in Serialize
|
||||||
|
}
|
||||||
|
|
||||||
|
public UnlockedUpgrades Unserialize()
|
||||||
|
{
|
||||||
|
UnlockedUpgrades upgrades = new();
|
||||||
|
foreach (BasicUpgrade upgrade in BasicUpgrades)
|
||||||
|
{
|
||||||
|
Debug.Log($"Restored [{upgrade}] upgrade");
|
||||||
|
upgrades.Unlocks.Add(upgrade);
|
||||||
|
}
|
||||||
|
|
||||||
|
return upgrades;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Serialized Serialize(UnlockedUpgrades upgrades)
|
||||||
|
{
|
||||||
|
Serialized serialized = new()
|
||||||
|
{
|
||||||
|
BasicUpgrades = upgrades.Unlocks.ToArray()
|
||||||
|
};
|
||||||
|
|
||||||
|
return serialized;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private HashSet<BasicUpgrade> Unlocks = new();
|
||||||
|
|
||||||
|
public void Unlock(BasicUpgrade upgrade)
|
||||||
|
{
|
||||||
|
Unlocks.Add(upgrade);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class UpgradeManager : MonoBehaviour
|
||||||
|
{
|
||||||
|
private static string Filepath => Path.Combine(Application.persistentDataPath, "upgrades.json");
|
||||||
|
private static UnlockedUpgrades CurrentUpgrades;
|
||||||
|
|
||||||
|
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
|
||||||
|
private static void LoadSavedUpgrades()
|
||||||
|
{
|
||||||
|
if (File.Exists(Filepath))
|
||||||
|
{
|
||||||
|
string json = File.ReadAllText(Filepath);
|
||||||
|
UnlockedUpgrades.Serialized serialized = JsonUtility.FromJson<UnlockedUpgrades.Serialized>(json);
|
||||||
|
|
||||||
|
if (serialized is not null)
|
||||||
|
{
|
||||||
|
CurrentUpgrades = JsonUtility.FromJson<UnlockedUpgrades.Serialized>(json).Unserialize();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CurrentUpgrades ??= new UnlockedUpgrades();
|
||||||
|
|
||||||
|
Application.quitting += SaveUpgradesToDisk;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void SaveUpgradesToDisk()
|
||||||
|
{
|
||||||
|
UnlockedUpgrades.Serialized serialized = UnlockedUpgrades.Serialized.Serialize(CurrentUpgrades);
|
||||||
|
string json = JsonUtility.ToJson(serialized, true);
|
||||||
|
File.WriteAllText(Filepath, json);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UnlockBasicUpgrade(string id)
|
||||||
|
{
|
||||||
|
BasicUpgrade upgrade = Enum.Parse<BasicUpgrade>(id);
|
||||||
|
CurrentUpgrades.Unlock(upgrade);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
3
Assets/Scripts/Game/UpgradeManager.cs.meta
Normal file
3
Assets/Scripts/Game/UpgradeManager.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 38c26644b322484cb5ca345985d03dd9
|
||||||
|
timeCreated: 1776174265
|
||||||
@@ -20,7 +20,7 @@ namespace Fruitomation.UI
|
|||||||
UpgradesButton.onClick.AddListener(() =>
|
UpgradesButton.onClick.AddListener(() =>
|
||||||
{
|
{
|
||||||
GameStateController.State = GameState.UpgradeMenu;
|
GameStateController.State = GameState.UpgradeMenu;
|
||||||
SceneController.StartLoadOf("SampleScene");
|
SceneController.StartLoadOf("UpgradesScene");
|
||||||
});
|
});
|
||||||
|
|
||||||
SimulateButton.onClick.AddListener(() =>
|
SimulateButton.onClick.AddListener(() =>
|
||||||
|
|||||||
@@ -6,6 +6,10 @@ EditorBuildSettings:
|
|||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
m_Scenes:
|
m_Scenes:
|
||||||
- enabled: 1
|
- enabled: 1
|
||||||
path: Assets/Scenes/SampleScene.unity
|
path: Assets/Scenes/GameScene.unity
|
||||||
guid: 99c9720ab356a0642a771bea13969a05
|
guid: 99c9720ab356a0642a771bea13969a05
|
||||||
|
- enabled: 1
|
||||||
|
path: Assets/Scenes/UpgradesScene.unity
|
||||||
|
guid: 4d80f82202f8e9e4a904349507d7458c
|
||||||
m_configObjects: {}
|
m_configObjects: {}
|
||||||
|
m_UseUCBPForAssetBundles: 0
|
||||||
|
|||||||
@@ -835,8 +835,10 @@ PlayerSettings:
|
|||||||
scriptingDefineSymbols: {}
|
scriptingDefineSymbols: {}
|
||||||
additionalCompilerArguments: {}
|
additionalCompilerArguments: {}
|
||||||
platformArchitecture: {}
|
platformArchitecture: {}
|
||||||
scriptingBackend: {}
|
scriptingBackend:
|
||||||
il2cppCompilerConfiguration: {}
|
Standalone: 1
|
||||||
|
il2cppCompilerConfiguration:
|
||||||
|
Standalone: 1
|
||||||
il2cppCodeGeneration: {}
|
il2cppCodeGeneration: {}
|
||||||
il2cppStacktraceInformation: {}
|
il2cppStacktraceInformation: {}
|
||||||
managedStrippingLevel:
|
managedStrippingLevel:
|
||||||
|
|||||||
Reference in New Issue
Block a user