You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
95 lines
3.1 KiB
95 lines
3.1 KiB
8 years ago
|
// 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)
|
||
9 years ago
|
|
||
9 years ago
|
using UnityEngine;
|
||
|
using UnityEngine.UI;
|
||
|
using UnityEngine.Serialization;
|
||
|
|
||
|
namespace Fungus
|
||
|
{
|
||
8 years ago
|
/// <summary>
|
||
|
/// Gets the text property from a UI Text object and stores it in a string variable.
|
||
|
/// </summary>
|
||
8 years ago
|
[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")]
|
||
8 years ago
|
[SerializeField] protected GameObject targetTextObject;
|
||
8 years ago
|
|
||
|
[Tooltip("String variable to store the text value in")]
|
||
|
[VariableProperty(typeof(StringVariable))]
|
||
8 years ago
|
[SerializeField] protected StringVariable stringVariable;
|
||
8 years ago
|
|
||
|
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)
|
||
|
{
|
||
8 years ago
|
stringVariable.Value = uiText.text;
|
||
8 years ago
|
}
|
||
|
else
|
||
|
{
|
||
|
InputField inputField = targetTextObject.GetComponent<InputField>();
|
||
|
if (inputField != null)
|
||
|
{
|
||
8 years ago
|
stringVariable.Value = inputField.text;
|
||
8 years ago
|
}
|
||
|
else
|
||
|
{
|
||
|
TextMesh textMesh = targetTextObject.GetComponent<TextMesh>();
|
||
|
if (textMesh != null)
|
||
|
{
|
||
8 years ago
|
stringVariable.Value = textMesh.text;
|
||
8 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
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);
|
||
|
}
|
||
9 years ago
|
|
||
8 years ago
|
// Backwards compatibility with Fungus v2.1.2
|
||
|
[HideInInspector]
|
||
|
[FormerlySerializedAs("textObject")]
|
||
|
public Text _textObjectObsolete;
|
||
|
protected virtual void OnEnable()
|
||
|
{
|
||
|
if (_textObjectObsolete != null)
|
||
|
{
|
||
|
targetTextObject = _textObjectObsolete.gameObject;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
9 years ago
|
}
|