Browse Source

Renamed SavedObjects to SaveData. Added support for multiple SaveDatas in a scene.

master
Christopher 8 years ago
parent
commit
2df05682b9
  1. 2
      Assets/Fungus/Resources/Prefabs/SaveData.prefab
  2. 0
      Assets/Fungus/Resources/Prefabs/SaveData.prefab.meta
  3. 16
      Assets/Fungus/Scripts/Components/SaveData.cs
  4. 0
      Assets/Fungus/Scripts/Components/SaveData.cs.meta
  5. 4
      Assets/Fungus/Scripts/Editor/SaveData.cs
  6. 0
      Assets/Fungus/Scripts/Editor/SaveData.cs.meta
  7. 6
      Assets/Fungus/Scripts/Editor/SaveMenuItems.cs
  8. 20
      Assets/Fungus/Scripts/Utils/SavePointData.cs
  9. 3023
      Assets/FungusExamples/SaveGame/SaveExample.unity

2
Assets/Fungus/Resources/Prefabs/SavedObjects.prefab → Assets/Fungus/Resources/Prefabs/SaveData.prefab

@ -21,7 +21,7 @@ GameObject:
- component: {fileID: 4704521519618994}
- component: {fileID: 114272980009688704}
m_Layer: 0
m_Name: SavedObjects
m_Name: SaveData
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0

0
Assets/Fungus/Resources/Prefabs/SavedObjects.prefab.meta → Assets/Fungus/Resources/Prefabs/SaveData.prefab.meta

16
Assets/Fungus/Scripts/Components/SavedObjects.cs → Assets/Fungus/Scripts/Components/SaveData.cs

@ -6,7 +6,7 @@ namespace Fungus
/// <summary>
/// Contains a list of game objects whose state will be saved for each Save Point.
/// </summary>
public class SavedObjects : MonoBehaviour
public class SaveData : MonoBehaviour
{
[Tooltip("A list of Flowchart objects whose variables will be encoded in the save data. Boolean, Integer, Float and String variables are supported.")]
[SerializeField] protected List<Flowchart> flowcharts = new List<Flowchart>();
@ -14,7 +14,7 @@ namespace Fungus
#region Public methods
/// <summary>
/// Encodes the list of saved objects and adds it to a Save Point Data object.
/// Encodes the list of Flowcharts and adds it to a Save Point Data object.
/// </summary>
public void Encode(SavePointData savePointData)
{
@ -26,6 +26,18 @@ namespace Fungus
}
}
/// <summary>
/// Decodes the Flowchart data from the save point data.
/// </summary>
public void Decode(SavePointData savePointData)
{
for (int i = 0; i < savePointData.FlowchartDatas.Count; i++)
{
var flowchartData = savePointData.FlowchartDatas[i];
FlowchartData.Decode(flowchartData);
}
}
#endregion
}
}

0
Assets/Fungus/Scripts/Components/SavedObjects.cs.meta → Assets/Fungus/Scripts/Components/SaveData.cs.meta

4
Assets/Fungus/Scripts/Editor/SavedObjectsEditor.cs → Assets/Fungus/Scripts/Editor/SaveData.cs

@ -4,8 +4,8 @@ using Rotorz.ReorderableList;
namespace Fungus.EditorUtils
{
[CustomEditor (typeof(SavedObjects), true)]
public class SavedObjectsEditor : Editor
[CustomEditor (typeof(SaveData), true)]
public class SaveDataEditor : Editor
{
protected SerializedProperty flowchartsProp;

0
Assets/Fungus/Scripts/Editor/SavedObjectsEditor.cs.meta → Assets/Fungus/Scripts/Editor/SaveData.cs.meta

6
Assets/Fungus/Scripts/Editor/SaveMenuItems.cs

@ -13,10 +13,10 @@ namespace Fungus.EditorUtils
FlowchartMenuItems.SpawnPrefab("SaveMenu");
}
[MenuItem("Tools/Fungus/Create/Saved Objects", false, 1101)]
static void CreateSavedObjects()
[MenuItem("Tools/Fungus/Create/Save Data", false, 1101)]
static void CreateSaveData()
{
FlowchartMenuItems.SpawnPrefab("SavedObjects");
FlowchartMenuItems.SpawnPrefab("SaveData");
}
}
}

20
Assets/Fungus/Scripts/Utils/SavePointData.cs

@ -29,15 +29,13 @@ namespace Fungus
}
SceneManager.sceneLoaded -= OnSceneLoaded;
var savePointData = tempSavePointData;
for (int i = 0; i < savePointData.FlowchartDatas.Count; i++)
var saveDatas = GameObject.FindObjectsOfType<SaveData>();
foreach (var saveData in saveDatas)
{
var flowchartData = savePointData.FlowchartDatas[i];
FlowchartData.Decode(flowchartData);
saveData.Decode(tempSavePointData);
}
SaveManagerSignals.DoSavePointLoaded(savePointData.savePointKey);
SaveManagerSignals.DoSavePointLoaded(tempSavePointData.savePointKey);
}
protected static SavePointData Create(string _savePointKey, string _savePointDescription, string _sceneName)
@ -80,14 +78,10 @@ namespace Fungus
{
var savePointData = Create(_savePointKey, _savePointDescription, _sceneName);
var saveGameObjects = GameObject.FindObjectOfType<SavedObjects>();
if (saveGameObjects == null)
{
Debug.LogWarning("Failed to find a SaveGameObjects in current scene");
}
else
var saveDatas = GameObject.FindObjectsOfType<SaveData>();
foreach (var saveData in saveDatas)
{
saveGameObjects.Encode(savePointData);
saveData.Encode(savePointData);
}
return JsonUtility.ToJson(savePointData, true);

3023
Assets/FungusExamples/SaveGame/SaveExample.unity

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save