Astra Child

Value Transformers

Estimated reading: 2 minutes 0 views

Value Transformers are used to transform a value either by applying some custom changes to it or by converting it from one type to another in a custom way. They are used in the Bindy system to provide additional functionality to the Bindables. A transformer is a ScriptableObject that defines the transformation logic for a specific value type.

How they work

A transformer is a ScriptableObject that can be referenced by a Bindable. When a Bindable receives a new value from the Bind it is connected to and has a transformer referenced, the transformer processes the value and returns a new one. If the new value is of a different type than the Bindable’s value type, a converter is used to finally set the new value to the Bindable’s target variable.

A Value Transformer is a ScriptableObject, which means that it can be saved as an asset with different settings for the same transformer. This allows for different settings to be used for different Bindables that use the same transformer.

Built-in Transformers

Bindy includes a variety of built-in value transformers that can be used to transform values between different types. These transformers can be used to format and manipulate values in various ways, from rounding a float to a certain number of decimal places, to converting an enum to a string.

Creating a new Transformer

Creating a new transformer is as simple as inheriting from the ValueTransformer base class and implementing the required methods. A transformer can have various settings that can be adjusted through the inspector, including the types that it can format from and to, and various parameters that can affect the transformation process.

Using Built-in Transformers

Bindy comes with a variety of built-in transformers that cover a wide range of use cases. These transformers can be used directly by referencing them from a Bindable, and they can also serve as examples of how to create custom transformers.

Here is a list of the available built-in transformers:

  • BooleanTransformer
  • ColorToHexTransformer
  • CreditCardTransformer
  • CurrencyTransformer
  • DateTimeToTimeAgoTransformer
  • DateTimeTransformer
  • DurationTransformer
  • EnumTransformer
  • FileSizeTransformer
  • FloatRoundingTransformer
  • FloatToVector2Transformer
  • FloatToVector3Transformer
  • ObjectTransformer
  • PasswordTransformer
  • PercentTransformer
  • PhoneNumberTransformer
  • RangeMappingTransformer
  • RectToFloatTransformer
  • StringToColorTransformer
  • StringTransformer
  • TextTransformer
  • TimeSpanToDurationTransformer
  • TimeSpanTransformer
  • TimeTransformer
  • UrlTransformer
  • Vector2ToFloatTransformer
  • Vector2Transformer
  • Vector3ToFloatTransformer
  • Vector3Transformer
  • Vector4ToFloatTransformer
  • Vector4Transformer
Share this Doc
CONTENTS
Scroll to Top