|
|
@ -11,10 +11,10 @@ namespace Fungus |
|
|
|
/// <summary> |
|
|
|
/// <summary> |
|
|
|
/// Presents story text to the player in a dialogue box. |
|
|
|
/// Presents story text to the player in a dialogue box. |
|
|
|
/// </summary> |
|
|
|
/// </summary> |
|
|
|
public class SayDialog : MonoBehaviour |
|
|
|
public class SayDialog : MonoBehaviour, ISayDialog |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Currently active Say Dialog used to display Say text |
|
|
|
// Currently active Say Dialog used to display Say text |
|
|
|
public static SayDialog activeSayDialog; |
|
|
|
public static ISayDialog activeSayDialog; |
|
|
|
|
|
|
|
|
|
|
|
// Most recent speaking character |
|
|
|
// Most recent speaking character |
|
|
|
public static Character speakingCharacter; |
|
|
|
public static Character speakingCharacter; |
|
|
@ -55,7 +55,7 @@ namespace Fungus |
|
|
|
|
|
|
|
|
|
|
|
protected Sprite currentCharacterImage; |
|
|
|
protected Sprite currentCharacterImage; |
|
|
|
|
|
|
|
|
|
|
|
public static SayDialog GetSayDialog() |
|
|
|
public static ISayDialog GetSayDialog() |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (activeSayDialog == null) |
|
|
|
if (activeSayDialog == null) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -75,14 +75,14 @@ namespace Fungus |
|
|
|
GameObject go = Instantiate(prefab) as GameObject; |
|
|
|
GameObject go = Instantiate(prefab) as GameObject; |
|
|
|
go.SetActive(false); |
|
|
|
go.SetActive(false); |
|
|
|
go.name = "SayDialog"; |
|
|
|
go.name = "SayDialog"; |
|
|
|
activeSayDialog = go.GetComponent<SayDialog>(); |
|
|
|
activeSayDialog = go.GetComponent<ISayDialog>(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return activeSayDialog; |
|
|
|
return activeSayDialog; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected Writer GetWriter() |
|
|
|
protected Writer GetWriter() |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (writer != null) |
|
|
|
if (writer != null) |
|
|
@ -158,11 +158,6 @@ namespace Fungus |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public virtual void Say(string text, bool clearPrevious, bool waitForInput, bool fadeWhenDone, bool stopVoiceover, AudioClip voiceOverClip, Action onComplete) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
StartCoroutine(SayInternal(text, clearPrevious, waitForInput, fadeWhenDone, stopVoiceover, voiceOverClip, onComplete)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public virtual IEnumerator SayInternal(string text, bool clearPrevious, bool waitForInput, bool fadeWhenDone, bool stopVoiceover, AudioClip voiceOverClip, Action onComplete) |
|
|
|
public virtual IEnumerator SayInternal(string text, bool clearPrevious, bool waitForInput, bool fadeWhenDone, bool stopVoiceover, AudioClip voiceOverClip, Action onComplete) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Writer writer = GetWriter(); |
|
|
|
Writer writer = GetWriter(); |
|
|
@ -206,19 +201,6 @@ namespace Fungus |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Tell dialog to fade out if it's finished writing. |
|
|
|
|
|
|
|
public virtual void FadeOut() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
fadeWhenDone = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Stop a Say Dialog while its writing text. |
|
|
|
|
|
|
|
public virtual void Stop() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
fadeWhenDone = true; |
|
|
|
|
|
|
|
GetWriter().Stop(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected virtual void UpdateAlpha() |
|
|
|
protected virtual void UpdateAlpha() |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (GetWriter().IsWriting) |
|
|
|
if (GetWriter().IsWriting) |
|
|
@ -238,7 +220,6 @@ namespace Fungus |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
CanvasGroup canvasGroup = GetCanvasGroup(); |
|
|
|
CanvasGroup canvasGroup = GetCanvasGroup(); |
|
|
|
float fadeDuration = GetSayDialog().fadeDuration; |
|
|
|
|
|
|
|
if (fadeDuration <= 0f) |
|
|
|
if (fadeDuration <= 0f) |
|
|
|
{ |
|
|
|
{ |
|
|
|
canvasGroup.alpha = targetAlpha; |
|
|
|
canvasGroup.alpha = targetAlpha; |
|
|
@ -257,6 +238,63 @@ namespace Fungus |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public virtual void SetCharacterName(string name, Color color) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (nameText != null) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
nameText.text = name; |
|
|
|
|
|
|
|
nameText.color = color; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public virtual void Clear() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
ClearStoryText(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Kill any active write coroutine |
|
|
|
|
|
|
|
StopAllCoroutines(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected virtual void ClearStoryText() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (storyText != null) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
storyText.text = ""; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void StopPortraitTweens() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// Stop all tweening portraits |
|
|
|
|
|
|
|
foreach( Character c in Character.activeCharacters ) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (c.State.portraitImage != null) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (LeanTween.isTweening(c.State.portraitImage.gameObject)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
LeanTween.cancel(c.State.portraitImage.gameObject, true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PortraitController.SetRectTransform(c.State.portraitImage.rectTransform, c.State.position); |
|
|
|
|
|
|
|
if (c.State.dimmed == true) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
c.State.portraitImage.color = new Color(0.5f, 0.5f, 0.5f, 1f); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
c.State.portraitImage.color = Color.white; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region ISayDialog implementation |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public virtual void SetActive(bool state) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
gameObject.SetActive(state); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public virtual void SetCharacter(Character character, Flowchart flowchart = null) |
|
|
|
public virtual void SetCharacter(Character character, Flowchart flowchart = null) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (character == null) |
|
|
|
if (character == null) |
|
|
@ -275,7 +313,7 @@ namespace Fungus |
|
|
|
{ |
|
|
|
{ |
|
|
|
Character prevSpeakingCharacter = speakingCharacter; |
|
|
|
Character prevSpeakingCharacter = speakingCharacter; |
|
|
|
speakingCharacter = character; |
|
|
|
speakingCharacter = character; |
|
|
|
|
|
|
|
|
|
|
|
// Dim portraits of non-speaking characters |
|
|
|
// Dim portraits of non-speaking characters |
|
|
|
foreach (Stage stage in Stage.activeStages) |
|
|
|
foreach (Stage stage in Stage.activeStages) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -298,24 +336,24 @@ namespace Fungus |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
string characterName = character.NameText; |
|
|
|
string characterName = character.NameText; |
|
|
|
|
|
|
|
|
|
|
|
if (characterName == "") |
|
|
|
if (characterName == "") |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Use game object name as default |
|
|
|
// Use game object name as default |
|
|
|
characterName = character.name; |
|
|
|
characterName = character.name; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (flowchart != null) |
|
|
|
if (flowchart != null) |
|
|
|
{ |
|
|
|
{ |
|
|
|
characterName = flowchart.SubstituteVariables(characterName); |
|
|
|
characterName = flowchart.SubstituteVariables(characterName); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
SetCharacterName(characterName, character.NameColor); |
|
|
|
SetCharacterName(characterName, character.NameColor); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public virtual void SetCharacterImage(Sprite image) |
|
|
|
public virtual void SetCharacterImage(Sprite image) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (characterImage == null) |
|
|
|
if (characterImage == null) |
|
|
@ -336,8 +374,8 @@ namespace Fungus |
|
|
|
if (startStoryTextWidth != 0) |
|
|
|
if (startStoryTextWidth != 0) |
|
|
|
{ |
|
|
|
{ |
|
|
|
storyText.rectTransform.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, |
|
|
|
storyText.rectTransform.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, |
|
|
|
startStoryTextInset, |
|
|
|
startStoryTextInset, |
|
|
|
startStoryTextWidth); |
|
|
|
startStoryTextWidth); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -356,66 +394,31 @@ namespace Fungus |
|
|
|
if (storyText.rectTransform.position.x < characterImage.rectTransform.position.x) |
|
|
|
if (storyText.rectTransform.position.x < characterImage.rectTransform.position.x) |
|
|
|
{ |
|
|
|
{ |
|
|
|
storyText.rectTransform.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, |
|
|
|
storyText.rectTransform.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, |
|
|
|
startStoryTextInset, |
|
|
|
startStoryTextInset, |
|
|
|
startStoryTextWidth - characterImage.rectTransform.rect.width); |
|
|
|
startStoryTextWidth - characterImage.rectTransform.rect.width); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
storyText.rectTransform.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Right, |
|
|
|
storyText.rectTransform.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Right, |
|
|
|
startStoryTextInset, |
|
|
|
startStoryTextInset, |
|
|
|
startStoryTextWidth - characterImage.rectTransform.rect.width); |
|
|
|
startStoryTextWidth - characterImage.rectTransform.rect.width); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public virtual void SetCharacterName(string name, Color color) |
|
|
|
public virtual void Say(string text, bool clearPrevious, bool waitForInput, bool fadeWhenDone, bool stopVoiceover, AudioClip voiceOverClip, Action onComplete) |
|
|
|
{ |
|
|
|
|
|
|
|
if (nameText != null) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
nameText.text = name; |
|
|
|
|
|
|
|
nameText.color = color; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public virtual void Clear() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
ClearStoryText(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Kill any active write coroutine |
|
|
|
|
|
|
|
StopAllCoroutines(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected virtual void ClearStoryText() |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
if (storyText != null) |
|
|
|
StartCoroutine(SayInternal(text, clearPrevious, waitForInput, fadeWhenDone, stopVoiceover, voiceOverClip, onComplete)); |
|
|
|
{ |
|
|
|
|
|
|
|
storyText.text = ""; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void StopPortraitTweens() |
|
|
|
public virtual bool FadeWhenDone { set { fadeWhenDone = value; } } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public virtual void Stop() |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Stop all tweening portraits |
|
|
|
fadeWhenDone = true; |
|
|
|
foreach( Character c in Character.activeCharacters ) |
|
|
|
GetWriter().Stop(); |
|
|
|
{ |
|
|
|
|
|
|
|
if (c.State.portraitImage != null) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (LeanTween.isTweening(c.State.portraitImage.gameObject)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
LeanTween.cancel(c.State.portraitImage.gameObject, true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PortraitController.SetRectTransform(c.State.portraitImage.rectTransform, c.State.position); |
|
|
|
|
|
|
|
if (c.State.dimmed == true) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
c.State.portraitImage.color = new Color(0.5f, 0.5f, 0.5f, 1f); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
c.State.portraitImage.color = Color.white; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|