add unlock system for tools

This commit is contained in:
2026-06-29 22:15:59 -05:00
parent 9dfcee6159
commit fc0bcf0201
12 changed files with 513 additions and 65 deletions
@@ -1,3 +1,5 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
@@ -5,6 +7,27 @@
public class PlayerManager : MonoBehaviour
{
public int CurrentToolIndex;
private SerializableDictionary<ToolEnum, bool> unlockedToolDict = null;
public bool IsToolUnlocked(ToolEnum tool)
{
if (unlockedToolDict.TryGetValue(tool, out bool unlocked)) return unlocked;
// If no tool dict saved, init the default one (only None is unlocked)
unlockedToolDict = new SerializableDictionary<ToolEnum, bool>();
foreach (ToolEnum toolType in Enum.GetValues(typeof(ToolEnum)))
{
if (toolType == ToolEnum.None)
unlockedToolDict.Add(toolType, true);
else
unlockedToolDict.Add(toolType, false);
}
// Try again
if (unlockedToolDict.TryGetValue(tool, out bool unlockedRetry)) return unlockedRetry;
return false;
}
#region Player Data Save/Load
public void SavePlayerData(ref PlayerSaveData data)
@@ -12,6 +35,7 @@ public void SavePlayerData(ref PlayerSaveData data)
data.activeToolIndex = GameManager.Instance.PlayerManager.CurrentToolIndex;
data.dougPosition = GameManager.Instance.PlayerController.transform.position;
data.currentScene = SceneManager.GetActiveScene().name;
data.unlockedToolDict = unlockedToolDict;
}
public void LoadPlayerData(PlayerSaveData data)
@@ -25,6 +49,24 @@ public void LoadPlayerData(PlayerSaveData data)
GameManager.Instance.PlayerManager.CurrentToolIndex = data.activeToolIndex;
GameManager.Instance.PlayerController.transform.position = data.dougPosition;
}
if (data.unlockedToolDict != null)
{
unlockedToolDict = data.unlockedToolDict;
}
else
{
// If no tool dict saved, init the default one (only None is unlocked)
unlockedToolDict = new SerializableDictionary<ToolEnum, bool>();
foreach (ToolEnum toolType in Enum.GetValues(typeof(ToolEnum)))
{
if (toolType == ToolEnum.None)
unlockedToolDict.Add(toolType, true);
else
unlockedToolDict.Add(toolType, false);
}
}
}
#endregion
}
@@ -35,4 +77,5 @@ public struct PlayerSaveData
public int activeToolIndex;
public Vector3 dougPosition;
public string currentScene;
public SerializableDictionary<ToolEnum, bool> unlockedToolDict;
}