diff --git a/Assets/Fungus/Scripts/Commands/FadeUI.cs b/Assets/Fungus/Scripts/Commands/FadeUI.cs index 7263e9df..0c47f735 100644 --- a/Assets/Fungus/Scripts/Commands/FadeUI.cs +++ b/Assets/Fungus/Scripts/Commands/FadeUI.cs @@ -1,7 +1,7 @@ // 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 UnityEngine; +using UnityEngine; using UnityEngine.UI; namespace Fungus @@ -128,6 +128,83 @@ namespace Fungus } } } + +#if UNITY_2018_1_OR_NEWER + var tmpros = go.GetComponentsInChildren(); + for (int i = 0; i < tmpros.Length; i++) + { + + var tmpro = tmpros[i]; + if (Mathf.Approximately(duration, 0f)) + { + switch (fadeMode) + { + case FadeMode.Alpha: + Color tempColor = tmpro.color; + tempColor.a = targetAlpha; + tmpro.color = tempColor; + break; + case FadeMode.Color: + tmpro.color = targetColor; + break; + } + } + else + { + switch (fadeMode) + { + case FadeMode.Alpha: + LeanTween.value(tmpro.gameObject, tmpro.color.a, targetAlpha.Value, duration) + .setEase(tweenType) + .setOnUpdate((float alphaValue) => + { + Color tempColor = tmpro.color; + tempColor.a = alphaValue; + tmpro.color = tempColor; + }); + break; + case FadeMode.Color: + LeanTween.value(tmpro.gameObject, tmpro.color, targetColor.Value, duration) + .setEase(tweenType) + .setOnUpdate((Color colorValue) => + { + tmpro.color = colorValue; + }); + break; + } + } + } +#endif + //canvas groups don't support color but we can anim the alpha IN the color + var canvasGroups = go.GetComponentsInChildren(); + for (int i = 0; i < canvasGroups.Length; i++) + { + var canvasGroup = canvasGroups[i]; + if (Mathf.Approximately(duration, 0f)) + { + switch (fadeMode) + { + case FadeMode.Alpha: + canvasGroup.alpha = targetAlpha.Value; + break; + case FadeMode.Color: + canvasGroup.alpha = targetColor.Value.a; + break; + } + } + else + { + switch (fadeMode) + { + case FadeMode.Alpha: + LeanTween.alphaCanvas(canvasGroup, targetAlpha, duration).setEase(tweenType); + break; + case FadeMode.Color: + LeanTween.alphaCanvas(canvasGroup, targetColor.Value.a, duration).setEase(tweenType); + break; + } + } + } } protected override string GetSummaryValue() diff --git a/Assets/Fungus/Scripts/Commands/GetText.cs b/Assets/Fungus/Scripts/Commands/GetText.cs index b9c2b057..f6c01b59 100644 --- a/Assets/Fungus/Scripts/Commands/GetText.cs +++ b/Assets/Fungus/Scripts/Commands/GetText.cs @@ -32,33 +32,15 @@ namespace Fungus Continue(); return; } - - if (targetTextObject != null) + + TextAdapter textAdapter = new TextAdapter(); + textAdapter.InitFromGameObject(targetTextObject); + + if (textAdapter.HasTextObject()) { - // Use first component found of Text, Input Field or Text Mesh type - Text uiText = targetTextObject.GetComponent(); - if (uiText != null) - { - stringVariable.Value = uiText.text; - } - else - { - InputField inputField = targetTextObject.GetComponent(); - if (inputField != null) - { - stringVariable.Value = inputField.text; - } - else - { - TextMesh textMesh = targetTextObject.GetComponent(); - if (textMesh != null) - { - stringVariable.Value = textMesh.text; - } - } - } + stringVariable.Value = textAdapter.Text; } - + Continue(); } diff --git a/Assets/Fungus/Scripts/Commands/SetText.cs b/Assets/Fungus/Scripts/Commands/SetText.cs index a3204549..500dd011 100644 --- a/Assets/Fungus/Scripts/Commands/SetText.cs +++ b/Assets/Fungus/Scripts/Commands/SetText.cs @@ -38,30 +38,15 @@ namespace Fungus Continue(); return; } - - // Use first component found of Text, Input Field or Text Mesh type - Text uiText = targetTextObject.GetComponent(); - if (uiText != null) - { - uiText.text = newText; - } - else + + TextAdapter textAdapter = new TextAdapter(); + textAdapter.InitFromGameObject(targetTextObject); + + if (textAdapter.HasTextObject()) { - InputField inputField = targetTextObject.GetComponent(); - if (inputField != null) - { - inputField.text = newText; - } - else - { - TextMesh textMesh = targetTextObject.GetComponent(); - if (textMesh != null) - { - textMesh.text = newText; - } - } + textAdapter.Text = newText; } - + Continue(); } diff --git a/Assets/Fungus/Scripts/Components/NarrativeLogMenu.cs b/Assets/Fungus/Scripts/Components/NarrativeLogMenu.cs index 89645ad4..cec4d64e 100644 --- a/Assets/Fungus/Scripts/Components/NarrativeLogMenu.cs +++ b/Assets/Fungus/Scripts/Components/NarrativeLogMenu.cs @@ -22,6 +22,8 @@ namespace Fungus [Tooltip("A scrollable text field used for displaying conversation history.")] [SerializeField] protected ScrollRect narrativeLogView; + + protected TextAdapter narLogViewtextAdapter = new TextAdapter(); [Tooltip("The CanvasGroup containing the save menu buttons")] [SerializeField] protected CanvasGroup narrativeLogMenuGroup; @@ -57,6 +59,8 @@ namespace Fungus logView.SetActive(false); this.enabled = false; } + + narLogViewtextAdapter.InitFromGameObject(narrativeLogView.gameObject, true); } protected virtual void Start() @@ -126,11 +130,8 @@ namespace Fungus { if (narrativeLogView.enabled) { - var historyText = narrativeLogView.GetComponentInChildren(); - if (historyText != null) - { - historyText.text = FungusManager.Instance.NarrativeLog.GetPrettyHistory(); - } + narLogViewtextAdapter.Text = FungusManager.Instance.NarrativeLog.GetPrettyHistory(); + Canvas.ForceUpdateCanvases(); narrativeLogView.verticalNormalizedPosition = 0f; Canvas.ForceUpdateCanvases(); diff --git a/Assets/Fungus/Scripts/Utils/TextAdapter.cs b/Assets/Fungus/Scripts/Utils/TextAdapter.cs index 6139c4af..0709066d 100644 --- a/Assets/Fungus/Scripts/Utils/TextAdapter.cs +++ b/Assets/Fungus/Scripts/Utils/TextAdapter.cs @@ -12,6 +12,9 @@ namespace Fungus protected Text textUI; protected InputField inputField; protected TextMesh textMesh; +#if UNITY_2018_1_OR_NEWER + protected TMPro.TMP_Text tmpro; +#endif protected Component textComponent; protected PropertyInfo textProperty; protected IWriterTextDestination writerTextDestination; @@ -28,6 +31,9 @@ namespace Fungus textUI = go.GetComponent(); inputField = go.GetComponent(); textMesh = go.GetComponent(); +#if UNITY_2018_1_OR_NEWER + tmpro = go.GetComponent(); +#endif writerTextDestination = go.GetComponent(); } else @@ -35,6 +41,9 @@ namespace Fungus textUI = go.GetComponentInChildren(); inputField = go.GetComponentInChildren(); textMesh = go.GetComponentInChildren(); +#if UNITY_2018_1_OR_NEWER + tmpro = go.GetComponentInChildren(); +#endif writerTextDestination = go.GetComponentInChildren(); } @@ -74,7 +83,14 @@ namespace Fungus textMesh.richText = true; } - if(writerTextDestination != null) +#if UNITY_2018_1_OR_NEWER + if(tmpro != null) + { + tmpro.richText = true; + } +#endif + + if (writerTextDestination != null) { writerTextDestination.ForceRichText(); } @@ -97,6 +113,12 @@ namespace Fungus { textMesh.color = textColor; } +#if UNITY_2018_1_OR_NEWER + else if (tmpro != null) + { + tmpro.color = textColor; + } +#endif else if (writerTextDestination != null) { writerTextDestination.SetTextColor(textColor); @@ -126,6 +148,12 @@ namespace Fungus tempColor.a = textAlpha; textMesh.color = tempColor; } +#if UNITY_2018_1_OR_NEWER + else if (tmpro != null) + { + tmpro.alpha = textAlpha; + } +#endif else if (writerTextDestination != null) { writerTextDestination.SetTextAlpha(textAlpha); @@ -134,7 +162,11 @@ namespace Fungus public bool HasTextObject() { - return (textUI != null || inputField != null || textMesh != null || textComponent != null || writerTextDestination != null); + return (textUI != null || inputField != null || textMesh != null || textComponent != null || +#if UNITY_2018_1_OR_NEWER + tmpro !=null || +#endif + writerTextDestination != null); } public bool SupportsRichText() @@ -151,6 +183,12 @@ namespace Fungus { return textMesh.richText; } +#if UNITY_2018_1_OR_NEWER + if (tmpro != null) + { + return true; + } +#endif if (writerTextDestination != null) { return writerTextDestination.SupportsRichText(); @@ -178,6 +216,12 @@ namespace Fungus { return textMesh.text; } +#if UNITY_2018_1_OR_NEWER + else if (tmpro != null) + { + return tmpro.text; + } +#endif else if (textProperty != null) { return textProperty.GetValue(textComponent, null) as string; @@ -204,6 +248,12 @@ namespace Fungus { textMesh.text = value; } +#if UNITY_2018_1_OR_NEWER + else if (tmpro != null) + { + tmpro.text = value; + } +#endif else if (textProperty != null) { textProperty.SetValue(textComponent, value, null);