Browse Source

Changed Save Points to use an explicit IsStartPoint property instead of using magic 'Start' block name.

master
Christopher 8 years ago
parent
commit
01867ce390
  1. 5
      Assets/Fungus/Scripts/Commands/SavePoint.cs
  2. 26
      Assets/Fungus/Scripts/Components/SaveManager.cs
  3. 40
      Assets/FungusExamples/SaveGame/SaveExample.unity

5
Assets/Fungus/Scripts/Commands/SavePoint.cs

@ -33,6 +33,9 @@ namespace Fungus
Custom Custom
} }
[Tooltip("Marks this Save Point as the starting point for Flowchart execution in the scene. Each scene in your game should have exactly one Save Point with this enabled.")]
[SerializeField] protected bool isStartPoint = false;
[Tooltip("How the Save Point Key for this Save Point is defined.")] [Tooltip("How the Save Point Key for this Save Point is defined.")]
[SerializeField] protected KeyMode keyMode = KeyMode.UseBlockName; [SerializeField] protected KeyMode keyMode = KeyMode.UseBlockName;
@ -53,6 +56,8 @@ namespace Fungus
#region Public members #region Public members
public bool IsStartPoint { get { return isStartPoint; } set { isStartPoint = value; } }
/// <summary> /// <summary>
/// Gets a string key which uniquely identifies this Save Point. /// Gets a string key which uniquely identifies this Save Point.
/// </summary> /// </summary>

26
Assets/Fungus/Scripts/Components/SaveManager.cs

@ -86,18 +86,18 @@ namespace Fungus
} }
/// <summary> /// <summary>
/// Starts execution at the first Save Point with the key 'Start'. /// Starts execution at the first Save Point found in the scene with the IsStartPoint property enabled.
/// </summary> /// </summary>
protected virtual void ExecuteStartBlock() protected virtual void ExecuteStartBlock()
{ {
// Each scene should have one Save Point with the 'Start' key. // Each scene should have one Save Point with the IsStartPoint property enabled.
// We automatically start execution from this command whenever the scene starts 'normally' (i.e. first play, restart or scene load via the Load Scene command or SceneManager.LoadScene). // We automatically start execution from this command whenever the scene starts 'normally' (i.e. first play, restart or scene load via the Load Scene command or SceneManager.LoadScene).
var savePoints = Object.FindObjectsOfType<SavePoint>(); var savePoints = Object.FindObjectsOfType<SavePoint>();
for (int i = 0; i < savePoints.Length; i++) for (int i = 0; i < savePoints.Length; i++)
{ {
var savePoint = savePoints[i]; var savePoint = savePoints[i];
if (string.Compare(savePoint.SavePointKey, "Start", true) == 0) if (savePoint.IsStartPoint)
{ {
savePoint.GetFlowchart().ExecuteBlock(savePoint.ParentBlock, savePoint.CommandIndex); savePoint.GetFlowchart().ExecuteBlock(savePoint.ParentBlock, savePoint.CommandIndex);
break; break;
@ -105,10 +105,19 @@ namespace Fungus
} }
} }
protected virtual void LoadSavedGame(string saveDataKey)
{
if (ReadSaveHistory(saveDataKey))
{
saveHistory.ClearRewoundSavePoints();
saveHistory.LoadLatestSavePoint();
}
}
// Scene loading in Unity is asynchronous so we need to take care to avoid race conditions. // Scene loading in Unity is asynchronous so we need to take care to avoid race conditions.
// The following callbacks tell us when a scene has been loaded and when // The following callbacks tell us when a scene has been loaded and when
// a saved game has been loaded. We delay taking action until the next // a saved game has been loaded. We delay taking action until the next
// frame (via a delegate) so that we're sure which case we're dealing with. // frame (via a delegate) so that we know for sure which case we're dealing with.
protected virtual void OnEnable() protected virtual void OnEnable()
{ {
@ -158,15 +167,6 @@ namespace Fungus
} }
} }
protected virtual void LoadSavedGame(string saveDataKey)
{
if (ReadSaveHistory(saveDataKey))
{
saveHistory.ClearRewoundSavePoints();
saveHistory.LoadLatestSavePoint();
}
}
#region Public members #region Public members
/// <summary> /// <summary>

40
Assets/FungusExamples/SaveGame/SaveExample.unity

@ -454,11 +454,11 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 8c0cbb63e218a4414a796a60ffe37dd3, type: 3} m_Script: {fileID: 11500000, guid: 8c0cbb63e218a4414a796a60ffe37dd3, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
info: 'This example shows how to use the Save Menu and the Save Point command to info: 'This example shows how to use the Save Menu prefab and the Save Point command
create a simple save game system. to create a simple save system.
Click the icon in the top right to show the Save Menu and try saving, loading Click the icon in the top right to display the Save Menu and try saving, loading
and rewinding the game at various points.' and rewinding the game at various points.'
--- !u!4 &493197090 --- !u!4 &493197090
Transform: Transform:
@ -632,11 +632,6 @@ Prefab:
propertyPath: m_Pivot.y propertyPath: m_Pivot.y
value: 0 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 224000013748593462, guid: bd2b99773f3e0489aae9f9b5053ad360,
type: 2}
propertyPath: m_AnchoredPosition.y
value: 0.079956055
objectReference: {fileID: 0}
- target: {fileID: 224000012150207008, guid: bd2b99773f3e0489aae9f9b5053ad360, - target: {fileID: 224000012150207008, guid: bd2b99773f3e0489aae9f9b5053ad360,
type: 2} type: 2}
propertyPath: m_AnchorMin.y propertyPath: m_AnchorMin.y
@ -655,7 +650,7 @@ Prefab:
- target: {fileID: 224000012150207008, guid: bd2b99773f3e0489aae9f9b5053ad360, - target: {fileID: 224000012150207008, guid: bd2b99773f3e0489aae9f9b5053ad360,
type: 2} type: 2}
propertyPath: m_AnchoredPosition.y propertyPath: m_AnchoredPosition.y
value: 0 value: -14.96
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 224000012150207008, guid: bd2b99773f3e0489aae9f9b5053ad360, - target: {fileID: 224000012150207008, guid: bd2b99773f3e0489aae9f9b5053ad360,
type: 2} type: 2}
@ -665,7 +660,7 @@ Prefab:
- target: {fileID: 224000012150207008, guid: bd2b99773f3e0489aae9f9b5053ad360, - target: {fileID: 224000012150207008, guid: bd2b99773f3e0489aae9f9b5053ad360,
type: 2} type: 2}
propertyPath: m_SizeDelta.y propertyPath: m_SizeDelta.y
value: 0 value: 29.92
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 224000013898185038, guid: bd2b99773f3e0489aae9f9b5053ad360, - target: {fileID: 224000013898185038, guid: bd2b99773f3e0489aae9f9b5053ad360,
type: 2} type: 2}
@ -685,7 +680,7 @@ Prefab:
- target: {fileID: 224000013898185038, guid: bd2b99773f3e0489aae9f9b5053ad360, - target: {fileID: 224000013898185038, guid: bd2b99773f3e0489aae9f9b5053ad360,
type: 2} type: 2}
propertyPath: m_AnchoredPosition.y propertyPath: m_AnchoredPosition.y
value: 0 value: -14.96
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 224000013898185038, guid: bd2b99773f3e0489aae9f9b5053ad360, - target: {fileID: 224000013898185038, guid: bd2b99773f3e0489aae9f9b5053ad360,
type: 2} type: 2}
@ -695,7 +690,7 @@ Prefab:
- target: {fileID: 224000013898185038, guid: bd2b99773f3e0489aae9f9b5053ad360, - target: {fileID: 224000013898185038, guid: bd2b99773f3e0489aae9f9b5053ad360,
type: 2} type: 2}
propertyPath: m_SizeDelta.y propertyPath: m_SizeDelta.y
value: 0 value: 29.92
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 224000012687811630, guid: bd2b99773f3e0489aae9f9b5053ad360, - target: {fileID: 224000012687811630, guid: bd2b99773f3e0489aae9f9b5053ad360,
type: 2} type: 2}
@ -715,7 +710,7 @@ Prefab:
- target: {fileID: 224000012687811630, guid: bd2b99773f3e0489aae9f9b5053ad360, - target: {fileID: 224000012687811630, guid: bd2b99773f3e0489aae9f9b5053ad360,
type: 2} type: 2}
propertyPath: m_AnchoredPosition.y propertyPath: m_AnchoredPosition.y
value: 0 value: -14.96
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 224000012687811630, guid: bd2b99773f3e0489aae9f9b5053ad360, - target: {fileID: 224000012687811630, guid: bd2b99773f3e0489aae9f9b5053ad360,
type: 2} type: 2}
@ -725,7 +720,7 @@ Prefab:
- target: {fileID: 224000012687811630, guid: bd2b99773f3e0489aae9f9b5053ad360, - target: {fileID: 224000012687811630, guid: bd2b99773f3e0489aae9f9b5053ad360,
type: 2} type: 2}
propertyPath: m_SizeDelta.y propertyPath: m_SizeDelta.y
value: 0 value: 29.92
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 224000012590701094, guid: bd2b99773f3e0489aae9f9b5053ad360, - target: {fileID: 224000012590701094, guid: bd2b99773f3e0489aae9f9b5053ad360,
type: 2} type: 2}
@ -745,7 +740,7 @@ Prefab:
- target: {fileID: 224000012590701094, guid: bd2b99773f3e0489aae9f9b5053ad360, - target: {fileID: 224000012590701094, guid: bd2b99773f3e0489aae9f9b5053ad360,
type: 2} type: 2}
propertyPath: m_AnchoredPosition.y propertyPath: m_AnchoredPosition.y
value: 0 value: -14.96
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 224000012590701094, guid: bd2b99773f3e0489aae9f9b5053ad360, - target: {fileID: 224000012590701094, guid: bd2b99773f3e0489aae9f9b5053ad360,
type: 2} type: 2}
@ -755,7 +750,7 @@ Prefab:
- target: {fileID: 224000012590701094, guid: bd2b99773f3e0489aae9f9b5053ad360, - target: {fileID: 224000012590701094, guid: bd2b99773f3e0489aae9f9b5053ad360,
type: 2} type: 2}
propertyPath: m_SizeDelta.y propertyPath: m_SizeDelta.y
value: 0 value: 29.92
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 224000013149320576, guid: bd2b99773f3e0489aae9f9b5053ad360, - target: {fileID: 224000013149320576, guid: bd2b99773f3e0489aae9f9b5053ad360,
type: 2} type: 2}
@ -775,7 +770,7 @@ Prefab:
- target: {fileID: 224000013149320576, guid: bd2b99773f3e0489aae9f9b5053ad360, - target: {fileID: 224000013149320576, guid: bd2b99773f3e0489aae9f9b5053ad360,
type: 2} type: 2}
propertyPath: m_AnchoredPosition.y propertyPath: m_AnchoredPosition.y
value: 0 value: -14.96
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 224000013149320576, guid: bd2b99773f3e0489aae9f9b5053ad360, - target: {fileID: 224000013149320576, guid: bd2b99773f3e0489aae9f9b5053ad360,
type: 2} type: 2}
@ -785,7 +780,7 @@ Prefab:
- target: {fileID: 224000013149320576, guid: bd2b99773f3e0489aae9f9b5053ad360, - target: {fileID: 224000013149320576, guid: bd2b99773f3e0489aae9f9b5053ad360,
type: 2} type: 2}
propertyPath: m_SizeDelta.y propertyPath: m_SizeDelta.y
value: 0 value: 29.92
objectReference: {fileID: 0} objectReference: {fileID: 0}
m_RemovedComponents: [] m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: bd2b99773f3e0489aae9f9b5053ad360, type: 2} m_ParentPrefab: {fileID: 100100000, guid: bd2b99773f3e0489aae9f9b5053ad360, type: 2}
@ -1427,9 +1422,9 @@ MonoBehaviour:
width: 1502.7736 width: 1502.7736
height: 1138.5048 height: 1138.5048
selectedBlocks: selectedBlocks:
- {fileID: 1889213500} - {fileID: 1889213482}
selectedCommands: selectedCommands:
- {fileID: 1889213509} - {fileID: 1889213478}
variables: variables:
- {fileID: 1889213489} - {fileID: 1889213489}
- {fileID: 1889213488} - {fileID: 1889213488}
@ -1469,6 +1464,7 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
itemId: 61 itemId: 61
indentLevel: 0 indentLevel: 0
isStartPoint: 1
keyMode: 0 keyMode: 0
customKey: customKey:
descriptionMode: 0 descriptionMode: 0
@ -1640,6 +1636,7 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
itemId: 21 itemId: 21
indentLevel: 0 indentLevel: 0
isStartPoint: 0
keyMode: 0 keyMode: 0
customKey: customKey:
descriptionMode: 0 descriptionMode: 0
@ -1962,6 +1959,7 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
itemId: 35 itemId: 35
indentLevel: 0 indentLevel: 0
isStartPoint: 0
keyMode: 0 keyMode: 0
customKey: customKey:
descriptionMode: 0 descriptionMode: 0
@ -1981,6 +1979,7 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
itemId: 34 itemId: 34
indentLevel: 0 indentLevel: 0
isStartPoint: 0
keyMode: 0 keyMode: 0
customKey: customKey:
descriptionMode: 0 descriptionMode: 0
@ -2248,6 +2247,7 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
itemId: 43 itemId: 43
indentLevel: 0 indentLevel: 0
isStartPoint: 0
keyMode: 0 keyMode: 0
customKey: customKey:
descriptionMode: 0 descriptionMode: 0

Loading…
Cancel
Save