Reverse#
Operations / Transform / Reverse
Can Read
Cannot Write
Description#
Returns the text with its characters in the opposite order
Parameters#
| Name | Description |
|---|---|
| Text | The text that is reversed |
Code#
using System;
using UnityEngine;
using VisualScript.Icons;
namespace VisualScript.Runtime
{
[Get]
[Title("Reverse")]
[Category("Operations/Transform/Reverse")]
[Description("Returns the text with its characters in the opposite order")]
[Image(typeof(IconReverse), ColorTheme.Type.Yellow)]
[Parameter("Text", "The text that is reversed")]
[Keywords("Invert", "Backwards", "Flip", "Mirror", "Text")]
[Serializable]
public class TypeStringReverse : TypeString
{
[SerializeField] private GetString m_Text = new GetString();
public override string GetPreview(GameObject source) => Reverse(this.m_Text.GetPreview(source));
public override string Get(Args args) => Reverse(this.m_Text.Get(args));
private static string Reverse(string text)
{
if (string.IsNullOrEmpty(text)) return string.Empty;
char[] characters = text.ToCharArray();
Array.Reverse(characters);
return new string(characters);
}
public override string ToString()
{
return $"Reverse {this.m_Text}";
}
protected override SubscriptionMode Subscription => SubscriptionMode.OnChange;
}
}