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

75 lines
1.9 KiB
C#
Raw Normal View History

2025-11-10 12:55:22 +01:00
using System;
2025-11-10 13:03:36 +01:00
using Core;
2025-11-10 12:55:22 +01:00
using Core.Lifecycle;
2025-10-17 14:38:42 +02:00
using UnityEngine;
2025-11-10 12:55:22 +01:00
namespace PuzzleS
2025-10-17 14:38:42 +02:00
{
2025-11-10 12:55:22 +01:00
/// <summary>
/// Tracks bird discovery progress in the bird finding minigame.
/// Saves scene-specific progress using the ManagedBehaviour lifecycle system.
/// </summary>
public class BirdGameStats : ManagedBehaviour
2025-10-17 14:38:42 +02:00
{
2025-11-10 12:55:22 +01:00
public int birdsFoundInLevel;
// Save system configuration
public override bool AutoRegisterForSave => true;
protected override void OnManagedStart()
2025-11-10 12:55:22 +01:00
{
// Initialize after all managers are ready
}
public void BirdFound()
{
birdsFoundInLevel += 1;
}
#region Save/Load Lifecycle Hooks
protected override string OnSceneSaveRequested()
{
// Save scene-specific progress
var state = new BirdGameState
{
birdsFoundInLevel = this.birdsFoundInLevel
};
return JsonUtility.ToJson(state);
}
protected override void OnSceneRestoreRequested(string serializedData)
{
if (string.IsNullOrEmpty(serializedData))
{
// No saved data, keep default values
return;
}
try
{
var state = JsonUtility.FromJson<BirdGameState>(serializedData);
if (state != null)
{
birdsFoundInLevel = state.birdsFoundInLevel;
}
}
catch (Exception ex)
{
2025-11-10 13:03:36 +01:00
Logging.Warning($"[BirdGameStats] Failed to restore state: {ex.Message}");
2025-11-10 12:55:22 +01:00
}
}
#endregion
2025-10-17 14:38:42 +02:00
}
2025-11-10 12:55:22 +01:00
/// <summary>
/// Serializable state for bird game progress
/// </summary>
[Serializable]
public class BirdGameState
2025-10-20 13:57:38 +02:00
{
2025-11-10 12:55:22 +01:00
public int birdsFoundInLevel;
2025-10-17 14:38:42 +02:00
}
}