Browse Source

Add Narrative Log to save menu

master
lealeelu 8 years ago
parent
commit
7fb0644300
  1. 8
      Assets/Fungus/Scripts/Components/FungusManager.cs
  2. 71
      Assets/Fungus/Scripts/Components/HistoryManager.cs
  3. 12
      Assets/Fungus/Scripts/Components/HistoryManager.cs.meta
  4. 55
      Assets/Fungus/Scripts/Components/SaveMenu.cs
  5. 1
      Assets/Fungus/Scripts/Components/SayDialog.cs
  6. BIN
      Assets/Fungus/Textures/HistoryIcon.png
  7. 68
      Assets/Fungus/Textures/HistoryIcon.png.meta
  8. 4222
      Assets/FungusExamples/Conversation/Say History.unity
  9. 8
      Assets/FungusExamples/Conversation/Say History.unity.meta

8
Assets/Fungus/Scripts/Components/FungusManager.cs

@ -14,6 +14,7 @@ namespace Fungus
[RequireComponent(typeof(EventDispatcher))] [RequireComponent(typeof(EventDispatcher))]
#if UNITY_5_3_OR_NEWER #if UNITY_5_3_OR_NEWER
[RequireComponent(typeof(SaveManager))] [RequireComponent(typeof(SaveManager))]
[RequireComponent(typeof(HistoryManager))]
#endif #endif
public sealed class FungusManager : MonoBehaviour public sealed class FungusManager : MonoBehaviour
{ {
@ -28,6 +29,7 @@ namespace Fungus
EventDispatcher = GetComponent<EventDispatcher>(); EventDispatcher = GetComponent<EventDispatcher>();
#if UNITY_5_3_OR_NEWER #if UNITY_5_3_OR_NEWER
SaveManager = GetComponent<SaveManager>(); SaveManager = GetComponent<SaveManager>();
HistoryManager = GetComponent<HistoryManager>();
#endif #endif
} }
@ -66,6 +68,12 @@ namespace Fungus
/// Gets the save manager singleton instance. /// Gets the save manager singleton instance.
/// </summary> /// </summary>
public SaveManager SaveManager { get; private set; } public SaveManager SaveManager { get; private set; }
/// <summary>
/// Gets the history manager singleton instance.
/// </summary>
public HistoryManager HistoryManager { get; private set; }
#endif #endif
/// <summary> /// <summary>

71
Assets/Fungus/Scripts/Components/HistoryManager.cs

@ -0,0 +1,71 @@
// 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;
}
}
}

12
Assets/Fungus/Scripts/Components/HistoryManager.cs.meta

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: c55d0d498086c9f4dabf854988212ae9
timeCreated: 1486763938
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

55
Assets/Fungus/Scripts/Components/SaveMenu.cs

@ -47,11 +47,22 @@ namespace Fungus
[Tooltip("The button which restarts the game.")] [Tooltip("The button which restarts the game.")]
[SerializeField] protected Button restartButton; [SerializeField] protected Button restartButton;
[Tooltip("The button that shows conversation history.")]
[SerializeField] protected Button historyButton;
[Tooltip("A scrollable text field used for displaying conversation history.")]
[SerializeField] protected ScrollRect historyView;
[Tooltip("The CanvasGroup containing the save menu buttons")]
[SerializeField] protected CanvasGroup historyMenuGroup;
[Tooltip("A scrollable text field used for debugging the save data. The text field should be disabled in normal use.")] [Tooltip("A scrollable text field used for debugging the save data. The text field should be disabled in normal use.")]
[SerializeField] protected ScrollRect debugView; [SerializeField] protected ScrollRect debugView;
protected static bool saveMenuActive = false; protected static bool saveMenuActive = false;
protected static bool historyMenuActive = false;
protected AudioSource clickAudioSource; protected AudioSource clickAudioSource;
protected LTDescr fadeTween; protected LTDescr fadeTween;
@ -81,6 +92,11 @@ namespace Fungus
saveMenuGroup.alpha = 0f; saveMenuGroup.alpha = 0f;
} }
if (!historyMenuActive)
{
historyMenuGroup.alpha = 0f;
}
var saveManager = FungusManager.Instance.SaveManager; var saveManager = FungusManager.Instance.SaveManager;
// Make a note of the current scene. This will be used when restarting the game. // Make a note of the current scene. This will be used when restarting the game.
@ -142,6 +158,15 @@ namespace Fungus
debugText.text = saveManager.GetDebugInfo(); debugText.text = saveManager.GetDebugInfo();
} }
} }
if (historyView.enabled)
{
var historyText = historyView.GetComponentInChildren<Text>();
if (historyText != null)
{
historyText.text = FungusManager.Instance.HistoryManager.GetPrettyHistory();
}
}
} }
protected virtual void OnEnable() protected virtual void OnEnable()
@ -295,6 +320,36 @@ namespace Fungus
SceneManager.LoadScene(saveManager.StartScene); SceneManager.LoadScene(saveManager.StartScene);
} }
public virtual void ToggleHistoryView()
{
if (fadeTween != null)
{
LeanTween.cancel(fadeTween.id, true);
fadeTween = null;
}
if (historyMenuActive)
{
// Switch menu off
LeanTween.value(historyMenuGroup.gameObject, historyMenuGroup.alpha, 0f, 0.5f).setOnUpdate((t) => {
historyMenuGroup.alpha = t;
}).setOnComplete(() => {
historyMenuGroup.alpha = 0f;
});
}
else
{
// Switch menu on
LeanTween.value(historyMenuGroup.gameObject, historyMenuGroup.alpha, 1f, 0.5f).setOnUpdate((t) => {
historyMenuGroup.alpha = t;
}).setOnComplete(() => {
historyMenuGroup.alpha = 1f;
});
}
historyMenuActive = !historyMenuActive;
}
#endregion #endregion
} }
} }

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

@ -435,6 +435,7 @@ 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.HistoryManager.AddLine(nameText.text, text);
StartCoroutine(DoSay(text, clearPrevious, waitForInput, fadeWhenDone, stopVoiceover, voiceOverClip, onComplete)); StartCoroutine(DoSay(text, clearPrevious, waitForInput, fadeWhenDone, stopVoiceover, voiceOverClip, onComplete));
} }

BIN
Assets/Fungus/Textures/HistoryIcon.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

68
Assets/Fungus/Textures/HistoryIcon.png.meta

@ -0,0 +1,68 @@
fileFormatVersion: 2
guid: 94b4465d12d983b45a5c1af59318e72e
timeCreated: 1486825113
licenseType: Pro
TextureImporter:
fileIDToRecycleName: {}
serializedVersion: 4
mipmaps:
mipMapMode: 0
enableMipMap: 0
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
filterMode: -1
aniso: -1
mipBias: -1
wrapMode: 1
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 1
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spritePixelsToUnits: 100
alphaUsage: 1
alphaIsTransparency: 1
spriteTessellationDetail: -1
textureType: 8
textureShape: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
platformSettings:
- buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
spritePackingTag:
userData:
assetBundleName:
assetBundleVariant:

4222
Assets/FungusExamples/Conversation/Say History.unity

File diff suppressed because it is too large Load Diff

8
Assets/FungusExamples/Conversation/Say History.unity.meta

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 376badd636d273a46b9e552a3b4cfb86
timeCreated: 1486764142
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
Loading…
Cancel
Save