Browse Source

Get Text and Set Text now work on any text object

including UI text, UI input fields & 3D text mesh
master
chrisgregan 9 years ago
parent
commit
784d75a883
  1. 57
      Assets/Fungus/Flowchart/Scripts/Commands/GetText.cs
  2. 47
      Assets/Fungus/Flowchart/Scripts/Commands/SetText.cs
  3. 93
      Assets/Fungus/UI/Scripts/Commands/GetText.cs
  4. 0
      Assets/Fungus/UI/Scripts/Commands/GetText.cs.meta
  5. 87
      Assets/Fungus/UI/Scripts/Commands/SetText.cs
  6. 0
      Assets/Fungus/UI/Scripts/Commands/SetText.cs.meta

57
Assets/Fungus/Flowchart/Scripts/Commands/GetText.cs

@ -1,57 +0,0 @@
using UnityEngine;
using UnityEngine.UI;
using System;
using System.Collections;
namespace Fungus
{
[CommandInfo("Scripting",
"Get Text",
"Gets the text property from a UI Text object and stores it in a string variable.")]
[AddComponentMenu("")]
public class GetText : Command
{
[Tooltip("Text object to get text value from")]
public Text textObject;
[Tooltip("String variable to store the text value in")]
[VariableProperty(typeof(StringVariable))]
public Variable variable;
public override void OnEnter()
{
if (textObject != null)
{
StringVariable stringVariable = variable as StringVariable;
if (stringVariable != null)
{
stringVariable.value = textObject.text;
}
}
Continue();
}
public override string GetSummary()
{
if (textObject == null)
{
return "Error: No text object selected";
}
if (variable == null)
{
return "Error: No variable selected";
}
return textObject.name + " : " + variable.name;
}
public override Color GetButtonColor()
{
return new Color32(235, 191, 217, 255);
}
}
}

47
Assets/Fungus/Flowchart/Scripts/Commands/SetText.cs

@ -1,47 +0,0 @@
using UnityEngine;
using UnityEngine.UI;
using System;
using System.Collections;
namespace Fungus
{
[CommandInfo("Scripting",
"Set Text",
"Sets the text property on a UI Text object.")]
[AddComponentMenu("")]
public class SetText : Command
{
[Tooltip("Text object to set text on")]
public Text textObject;
[Tooltip("String value to assign to the text object")]
public StringData stringData;
public override void OnEnter()
{
if (textObject != null)
{
textObject.text = stringData.Value;
}
Continue();
}
public override string GetSummary()
{
if (textObject == null)
{
return "Error: No text object selected";
}
return textObject.name + " : " + stringData.Value;
}
public override Color GetButtonColor()
{
return new Color32(235, 191, 217, 255);
}
}
}

93
Assets/Fungus/UI/Scripts/Commands/GetText.cs

@ -0,0 +1,93 @@
using UnityEngine;
using UnityEngine.UI;
using System;
using System.Collections;
using UnityEngine.Serialization;
namespace Fungus
{
[CommandInfo("UI",
"Get Text",
"Gets the text property from a UI Text object and stores it in a string variable.")]
[AddComponentMenu("")]
public class GetText : Command
{
[Tooltip("Text object to get text value from")]
public GameObject targetTextObject;
[Tooltip("String variable to store the text value in")]
[VariableProperty(typeof(StringVariable))]
public StringVariable stringVariable;
public override void OnEnter()
{
if (stringVariable == null)
{
Continue();
return;
}
if (targetTextObject != null)
{
// Use first component found of Text, Input Field or Text Mesh type
Text uiText = targetTextObject.GetComponent<Text>();
if (uiText != null)
{
stringVariable.value = uiText.text;
}
else
{
InputField inputField = targetTextObject.GetComponent<InputField>();
if (inputField != null)
{
stringVariable.value = inputField.text;
}
else
{
TextMesh textMesh = targetTextObject.GetComponent<TextMesh>();
if (textMesh != null)
{
stringVariable.value = textMesh.text;
}
}
}
}
Continue();
}
public override string GetSummary()
{
if (targetTextObject == null)
{
return "Error: No text object selected";
}
if (stringVariable == null)
{
return "Error: No variable selected";
}
return targetTextObject.name + " : " + stringVariable.name;
}
public override Color GetButtonColor()
{
return new Color32(235, 191, 217, 255);
}
// Backwards compatibility with Fungus v2.1.2
[HideInInspector]
[FormerlySerializedAs("textObject")]
public Text _textObjectObsolete;
protected virtual void OnEnable()
{
if (_textObjectObsolete != null)
{
targetTextObject = _textObjectObsolete.gameObject;
}
}
}
}

0
Assets/Fungus/Flowchart/Scripts/Commands/GetText.cs.meta → Assets/Fungus/UI/Scripts/Commands/GetText.cs.meta

87
Assets/Fungus/UI/Scripts/Commands/SetText.cs

@ -0,0 +1,87 @@
using UnityEngine;
using UnityEngine.UI;
using System;
using System.Collections;
using UnityEngine.Serialization;
namespace Fungus
{
[CommandInfo("UI",
"Set Text",
"Sets the text property on a UI Text object and/or an Input Field object.")]
[AddComponentMenu("")]
public class SetText : Command
{
[Tooltip("Text object to set text on. Can be a UI Text, Text Field or Text Mesh object.")]
public GameObject targetTextObject;
[Tooltip("String value to assign to the text object")]
public StringData stringData;
public override void OnEnter()
{
Flowchart flowchart = GetFlowchart();
string newText = flowchart.SubstituteVariables(stringData.Value);
if (targetTextObject == null)
{
Continue();
return;
}
// Use first component found of Text, Input Field or Text Mesh type
Text uiText = targetTextObject.GetComponent<Text>();
if (uiText != null)
{
uiText.text = newText;
}
else
{
InputField inputField = targetTextObject.GetComponent<InputField>();
if (inputField != null)
{
inputField.text = newText;
}
else
{
TextMesh textMesh = targetTextObject.GetComponent<TextMesh>();
if (textMesh != null)
{
textMesh.text = newText;
}
}
}
Continue();
}
public override string GetSummary()
{
if (targetTextObject != null)
{
return targetTextObject.name + " : " + stringData.Value;
}
return "Error: No text object selected";
}
public override Color GetButtonColor()
{
return new Color32(235, 191, 217, 255);
}
// Backwards compatibility with Fungus v2.1.2
[HideInInspector]
[FormerlySerializedAs("textObject")]
public Text _textObjectObsolete;
protected virtual void OnEnable()
{
if (_textObjectObsolete != null)
{
targetTextObject = _textObjectObsolete.gameObject;
}
}
}
}

0
Assets/Fungus/Flowchart/Scripts/Commands/SetText.cs.meta → Assets/Fungus/UI/Scripts/Commands/SetText.cs.meta

Loading…
Cancel
Save