Number#
Number / Number
Can Read
Cannot Write
Description#
The number in the specified string format
Parameters#
| Name | Description |
|---|---|
| Number | The number value converted to text |
| Format | The numeric format specifier used. 'G' if left empty |
Code#
using System;
using UnityEngine;
using VisualScript.Icons;
namespace VisualScript.Runtime
{
[Get]
[Title("Number")]
[Category("Number/Number")]
[Description("The number in the specified string format")]
[Image(typeof(IconNumber), ColorTheme.Type.Teal)]
[Parameter("Number", "The number value converted to text")]
[Parameter("Format", "The numeric format specifier used. 'G' if left empty")]
[Keywords("Float", "Decimal", "Text", "Convert")]
[Serializable]
public class TypeStringNumberGet : TypeString
{
private const string FORMAT = "G";
[SerializeField] private GetNumber m_Number;
[SerializeField] private string m_Format = FORMAT;
public override string GetPreview(GameObject source) => Format(
this.m_Number.GetPreview(source),
this.m_Format
);
public TypeStringNumberGet() : this(new GetNumber())
{ }
public TypeStringNumberGet(GetNumber number)
{
this.m_Number = number;
}
public override string Get(Args args)
{
return Format(this.m_Number.Get(args), this.m_Format);
}
private static string Format(double value, string format)
{
return value.ToString(string.IsNullOrEmpty(format) ? FORMAT : format);
}
public override string ToString()
{
return this.m_Number.ToString();
}
protected override SubscriptionMode Subscription => SubscriptionMode.OnChange;
}
}