Browse Source

If Save Point Key is empty use the parent Block Name. If Save Point Description is empty use the current date and time.

master
Christopher 8 years ago
parent
commit
b650b80cf5
  1. 53
      Assets/Fungus/Scripts/Commands/SavePoint.cs
  2. 84
      Assets/FungusExamples/SaveGame/SaveExample.unity

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

@ -7,14 +7,14 @@ namespace Fungus
{ {
[CommandInfo("Flow", [CommandInfo("Flow",
"Save Point", "Save Point",
"Creates a save point which can be saved to persistant storage and loaded again later.")] "Creates a Save Point and adds it to the Save History. The player can save the Save History to peristent storage and load it again later.")]
public class SavePoint : Command public class SavePoint : Command
{ {
[Tooltip("A string key which identifies this save point. Must be unique in this scene.")] [Tooltip("A string key which uniquely identifies this save point. If empty then the parent Block's name will be used.")]
[SerializeField] protected string savePointKey; [SerializeField] protected string savePointKey = "";
[Tooltip("A short description of this save point.")] [Tooltip("A short description of this save point. If empty then the current time and date will be used.")]
[SerializeField] protected StringData savePointDescription; [SerializeField] protected string savePointDescription;
[Tooltip("Fire an event that will be handled by any Save Point Loaded event handler with matching key.")] [Tooltip("Fire an event that will be handled by any Save Point Loaded event handler with matching key.")]
[SerializeField] protected bool fireEvent = true; [SerializeField] protected bool fireEvent = true;
@ -25,9 +25,36 @@ namespace Fungus
#region Public members #region Public members
/// <summary> /// <summary>
/// A string key which identifies this save point. Must be unique in this scene. /// A string key which uniquely identifies this Save Point.
/// If the save point key is empty then the parent Block's name is returned.
/// </summary> /// </summary>
public string SavePointKey { get { return savePointKey; } } public string SavePointKey
{
get
{
if (string.IsNullOrEmpty(savePointKey))
{
return ParentBlock.BlockName;
}
return savePointKey;
}
}
/// <summary>
/// Gets the save point description.
/// If the description is empty then the current time and date will be returned.
/// </summary>
public string SavePointDescription
{
get
{
if (string.IsNullOrEmpty(savePointDescription))
{
return System.DateTime.UtcNow.ToString("HH:mm dd MMMM, yyyy");
}
return savePointDescription;
}
}
/// <summary> /// <summary>
/// Resume execution from this command after loading a save point. /// Resume execution from this command after loading a save point.
@ -36,15 +63,9 @@ namespace Fungus
public override void OnEnter() public override void OnEnter()
{ {
if (string.IsNullOrEmpty(savePointKey))
{
Continue();
return;
}
var saveManager = FungusManager.Instance.SaveManager; var saveManager = FungusManager.Instance.SaveManager;
saveManager.AddSavePoint(savePointKey, savePointDescription.Value); saveManager.AddSavePoint(SavePointKey, SavePointDescription);
if (fireEvent) if (fireEvent)
{ {
@ -58,10 +79,10 @@ namespace Fungus
{ {
if (string.IsNullOrEmpty(savePointKey)) if (string.IsNullOrEmpty(savePointKey))
{ {
return "Error: Save Point Key not specified"; return "<Block Name>";
} }
return savePointKey + " : " + savePointDescription.Value; return savePointKey;
} }
public override Color GetButtonColor() public override Color GetButtonColor()

84
Assets/FungusExamples/SaveGame/SaveExample.unity

@ -697,7 +697,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: -10.5
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 224000012150207008, guid: bd2b99773f3e0489aae9f9b5053ad360, - target: {fileID: 224000012150207008, guid: bd2b99773f3e0489aae9f9b5053ad360,
type: 2} type: 2}
@ -707,7 +707,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: 21
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 224000013898185038, guid: bd2b99773f3e0489aae9f9b5053ad360, - target: {fileID: 224000013898185038, guid: bd2b99773f3e0489aae9f9b5053ad360,
type: 2} type: 2}
@ -727,7 +727,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: -10.5
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 224000013898185038, guid: bd2b99773f3e0489aae9f9b5053ad360, - target: {fileID: 224000013898185038, guid: bd2b99773f3e0489aae9f9b5053ad360,
type: 2} type: 2}
@ -737,7 +737,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: 21
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 224000012687811630, guid: bd2b99773f3e0489aae9f9b5053ad360, - target: {fileID: 224000012687811630, guid: bd2b99773f3e0489aae9f9b5053ad360,
type: 2} type: 2}
@ -757,7 +757,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: -10.5
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 224000012687811630, guid: bd2b99773f3e0489aae9f9b5053ad360, - target: {fileID: 224000012687811630, guid: bd2b99773f3e0489aae9f9b5053ad360,
type: 2} type: 2}
@ -767,7 +767,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: 21
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 224000012590701094, guid: bd2b99773f3e0489aae9f9b5053ad360, - target: {fileID: 224000012590701094, guid: bd2b99773f3e0489aae9f9b5053ad360,
type: 2} type: 2}
@ -787,7 +787,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: -10.5
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 224000012590701094, guid: bd2b99773f3e0489aae9f9b5053ad360, - target: {fileID: 224000012590701094, guid: bd2b99773f3e0489aae9f9b5053ad360,
type: 2} type: 2}
@ -797,7 +797,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: 21
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 224000013149320576, guid: bd2b99773f3e0489aae9f9b5053ad360, - target: {fileID: 224000013149320576, guid: bd2b99773f3e0489aae9f9b5053ad360,
type: 2} type: 2}
@ -817,7 +817,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: -10.5
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 224000013149320576, guid: bd2b99773f3e0489aae9f9b5053ad360, - target: {fileID: 224000013149320576, guid: bd2b99773f3e0489aae9f9b5053ad360,
type: 2} type: 2}
@ -827,7 +827,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: 21
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}
@ -1293,7 +1293,6 @@ GameObject:
- component: {fileID: 1889213480} - component: {fileID: 1889213480}
- component: {fileID: 1889213479} - component: {fileID: 1889213479}
- component: {fileID: 1889213475} - component: {fileID: 1889213475}
- component: {fileID: 1889213472}
m_Layer: 0 m_Layer: 0
m_Name: Flowchart m_Name: Flowchart
m_TagString: Untagged m_TagString: Untagged
@ -1314,8 +1313,8 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
nodeRect: nodeRect:
serializedVersion: 2 serializedVersion: 2
x: 64.99671 x: 76.99671
y: 268.1121 y: 228.11209
width: 120 width: 120
height: 40 height: 40
tint: {r: 1, g: 1, b: 1, a: 1} tint: {r: 1, g: 1, b: 1, a: 1}
@ -1340,27 +1339,7 @@ MonoBehaviour:
parentBlock: {fileID: 1889213470} parentBlock: {fileID: 1889213470}
savePointKeys: savePointKeys:
- new_game - new_game
- queens_chamber - Queens Chamber
--- !u!114 &1889213472
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1889213469}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 050fb9e6e72f442b3b883da8a965bdeb, type: 3}
m_Name:
m_EditorClassIdentifier:
itemId: 60
indentLevel: 0
targetFlowchart: {fileID: 0}
targetBlock: {fileID: 1889213481}
startLabel:
stringRef: {fileID: 0}
stringVal:
startIndex: 0
callMode: 0
--- !u!114 &1889213473 --- !u!114 &1889213473
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -1443,7 +1422,7 @@ MonoBehaviour:
width: 1502.7736 width: 1502.7736
height: 1138.5048 height: 1138.5048
selectedBlocks: selectedBlocks:
- {fileID: 1889213496} - {fileID: 1889213481}
selectedCommands: [] selectedCommands: []
variables: variables:
- {fileID: 1889213489} - {fileID: 1889213489}
@ -1484,9 +1463,9 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
parentBlock: {fileID: 1889213481} parentBlock: {fileID: 1889213481}
savePointKeys: savePointKeys:
- use_umbrella - Use Umbrella
- duck_down - Duck Down
- queen_fight - The Queen
--- !u!114 &1889213480 --- !u!114 &1889213480
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -1517,8 +1496,8 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
nodeRect: nodeRect:
serializedVersion: 2 serializedVersion: 2
x: 63.28943 x: 81.28943
y: 337.5421 y: 288.5421
width: 120 width: 120
height: 40 height: 40
tint: {r: 1, g: 1, b: 1, a: 1} tint: {r: 1, g: 1, b: 1, a: 1}
@ -1621,14 +1600,14 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
nodeRect: nodeRect:
serializedVersion: 2 serializedVersion: 2
x: 232.40749 x: 233.40749
y: 144.44666 y: 144.44666
width: 140 width: 143
height: 40 height: 40
tint: {r: 1, g: 1, b: 1, a: 1} tint: {r: 1, g: 1, b: 1, a: 1}
useCustomTint: 0 useCustomTint: 0
itemId: 20 itemId: 20
blockName: QueensChamber blockName: Queens Chamber
description: description:
eventHandler: {fileID: 0} eventHandler: {fileID: 0}
commandList: commandList:
@ -1638,7 +1617,6 @@ MonoBehaviour:
- {fileID: 1889213495} - {fileID: 1889213495}
- {fileID: 1889213494} - {fileID: 1889213494}
- {fileID: 1889213491} - {fileID: 1889213491}
- {fileID: 1889213472}
--- !u!114 &1889213487 --- !u!114 &1889213487
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 2 m_ObjectHideFlags: 2
@ -1652,10 +1630,11 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
itemId: 21 itemId: 21
indentLevel: 0 indentLevel: 0
savePointKey: queens_chamber savePointKey:
savePointDescription: savePointDescription:
stringRef: {fileID: 0} stringRef: {fileID: 0}
stringVal: stringVal:
fireEvent: 1
resumeFromHere: 1 resumeFromHere: 1
--- !u!114 &1889213488 --- !u!114 &1889213488
MonoBehaviour: MonoBehaviour:
@ -1747,7 +1726,7 @@ MonoBehaviour:
nodeRect: nodeRect:
serializedVersion: 2 serializedVersion: 2
x: 394.38702 x: 394.38702
y: 183.56548 y: 184.56548
width: 120 width: 120
height: 40 height: 40
tint: {r: 1, g: 1, b: 1, a: 1} tint: {r: 1, g: 1, b: 1, a: 1}
@ -1836,7 +1815,7 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
nodeRect: nodeRect:
serializedVersion: 2 serializedVersion: 2
x: 392.23532 x: 391.23532
y: 97.65081 y: 97.65081
width: 121 width: 121
height: 40 height: 40
@ -1943,7 +1922,7 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
nodeRect: nodeRect:
serializedVersion: 2 serializedVersion: 2
x: 541.1676 x: 542.1676
y: 144.44673 y: 144.44673
width: 120 width: 120
height: 40 height: 40
@ -1973,10 +1952,11 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
itemId: 35 itemId: 35
indentLevel: 0 indentLevel: 0
savePointKey: duck_down savePointKey:
savePointDescription: savePointDescription:
stringRef: {fileID: 0} stringRef: {fileID: 0}
stringVal: stringVal:
fireEvent: 1
resumeFromHere: 1 resumeFromHere: 1
--- !u!114 &1889213502 --- !u!114 &1889213502
MonoBehaviour: MonoBehaviour:
@ -1991,10 +1971,11 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
itemId: 34 itemId: 34
indentLevel: 0 indentLevel: 0
savePointKey: use_umbrella savePointKey:
savePointDescription: savePointDescription:
stringRef: {fileID: 0} stringRef: {fileID: 0}
stringVal: stringVal:
fireEvent: 1
resumeFromHere: 1 resumeFromHere: 1
--- !u!114 &1889213503 --- !u!114 &1889213503
MonoBehaviour: MonoBehaviour:
@ -2257,10 +2238,11 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
itemId: 43 itemId: 43
indentLevel: 0 indentLevel: 0
savePointKey: queen_fight savePointKey:
savePointDescription: savePointDescription:
stringRef: {fileID: 0} stringRef: {fileID: 0}
stringVal: stringVal:
fireEvent: 1
resumeFromHere: 1 resumeFromHere: 1
--- !u!1 &2025975869 --- !u!1 &2025975869
GameObject: GameObject:

Loading…
Cancel
Save