Browse Source
- Changed the name of the HistoryManager to NarrativeLog - Created the SaveReset SaveManagerSignal but it needs to be tied in - Made the PrettyPrint only show previous logs, not the current dialog.master
lealeelu
8 years ago
9 changed files with 1123 additions and 192 deletions
@ -1,71 +0,0 @@
|
||||
// This code is part of the Fungus library (http://fungusgames.com) maintained by Chris Gregan (http://twitter.com/gofungus). |
||||
// It is released for free under the MIT open source license (https://github.com/snozbot/fungus/blob/master/LICENSE) |
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using UnityEngine; |
||||
|
||||
namespace Fungus |
||||
{ |
||||
/// <summary> |
||||
/// A single line of dialog |
||||
/// </summary> |
||||
[Serializable] |
||||
public class Line |
||||
{ |
||||
public string name; |
||||
public string text; |
||||
|
||||
} |
||||
|
||||
|
||||
[Serializable] |
||||
public class HistoryData |
||||
{ |
||||
public List<Line> lines; |
||||
|
||||
public HistoryData() { |
||||
lines = new List<Line>(); |
||||
} |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Controls dialog history |
||||
/// </summary> |
||||
public class HistoryManager : MonoBehaviour |
||||
{ |
||||
|
||||
HistoryData history; |
||||
|
||||
protected virtual void Awake() |
||||
{ |
||||
history = new HistoryData(); |
||||
} |
||||
|
||||
public void AddLine(string name, string text) |
||||
{ |
||||
Line line = new Line(); |
||||
line.name = name; |
||||
line.text = text; |
||||
history.lines.Add(line); |
||||
} |
||||
|
||||
public string GetHistory() |
||||
{ |
||||
string jsonText = JsonUtility.ToJson(history, true); |
||||
return jsonText; |
||||
} |
||||
|
||||
public string GetPrettyHistory() |
||||
{ |
||||
string output = ""; |
||||
|
||||
for (int i = 0; i < history.lines.Count; i++) |
||||
{ |
||||
output += "<b>" + history.lines[i].name + "</b>\n"; |
||||
output += history.lines[i].text + "\n\n"; |
||||
} |
||||
return output; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,109 @@
|
||||
// This code is part of the Fungus library (http://fungusgames.com) maintained by Chris Gregan (http://twitter.com/gofungus). |
||||
// It is released for free under the MIT open source license (https://github.com/snozbot/fungus/blob/master/LICENSE) |
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using UnityEngine; |
||||
|
||||
namespace Fungus |
||||
{ |
||||
/// <summary> |
||||
/// A single line of dialog |
||||
/// </summary> |
||||
[Serializable] |
||||
public class Line |
||||
{ |
||||
[SerializeField] public string name; |
||||
[SerializeField] public string text; |
||||
|
||||
} |
||||
|
||||
/// <summary> |
||||
/// Serializable object to store Narrative Lines |
||||
/// </summary> |
||||
[Serializable] |
||||
public class NarrativeData |
||||
{ |
||||
[SerializeField] public List<Line> lines; |
||||
|
||||
public NarrativeData() { |
||||
lines = new List<Line>(); |
||||
} |
||||
|
||||
} |
||||
|
||||
/// <summary> |
||||
/// Controls dialog history |
||||
/// </summary> |
||||
public class NarrativeLog : MonoBehaviour |
||||
{ |
||||
|
||||
NarrativeData history; |
||||
|
||||
protected virtual void Awake() |
||||
{ |
||||
history = new NarrativeData(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Add a line of dialog to the Narrative Log |
||||
/// </summary> |
||||
/// <param name="name"></param> |
||||
/// <param name="text"></param> |
||||
public void AddLine(string name, string text) |
||||
{ |
||||
Line line = new Line(); |
||||
line.name = name; |
||||
line.text = text; |
||||
history.lines.Add(line); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Clear line history after reset |
||||
/// </summary> |
||||
public void Clear() |
||||
{ |
||||
history.lines.Clear(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Convert history into Json for saving in SaveData |
||||
/// </summary> |
||||
/// <returns></returns> |
||||
public string GetJsonHistory() |
||||
{ |
||||
string jsonText = JsonUtility.ToJson(history, true); |
||||
return jsonText; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Show previous lines for display purposes |
||||
/// </summary> |
||||
/// <returns></returns> |
||||
public string GetPrettyHistory() |
||||
{ |
||||
string output = ""; |
||||
|
||||
for (int i = 0; i < history.lines.Count-1; i++) |
||||
{ |
||||
output += "<b>" + history.lines[i].name + "</b>\n"; |
||||
output += history.lines[i].text + "\n\n"; |
||||
} |
||||
return output; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Load History from Json |
||||
/// </summary> |
||||
/// <param name="narrativeData"></param> |
||||
public void LoadHistory(string narrativeData) |
||||
{ |
||||
if (narrativeData == null) |
||||
{ |
||||
Debug.LogError("Failed to decode History save data item"); |
||||
return; |
||||
} |
||||
history = JsonUtility.FromJson<NarrativeData>(narrativeData); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue