using UnityEngine;
using System.Collections.Generic;
using System;
///
/// ScriptableObject representing a single puzzle step, its display info, and which steps it unlocks.
///
[CreateAssetMenu(fileName = "PuzzleStepSO", menuName = "AppleHills/Items & Puzzles/Step")]
public class PuzzleStepSO : ScriptableObject
{
///
/// Unique identifier for this puzzle step.
///
public string stepId;
///
/// Display name for this step.
///
public string displayName;
///
/// Description of this step.
///
[TextArea]
public string description;
///
/// Icon for this step.
///
public Sprite icon;
///
/// List of steps that this step unlocks when completed.
///
[Header("Unlocks")]
public List unlocks = new List();
///
/// Override Equals to compare by stepId rather than reference equality.
/// This ensures consistent behavior across different platforms (Editor vs Mobile).
///
/// Object to compare to
/// True if the objects represent the same puzzle step
public override bool Equals(object obj)
{
if (obj == null) return false;
// Check if the object is actually a PuzzleStepSO
PuzzleStepSO other = obj as PuzzleStepSO;
if (other == null) return false;
// Compare by stepId instead of reference
return string.Equals(stepId, other.stepId, StringComparison.Ordinal);
}
///
/// Override GetHashCode to be consistent with the Equals method.
/// This is crucial for HashSet and Dictionary to work properly.
///
/// Hash code based on stepId
public override int GetHashCode()
{
// Generate hash code from stepId to ensure consistent hashing
return stepId != null ? stepId.GetHashCode() : 0;
}
///
/// Override == operator to use our custom equality logic
///
public static bool operator ==(PuzzleStepSO a, PuzzleStepSO b)
{
// Check if both are null or if they're the same instance
if (ReferenceEquals(a, b))
return true;
// Check if either is null (but not both, as that's handled above)
if (((object)a == null) || ((object)b == null))
return false;
// Use our custom Equals method
return a.Equals(b);
}
///
/// Override != operator to be consistent with == operator
///
public static bool operator !=(PuzzleStepSO a, PuzzleStepSO b)
{
return !(a == b);
}
}