123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762 |
- #if LITMOTION_SUPPORT_UIELEMENTS
- using Unity.Collections;
- using UnityEngine;
- using UnityEngine.UIElements;
- #if LITMOTION_SUPPORT_ZSTRING
- using Cysharp.Text;
- #endif
- namespace LitMotion.Extensions
- {
- /// <summary>
- /// Provides binding extension methods for UIElements.
- /// </summary>
- public static class LitMotionUIToolkitExtensions
- {
- #region VisualElement
- /// <summary>
- /// Create a motion data and bind it to VisualElement.style.left
- /// </summary>
- /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
- /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
- /// <param name="builder">This builder</param>
- /// <param name="transform"></param>
- /// <returns>Handle of the created motion data.</returns>
- public static MotionHandle BindToStyleLeft<TOptions, TAdapter>(this MotionBuilder<float, TOptions, TAdapter> builder, VisualElement visualElement)
- where TOptions : unmanaged, IMotionOptions
- where TAdapter : unmanaged, IMotionAdapter<float, TOptions>
- {
- Error.IsNull(visualElement);
- return builder.BindWithState(visualElement, static (x, target) =>
- {
- target.style.left = x;
- });
- }
- /// <summary>
- /// Create a motion data and bind it to VisualElement.style.right
- /// </summary>
- /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
- /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
- /// <param name="builder">This builder</param>
- /// <param name="transform"></param>
- /// <returns>Handle of the created motion data.</returns>
- public static MotionHandle BindToStyleRight<TOptions, TAdapter>(this MotionBuilder<float, TOptions, TAdapter> builder, VisualElement visualElement)
- where TOptions : unmanaged, IMotionOptions
- where TAdapter : unmanaged, IMotionAdapter<float, TOptions>
- {
- Error.IsNull(visualElement);
- return builder.BindWithState(visualElement, static (x, target) =>
- {
- target.style.right = x;
- });
- }
- /// <summary>
- /// Create a motion data and bind it to VisualElement.style.top
- /// </summary>
- /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
- /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
- /// <param name="builder">This builder</param>
- /// <param name="transform"></param>
- /// <returns>Handle of the created motion data.</returns>
- public static MotionHandle BindToStyleTop<TOptions, TAdapter>(this MotionBuilder<float, TOptions, TAdapter> builder, VisualElement visualElement)
- where TOptions : unmanaged, IMotionOptions
- where TAdapter : unmanaged, IMotionAdapter<float, TOptions>
- {
- Error.IsNull(visualElement);
- return builder.BindWithState(visualElement, static (x, target) =>
- {
- target.style.top = x;
- });
- }
- /// <summary>
- /// Create a motion data and bind it to VisualElement.style.bottom
- /// </summary>
- /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
- /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
- /// <param name="builder">This builder</param>
- /// <param name="transform"></param>
- /// <returns>Handle of the created motion data.</returns>
- public static MotionHandle BindToStyleBottom<TOptions, TAdapter>(this MotionBuilder<float, TOptions, TAdapter> builder, VisualElement visualElement)
- where TOptions : unmanaged, IMotionOptions
- where TAdapter : unmanaged, IMotionAdapter<float, TOptions>
- {
- Error.IsNull(visualElement);
- return builder.BindWithState(visualElement, static (x, target) =>
- {
- target.style.bottom = x;
- });
- }
- /// <summary>
- /// Create a motion data and bind it to VisualElement.style.width
- /// </summary>
- /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
- /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
- /// <param name="builder">This builder</param>
- /// <param name="transform"></param>
- /// <returns>Handle of the created motion data.</returns>
- public static MotionHandle BindToStyleWidth<TOptions, TAdapter>(this MotionBuilder<float, TOptions, TAdapter> builder, VisualElement visualElement)
- where TOptions : unmanaged, IMotionOptions
- where TAdapter : unmanaged, IMotionAdapter<float, TOptions>
- {
- Error.IsNull(visualElement);
- return builder.BindWithState(visualElement, static (x, target) =>
- {
- target.style.width = x;
- });
- }
- /// <summary>
- /// Create a motion data and bind it to VisualElement.style.height
- /// </summary>
- /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
- /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
- /// <param name="builder">This builder</param>
- /// <param name="transform"></param>
- /// <returns>Handle of the created motion data.</returns>
- public static MotionHandle BindToStyleHeight<TOptions, TAdapter>(this MotionBuilder<float, TOptions, TAdapter> builder, VisualElement visualElement)
- where TOptions : unmanaged, IMotionOptions
- where TAdapter : unmanaged, IMotionAdapter<float, TOptions>
- {
- Error.IsNull(visualElement);
- return builder.BindWithState(visualElement, static (x, target) =>
- {
- target.style.height = x;
- });
- }
- /// <summary>
- /// Create a motion data and bind it to VisualElement.style.color
- /// </summary>
- /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
- /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
- /// <param name="builder">This builder</param>
- /// <param name="transform"></param>
- /// <returns>Handle of the created motion data.</returns>
- public static MotionHandle BindToStyleColor<TOptions, TAdapter>(this MotionBuilder<Color, TOptions, TAdapter> builder, VisualElement visualElement)
- where TOptions : unmanaged, IMotionOptions
- where TAdapter : unmanaged, IMotionAdapter<Color, TOptions>
- {
- Error.IsNull(visualElement);
- return builder.BindWithState(visualElement, static (x, target) =>
- {
- target.style.color = x;
- });
- }
- /// <summary>
- /// Create a motion data and bind it to VisualElement.style.color.r
- /// </summary>
- /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
- /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
- /// <param name="builder">This builder</param>
- /// <param name="transform"></param>
- /// <returns>Handle of the created motion data.</returns>
- public static MotionHandle BindToStyleColorR<TOptions, TAdapter>(this MotionBuilder<float, TOptions, TAdapter> builder, VisualElement visualElement)
- where TOptions : unmanaged, IMotionOptions
- where TAdapter : unmanaged, IMotionAdapter<float, TOptions>
- {
- Error.IsNull(visualElement);
- return builder.BindWithState(visualElement, static (x, target) =>
- {
- var c = target.style.color.value;
- c.r = x;
- target.style.color = c;
- });
- }
- /// <summary>
- /// Create a motion data and bind it to VisualElement.style.color.g
- /// </summary>
- /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
- /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
- /// <param name="builder">This builder</param>
- /// <param name="transform"></param>
- /// <returns>Handle of the created motion data.</returns>
- public static MotionHandle BindToStyleColorG<TOptions, TAdapter>(this MotionBuilder<float, TOptions, TAdapter> builder, VisualElement visualElement)
- where TOptions : unmanaged, IMotionOptions
- where TAdapter : unmanaged, IMotionAdapter<float, TOptions>
- {
- Error.IsNull(visualElement);
- return builder.BindWithState(visualElement, static (x, target) =>
- {
- var c = target.style.color.value;
- c.g = x;
- target.style.color = c;
- });
- }
- /// <summary>
- /// Create a motion data and bind it to VisualElement.style.color.b
- /// </summary>
- /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
- /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
- /// <param name="builder">This builder</param>
- /// <param name="transform"></param>
- /// <returns>Handle of the created motion data.</returns>
- public static MotionHandle BindToStyleColorB<TOptions, TAdapter>(this MotionBuilder<float, TOptions, TAdapter> builder, VisualElement visualElement)
- where TOptions : unmanaged, IMotionOptions
- where TAdapter : unmanaged, IMotionAdapter<float, TOptions>
- {
- Error.IsNull(visualElement);
- return builder.BindWithState(visualElement, static (x, target) =>
- {
- var c = target.style.color.value;
- c.b = x;
- target.style.color = c;
- });
- }
- /// <summary>
- /// Create a motion data and bind it to VisualElement.style.color.a
- /// </summary>
- /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
- /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
- /// <param name="builder">This builder</param>
- /// <param name="transform"></param>
- /// <returns>Handle of the created motion data.</returns>
- public static MotionHandle BindToStyleColorA<TOptions, TAdapter>(this MotionBuilder<float, TOptions, TAdapter> builder, VisualElement visualElement)
- where TOptions : unmanaged, IMotionOptions
- where TAdapter : unmanaged, IMotionAdapter<float, TOptions>
- {
- Error.IsNull(visualElement);
- return builder.BindWithState(visualElement, static (x, target) =>
- {
- var c = target.style.color.value;
- c.a = x;
- target.style.color = c;
- });
- }
- /// <summary>
- /// Create a motion data and bind it to VisualElement.style.backgroundColor
- /// </summary>
- /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
- /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
- /// <param name="builder">This builder</param>
- /// <param name="transform"></param>
- /// <returns>Handle of the created motion data.</returns>
- public static MotionHandle BindToStyleBackgroundColor<TOptions, TAdapter>(this MotionBuilder<Color, TOptions, TAdapter> builder, VisualElement visualElement)
- where TOptions : unmanaged, IMotionOptions
- where TAdapter : unmanaged, IMotionAdapter<Color, TOptions>
- {
- Error.IsNull(visualElement);
- return builder.BindWithState(visualElement, static (x, target) =>
- {
- target.style.backgroundColor = x;
- });
- }
- /// <summary>
- /// Create a motion data and bind it to VisualElement.style.backgroundColor.r
- /// </summary>
- /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
- /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
- /// <param name="builder">This builder</param>
- /// <param name="transform"></param>
- /// <returns>Handle of the created motion data.</returns>
- public static MotionHandle BindToStyleBackgroundColorR<TOptions, TAdapter>(this MotionBuilder<float, TOptions, TAdapter> builder, VisualElement visualElement)
- where TOptions : unmanaged, IMotionOptions
- where TAdapter : unmanaged, IMotionAdapter<float, TOptions>
- {
- Error.IsNull(visualElement);
- return builder.BindWithState(visualElement, static (x, target) =>
- {
- var c = target.style.backgroundColor.value;
- c.r = x;
- target.style.backgroundColor = c;
- });
- }
- /// <summary>
- /// Create a motion data and bind it to VisualElement.style.backgroundColor.g
- /// </summary>
- /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
- /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
- /// <param name="builder">This builder</param>
- /// <param name="transform"></param>
- /// <returns>Handle of the created motion data.</returns>
- public static MotionHandle BindToStyleBackgroundColorG<TOptions, TAdapter>(this MotionBuilder<float, TOptions, TAdapter> builder, VisualElement visualElement)
- where TOptions : unmanaged, IMotionOptions
- where TAdapter : unmanaged, IMotionAdapter<float, TOptions>
- {
- Error.IsNull(visualElement);
- return builder.BindWithState(visualElement, static (x, target) =>
- {
- var c = target.style.backgroundColor.value;
- c.g = x;
- target.style.backgroundColor = c;
- });
- }
- /// <summary>
- /// Create a motion data and bind it to VisualElement.style.backgroundColor.b
- /// </summary>
- /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
- /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
- /// <param name="builder">This builder</param>
- /// <param name="transform"></param>
- /// <returns>Handle of the created motion data.</returns>
- public static MotionHandle BindToStyleBackgroundColorB<TOptions, TAdapter>(this MotionBuilder<float, TOptions, TAdapter> builder, VisualElement visualElement)
- where TOptions : unmanaged, IMotionOptions
- where TAdapter : unmanaged, IMotionAdapter<float, TOptions>
- {
- Error.IsNull(visualElement);
- return builder.BindWithState(visualElement, static (x, target) =>
- {
- var c = target.style.backgroundColor.value;
- c.b = x;
- target.style.backgroundColor = c;
- });
- }
- /// <summary>
- /// Create a motion data and bind it to VisualElement.style.backgroundColor.a
- /// </summary>
- /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
- /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
- /// <param name="builder">This builder</param>
- /// <param name="transform"></param>
- /// <returns>Handle of the created motion data.</returns>
- public static MotionHandle BindToStyleBackgroundColorA<TOptions, TAdapter>(this MotionBuilder<float, TOptions, TAdapter> builder, VisualElement visualElement)
- where TOptions : unmanaged, IMotionOptions
- where TAdapter : unmanaged, IMotionAdapter<float, TOptions>
- {
- Error.IsNull(visualElement);
- return builder.BindWithState(visualElement, static (x, target) =>
- {
- var c = target.style.backgroundColor.value;
- c.a = x;
- target.style.backgroundColor = c;
- });
- }
- /// <summary>
- /// Create a motion data and bind it to VisualElement.style.opacity
- /// </summary>
- /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
- /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
- /// <param name="builder">This builder</param>
- /// <param name="transform"></param>
- /// <returns>Handle of the created motion data.</returns>
- public static MotionHandle BindToStyleOpacity<TOptions, TAdapter>(this MotionBuilder<float, TOptions, TAdapter> builder, VisualElement visualElement)
- where TOptions : unmanaged, IMotionOptions
- where TAdapter : unmanaged, IMotionAdapter<float, TOptions>
- {
- Error.IsNull(visualElement);
- return builder.BindWithState(visualElement, static (x, target) =>
- {
- target.style.opacity = x;
- });
- }
- /// <summary>
- /// Create a motion data and bind it to VisualElement.style.fontSize
- /// </summary>
- /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
- /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
- /// <param name="builder">This builder</param>
- /// <param name="transform"></param>
- /// <returns>Handle of the created motion data.</returns>
- public static MotionHandle BindToStyleFontSize<TOptions, TAdapter>(this MotionBuilder<float, TOptions, TAdapter> builder, VisualElement visualElement)
- where TOptions : unmanaged, IMotionOptions
- where TAdapter : unmanaged, IMotionAdapter<float, TOptions>
- {
- Error.IsNull(visualElement);
- return builder.BindWithState(visualElement, static (x, target) =>
- {
- target.style.fontSize = x;
- });
- }
- /// <summary>
- /// Create a motion data and bind it to VisualElement.style.wordSpacing
- /// </summary>
- /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
- /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
- /// <param name="builder">This builder</param>
- /// <param name="transform"></param>
- /// <returns>Handle of the created motion data.</returns>
- public static MotionHandle BindToStyleWordSpacing<TOptions, TAdapter>(this MotionBuilder<float, TOptions, TAdapter> builder, VisualElement visualElement)
- where TOptions : unmanaged, IMotionOptions
- where TAdapter : unmanaged, IMotionAdapter<float, TOptions>
- {
- Error.IsNull(visualElement);
- return builder.BindWithState(visualElement, static (x, target) =>
- {
- target.style.wordSpacing = x;
- });
- }
- /// <summary>
- /// Create a motion data and bind it to VisualElement.style.translate
- /// </summary>
- /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
- /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
- /// <param name="builder">This builder</param>
- /// <param name="transform"></param>
- /// <returns>Handle of the created motion data.</returns>
- public static MotionHandle BindToStyleTranslate<TOptions, TAdapter>(this MotionBuilder<Vector3, TOptions, TAdapter> builder, VisualElement visualElement)
- where TOptions : unmanaged, IMotionOptions
- where TAdapter : unmanaged, IMotionAdapter<Vector3, TOptions>
- {
- Error.IsNull(visualElement);
- return builder.BindWithState(visualElement, static (x, target) =>
- {
- target.style.translate = new Translate(x.x, x.y, x.z);
- });
- }
- /// <summary>
- /// Create a motion data and bind it to VisualElement.style.translate
- /// </summary>
- /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
- /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
- /// <param name="builder">This builder</param>
- /// <param name="transform"></param>
- /// <returns>Handle of the created motion data.</returns>
- public static MotionHandle BindToStyleTranslate<TOptions, TAdapter>(this MotionBuilder<Vector2, TOptions, TAdapter> builder, VisualElement visualElement)
- where TOptions : unmanaged, IMotionOptions
- where TAdapter : unmanaged, IMotionAdapter<Vector2, TOptions>
- {
- Error.IsNull(visualElement);
- return builder.BindWithState(visualElement, static (x, target) =>
- {
- target.style.translate = new Translate(x.x, x.y);
- });
- }
- /// <summary>
- /// Create a motion data and bind it to VisualElement.style.rotate
- /// </summary>
- /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
- /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
- /// <param name="builder">This builder</param>
- /// <param name="transform"></param>
- /// <returns>Handle of the created motion data.</returns>
- public static MotionHandle BindToStyleRotate<TOptions, TAdapter>(this MotionBuilder<float, TOptions, TAdapter> builder, VisualElement visualElement, AngleUnit angleUnit = AngleUnit.Degree)
- where TOptions : unmanaged, IMotionOptions
- where TAdapter : unmanaged, IMotionAdapter<float, TOptions>
- {
- Error.IsNull(visualElement);
- return builder.BindWithState(visualElement, (x, target) =>
- {
- target.style.rotate = new Rotate(new Angle(x, angleUnit));
- });
- }
- /// <summary>
- /// Create a motion data and bind it to VisualElement.style.scale
- /// </summary>
- /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
- /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
- /// <param name="builder">This builder</param>
- /// <param name="transform"></param>
- /// <returns>Handle of the created motion data.</returns>
- public static MotionHandle BindToStyleScale<TOptions, TAdapter>(this MotionBuilder<Vector3, TOptions, TAdapter> builder, VisualElement visualElement)
- where TOptions : unmanaged, IMotionOptions
- where TAdapter : unmanaged, IMotionAdapter<Vector3, TOptions>
- {
- Error.IsNull(visualElement);
- return builder.BindWithState(visualElement, static (x, target) =>
- {
- target.style.scale = new Scale(x);
- });
- }
- /// <summary>
- /// Create a motion data and bind it to VisualElement.style.transformOrigin
- /// </summary>
- /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
- /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
- /// <param name="builder">This builder</param>
- /// <param name="transform"></param>
- /// <returns>Handle of the created motion data.</returns>
- public static MotionHandle BindToStyleTransformOrigin<TOptions, TAdapter>(this MotionBuilder<Vector3, TOptions, TAdapter> builder, VisualElement visualElement)
- where TOptions : unmanaged, IMotionOptions
- where TAdapter : unmanaged, IMotionAdapter<Vector3, TOptions>
- {
- Error.IsNull(visualElement);
- return builder.BindWithState(visualElement, static (x, target) =>
- {
- target.style.transformOrigin = new TransformOrigin(x.x, x.y, x.z);
- });
- }
- /// <summary>
- /// Create a motion data and bind it to VisualElement.style.transformOrigin
- /// </summary>
- /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
- /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
- /// <param name="builder">This builder</param>
- /// <param name="transform"></param>
- /// <returns>Handle of the created motion data.</returns>
- public static MotionHandle BindToStyleTransformOrigin<TOptions, TAdapter>(this MotionBuilder<Vector2, TOptions, TAdapter> builder, VisualElement visualElement)
- where TOptions : unmanaged, IMotionOptions
- where TAdapter : unmanaged, IMotionAdapter<Vector2, TOptions>
- {
- Error.IsNull(visualElement);
- return builder.BindWithState(visualElement, static (x, target) =>
- {
- target.style.transformOrigin = new TransformOrigin(x.x, x.y);
- });
- }
- #endregion
- #region AbstractProgressBar
- /// <summary>
- /// Create a motion data and bind it to AbstractProgressBar.value
- /// </summary>
- /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
- /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
- /// <param name="builder">This builder</param>
- /// <param name="transform"></param>
- /// <returns>Handle of the created motion data.</returns>
- public static MotionHandle BindToProgressBar<TOptions, TAdapter>(this MotionBuilder<float, TOptions, TAdapter> builder, AbstractProgressBar progressBar)
- where TOptions : unmanaged, IMotionOptions
- where TAdapter : unmanaged, IMotionAdapter<float, TOptions>
- {
- Error.IsNull(progressBar);
- return builder.BindWithState(progressBar, static (x, target) =>
- {
- target.value = x;
- });
- }
- #endregion
- #region TextElement
- /// <summary>
- /// Create a motion data and bind it to TextElement.text
- /// </summary>
- /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
- /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
- /// <param name="builder">This builder</param>
- /// <param name="transform"></param>
- /// <returns>Handle of the created motion data.</returns>
- public static MotionHandle BindToText<TOptions, TAdapter>(this MotionBuilder<FixedString32Bytes, TOptions, TAdapter> builder, TextElement textElement)
- where TOptions : unmanaged, IMotionOptions
- where TAdapter : unmanaged, IMotionAdapter<FixedString32Bytes, TOptions>
- {
- Error.IsNull(textElement);
- return builder.BindWithState(textElement, static (x, target) =>
- {
- target.text = x.ConvertToString();
- });
- }
- /// <summary>
- /// Create a motion data and bind it to TextElement.text
- /// </summary>
- /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
- /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
- /// <param name="builder">This builder</param>
- /// <param name="transform"></param>
- /// <returns>Handle of the created motion data.</returns>
- public static MotionHandle BindToText<TOptions, TAdapter>(this MotionBuilder<FixedString64Bytes, TOptions, TAdapter> builder, TextElement textElement)
- where TOptions : unmanaged, IMotionOptions
- where TAdapter : unmanaged, IMotionAdapter<FixedString64Bytes, TOptions>
- {
- Error.IsNull(textElement);
- return builder.BindWithState(textElement, static (x, target) =>
- {
- target.text = x.ConvertToString();
- });
- }
- /// <summary>
- /// Create a motion data and bind it to TextElement.text
- /// </summary>
- /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
- /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
- /// <param name="builder">This builder</param>
- /// <param name="transform"></param>
- /// <returns>Handle of the created motion data.</returns>
- public static MotionHandle BindToText<TOptions, TAdapter>(this MotionBuilder<FixedString128Bytes, TOptions, TAdapter> builder, TextElement textElement)
- where TOptions : unmanaged, IMotionOptions
- where TAdapter : unmanaged, IMotionAdapter<FixedString128Bytes, TOptions>
- {
- Error.IsNull(textElement);
- return builder.BindWithState(textElement, static (x, target) =>
- {
- target.text = x.ConvertToString();
- });
- }
- /// <summary>
- /// Create a motion data and bind it to TextElement.text
- /// </summary>
- /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
- /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
- /// <param name="builder">This builder</param>
- /// <param name="transform"></param>
- /// <returns>Handle of the created motion data.</returns>
- public static MotionHandle BindToText<TOptions, TAdapter>(this MotionBuilder<FixedString512Bytes, TOptions, TAdapter> builder, TextElement textElement)
- where TOptions : unmanaged, IMotionOptions
- where TAdapter : unmanaged, IMotionAdapter<FixedString512Bytes, TOptions>
- {
- Error.IsNull(textElement);
- return builder.BindWithState(textElement, static (x, target) =>
- {
- target.text = x.ConvertToString();
- });
- }
- /// <summary>
- /// Create a motion data and bind it to TextElement.text
- /// </summary>
- /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
- /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
- /// <param name="builder">This builder</param>
- /// <param name="transform"></param>
- /// <returns>Handle of the created motion data.</returns>
- public static MotionHandle BindToText<TOptions, TAdapter>(this MotionBuilder<FixedString4096Bytes, TOptions, TAdapter> builder, TextElement textElement)
- where TOptions : unmanaged, IMotionOptions
- where TAdapter : unmanaged, IMotionAdapter<FixedString4096Bytes, TOptions>
- {
- Error.IsNull(textElement);
- return builder.BindWithState(textElement, static (x, target) =>
- {
- target.text = x.ConvertToString();
- });
- }
- /// <summary>
- /// Create a motion data and bind it to Text.text
- /// </summary>
- /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
- /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
- /// <param name="builder">This builder</param>
- /// <param name="transform"></param>
- /// <returns>Handle of the created motion data.</returns>
- public static MotionHandle BindToText<TOptions, TAdapter>(this MotionBuilder<int, TOptions, TAdapter> builder, TextElement textElement)
- where TOptions : unmanaged, IMotionOptions
- where TAdapter : unmanaged, IMotionAdapter<int, TOptions>
- {
- Error.IsNull(textElement);
- return builder.BindWithState(textElement, static (x, target) =>
- {
- target.text = x.ToString();
- });
- }
- /// <summary>
- /// Create a motion data and bind it to Text.text
- /// </summary>
- /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
- /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
- /// <param name="builder">This builder</param>
- /// <param name="transform"></param>
- /// <param name="format">Format string</param>
- /// <returns>Handle of the created motion data.</returns>
- public static MotionHandle BindToText<TOptions, TAdapter>(this MotionBuilder<int, TOptions, TAdapter> builder, TextElement textElement, string format)
- where TOptions : unmanaged, IMotionOptions
- where TAdapter : unmanaged, IMotionAdapter<int, TOptions>
- {
- Error.IsNull(textElement);
- return builder.BindWithState(textElement, format, static (x, target, f) =>
- {
- #if LITMOTION_SUPPORT_ZSTRING
- target.text = ZString.Format(f, x);
- #else
- target.text = string.Format(f, x);
- #endif
- });
- }
- /// <summary>
- /// Create a motion data and bind it to Text.text
- /// </summary>
- /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
- /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
- /// <param name="builder">This builder</param>
- /// <param name="transform"></param>
- /// <returns>Handle of the created motion data.</returns>
- public static MotionHandle BindToText<TOptions, TAdapter>(this MotionBuilder<long, TOptions, TAdapter> builder, TextElement textElement)
- where TOptions : unmanaged, IMotionOptions
- where TAdapter : unmanaged, IMotionAdapter<long, TOptions>
- {
- Error.IsNull(textElement);
- return builder.BindWithState(textElement, static (x, target) =>
- {
- target.text = x.ToString();
- });
- }
- /// <summary>
- /// Create a motion data and bind it to Text.text
- /// </summary>
- /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
- /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
- /// <param name="builder">This builder</param>
- /// <param name="transform"></param>
- /// <param name="format">Format string</param>
- /// <returns>Handle of the created motion data.</returns>
- public static MotionHandle BindToText<TOptions, TAdapter>(this MotionBuilder<long, TOptions, TAdapter> builder, TextElement textElement, string format)
- where TOptions : unmanaged, IMotionOptions
- where TAdapter : unmanaged, IMotionAdapter<long, TOptions>
- {
- Error.IsNull(textElement);
- return builder.BindWithState(textElement, format, static (x, target, format) =>
- {
- #if LITMOTION_SUPPORT_ZSTRING
- target.text = ZString.Format(format, x);
- #else
- target.text = string.Format(format, x);
- #endif
- });
- }
- /// <summary>
- /// Create a motion data and bind it to Text.text
- /// </summary>
- /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
- /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
- /// <param name="builder">This builder</param>
- /// <param name="transform"></param>
- /// <returns>Handle of the created motion data.</returns>
- public static MotionHandle BindToText<TOptions, TAdapter>(this MotionBuilder<float, TOptions, TAdapter> builder, TextElement textElement)
- where TOptions : unmanaged, IMotionOptions
- where TAdapter : unmanaged, IMotionAdapter<float, TOptions>
- {
- Error.IsNull(textElement);
- return builder.BindWithState(textElement, static (x, target) =>
- {
- target.text = x.ToString();
- });
- }
- /// <summary>
- /// Create a motion data and bind it to Text.text
- /// </summary>
- /// <typeparam name="TOptions">The type of special parameters given to the motion data</typeparam>
- /// <typeparam name="TAdapter">The type of adapter that support value animation</typeparam>
- /// <param name="builder">This builder</param>
- /// <param name="transform"></param>
- /// <param name="format">Format string</param>
- /// <returns>Handle of the created motion data.</returns>
- public static MotionHandle BindToText<TOptions, TAdapter>(this MotionBuilder<float, TOptions, TAdapter> builder, TextElement textElement, string format)
- where TOptions : unmanaged, IMotionOptions
- where TAdapter : unmanaged, IMotionAdapter<float, TOptions>
- {
- Error.IsNull(textElement);
- return builder.BindWithState(textElement, format, static (x, target, format) =>
- {
- #if LITMOTION_SUPPORT_ZSTRING
- target.text = ZString.Format(format, x);
- #else
- target.text = string.Format(format, x);
- #endif
- });
- }
- #endregion
- }
- }
- #endif
|