Browse Source

Move addline to dosay

master
lealeelu 8 years ago
parent
commit
a562d2897a
  1. 29
      Assets/Fungus/Scripts/Components/NarrativeLog.cs
  2. 11
      Assets/Fungus/Scripts/Components/NarrativeLogMenu.cs
  3. 2
      Assets/Fungus/Scripts/Components/SayDialog.cs
  4. 10
      Assets/FungusExamples/Conversation/Say History.unity

29
Assets/Fungus/Scripts/Components/NarrativeLog.cs

@ -38,6 +38,13 @@ namespace Fungus
public class NarrativeLog : MonoBehaviour public class NarrativeLog : MonoBehaviour
{ {
/// <summary>
/// NarrativeAdded signal. Sent when a line is added.
/// </summary>
public static event NarrativeAddedHandler OnNarrativeAdded;
public delegate void NarrativeAddedHandler();
public static void DoNarrativeAdded() { if (OnNarrativeAdded != null) OnNarrativeAdded(); }
NarrativeData history; NarrativeData history;
protected virtual void Awake() protected virtual void Awake()
@ -45,8 +52,27 @@ namespace Fungus
history = new NarrativeData(); history = new NarrativeData();
} }
#region Public Methods protected virtual void OnEnable()
{
WriterSignals.OnWriterState += OnWriterState;
}
protected virtual void OnDisable()
{
WriterSignals.OnWriterState -= OnWriterState;
}
protected virtual void OnWriterState(Writer writer, WriterState writerState)
{
if (writerState == WriterState.End)
{
AddLine(SayDialog.GetSayDialog().NameText.text,
SayDialog.GetSayDialog().StoryText.text);
}
}
#region Public Methods
/// <summary> /// <summary>
/// Add a line of dialog to the Narrative Log /// Add a line of dialog to the Narrative Log
/// </summary> /// </summary>
@ -58,6 +84,7 @@ namespace Fungus
line.name = name; line.name = name;
line.text = text; line.text = text;
history.lines.Add(line); history.lines.Add(line);
DoNarrativeAdded();
} }
/// <summary> /// <summary>

11
Assets/Fungus/Scripts/Components/NarrativeLogMenu.cs

@ -77,6 +77,7 @@ namespace Fungus
SaveManagerSignals.OnSavePointLoaded += OnSavePointLoaded; SaveManagerSignals.OnSavePointLoaded += OnSavePointLoaded;
SaveManagerSignals.OnSaveReset += OnSaveReset; SaveManagerSignals.OnSaveReset += OnSaveReset;
BlockSignals.OnBlockEnd += OnBlockEnd; BlockSignals.OnBlockEnd += OnBlockEnd;
NarrativeLog.OnNarrativeAdded += OnNarrativeAdded;
} }
protected virtual void OnDisable() protected virtual void OnDisable()
@ -85,11 +86,17 @@ namespace Fungus
SaveManagerSignals.OnSavePointLoaded -= OnSavePointLoaded; SaveManagerSignals.OnSavePointLoaded -= OnSavePointLoaded;
SaveManagerSignals.OnSaveReset -= OnSaveReset; SaveManagerSignals.OnSaveReset -= OnSaveReset;
BlockSignals.OnBlockEnd -= OnBlockEnd; BlockSignals.OnBlockEnd -= OnBlockEnd;
NarrativeLog.OnNarrativeAdded -= OnNarrativeAdded;
}
protected virtual void OnNarrativeAdded()
{
UpdateNarrativeLogText();
} }
protected virtual void OnWriterState(Writer writer, WriterState writerState) protected virtual void OnWriterState(Writer writer, WriterState writerState)
{ {
if (writerState == WriterState.End || writerState == WriterState.Start) if (writerState == WriterState.Start)
{ {
UpdateNarrativeLogText(); UpdateNarrativeLogText();
} }
@ -123,7 +130,7 @@ namespace Fungus
var historyText = narrativeLogView.GetComponentInChildren<Text>(); var historyText = narrativeLogView.GetComponentInChildren<Text>();
if (historyText != null) if (historyText != null)
{ {
historyText.text = FungusManager.Instance.NarrativeLog.GetPrettyHistory(previousLines); historyText.text = FungusManager.Instance.NarrativeLog.GetPrettyHistory();
} }
} }
} }

2
Assets/Fungus/Scripts/Components/SayDialog.cs

@ -25,6 +25,7 @@ namespace Fungus
[Tooltip("The name text UI object")] [Tooltip("The name text UI object")]
[SerializeField] protected Text nameText; [SerializeField] protected Text nameText;
public virtual Text NameText { get { return nameText; } }
[Tooltip("The story text UI object")] [Tooltip("The story text UI object")]
[SerializeField] protected Text storyText; [SerializeField] protected Text storyText;
@ -435,7 +436,6 @@ namespace Fungus
/// <param name="onComplete">Callback to execute when writing and player input have finished.</param> /// <param name="onComplete">Callback to execute when writing and player input have finished.</param>
public virtual void Say(string text, bool clearPrevious, bool waitForInput, bool fadeWhenDone, bool stopVoiceover, AudioClip voiceOverClip, Action onComplete) public virtual void Say(string text, bool clearPrevious, bool waitForInput, bool fadeWhenDone, bool stopVoiceover, AudioClip voiceOverClip, Action onComplete)
{ {
FungusManager.Instance.NarrativeLog.AddLine(nameText.text, text);
StartCoroutine(DoSay(text, clearPrevious, waitForInput, fadeWhenDone, stopVoiceover, voiceOverClip, onComplete)); StartCoroutine(DoSay(text, clearPrevious, waitForInput, fadeWhenDone, stopVoiceover, voiceOverClip, onComplete));
} }

10
Assets/FungusExamples/Conversation/Say History.unity

@ -2033,7 +2033,7 @@ MonoBehaviour:
selectedBlocks: selectedBlocks:
- {fileID: 775007736} - {fileID: 775007736}
selectedCommands: selectedCommands:
- {fileID: 775007749} - {fileID: 775007735}
variables: [] variables: []
description: description:
stepPause: 0 stepPause: 0
@ -2058,7 +2058,11 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
itemId: 1 itemId: 1
indentLevel: 0 indentLevel: 0
storyText: After Save 1! storyText: '{b}After Save 1!{/b}{w}
{color=Blue}What do we do now?{/color}
{flash=0.5}On to the next save!'
description: description:
character: {fileID: 1021439244} character: {fileID: 1021439244}
portrait: {fileID: 0} portrait: {fileID: 0}
@ -4365,7 +4369,7 @@ MonoBehaviour:
m_HandleRect: {fileID: 282981322} m_HandleRect: {fileID: 282981322}
m_Direction: 2 m_Direction: 2
m_Value: 1 m_Value: 1
m_Size: 0.98689735 m_Size: 1
m_NumberOfSteps: 0 m_NumberOfSteps: 0
m_OnValueChanged: m_OnValueChanged:
m_PersistentCalls: m_PersistentCalls:

Loading…
Cancel
Save