2025-09-06 21:01:54 +02:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
using System.Collections.Generic;
|
2025-10-16 19:43:19 +02:00
|
|
|
|
using System;
|
2025-09-06 21:01:54 +02:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// ScriptableObject representing a single puzzle step, its display info, and which steps it unlocks.
|
|
|
|
|
|
/// </summary>
|
2025-10-10 15:47:38 +02:00
|
|
|
|
[CreateAssetMenu(fileName = "PuzzleStepSO", menuName = "AppleHills/Items & Puzzles/Step")]
|
2025-09-06 21:01:54 +02:00
|
|
|
|
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>();
|
2025-10-16 19:43:19 +02:00
|
|
|
|
|
|
|
|
|
|
/// <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);
|
|
|
|
|
|
}
|
2025-09-06 21:01:54 +02:00
|
|
|
|
}
|