#if LITMOTION_SUPPORT_UGUI using UnityEngine; using UnityEngine.UI; using Unity.Collections; #if LITMOTION_SUPPORT_ZSTRING using Cysharp.Text; #endif namespace LitMotion.Extensions { /// /// Provides binding extension methods for Unity UI (uGUI) components. /// public static class LitMotionUGUIExtensions { /// /// Create a motion data and bind it to Graphic.color /// /// The type of special parameters given to the motion data /// The type of adapter that support value animation /// This builder /// /// Handle of the created motion data. public static MotionHandle BindToColor(this MotionBuilder builder, Graphic graphic) where TOptions : unmanaged, IMotionOptions where TAdapter : unmanaged, IMotionAdapter { Error.IsNull(graphic); return builder.BindWithState(graphic, static (x, target) => { target.color = x; }); } /// /// Create a motion data and bind it to Graphic.color.r /// /// The type of special parameters given to the motion data /// The type of adapter that support value animation /// This builder /// /// Handle of the created motion data. public static MotionHandle BindToColorR(this MotionBuilder builder, Graphic graphic) where TOptions : unmanaged, IMotionOptions where TAdapter : unmanaged, IMotionAdapter { Error.IsNull(graphic); return builder.BindWithState(graphic, static (x, target) => { var c = target.color; c.r = x; target.color = c; }); } /// /// Create a motion data and bind it to Graphic.color.g /// /// The type of special parameters given to the motion data /// The type of adapter that support value animation /// This builder /// /// Handle of the created motion data. public static MotionHandle BindToColorG(this MotionBuilder builder, Graphic graphic) where TOptions : unmanaged, IMotionOptions where TAdapter : unmanaged, IMotionAdapter { Error.IsNull(graphic); return builder.BindWithState(graphic, static (x, target) => { var c = target.color; c.g = x; target.color = c; }); } /// /// Create a motion data and bind it to Graphic.color.b /// /// The type of special parameters given to the motion data /// The type of adapter that support value animation /// This builder /// /// Handle of the created motion data. public static MotionHandle BindToColorB(this MotionBuilder builder, Graphic graphic) where TOptions : unmanaged, IMotionOptions where TAdapter : unmanaged, IMotionAdapter { Error.IsNull(graphic); return builder.BindWithState(graphic, static (x, target) => { var c = target.color; c.b = x; target.color = c; }); } /// /// Create a motion data and bind it to Graphic.color.a /// /// The type of special parameters given to the motion data /// The type of adapter that support value animation /// This builder /// /// Handle of the created motion data. public static MotionHandle BindToColorA(this MotionBuilder builder, Graphic graphic) where TOptions : unmanaged, IMotionOptions where TAdapter : unmanaged, IMotionAdapter { Error.IsNull(graphic); return builder.BindWithState(graphic, static (x, target) => { var c = target.color; c.a = x; target.color = c; }); } /// /// Create a motion data and bind it to Image.FillAmount /// /// The type of special parameters given to the motion data /// The type of adapter that support value animation /// This builder /// /// Handle of the created motion data. public static MotionHandle BindToFillAmount(this MotionBuilder builder, Image image) where TOptions : unmanaged, IMotionOptions where TAdapter : unmanaged, IMotionAdapter { Error.IsNull(image); return builder.BindWithState(image, static (x, target) => { target.fillAmount = x; }); } /// /// Create a motion data and bind it to CanvasGroup.alpha /// /// The type of special parameters given to the motion data /// The type of adapter that support value animation /// This builder /// /// Handle of the created motion data. public static MotionHandle BindToCanvasGroupAlpha(this MotionBuilder builder, CanvasGroup canvasGroup) where TOptions : unmanaged, IMotionOptions where TAdapter : unmanaged, IMotionAdapter { Error.IsNull(canvasGroup); return builder.BindWithState(canvasGroup, static (x, target) => { target.alpha = x; }); } /// /// Create a motion data and bind it to Text.fontSize /// /// The type of special parameters given to the motion data /// The type of adapter that support value animation /// This builder /// /// Handle of the created motion data. public static MotionHandle BindToFontSize(this MotionBuilder builder, Text text) where TOptions : unmanaged, IMotionOptions where TAdapter : unmanaged, IMotionAdapter { Error.IsNull(text); return builder.BindWithState(text, static (x, target) => { target.fontSize = x; }); } /// /// Create a motion data and bind it to Text.text /// /// The type of special parameters given to the motion data /// The type of adapter that support value animation /// This builder /// /// Handle of the created motion data. public static MotionHandle BindToText(this MotionBuilder builder, Text text) where TOptions : unmanaged, IMotionOptions where TAdapter : unmanaged, IMotionAdapter { Error.IsNull(text); return builder.BindWithState(text, static (x, target) => { target.text = x.ConvertToString(); }); } /// /// Create a motion data and bind it to Text.text /// /// The type of special parameters given to the motion data /// The type of adapter that support value animation /// This builder /// /// Handle of the created motion data. public static MotionHandle BindToText(this MotionBuilder builder, Text text) where TOptions : unmanaged, IMotionOptions where TAdapter : unmanaged, IMotionAdapter { Error.IsNull(text); return builder.BindWithState(text, static (x, target) => { target.text = x.ConvertToString(); }); } /// /// Create a motion data and bind it to Text.text /// /// The type of special parameters given to the motion data /// The type of adapter that support value animation /// This builder /// /// Handle of the created motion data. public static MotionHandle BindToText(this MotionBuilder builder, Text text) where TOptions : unmanaged, IMotionOptions where TAdapter : unmanaged, IMotionAdapter { Error.IsNull(text); return builder.BindWithState(text, static (x, target) => { target.text = x.ConvertToString(); }); } /// /// Create a motion data and bind it to Text.text /// /// The type of special parameters given to the motion data /// The type of adapter that support value animation /// This builder /// /// Handle of the created motion data. public static MotionHandle BindToText(this MotionBuilder builder, Text text) where TOptions : unmanaged, IMotionOptions where TAdapter : unmanaged, IMotionAdapter { Error.IsNull(text); return builder.BindWithState(text, static (x, target) => { target.text = x.ConvertToString(); }); } /// /// Create a motion data and bind it to Text.text /// /// The type of special parameters given to the motion data /// The type of adapter that support value animation /// This builder /// /// Handle of the created motion data. public static MotionHandle BindToText(this MotionBuilder builder, Text text) where TOptions : unmanaged, IMotionOptions where TAdapter : unmanaged, IMotionAdapter { Error.IsNull(text); return builder.BindWithState(text, static (x, target) => { target.text = x.ConvertToString(); }); } /// /// Create a motion data and bind it to Text.text /// /// The type of special parameters given to the motion data /// The type of adapter that support value animation /// This builder /// /// Handle of the created motion data. public static MotionHandle BindToText(this MotionBuilder builder, Text text) where TOptions : unmanaged, IMotionOptions where TAdapter : unmanaged, IMotionAdapter { Error.IsNull(text); return builder.BindWithState(text, static (x, target) => { target.text = x.ToString(); }); } /// /// Create a motion data and bind it to Text.text /// /// The type of special parameters given to the motion data /// The type of adapter that support value animation /// This builder /// /// Format string /// Handle of the created motion data. public static MotionHandle BindToText(this MotionBuilder builder, Text text, string format) where TOptions : unmanaged, IMotionOptions where TAdapter : unmanaged, IMotionAdapter { Error.IsNull(text); return builder.BindWithState(text, format, static (x, target, format) => { #if LITMOTION_SUPPORT_ZSTRING target.text = ZString.Format(format, x); #else target.text = string.Format(format, x); #endif }); } /// /// Create a motion data and bind it to Text.text /// /// The type of special parameters given to the motion data /// The type of adapter that support value animation /// This builder /// /// Handle of the created motion data. public static MotionHandle BindToText(this MotionBuilder builder, Text text) where TOptions : unmanaged, IMotionOptions where TAdapter : unmanaged, IMotionAdapter { Error.IsNull(text); return builder.BindWithState(text, static (x, target) => { target.text = x.ToString(); }); } /// /// Create a motion data and bind it to Text.text /// /// The type of special parameters given to the motion data /// The type of adapter that support value animation /// This builder /// /// Format string /// Handle of the created motion data. public static MotionHandle BindToText(this MotionBuilder builder, Text text, string format) where TOptions : unmanaged, IMotionOptions where TAdapter : unmanaged, IMotionAdapter { Error.IsNull(text); return builder.BindWithState(text, format, static (x, target, format) => { #if LITMOTION_SUPPORT_ZSTRING target.text = ZString.Format(format, x); #else target.text = string.Format(format, x); #endif }); } /// /// Create a motion data and bind it to Text.text /// /// The type of special parameters given to the motion data /// The type of adapter that support value animation /// This builder /// /// Handle of the created motion data. public static MotionHandle BindToText(this MotionBuilder builder, Text text) where TOptions : unmanaged, IMotionOptions where TAdapter : unmanaged, IMotionAdapter { Error.IsNull(text); return builder.BindWithState(text, static (x, target) => { target.text = x.ToString(); }); } /// /// Create a motion data and bind it to Text.text /// /// The type of special parameters given to the motion data /// The type of adapter that support value animation /// This builder /// /// Format string /// Handle of the created motion data. public static MotionHandle BindToText(this MotionBuilder builder, Text text, string format) where TOptions : unmanaged, IMotionOptions where TAdapter : unmanaged, IMotionAdapter { Error.IsNull(text); return builder.BindWithState(text, format, static (x, target, format) => { #if LITMOTION_SUPPORT_ZSTRING target.text = ZString.Format(format, x); #else target.text = string.Format(format, x); #endif }); } } } #endif