diff --git a/Assets/Fungus/Scripts/Components/MenuDialog.cs b/Assets/Fungus/Scripts/Components/MenuDialog.cs index 93019211..75da12d5 100644 --- a/Assets/Fungus/Scripts/Components/MenuDialog.cs +++ b/Assets/Fungus/Scripts/Components/MenuDialog.cs @@ -315,13 +315,16 @@ namespace Fungus { EventSystem.current.SetSelectedGameObject(button.gameObject); } - Text textComponent = button.GetComponentInChildren(); - if (textComponent != null) + + TextAdapter textAdapter = new TextAdapter(); + textAdapter.InitFromGameObject(button.gameObject, true); + if (textAdapter.HasTextObject()) { text = TextVariationHandler.SelectVariations(text); - textComponent.text = text; + textAdapter.Text = text; } + button.onClick.AddListener(action); return true; diff --git a/Assets/Fungus/Scripts/Utils/TextAdapter.cs b/Assets/Fungus/Scripts/Utils/TextAdapter.cs index f17e8bfd..df169f01 100644 --- a/Assets/Fungus/Scripts/Utils/TextAdapter.cs +++ b/Assets/Fungus/Scripts/Utils/TextAdapter.cs @@ -16,17 +16,32 @@ namespace Fungus protected PropertyInfo textProperty; protected IWriterTextDestination writerTextDestination; - public void InitFromGameObject(GameObject go) + public void InitFromGameObject(GameObject go, bool includeChildren = false) { - textUI = go.GetComponent(); - inputField = go.GetComponent(); - textMesh = go.GetComponent(); - writerTextDestination = go.GetComponent(); - + if (!includeChildren) + { + textUI = go.GetComponent(); + inputField = go.GetComponent(); + textMesh = go.GetComponent(); + writerTextDestination = go.GetComponent(); + } + else + { + textUI = go.GetComponentInChildren(); + inputField = go.GetComponentInChildren(); + textMesh = go.GetComponentInChildren(); + writerTextDestination = go.GetComponentInChildren(); + } + // Try to find any component with a text property if (textUI == null && inputField == null && textMesh == null && writerTextDestination == null) { - var allcomponents = go.GetComponents(); + Component[] allcomponents = null; + if (!includeChildren) + allcomponents = go.GetComponents(); + else + allcomponents = go.GetComponentsInChildren(); + for (int i = 0; i < allcomponents.Length; i++) { var c = allcomponents[i];