Chris Gregan
7 years ago
committed by
GitHub
19 changed files with 6740 additions and 102 deletions
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,143 @@ |
|||||||
|
// 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 |
||||||
|
{ |
||||||
|
|
||||||
|
/// <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() |
||||||
|
{ |
||||||
|
history = new NarrativeData(); |
||||||
|
} |
||||||
|
|
||||||
|
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> |
||||||
|
/// <param name="name">Character Name</param> |
||||||
|
/// <param name="text">Narrative Text</param> |
||||||
|
public void AddLine(string name, string text) |
||||||
|
{ |
||||||
|
Line line = new Line(); |
||||||
|
line.name = name; |
||||||
|
line.text = text; |
||||||
|
history.lines.Add(line); |
||||||
|
DoNarrativeAdded(); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary> |
||||||
|
/// Clear all lines of the narrative log |
||||||
|
/// Usually used on restart |
||||||
|
/// </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(bool previousOnly = false) |
||||||
|
{ |
||||||
|
string output = "\n "; |
||||||
|
int count; |
||||||
|
|
||||||
|
count = previousOnly ? history.lines.Count - 1: history.lines.Count; |
||||||
|
|
||||||
|
for (int i = 0; i < count; 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); |
||||||
|
} |
||||||
|
#endregion |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,12 @@ |
|||||||
|
fileFormatVersion: 2 |
||||||
|
guid: c55d0d498086c9f4dabf854988212ae9 |
||||||
|
timeCreated: 1486763938 |
||||||
|
licenseType: Pro |
||||||
|
MonoImporter: |
||||||
|
serializedVersion: 2 |
||||||
|
defaultReferences: [] |
||||||
|
executionOrder: 0 |
||||||
|
icon: {instanceID: 0} |
||||||
|
userData: |
||||||
|
assetBundleName: |
||||||
|
assetBundleVariant: |
@ -0,0 +1,190 @@ |
|||||||
|
// 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) |
||||||
|
|
||||||
|
#if UNITY_5_3_OR_NEWER |
||||||
|
|
||||||
|
using UnityEngine; |
||||||
|
using UnityEngine.UI; |
||||||
|
using UnityEngine.SceneManagement; |
||||||
|
|
||||||
|
namespace Fungus |
||||||
|
{ |
||||||
|
/// <summary> |
||||||
|
/// A singleton game object which displays a simple UI for the Narrative Log. |
||||||
|
/// </summary> |
||||||
|
public class NarrativeLogMenu : MonoBehaviour |
||||||
|
{ |
||||||
|
[Tooltip("Show the Narrative Log Menu")] |
||||||
|
[SerializeField] protected bool showLog = true; |
||||||
|
|
||||||
|
[Tooltip("Show previous lines instead of previous and current")] |
||||||
|
[SerializeField] protected bool previousLines = true; |
||||||
|
|
||||||
|
[Tooltip("A scrollable text field used for displaying conversation history.")] |
||||||
|
[SerializeField] protected ScrollRect narrativeLogView; |
||||||
|
|
||||||
|
[Tooltip("The CanvasGroup containing the save menu buttons")] |
||||||
|
[SerializeField] protected CanvasGroup narrativeLogMenuGroup; |
||||||
|
|
||||||
|
protected static bool narrativeLogActive = false; |
||||||
|
|
||||||
|
protected AudioSource clickAudioSource; |
||||||
|
|
||||||
|
protected LTDescr fadeTween; |
||||||
|
|
||||||
|
protected static NarrativeLogMenu instance; |
||||||
|
|
||||||
|
protected virtual void Awake() |
||||||
|
{ |
||||||
|
if (showLog) |
||||||
|
{ |
||||||
|
// Only one instance of NarrativeLogMenu may exist |
||||||
|
if (instance != null) |
||||||
|
{ |
||||||
|
Destroy(gameObject); |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
instance = this; |
||||||
|
|
||||||
|
GameObject.DontDestroyOnLoad(this); |
||||||
|
|
||||||
|
clickAudioSource = GetComponent<AudioSource>(); |
||||||
|
} |
||||||
|
else |
||||||
|
{ |
||||||
|
GameObject logView = GameObject.Find("NarrativeLogView"); |
||||||
|
logView.SetActive(false); |
||||||
|
this.enabled = false; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
protected virtual void Start() |
||||||
|
{ |
||||||
|
if (!narrativeLogActive) |
||||||
|
{ |
||||||
|
narrativeLogMenuGroup.alpha = 0f; |
||||||
|
} |
||||||
|
|
||||||
|
//Clear up the lorem ipsum |
||||||
|
UpdateNarrativeLogText(); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
protected virtual void OnEnable() |
||||||
|
{ |
||||||
|
WriterSignals.OnWriterState += OnWriterState; |
||||||
|
SaveManagerSignals.OnSavePointLoaded += OnSavePointLoaded; |
||||||
|
SaveManagerSignals.OnSaveReset += OnSaveReset; |
||||||
|
BlockSignals.OnBlockEnd += OnBlockEnd; |
||||||
|
NarrativeLog.OnNarrativeAdded += OnNarrativeAdded; |
||||||
|
} |
||||||
|
|
||||||
|
protected virtual void OnDisable() |
||||||
|
{ |
||||||
|
WriterSignals.OnWriterState -= OnWriterState; |
||||||
|
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.Start) |
||||||
|
{ |
||||||
|
UpdateNarrativeLogText(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
protected virtual void OnSavePointLoaded(string savePointKey) |
||||||
|
{ |
||||||
|
UpdateNarrativeLogText(); |
||||||
|
} |
||||||
|
|
||||||
|
protected virtual void OnSaveReset() |
||||||
|
{ |
||||||
|
FungusManager.Instance.NarrativeLog.Clear(); |
||||||
|
UpdateNarrativeLogText(); |
||||||
|
} |
||||||
|
|
||||||
|
protected virtual void OnBlockEnd (Block block) |
||||||
|
{ |
||||||
|
// At block end update to get the last line of the block |
||||||
|
bool defaultPreviousLines = previousLines; |
||||||
|
previousLines = false; |
||||||
|
UpdateNarrativeLogText(); |
||||||
|
previousLines = defaultPreviousLines; |
||||||
|
} |
||||||
|
|
||||||
|
protected void UpdateNarrativeLogText() |
||||||
|
{ |
||||||
|
if (narrativeLogView.enabled) |
||||||
|
{ |
||||||
|
var historyText = narrativeLogView.GetComponentInChildren<Text>(); |
||||||
|
if (historyText != null) |
||||||
|
{ |
||||||
|
historyText.text = FungusManager.Instance.NarrativeLog.GetPrettyHistory(); |
||||||
|
} |
||||||
|
Canvas.ForceUpdateCanvases(); |
||||||
|
narrativeLogView.verticalNormalizedPosition = 0f; |
||||||
|
Canvas.ForceUpdateCanvases(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
protected void PlayClickSound() |
||||||
|
{ |
||||||
|
if (clickAudioSource != null) |
||||||
|
{ |
||||||
|
clickAudioSource.Play(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
#region Public methods |
||||||
|
|
||||||
|
public virtual void ToggleNarrativeLogView() |
||||||
|
{ |
||||||
|
if (fadeTween != null) |
||||||
|
{ |
||||||
|
LeanTween.cancel(fadeTween.id, true); |
||||||
|
fadeTween = null; |
||||||
|
} |
||||||
|
|
||||||
|
if (narrativeLogActive) |
||||||
|
{ |
||||||
|
// Switch menu off |
||||||
|
LeanTween.value(narrativeLogMenuGroup.gameObject, narrativeLogMenuGroup.alpha, 0f, .2f) |
||||||
|
.setEase(LeanTweenType.easeOutQuint) |
||||||
|
.setOnUpdate((t) => { |
||||||
|
narrativeLogMenuGroup.alpha = t; |
||||||
|
}).setOnComplete(() => { |
||||||
|
narrativeLogMenuGroup.alpha = 0f; |
||||||
|
}); |
||||||
|
|
||||||
|
} |
||||||
|
else |
||||||
|
{ |
||||||
|
// Switch menu on |
||||||
|
LeanTween.value(narrativeLogMenuGroup.gameObject, narrativeLogMenuGroup.alpha, 1f, .2f) |
||||||
|
.setEase(LeanTweenType.easeOutQuint) |
||||||
|
.setOnUpdate((t) => { |
||||||
|
narrativeLogMenuGroup.alpha = t; |
||||||
|
}).setOnComplete(() => { |
||||||
|
narrativeLogMenuGroup.alpha = 1f; |
||||||
|
}); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
narrativeLogActive = !narrativeLogActive; |
||||||
|
} |
||||||
|
|
||||||
|
#endregion |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
#endif |
@ -0,0 +1,12 @@ |
|||||||
|
fileFormatVersion: 2 |
||||||
|
guid: 76befdada4ed8754db75aeb0b0d42976 |
||||||
|
timeCreated: 1487446345 |
||||||
|
licenseType: Pro |
||||||
|
MonoImporter: |
||||||
|
serializedVersion: 2 |
||||||
|
defaultReferences: [] |
||||||
|
executionOrder: 0 |
||||||
|
icon: {instanceID: 0} |
||||||
|
userData: |
||||||
|
assetBundleName: |
||||||
|
assetBundleVariant: |
After Width: | Height: | Size: 1.4 KiB |
@ -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: |
After Width: | Height: | Size: 1.1 KiB |
@ -0,0 +1,68 @@ |
|||||||
|
fileFormatVersion: 2 |
||||||
|
guid: 240416d45df4c6c4daec987220246861 |
||||||
|
timeCreated: 1489595536 |
||||||
|
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: |
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue