Started adding building unlocks
This commit is contained in:
@@ -9,6 +9,7 @@ namespace Fruitomation.Game
|
|||||||
[System.Serializable] public class BuildingInfo
|
[System.Serializable] public class BuildingInfo
|
||||||
{
|
{
|
||||||
public string Name;
|
public string Name;
|
||||||
|
public BuildingUnlock Requirement;
|
||||||
public GameObject Prefab;
|
public GameObject Prefab;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using UnityEngine;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
@@ -12,6 +13,7 @@ namespace Fruitomation.Game
|
|||||||
{
|
{
|
||||||
[Serializable] public enum BasicUpgrade
|
[Serializable] public enum BasicUpgrade
|
||||||
{
|
{
|
||||||
|
//Apple, - Unlocked by default
|
||||||
Grapes,
|
Grapes,
|
||||||
Bananas,
|
Bananas,
|
||||||
Kiwi,
|
Kiwi,
|
||||||
@@ -50,8 +52,25 @@ namespace Fruitomation.Game
|
|||||||
SpicedPitayaIceCream,
|
SpicedPitayaIceCream,
|
||||||
}
|
}
|
||||||
|
|
||||||
[Serializable] public enum IncrementalUpgrade
|
[Serializable] public enum BuildingUnlock
|
||||||
{
|
{
|
||||||
|
None,
|
||||||
|
|
||||||
|
//Wall, - Unlocked by default
|
||||||
|
//Slope,
|
||||||
|
Floor,
|
||||||
|
|
||||||
|
//Spring, - Unlocked by default
|
||||||
|
Fan,
|
||||||
|
Alternator,
|
||||||
|
|
||||||
|
//Slicer, - Unlocked by default
|
||||||
|
//Presser, - Unlocked by default
|
||||||
|
HeatExchanger,
|
||||||
|
Grinder,
|
||||||
|
Mixer,
|
||||||
|
Fermenter,
|
||||||
|
Peeler,
|
||||||
}
|
}
|
||||||
|
|
||||||
public class UnlockedUpgrades
|
public class UnlockedUpgrades
|
||||||
@@ -87,17 +106,20 @@ namespace Fruitomation.Game
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private HashSet<BuildingUnlock> Buildings = new();
|
||||||
private HashSet<BasicUpgrade> Unlocks = new();
|
private HashSet<BasicUpgrade> Unlocks = new();
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public void Unlock(BuildingUnlock unlock) => Buildings.Add(unlock);
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public void Unlock(BasicUpgrade upgrade) => Unlocks.Add(upgrade);
|
||||||
|
|
||||||
public void Unlock(BasicUpgrade upgrade)
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
{
|
public bool IsUnlocked(BuildingUnlock unlock) => Buildings.Contains(unlock);
|
||||||
Unlocks.Add(upgrade);
|
|
||||||
}
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public bool IsUnlocked(BasicUpgrade upgrade) => Unlocks.Contains(upgrade);
|
||||||
public bool IsUnlocked(BasicUpgrade upgrade)
|
|
||||||
{
|
|
||||||
return Unlocks.Contains(upgrade);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class UpgradeManager
|
public static class UpgradeManager
|
||||||
@@ -131,10 +153,31 @@ namespace Fruitomation.Game
|
|||||||
File.WriteAllText(Filepath, json);
|
File.WriteAllText(Filepath, json);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public static void Unlock(BuildingUnlock unlock)
|
||||||
|
{
|
||||||
|
if (unlock == BuildingUnlock.None)
|
||||||
|
{
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(unlock));
|
||||||
|
}
|
||||||
|
|
||||||
|
CurrentUpgrades.Unlock(unlock);
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static void Unlock(BasicUpgrade upgrade) => CurrentUpgrades.Unlock(upgrade);
|
public static void Unlock(BasicUpgrade upgrade) => CurrentUpgrades.Unlock(upgrade);
|
||||||
|
|
||||||
public static bool Is(BasicUpgrade upgrade) => CurrentUpgrades.IsUnlocked(upgrade);
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public static bool Is(BuildingUnlock unlock)
|
||||||
|
{
|
||||||
|
return unlock == BuildingUnlock.None
|
||||||
|
? throw new ArgumentOutOfRangeException(nameof(unlock))
|
||||||
|
: CurrentUpgrades.IsUnlocked(unlock);
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public static bool Is(BasicUpgrade upgrade) => CurrentUpgrades.IsUnlocked(upgrade);
|
||||||
|
|
||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
[MenuItem("Fruitomation/Reset Upgrades")]
|
[MenuItem("Fruitomation/Reset Upgrades")]
|
||||||
public static void ResetUpgrades() => CurrentUpgrades = new UnlockedUpgrades();
|
public static void ResetUpgrades() => CurrentUpgrades = new UnlockedUpgrades();
|
||||||
|
|||||||
Reference in New Issue
Block a user