Fome further save load work
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
using Input;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using System.Linq; // added for Action<T>
|
||||
using System.Linq;
|
||||
using Bootstrap; // added for Action<T>
|
||||
using Core; // register with ItemManager
|
||||
|
||||
namespace Interactions
|
||||
@@ -13,6 +14,7 @@ namespace Interactions
|
||||
public class PickupSaveData
|
||||
{
|
||||
public bool isPickedUp;
|
||||
public bool wasHeldByFollower; // Track if held by follower for bilateral restoration
|
||||
public Vector3 worldPosition;
|
||||
public Quaternion worldRotation;
|
||||
public bool isActive;
|
||||
@@ -52,11 +54,13 @@ namespace Interactions
|
||||
{
|
||||
base.Start(); // Register with save system
|
||||
|
||||
// Don't register with ItemManager if already picked up (restored from save)
|
||||
if (!IsPickedUp)
|
||||
// Always register with ItemManager, even if picked up
|
||||
// This allows the save/load system to find held items when restoring state
|
||||
BootCompletionService.RegisterInitAction(() =>
|
||||
{
|
||||
ItemManager.Instance?.RegisterPickup(this);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -162,9 +166,13 @@ namespace Interactions
|
||||
|
||||
protected override object GetSerializableState()
|
||||
{
|
||||
// Check if this pickup is currently held by the follower
|
||||
bool isHeldByFollower = IsPickedUp && !gameObject.activeSelf && transform.parent != null;
|
||||
|
||||
return new PickupSaveData
|
||||
{
|
||||
isPickedUp = this.IsPickedUp,
|
||||
wasHeldByFollower = isHeldByFollower,
|
||||
worldPosition = transform.position,
|
||||
worldRotation = transform.rotation,
|
||||
isActive = gameObject.activeSelf
|
||||
@@ -187,6 +195,18 @@ namespace Interactions
|
||||
{
|
||||
// Hide the pickup if it was already picked up
|
||||
gameObject.SetActive(false);
|
||||
|
||||
// If this was held by the follower, try bilateral restoration
|
||||
if (data.wasHeldByFollower)
|
||||
{
|
||||
// Try to give this pickup to the follower
|
||||
// This might succeed or fail depending on timing
|
||||
var follower = FollowerController.FindInstance();
|
||||
if (follower != null)
|
||||
{
|
||||
follower.TryClaimHeldItem(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -14,6 +14,15 @@ namespace Interactions
|
||||
[SerializeField]
|
||||
[Tooltip("Optional custom save ID. If empty, will auto-generate from hierarchy path.")]
|
||||
private string customSaveId = "";
|
||||
|
||||
/// <summary>
|
||||
/// Sets a custom save ID for this interactable.
|
||||
/// Used when spawning dynamic objects that need stable save IDs.
|
||||
/// </summary>
|
||||
public void SetCustomSaveId(string saveId)
|
||||
{
|
||||
customSaveId = saveId;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Flag to indicate we're currently restoring from save data.
|
||||
@@ -258,4 +267,3 @@ namespace Interactions
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user