Hi guys!
I use a third-party script for the save system (from the Pixel Crushers "Dialogue System")
This script finds all Playmaker global arrays and serializes them into Json (also using another script from the Dialogue system)
using System;
using System.Collections.Generic;
using UnityEngine;
using HutongGames.PlayMaker;
namespace PixelCrushers
{
/// <summary>
/// Saves a global FsmArray.
/// </summary>
[AddComponentMenu("Pixel Crushers/Third Party/PlayMaker Support/FsmArray Saver")]
public class FsmArraySaver : Saver
{
public string fsmArrayName;
[Serializable]
public class Data
{
public List<bool> boolValues = new List<bool>();
public List<int> intValues = new List<int>();
public List<float> floatValues = new List<float>();
public List<string> stringValues = new List<string>();
}
public override string RecordData()
{
var data = new Data();
var fsmArray = FsmVariables.GlobalVariables.FindFsmArray(fsmArrayName);
if (fsmArray == null) return string.Empty;
if (fsmArray.boolValues != null) data.boolValues.AddRange(fsmArray.boolValues);
if (fsmArray.intValues != null) data.intValues.AddRange(fsmArray.intValues);
if (fsmArray.floatValues != null) data.floatValues.AddRange(fsmArray.floatValues);
if (fsmArray.stringValues != null) data.stringValues.AddRange(fsmArray.stringValues);
return SaveSystem.Serialize(data);
}
public override void ApplyData(string s)
{
var fsmArray = FsmVariables.GlobalVariables.FindFsmArray(fsmArrayName);
if (fsmArray == null) return;
if (string.IsNullOrEmpty(s)) return;
var data = SaveSystem.Deserialize<Data>(s);
if (data == null) return;
fsmArray.boolValues = data.boolValues.ToArray();
fsmArray.intValues = data.intValues.ToArray();
fsmArray.floatValues = data.floatValues.ToArray();
fsmArray.stringValues = data.stringValues.ToArray();
}
}
}
For my project I created a new class for the inventory (Scriptable Object with an Int object ID and Sprite with an image of the item) and named it "InvItem" and added it to Playmaker using Variable Type Definition
And I would like my InItem array to be serialized in the SaveSystem script as well. As far as I understand, to do that I need to add a line in the "FsmArray.cs" script, to make it look like this:
public class FsmArray : NamedVariable
{
public float[] floatValues;
public int[] intValues;
public bool[] boolValues;
public string[] stringValues;
public InvItem[] invItemValues;
So after that in the first SaveSystem script in RecordData() I can tell the script to check for InvItem arrays and save them.
But unfortunately FsmArray.cs is locked for editing.
Can you tell me if I'm doing it right, and if so, how can I change FsmArray.cs?
I'll be honest: I'm very bad at C# and most of the project I use PlayMaker in combination with simple C# scripts. So maybe I don't understand something (for example whether SaveSystem can serialize ScriptableObject). But I try to understand it.
Thanks