Browse Source

Fast Forward button

master
Christopher 8 years ago
parent
commit
51004f9bfd
  1. 17
      Assets/Fungus/Scripts/Components/SaveGameHelper.cs
  2. 13
      Assets/Fungus/Scripts/Components/SaveManager.cs
  3. 19
      Assets/Fungus/Scripts/SavePoints/SaveHistory.cs
  4. 234
      Assets/FungusExamples/SaveGame/SaveExample.unity

17
Assets/Fungus/Scripts/Components/SaveGameHelper.cs

@ -30,6 +30,8 @@ namespace Fungus
[SerializeField] protected Button rewindButton; [SerializeField] protected Button rewindButton;
[SerializeField] protected Button forwardButton;
[SerializeField] protected Button restartButton; [SerializeField] protected Button restartButton;
[SerializeField] protected SaveGameObjects saveGameObjects = new SaveGameObjects(); [SerializeField] protected SaveGameObjects saveGameObjects = new SaveGameObjects();
@ -79,6 +81,10 @@ namespace Fungus
{ {
rewindButton.interactable = saveManager.NumSavePoints > 1; rewindButton.interactable = saveManager.NumSavePoints > 1;
} }
if (forwardButton != null)
{
forwardButton.interactable = saveManager.NumRewoundSavePoints > 0;
}
} }
protected void CheckSavePointKeys() protected void CheckSavePointKeys()
@ -176,6 +182,17 @@ namespace Fungus
} }
} }
public virtual void Forward()
{
PlayClickSound();
var saveManager = FungusManager.Instance.SaveManager;
if (saveManager.NumRewoundSavePoints > 0)
{
saveManager.FastForward();
}
}
public virtual void Restart() public virtual void Restart()
{ {
if (string.IsNullOrEmpty(startScene)) if (string.IsNullOrEmpty(startScene))

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

@ -40,6 +40,8 @@ namespace Fungus
public virtual int NumSavePoints { get { return saveHistory.NumSavePoints; } } public virtual int NumSavePoints { get { return saveHistory.NumSavePoints; } }
public virtual int NumRewoundSavePoints { get { return saveHistory.NumRewoundSavePoints; } }
public virtual void Save(string saveDataKey) public virtual void Save(string saveDataKey)
{ {
WriteSaveHistory(saveDataKey); WriteSaveHistory(saveDataKey);
@ -79,7 +81,16 @@ namespace Fungus
{ {
if (saveHistory.NumSavePoints > 0) if (saveHistory.NumSavePoints > 0)
{ {
saveHistory.RemoveSavePoint(); saveHistory.Rewind();
saveHistory.LoadLatestSavePoint();
}
}
public virtual void FastForward()
{
if (saveHistory.NumRewoundSavePoints > 0)
{
saveHistory.FastForward();
saveHistory.LoadLatestSavePoint(); saveHistory.LoadLatestSavePoint();
} }
} }

19
Assets/Fungus/Scripts/SavePoints/SaveHistory.cs

@ -17,10 +17,14 @@ namespace Fungus
[SerializeField] protected List<string> savePoints = new List<string>(); [SerializeField] protected List<string> savePoints = new List<string>();
[SerializeField] protected List<string> rewoundSavePoints = new List<string>();
#region Public methods #region Public methods
public int NumSavePoints { get { return savePoints.Count; } } public int NumSavePoints { get { return savePoints.Count; } }
public int NumRewoundSavePoints { get { return rewoundSavePoints.Count; } }
public void AddSavePoint(string savePointKey, string savePointDescription) public void AddSavePoint(string savePointKey, string savePointDescription)
{ {
string sceneName = SceneManager.GetActiveScene().name; string sceneName = SceneManager.GetActiveScene().name;
@ -28,17 +32,24 @@ namespace Fungus
savePoints.Add(savePointData); savePoints.Add(savePointData);
} }
/// <summary> public void Rewind()
/// Removes the latest save point.
/// </summary>
public void RemoveSavePoint()
{ {
if (savePoints.Count > 0) if (savePoints.Count > 0)
{ {
rewoundSavePoints.Add(savePoints[savePoints.Count - 1]);
savePoints.RemoveAt(savePoints.Count - 1); savePoints.RemoveAt(savePoints.Count - 1);
} }
} }
public void FastForward()
{
if (rewoundSavePoints.Count > 0)
{
savePoints.Add(rewoundSavePoints[rewoundSavePoints.Count - 1]);
rewoundSavePoints.RemoveAt(rewoundSavePoints.Count - 1);
}
}
public void LoadLatestSavePoint() public void LoadLatestSavePoint()
{ {
if (savePoints.Count > 0) if (savePoints.Count > 0)

234
Assets/FungusExamples/SaveGame/SaveExample.unity

@ -497,8 +497,9 @@ RectTransform:
m_Children: m_Children:
- {fileID: 1074900347} - {fileID: 1074900347}
- {fileID: 1909782092} - {fileID: 1909782092}
- {fileID: 1671345596}
- {fileID: 767364851} - {fileID: 767364851}
- {fileID: 1523935888}
- {fileID: 1671345596}
m_Father: {fileID: 959305724} m_Father: {fileID: 959305724}
m_RootOrder: 0 m_RootOrder: 0
m_AnchorMin: {x: 1, y: 1} m_AnchorMin: {x: 1, y: 1}
@ -514,7 +515,7 @@ MonoBehaviour:
m_GameObject: {fileID: 183359390} m_GameObject: {fileID: 183359390}
m_Enabled: 1 m_Enabled: 1
m_EditorHideFlags: 0 m_EditorHideFlags: 0
m_Script: {fileID: -405508275, guid: f70555f144d8491a825f0804e09c671c, type: 3} m_Script: {fileID: -405508275, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
m_Padding: m_Padding:
@ -535,7 +536,7 @@ MonoBehaviour:
m_GameObject: {fileID: 183359390} m_GameObject: {fileID: 183359390}
m_Enabled: 1 m_Enabled: 1
m_EditorHideFlags: 0 m_EditorHideFlags: 0
m_Script: {fileID: -405508275, guid: f70555f144d8491a825f0804e09c671c, type: 3} m_Script: {fileID: -405508275, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
m_Padding: m_Padding:
@ -817,7 +818,7 @@ RectTransform:
m_Children: m_Children:
- {fileID: 167287878} - {fileID: 167287878}
m_Father: {fileID: 183359391} m_Father: {fileID: 183359391}
m_RootOrder: 3 m_RootOrder: 2
m_AnchorMin: {x: 0, y: 0} m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0} m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0} m_AnchoredPosition: {x: 0, y: 0}
@ -893,7 +894,7 @@ MonoBehaviour:
m_HorizontalOverflow: 0 m_HorizontalOverflow: 0
m_VerticalOverflow: 0 m_VerticalOverflow: 0
m_LineSpacing: 1 m_LineSpacing: 1
m_Text: Rewind m_Text: '>>>'
--- !u!222 &783363808 --- !u!222 &783363808
CanvasRenderer: CanvasRenderer:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -901,6 +902,86 @@ CanvasRenderer:
type: 2} type: 2}
m_PrefabInternal: {fileID: 0} m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 783363805} m_GameObject: {fileID: 783363805}
--- !u!1 &792682610
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 1000012365707562, guid: ac03b2b3b2c07411da18c6ddc7c6e9ec,
type: 2}
m_PrefabInternal: {fileID: 0}
serializedVersion: 4
m_Component:
- 224: {fileID: 792682611}
- 222: {fileID: 792682613}
- 114: {fileID: 792682612}
m_Layer: 5
m_Name: Text
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &792682611
RectTransform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 224000010128387060, guid: ac03b2b3b2c07411da18c6ddc7c6e9ec,
type: 2}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 792682610}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_Children: []
m_Father: {fileID: 1523935888}
m_RootOrder: 0
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &792682612
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 114000012760269958, guid: ac03b2b3b2c07411da18c6ddc7c6e9ec,
type: 2}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 792682610}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 708705254, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 1}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 12
m_FontStyle: 0
m_BestFit: 0
m_MinSize: 1
m_MaxSize: 40
m_Alignment: 4
m_AlignByGeometry: 0
m_RichText: 1
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text: '<<<
'
--- !u!222 &792682613
CanvasRenderer:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 222000012419091150, guid: ac03b2b3b2c07411da18c6ddc7c6e9ec,
type: 2}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 792682610}
--- !u!1 &878402649 --- !u!1 &878402649
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -1089,12 +1170,14 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
startScene: SaveExample startScene: SaveExample
autoStartGame: 1 autoStartGame: 1
saveMenuActive: 0
restartDeletesSave: 1 restartDeletesSave: 1
saveMenuGroup: {fileID: 183359396} saveMenuGroup: {fileID: 183359396}
saveMenuButton: {fileID: 2029405579} saveMenuButton: {fileID: 2029405579}
saveButton: {fileID: 1074900350} saveButton: {fileID: 1074900350}
loadButton: {fileID: 1909782095} loadButton: {fileID: 1909782095}
rewindButton: {fileID: 1671345599} rewindButton: {fileID: 1523935889}
forwardButton: {fileID: 1671345599}
restartButton: {fileID: 767364848} restartButton: {fileID: 767364848}
saveGameObjects: saveGameObjects:
flowcharts: flowcharts:
@ -1739,6 +1822,133 @@ CanvasRenderer:
type: 2} type: 2}
m_PrefabInternal: {fileID: 0} m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1446308202} m_GameObject: {fileID: 1446308202}
--- !u!1 &1523935887
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 1000013442374998, guid: ac03b2b3b2c07411da18c6ddc7c6e9ec,
type: 2}
m_PrefabInternal: {fileID: 0}
serializedVersion: 4
m_Component:
- 224: {fileID: 1523935888}
- 222: {fileID: 1523935891}
- 114: {fileID: 1523935890}
- 114: {fileID: 1523935889}
m_Layer: 5
m_Name: RewindButton
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &1523935888
RectTransform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 224000012955523454, guid: ac03b2b3b2c07411da18c6ddc7c6e9ec,
type: 2}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1523935887}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_Children:
- {fileID: 792682611}
m_Father: {fileID: 183359391}
m_RootOrder: 3
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1523935889
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 114000012890081690, guid: ac03b2b3b2c07411da18c6ddc7c6e9ec,
type: 2}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1523935887}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 1392445389, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Navigation:
m_Mode: 3
m_SelectOnUp: {fileID: 0}
m_SelectOnDown: {fileID: 0}
m_SelectOnLeft: {fileID: 0}
m_SelectOnRight: {fileID: 0}
m_Transition: 1
m_Colors:
m_NormalColor: {r: 1, g: 1, b: 1, a: 1}
m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1}
m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608}
m_ColorMultiplier: 1
m_FadeDuration: 0.1
m_SpriteState:
m_HighlightedSprite: {fileID: 0}
m_PressedSprite: {fileID: 0}
m_DisabledSprite: {fileID: 0}
m_AnimationTriggers:
m_NormalTrigger: Normal
m_HighlightedTrigger: Highlighted
m_PressedTrigger: Pressed
m_DisabledTrigger: Disabled
m_Interactable: 1
m_TargetGraphic: {fileID: 1523935890}
m_OnClick:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 959305720}
m_MethodName: Rewind
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
m_TypeName: UnityEngine.UI.Button+ButtonClickedEvent, UnityEngine.UI, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null
--- !u!114 &1523935890
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 114000013334863018, guid: ac03b2b3b2c07411da18c6ddc7c6e9ec,
type: 2}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1523935887}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: -765806418, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_Sprite: {fileID: 10905, guid: 0000000000000000f000000000000000, type: 0}
m_Type: 1
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
--- !u!222 &1523935891
CanvasRenderer:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 222000010513565616, guid: ac03b2b3b2c07411da18c6ddc7c6e9ec,
type: 2}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1523935887}
--- !u!1 &1671345595 --- !u!1 &1671345595
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -1752,7 +1962,7 @@ GameObject:
- 114: {fileID: 1671345597} - 114: {fileID: 1671345597}
- 114: {fileID: 1671345599} - 114: {fileID: 1671345599}
m_Layer: 5 m_Layer: 5
m_Name: RewindButton m_Name: FastForwardButton
m_TagString: Untagged m_TagString: Untagged
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
@ -1772,7 +1982,7 @@ RectTransform:
m_Children: m_Children:
- {fileID: 783363806} - {fileID: 783363806}
m_Father: {fileID: 183359391} m_Father: {fileID: 183359391}
m_RootOrder: 2 m_RootOrder: 4
m_AnchorMin: {x: 0, y: 0} m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0} m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0} m_AnchoredPosition: {x: 0, y: 0}
@ -1854,7 +2064,7 @@ MonoBehaviour:
m_PersistentCalls: m_PersistentCalls:
m_Calls: m_Calls:
- m_Target: {fileID: 959305720} - m_Target: {fileID: 959305720}
m_MethodName: Rewind m_MethodName: Forward
m_Mode: 1 m_Mode: 1
m_Arguments: m_Arguments:
m_ObjectArgument: {fileID: 0} m_ObjectArgument: {fileID: 0}
@ -2504,7 +2714,7 @@ MonoBehaviour:
m_GameObject: {fileID: 2029405576} m_GameObject: {fileID: 2029405576}
m_Enabled: 1 m_Enabled: 1
m_EditorHideFlags: 0 m_EditorHideFlags: 0
m_Script: {fileID: 1679637790, guid: f70555f144d8491a825f0804e09c671c, type: 3} m_Script: {fileID: 1679637790, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
m_IgnoreLayout: 1 m_IgnoreLayout: 1
@ -2523,7 +2733,7 @@ MonoBehaviour:
m_GameObject: {fileID: 2029405576} m_GameObject: {fileID: 2029405576}
m_Enabled: 1 m_Enabled: 1
m_EditorHideFlags: 0 m_EditorHideFlags: 0
m_Script: {fileID: 1392445389, guid: f70555f144d8491a825f0804e09c671c, type: 3} m_Script: {fileID: 1392445389, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
m_Navigation: m_Navigation:
@ -2576,7 +2786,7 @@ MonoBehaviour:
m_GameObject: {fileID: 2029405576} m_GameObject: {fileID: 2029405576}
m_Enabled: 1 m_Enabled: 1
m_EditorHideFlags: 0 m_EditorHideFlags: 0
m_Script: {fileID: -765806418, guid: f70555f144d8491a825f0804e09c671c, type: 3} m_Script: {fileID: -765806418, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
m_Material: {fileID: 0} m_Material: {fileID: 0}

Loading…
Cancel
Save