Files
AppleHillsProduction/Assets/Scripts/PuzzleS/PuzzleChainSO.cs

104 lines
3.4 KiB
C#

using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AddressableAssets;
namespace PuzzleS
{
/// <summary>
/// Represents a complete chain of puzzle steps that form a logical sequence.
/// This is automatically generated from folder structure during asset import.
/// </summary>
[CreateAssetMenu(fileName = "PuzzleChain", menuName = "AppleHills/Items & Puzzles/PuzzleChain")]
public class PuzzleChainSO : ScriptableObject
{
/// <summary>
/// Unique identifier for this puzzle chain, automatically set to match folder name
/// </summary>
public string chainId;
/// <summary>
/// Display name for this chain
/// </summary>
public string displayName;
/// <summary>
/// Description of this puzzle chain
/// </summary>
[TextArea]
public string description;
/// <summary>
/// All steps that belong to this puzzle chain
/// </summary>
public List<PuzzleStepSO> allSteps = new List<PuzzleStepSO>();
/// <summary>
/// Initial steps that should be unlocked when the puzzle chain starts
/// (steps with no dependencies)
/// </summary>
public List<PuzzleStepSO> initialSteps = new List<PuzzleStepSO>();
/// <summary>
/// Optional requirement for this entire chain to be activated
/// If not null, this chain requires the specified chain to be completed first
/// </summary>
public PuzzleChainSO requiredChain;
/// <summary>
/// Pre-processed dependency data built at edit time.
/// Maps step IDs to arrays of dependency step IDs
/// </summary>
[HideInInspector]
public Dictionary<string, string[]> stepDependencies = new Dictionary<string, string[]>();
/// <summary>
/// Gets all steps that will be unlocked by completing the given step
/// </summary>
public List<PuzzleStepSO> GetUnlockedSteps(string stepId)
{
var result = new List<PuzzleStepSO>();
foreach (var step in allSteps)
{
if (step.stepId == stepId && step != null)
{
return step.unlocks;
}
}
return result;
}
/// <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);
}
/// <summary>
/// Check if all steps in this chain are completed
/// </summary>
public bool IsChainComplete(HashSet<PuzzleStepSO> completedSteps)
{
if (completedSteps == null) return false;
foreach (var step in allSteps)
{
if (step != null && !completedSteps.Contains(step))
{
return false;
}
}
return true;
}
}
}