Last improvements on the save front
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user