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
{
/// <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;
protected virtual void Awake()
@ -45,8 +52,27 @@ namespace Fungus
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>
/// Add a line of dialog to the Narrative Log
/// </summary>
@ -58,6 +84,7 @@ namespace Fungus
line.name = name;
line.text = text;
history.lines.Add(line);
DoNarrativeAdded();
}
/// <summary>

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

@ -77,6 +77,7 @@ namespace Fungus
SaveManagerSignals.OnSavePointLoaded += OnSavePointLoaded;
SaveManagerSignals.OnSaveReset += OnSaveReset;
BlockSignals.OnBlockEnd += OnBlockEnd;
NarrativeLog.OnNarrativeAdded += OnNarrativeAdded;
}
protected virtual void OnDisable()
@ -85,11 +86,17 @@ namespace Fungus
SaveManagerSignals.OnSavePointLoaded -= OnSavePointLoaded;
SaveManagerSignals.OnSaveReset -= OnSaveReset;
BlockSignals.OnBlockEnd -= OnBlockEnd;
NarrativeLog.OnNarrativeAdded -= OnNarrativeAdded;
}
protected virtual void OnNarrativeAdded()
{
UpdateNarrativeLogText();
}
protected virtual void OnWriterState(Writer writer, WriterState writerState)
{
if (writerState == WriterState.End || writerState == WriterState.Start)
if (writerState == WriterState.Start)
{
UpdateNarrativeLogText();
}
@ -123,7 +130,7 @@ namespace Fungus
var historyText = narrativeLogView.GetComponentInChildren<Text>();
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")]
[SerializeField] protected Text nameText;
public virtual Text NameText { get { return nameText; } }
[Tooltip("The story text UI object")]
[SerializeField] protected Text storyText;
@ -435,7 +436,6 @@ namespace Fungus
/// <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)
{
FungusManager.Instance.NarrativeLog.AddLine(nameText.text, text);
StartCoroutine(DoSay(text, clearPrevious, waitForInput, fadeWhenDone, stopVoiceover, voiceOverClip, onComplete));
}

10
Assets/FungusExamples/Conversation/Say History.unity

@ -2033,7 +2033,7 @@ MonoBehaviour:
selectedBlocks:
- {fileID: 775007736}
selectedCommands:
- {fileID: 775007749}
- {fileID: 775007735}
variables: []
description:
stepPause: 0
@ -2058,7 +2058,11 @@ MonoBehaviour:
m_EditorClassIdentifier:
itemId: 1
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:
character: {fileID: 1021439244}
portrait: {fileID: 0}
@ -4365,7 +4369,7 @@ MonoBehaviour:
m_HandleRect: {fileID: 282981322}
m_Direction: 2
m_Value: 1
m_Size: 0.98689735
m_Size: 1
m_NumberOfSteps: 0
m_OnValueChanged:
m_PersistentCalls:

Loading…
Cancel
Save