Change the puzzle system to an offline-processed data structure to get around activation issues
This commit is contained in:
75
Assets/Scripts/PuzzleS/PuzzleLevelDataSO.cs
Normal file
75
Assets/Scripts/PuzzleS/PuzzleLevelDataSO.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
|
||||
namespace PuzzleS
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents all puzzle steps in a level.
|
||||
/// This is automatically generated from folder structure during asset import.
|
||||
/// </summary>
|
||||
[CreateAssetMenu(fileName = "LevelPuzzleData", menuName = "AppleHills/Items & Puzzles/LevelPuzzleData")]
|
||||
public class PuzzleLevelDataSO : ScriptableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Unique identifier for this level, automatically set to match folder name
|
||||
/// </summary>
|
||||
public string levelId;
|
||||
|
||||
/// <summary>
|
||||
/// Display name for this level
|
||||
/// </summary>
|
||||
public string displayName;
|
||||
|
||||
/// <summary>
|
||||
/// All puzzle steps in this level
|
||||
/// </summary>
|
||||
public List<PuzzleStepSO> allSteps = new List<PuzzleStepSO>();
|
||||
|
||||
/// <summary>
|
||||
/// Steps that should be unlocked at level start (no dependencies)
|
||||
/// </summary>
|
||||
[HideInInspector]
|
||||
public List<PuzzleStepSO> initialSteps = new List<PuzzleStepSO>();
|
||||
|
||||
/// <summary>
|
||||
/// Pre-processed dependency data built at edit time.
|
||||
/// Maps step IDs to arrays of dependency step IDs (which steps are required by each step)
|
||||
/// </summary>
|
||||
[HideInInspector]
|
||||
public Dictionary<string, string[]> stepDependencies = new Dictionary<string, string[]>();
|
||||
|
||||
/// <summary>
|
||||
/// Check if all steps in the level are complete
|
||||
/// </summary>
|
||||
public bool IsLevelComplete(HashSet<PuzzleStepSO> completedSteps)
|
||||
{
|
||||
if (completedSteps == null) return false;
|
||||
|
||||
foreach (var step in allSteps)
|
||||
{
|
||||
if (step != null && !completedSteps.Contains(step))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all steps that will be unlocked by completing the given step
|
||||
/// </summary>
|
||||
public List<PuzzleStepSO> GetUnlockedSteps(PuzzleStepSO completedStep)
|
||||
{
|
||||
return completedStep != null ? completedStep.unlocks : new List<PuzzleStepSO>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if this step is an initial step (no dependencies)
|
||||
/// </summary>
|
||||
public bool IsInitialStep(PuzzleStepSO step)
|
||||
{
|
||||
return step != null && initialSteps.Contains(step);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user