Browse Source

TextAdapter can be asked to include children in text output search

MenuDialogue now uses TextAdapter rather than assuming UI.Text
master
desktop-maesty/steve 6 years ago
parent
commit
9fcd21de77
  1. 9
      Assets/Fungus/Scripts/Components/MenuDialog.cs
  2. 29
      Assets/Fungus/Scripts/Utils/TextAdapter.cs

9
Assets/Fungus/Scripts/Components/MenuDialog.cs

@ -315,13 +315,16 @@ namespace Fungus
{
EventSystem.current.SetSelectedGameObject(button.gameObject);
}
Text textComponent = button.GetComponentInChildren<Text>();
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;

29
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<Text>();
inputField = go.GetComponent<InputField>();
textMesh = go.GetComponent<TextMesh>();
writerTextDestination = go.GetComponent<IWriterTextDestination>();
if (!includeChildren)
{
textUI = go.GetComponent<Text>();
inputField = go.GetComponent<InputField>();
textMesh = go.GetComponent<TextMesh>();
writerTextDestination = go.GetComponent<IWriterTextDestination>();
}
else
{
textUI = go.GetComponentInChildren<Text>();
inputField = go.GetComponentInChildren<InputField>();
textMesh = go.GetComponentInChildren<TextMesh>();
writerTextDestination = go.GetComponentInChildren<IWriterTextDestination>();
}
// Try to find any component with a text property
if (textUI == null && inputField == null && textMesh == null && writerTextDestination == null)
{
var allcomponents = go.GetComponents<Component>();
Component[] allcomponents = null;
if (!includeChildren)
allcomponents = go.GetComponents<Component>();
else
allcomponents = go.GetComponentsInChildren<Component>();
for (int i = 0; i < allcomponents.Length; i++)
{
var c = allcomponents[i];

Loading…
Cancel
Save