Last improvements on the save front

This commit is contained in:
Michal Pikulski
2025-11-05 17:34:26 +01:00
parent 210823344a
commit c527ba334d
14 changed files with 610 additions and 176 deletions

View File

@@ -1,23 +1,51 @@
using UnityEngine;
using Core.Lifecycle;
public class soundBird_CanFly : MonoBehaviour
[System.Serializable]
public class SoundBirdSaveData
{
public bool canFly;
}
public class soundBird_CanFly : ManagedBehaviour
{
public bool canFly = true;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
}
// Enable save/load participation
public override bool AutoRegisterForSave => true;
public void birdCanHear(bool canhear)
{
if (canhear)
canFly = canhear;
}
#region Save/Load Implementation
protected override string OnSceneSaveRequested()
{
var saveData = new SoundBirdSaveData
{
canFly = true;
canFly = this.canFly
};
return JsonUtility.ToJson(saveData);
}
protected override void OnSceneRestoreRequested(string serializedData)
{
if (string.IsNullOrEmpty(serializedData))
{
Debug.LogWarning($"[soundBird_CanFly] No save data to restore for {gameObject.name}");
return;
}
else
var saveData = JsonUtility.FromJson<SoundBirdSaveData>(serializedData);
if (saveData != null)
{
canFly = false;
canFly = saveData.canFly;
Debug.Log($"[soundBird_CanFly] Restored canFly state: {canFly}");
}
}
#endregion
}