summaryrefslogtreecommitdiff
path: root/Client/Assets/Behavior Designer/Runtime/Basic Tasks/String/Format.cs
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-01-27 16:15:06 +0800
committerchai <chaifix@163.com>2021-01-27 16:15:06 +0800
commit97da432c35b8c7aaf9dd2c39e2aa4b1f55f36065 (patch)
treed9b1db5908a3a030c529e230386fe01062923b09 /Client/Assets/Behavior Designer/Runtime/Basic Tasks/String/Format.cs
parent1fe4ffba72f56ccc6a89d1896142425c666887d4 (diff)
+behaviour designer
Diffstat (limited to 'Client/Assets/Behavior Designer/Runtime/Basic Tasks/String/Format.cs')
-rw-r--r--Client/Assets/Behavior Designer/Runtime/Basic Tasks/String/Format.cs47
1 files changed, 47 insertions, 0 deletions
diff --git a/Client/Assets/Behavior Designer/Runtime/Basic Tasks/String/Format.cs b/Client/Assets/Behavior Designer/Runtime/Basic Tasks/String/Format.cs
new file mode 100644
index 00000000..96e57f85
--- /dev/null
+++ b/Client/Assets/Behavior Designer/Runtime/Basic Tasks/String/Format.cs
@@ -0,0 +1,47 @@
+using UnityEngine;
+using System;
+
+namespace BehaviorDesigner.Runtime.Tasks.Basic.UnityString
+{
+ [TaskCategory("Basic/String")]
+ [TaskDescription("Stores a string with the specified format.")]
+ public class Format : Action
+ {
+ [Tooltip("The format of the string")]
+ public SharedString format;
+ [Tooltip("Any variables to appear in the string")]
+ public SharedGenericVariable[] variables;
+ [Tooltip("The result of the format")]
+ [RequiredField]
+ public SharedString storeResult;
+
+ private object[] variableValues;
+
+ public override void OnAwake()
+ {
+ variableValues = new object[variables.Length];
+ }
+
+ public override TaskStatus OnUpdate()
+ {
+ for (int i = 0; i < variableValues.Length; ++i) {
+ variableValues[i] = variables[i].Value.value.GetValue();
+ }
+
+ try {
+ storeResult.Value = string.Format(format.Value, variableValues);
+ } catch (Exception e) {
+ Debug.LogError(e.Message);
+ return TaskStatus.Failure;
+ }
+ return TaskStatus.Success;
+ }
+
+ public override void OnReset()
+ {
+ format = "";
+ variables = null;
+ storeResult = null;
+ }
+ }
+} \ No newline at end of file