I know it is not your place to "teach" me how to be a proper or decent programmer... yet you do... and i cannot thank you enough for all you have done!! I can only hope that your business is profitable and that you have a decent living!!
Back to this "new" thing i'm trying to achieve...
I have made a ton of progress on creating my "Saver" module... made my own class which works PERFECTLY now!
I'm gonig to paste a copy here (just for reference so you see the type and logic I created which might help you understand what I'm trying to achieve with my actual question)
Code: Select all
namespace PixelCrushers
{
public class ShumaPickupSaver : Saver
{
[Serializable]
public class Data
{
public PickupSpawner pickup;
public Vector3 position;
public InventoryItem item;
public int number;
public bool boolPickupPickedUp;
public bool boolInstanciated;
}
public override string RecordData()
{
/// This method should return a string that represents the data you want to save.
/// You can use SaveSystem.Serialize() to serialize a serializable object to a
/// string. This will use the serializer component on the Save System GameObject,
/// which defaults to Unity's built-in JSON serialization. Remember that Unity
/// cannot directly serialize lists or arrays, so you must put them inside a
/// class.
///
/// If you use a class to hold the data, use SaveSystem.Serialize to return a
/// serialized version:
///
Data data = new Data();
data.pickup = GetComponent<PickupSpawner>();
data.boolPickupPickedUp = GetComponent<PickupSpawner>().boolPickupPickedUp;
data.item = GetComponent<PickupSpawner>().item;
data.number = GetComponent<PickupSpawner>().number;
data.boolInstanciated = GetComponent<PickupSpawner>().boolPickupInstanciated;
return SaveSystem.Serialize(data);
//return string.Empty;
}
public override void ApplyData(string s)
{
/// This method should process the string representation of saved data and apply
/// it to the current state of the game. You can use SaveSystem.Deserialize()
/// to deserialize the string to an object that specifies the state to apply to
/// the game.
///
if (string.IsNullOrEmpty(s)) return; // No data to apply.
Data data = SaveSystem.Deserialize<Data>(s);
if (data == null) return; // Serialized string isn't valid.
if (data.boolInstanciated)
{
GetComponent<PickupSpawner>().item = data.item;
GetComponent<PickupSpawner>().number = data.number;
}
if (data.boolPickupPickedUp)
{
GetComponent<PickupSpawner>().boolPickupPickedUp = true;
if (GetComponent<PickupSpawner>().boolPickupSpawned == false)
{
GetComponent<PickupSpawner>().SpawnPickup();
}
GetComponent<PickupSpawner>().DestroyPickup();
}
else if (GetComponent<PickupSpawner>().boolPickupSpawned == false)
{
GetComponent<PickupSpawner>().SpawnPickup();
}
}
The destructible saver works great no problems here...
The Spawned Object also works, and gets restored by the SpawnedObjectManager
However, the "spawned object" contains a very important script reference (InventoryItem item) and (int Number) which are not getting saved or restored...
Any tips on how where to edit/modify your script to make them work with it?
Thanks again and have a great weekend!