Vector2#
Vector2 / Vector2
Can Read
Cannot Write
Description#
The Vector2 in the specified string format
Parameters#
| Name | Description |
|---|---|
| Vector | The Vector2 value converted to text |
| Format | The numeric format specifier used for each axis. 'F2' if left empty |
Code#
using System;
using UnityEngine;
using VisualScript.Icons;
namespace VisualScript.Runtime
{
[Get]
[Title("Vector2")]
[Category("Vector2/Vector2")]
[Description("The Vector2 in the specified string format")]
[Image(typeof(IconVector2), ColorTheme.Type.Lime)]
[Parameter("Vector", "The Vector2 value converted to text")]
[Parameter("Format", "The numeric format specifier used for each axis. 'F2' if left empty")]
[Keywords("Vector", "Axis", "X", "Y", "Text", "Convert")]
[Serializable]
public class TypeStringVector2Get : TypeString
{
private const string FORMAT = "F2";
[SerializeField] private GetVector2 m_Vector = new GetVector2();
[SerializeField] private string m_Format = FORMAT;
public override string GetPreview(GameObject source) => Format(
this.m_Vector.GetPreview(source),
this.m_Format
);
public override string Get(Args args) => Format(this.m_Vector.Get(args), this.m_Format);
private static string Format(Vector2 vector, string format)
{
return vector.ToString(string.IsNullOrEmpty(format) ? FORMAT : format);
}
public override string ToString()
{
return this.m_Vector.ToString();
}
protected override SubscriptionMode Subscription => SubscriptionMode.OnChange;
}
}