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

88 lines
2.8 KiB
C#
Raw Normal View History

using UnityEngine;
using System.Collections.Generic;
using System;
/// <summary>
/// ScriptableObject representing a single puzzle step, its display info, and which steps it unlocks.
/// </summary>
[CreateAssetMenu(fileName = "PuzzleStepSO", menuName = "AppleHills/Items & Puzzles/Step")]
public class PuzzleStepSO : ScriptableObject
{
/// <summary>
/// Unique identifier for this puzzle step.
/// </summary>
public string stepId;
/// <summary>
/// Display name for this step.
/// </summary>
public string displayName;
/// <summary>
/// Description of this step.
/// </summary>
[TextArea]
public string description;
/// <summary>
/// Icon for this step.
/// </summary>
public Sprite icon;
/// <summary>
/// List of steps that this step unlocks when completed.
/// </summary>
[Header("Unlocks")]
public List<PuzzleStepSO> unlocks = new List<PuzzleStepSO>();
/// <summary>
/// Override Equals to compare by stepId rather than reference equality.
/// This ensures consistent behavior across different platforms (Editor vs Mobile).
/// </summary>
/// <param name="obj">Object to compare to</param>
/// <returns>True if the objects represent the same puzzle step</returns>
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);
}
/// <summary>
/// Override GetHashCode to be consistent with the Equals method.
/// This is crucial for HashSet and Dictionary to work properly.
/// </summary>
/// <returns>Hash code based on stepId</returns>
public override int GetHashCode()
{
// Generate hash code from stepId to ensure consistent hashing
return stepId != null ? stepId.GetHashCode() : 0;
}
/// <summary>
/// Override == operator to use our custom equality logic
/// </summary>
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);
}
/// <summary>
/// Override != operator to be consistent with == operator
/// </summary>
public static bool operator !=(PuzzleStepSO a, PuzzleStepSO b)
{
return !(a == b);
}
}