From 107f4f4756bcd5287462f67e0a85a5857538ca6f Mon Sep 17 00:00:00 2001 From: chrisgregan Date: Wed, 13 May 2015 16:36:06 +0100 Subject: [PATCH] Added Set Text and Get Text commands Set and get text property from a UI text object. --- .../Flowchart/Scripts/Commands/GetText.cs | 57 +++++++++++++++++++ .../Scripts/Commands/GetText.cs.meta | 12 ++++ .../Flowchart/Scripts/Commands/SetText.cs | 47 +++++++++++++++ .../Scripts/Commands/SetText.cs.meta | 12 ++++ 4 files changed, 128 insertions(+) create mode 100644 Assets/Fungus/Flowchart/Scripts/Commands/GetText.cs create mode 100644 Assets/Fungus/Flowchart/Scripts/Commands/GetText.cs.meta create mode 100644 Assets/Fungus/Flowchart/Scripts/Commands/SetText.cs create mode 100644 Assets/Fungus/Flowchart/Scripts/Commands/SetText.cs.meta diff --git a/Assets/Fungus/Flowchart/Scripts/Commands/GetText.cs b/Assets/Fungus/Flowchart/Scripts/Commands/GetText.cs new file mode 100644 index 00000000..749d0874 --- /dev/null +++ b/Assets/Fungus/Flowchart/Scripts/Commands/GetText.cs @@ -0,0 +1,57 @@ +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); + } + } + +} \ No newline at end of file diff --git a/Assets/Fungus/Flowchart/Scripts/Commands/GetText.cs.meta b/Assets/Fungus/Flowchart/Scripts/Commands/GetText.cs.meta new file mode 100644 index 00000000..2d8509b5 --- /dev/null +++ b/Assets/Fungus/Flowchart/Scripts/Commands/GetText.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 54baf7aee38a7425ca4bd2addbfcfdcf +timeCreated: 1431530474 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Flowchart/Scripts/Commands/SetText.cs b/Assets/Fungus/Flowchart/Scripts/Commands/SetText.cs new file mode 100644 index 00000000..ba996584 --- /dev/null +++ b/Assets/Fungus/Flowchart/Scripts/Commands/SetText.cs @@ -0,0 +1,47 @@ +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); + } + } + +} \ No newline at end of file diff --git a/Assets/Fungus/Flowchart/Scripts/Commands/SetText.cs.meta b/Assets/Fungus/Flowchart/Scripts/Commands/SetText.cs.meta new file mode 100644 index 00000000..a3987454 --- /dev/null +++ b/Assets/Fungus/Flowchart/Scripts/Commands/SetText.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 7ec5abc702c3f400b91bbeb2b8328d02 +timeCreated: 1431529735 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: