Files
AppleHillsProduction/Assets/Scripts/DamianExperiments/SoundBirdPuzzleSection/soundBird_CanFly.cs

52 lines
1.2 KiB
C#
Raw Normal View History

using UnityEngine;
2025-11-05 17:34:26 +01:00
using Core.Lifecycle;
2025-11-05 17:34:26 +01:00
[System.Serializable]
public class SoundBirdSaveData
{
public bool canFly;
}
public class soundBird_CanFly : ManagedBehaviour
{
public bool canFly = true;
2025-11-05 17:34:26 +01:00
// Enable save/load participation
public override bool AutoRegisterForSave => true;
public void birdCanHear(bool canhear)
{
canFly = canhear;
}
#region Save/Load Implementation
protected override string OnSceneSaveRequested()
{
2025-11-05 17:34:26 +01:00
var saveData = new SoundBirdSaveData
{
canFly = this.canFly
};
2025-11-05 17:34:26 +01:00
return JsonUtility.ToJson(saveData);
}
2025-11-05 17:34:26 +01:00
protected override void OnSceneRestoreRequested(string serializedData)
{
2025-11-05 17:34:26 +01:00
if (string.IsNullOrEmpty(serializedData))
{
2025-11-05 17:34:26 +01:00
Debug.LogWarning($"[soundBird_CanFly] No save data to restore for {gameObject.name}");
return;
}
2025-11-05 17:34:26 +01:00
var saveData = JsonUtility.FromJson<SoundBirdSaveData>(serializedData);
if (saveData != null)
{
2025-11-05 17:34:26 +01:00
canFly = saveData.canFly;
Debug.Log($"[soundBird_CanFly] Restored canFly state: {canFly}");
}
}
2025-11-05 17:34:26 +01:00
#endregion
}