#if LITMOTION_SUPPORT_TMP
using System.Buffers;
using UnityEngine;
using Unity.Collections;
using TMPro;
#if LITMOTION_SUPPORT_ZSTRING
using Cysharp.Text;
#endif
namespace LitMotion.Extensions
{
///
/// Provides binding extension methods for TMP_Text
///
public static class LitMotionTextMeshProExtensions
{
///
/// Create a motion data and bind it to TMP_Text.fontSize
///
/// The type of special parameters given to the motion data
/// The type of adapter that support value animation
/// This builder
/// Target TMP_Text
/// Handle of the created motion data.
public static MotionHandle BindToFontSize(this MotionBuilder builder, TMP_Text text)
where TOptions : unmanaged, IMotionOptions
where TAdapter : unmanaged, IMotionAdapter
{
Error.IsNull(text);
return builder.Bind(text, static (x, target) =>
{
target.fontSize = x;
});
}
///
/// Create a motion data and bind it to TMP_Text.maxVisibleCharacters
///
/// The type of special parameters given to the motion data
/// The type of adapter that support value animation
/// This builder
/// Target TMP_Text
/// Handle of the created motion data.
public static MotionHandle BindToMaxVisibleCharacters(this MotionBuilder builder, TMP_Text text)
where TOptions : unmanaged, IMotionOptions
where TAdapter : unmanaged, IMotionAdapter
{
Error.IsNull(text);
return builder.Bind(text, static (x, target) =>
{
target.maxVisibleCharacters = x;
});
}
///
/// Create a motion data and bind it to TMP_Text.maxVisibleLines
///
/// The type of special parameters given to the motion data
/// The type of adapter that support value animation
/// This builder
/// Target TMP_Text
/// Handle of the created motion data.
public static MotionHandle BindToMaxVisibleLines(this MotionBuilder builder, TMP_Text text)
where TOptions : unmanaged, IMotionOptions
where TAdapter : unmanaged, IMotionAdapter
{
Error.IsNull(text);
return builder.Bind(text, static (x, target) =>
{
target.maxVisibleLines = x;
});
}
///
/// Create a motion data and bind it to TMP_Text.characterSpacing
///
/// The type of special parameters given to the motion data
/// The type of adapter that support value animation
/// This builder
/// Target TMP_Text
/// Handle of the created motion data.
public static MotionHandle BindToCharacterSpacing(this MotionBuilder builder, TMP_Text text)
where TOptions : unmanaged, IMotionOptions
where TAdapter : unmanaged, IMotionAdapter
{
Error.IsNull(text);
return builder.Bind(text, static (x, target) =>
{
target.characterSpacing = x;
});
}
///
/// Create a motion data and bind it to TMP_Text.wordSpacing
///
/// The type of special parameters given to the motion data
/// The type of adapter that support value animation
/// This builder
/// Target TMP_Text
/// Handle of the created motion data.
public static MotionHandle BindToWordSpacing(this MotionBuilder builder, TMP_Text text)
where TOptions : unmanaged, IMotionOptions
where TAdapter : unmanaged, IMotionAdapter
{
Error.IsNull(text);
return builder.Bind(text, static (x, target) =>
{
target.wordSpacing = x;
});
}
///
/// Create a motion data and bind it to TMP_Text.paragraphSpacing
///
/// The type of special parameters given to the motion data
/// The type of adapter that support value animation
/// This builder
/// Target TMP_Text
/// Handle of the created motion data.
public static MotionHandle BindToParagraphSpacing(this MotionBuilder builder, TMP_Text text)
where TOptions : unmanaged, IMotionOptions
where TAdapter : unmanaged, IMotionAdapter
{
Error.IsNull(text);
return builder.Bind(text, static (x, target) =>
{
target.paragraphSpacing = x;
});
}
///
/// Create a motion data and bind it to TMP_Text.lineSpacing
///
/// The type of special parameters given to the motion data
/// The type of adapter that support value animation
/// This builder
/// Target TMP_Text
/// Handle of the created motion data.
public static MotionHandle BindToLineSpacing(this MotionBuilder builder, TMP_Text text)
where TOptions : unmanaged, IMotionOptions
where TAdapter : unmanaged, IMotionAdapter
{
Error.IsNull(text);
return builder.Bind(text, static (x, target) =>
{
target.lineSpacing = x;
});
}
///
/// Create a motion data and bind it to TMP_Text.maxVisibleWords
///
/// The type of special parameters given to the motion data
/// The type of adapter that support value animation
/// This builder
/// Target TMP_Text
/// Handle of the created motion data.
public static MotionHandle BindToMaxVisibleWords(this MotionBuilder builder, TMP_Text text)
where TOptions : unmanaged, IMotionOptions
where TAdapter : unmanaged, IMotionAdapter
{
Error.IsNull(text);
return builder.Bind(text, static (x, target) =>
{
target.maxVisibleWords = x;
});
}
///
/// Create a motion data and bind it to TMP_Text.color
///
/// The type of special parameters given to the motion data
/// The type of adapter that support value animation
/// This builder
/// Target TMP_Text
/// Handle of the created motion data.
public static MotionHandle BindToColor(this MotionBuilder builder, TMP_Text text)
where TOptions : unmanaged, IMotionOptions
where TAdapter : unmanaged, IMotionAdapter
{
Error.IsNull(text);
return builder.Bind(text, static (x, target) =>
{
target.color = x;
});
}
///
/// Create a motion data and bind it to TMP_Text.color.r
///
/// The type of special parameters given to the motion data
/// The type of adapter that support value animation
/// This builder
/// Target TMP_Text
/// Handle of the created motion data.
public static MotionHandle BindToColorR(this MotionBuilder builder, TMP_Text text)
where TOptions : unmanaged, IMotionOptions
where TAdapter : unmanaged, IMotionAdapter
{
Error.IsNull(text);
return builder.Bind(text, static (x, target) =>
{
var c = target.color;
c.r = x;
target.color = c;
});
}
///
/// Create a motion data and bind it to TMP_Text.color.g
///
/// The type of special parameters given to the motion data
/// The type of adapter that support value animation
/// This builder
/// Target TMP_Text
/// Handle of the created motion data.
public static MotionHandle BindToColorG(this MotionBuilder builder, TMP_Text text)
where TOptions : unmanaged, IMotionOptions
where TAdapter : unmanaged, IMotionAdapter
{
Error.IsNull(text);
return builder.Bind(text, static (x, target) =>
{
var c = target.color;
c.g = x;
target.color = c;
});
}
///
/// Create a motion data and bind it to TMP_Text.color.b
///
/// The type of special parameters given to the motion data
/// The type of adapter that support value animation
/// This builder
/// Target TMP_Text
/// Handle of the created motion data.
public static MotionHandle BindToColorB(this MotionBuilder builder, TMP_Text text)
where TOptions : unmanaged, IMotionOptions
where TAdapter : unmanaged, IMotionAdapter
{
Error.IsNull(text);
return builder.Bind(text, static (x, target) =>
{
var c = target.color;
c.b = x;
target.color = c;
});
}
///
/// Create a motion data and bind it to TMP_Text.color.a
///
/// The type of special parameters given to the motion data
/// The type of adapter that support value animation
/// This builder
/// Target TMP_Text
/// Handle of the created motion data.
public static MotionHandle BindToColorA(this MotionBuilder builder, TMP_Text text)
where TOptions : unmanaged, IMotionOptions
where TAdapter : unmanaged, IMotionAdapter
{
Error.IsNull(text);
return builder.Bind(text, static (x, target) =>
{
var c = target.color;
c.a = x;
target.color = c;
});
}
///
/// Create a motion data and bind it to TMP_Text.text.
///
///
/// Note: This extension method uses TMP_Text.SetText() to achieve zero allocation, so it is recommended to use this method when binding to text.
///
/// The type of special parameters given to the motion data
/// The type of adapter that support value animation
/// This builder
/// Target TMP_Text
/// Handle of the created motion data.
public unsafe static MotionHandle BindToText(this MotionBuilder builder, TMP_Text text)
where TOptions : unmanaged, IMotionOptions
where TAdapter : unmanaged, IMotionAdapter
{
Error.IsNull(text);
return builder.Bind(text, static (x, target) =>
{
var enumerator = x.GetEnumerator();
var length = 0;
var buffer = ArrayPool.Shared.Rent(64);
fixed (char* c = buffer)
{
Unicode.Utf8ToUtf16(x.GetUnsafePtr(), x.Length, c, out length, x.Length * 2);
}
target.SetText(buffer, 0, length);
ArrayPool.Shared.Return(buffer);
});
}
///
/// Create a motion data and bind it to TMP_Text.text.
///
///
/// Note: This extension method uses TMP_Text.SetText() to achieve zero allocation, so it is recommended to use this method when binding to text.
///
/// The type of special parameters given to the motion data
/// The type of adapter that support value animation
/// This builder
/// Target TMP_Text
/// Handle of the created motion data.
public unsafe static MotionHandle BindToText(this MotionBuilder builder, TMP_Text text)
where TOptions : unmanaged, IMotionOptions
where TAdapter : unmanaged, IMotionAdapter
{
Error.IsNull(text);
return builder.Bind(text, static (x, target) =>
{
var enumerator = x.GetEnumerator();
var length = 0;
var buffer = ArrayPool.Shared.Rent(128);
fixed (char* c = buffer)
{
Unicode.Utf8ToUtf16(x.GetUnsafePtr(), x.Length, c, out length, x.Length * 2);
}
target.SetText(buffer, 0, length);
ArrayPool.Shared.Return(buffer);
});
}
///
/// Create a motion data and bind it to TMP_Text.text.
///
///
/// Note: This extension method uses TMP_Text.SetText() to achieve zero allocation, so it is recommended to use this method when binding to text.
///
/// The type of special parameters given to the motion data
/// The type of adapter that support value animation
/// This builder
/// Target TMP_Text
/// Handle of the created motion data.
public unsafe static MotionHandle BindToText(this MotionBuilder builder, TMP_Text text)
where TOptions : unmanaged, IMotionOptions
where TAdapter : unmanaged, IMotionAdapter
{
Error.IsNull(text);
return builder.Bind(text, static (x, target) =>
{
var enumerator = x.GetEnumerator();
var length = 0;
var buffer = ArrayPool.Shared.Rent(256);
fixed (char* c = buffer)
{
Unicode.Utf8ToUtf16(x.GetUnsafePtr(), x.Length, c, out length, x.Length * 2);
}
target.SetText(buffer, 0, length);
ArrayPool.Shared.Return(buffer);
});
}
///
/// Create a motion data and bind it to TMP_Text.text.
///
///
/// Note: This extension method uses TMP_Text.SetText() to achieve zero allocation, so it is recommended to use this method when binding to text.
///
/// The type of special parameters given to the motion data
/// The type of adapter that support value animation
/// This builder
/// Target TMP_Text
/// Handle of the created motion data.
public unsafe static MotionHandle BindToText(this MotionBuilder builder, TMP_Text text)
where TOptions : unmanaged, IMotionOptions
where TAdapter : unmanaged, IMotionAdapter
{
Error.IsNull(text);
return builder.Bind(text, static (x, target) =>
{
var enumerator = x.GetEnumerator();
var length = 0;
var buffer = ArrayPool.Shared.Rent(1024);
fixed (char* c = buffer)
{
Unicode.Utf8ToUtf16(x.GetUnsafePtr(), x.Length, c, out length, x.Length * 2);
}
target.SetText(buffer, 0, length);
ArrayPool.Shared.Return(buffer);
});
}
///
/// Create a motion data and bind it to TMP_Text.text.
///
///
/// Note: This extension method uses TMP_Text.SetText() to achieve zero allocation, so it is recommended to use this method when binding to text.
///
/// The type of special parameters given to the motion data
/// The type of adapter that support value animation
/// This builder
/// Target TMP_Text
/// Handle of the created motion data.
public unsafe static MotionHandle BindToText(this MotionBuilder builder, TMP_Text text)
where TOptions : unmanaged, IMotionOptions
where TAdapter : unmanaged, IMotionAdapter
{
Error.IsNull(text);
return builder.Bind(text, static (x, target) =>
{
var enumerator = x.GetEnumerator();
var length = 0;
var buffer = ArrayPool.Shared.Rent(8192);
fixed (char* c = buffer)
{
Unicode.Utf8ToUtf16(x.GetUnsafePtr(), x.Length, c, out length, x.Length * 2);
}
target.SetText(buffer, 0, length);
ArrayPool.Shared.Return(buffer);
});
}
///
/// Create a motion data and bind it to TMP_Text.text.
///
///
/// Note: This extension method uses TMP_Text.SetText() to achieve zero allocation, so it is recommended to use this method when binding to 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 unsafe static MotionHandle BindToText(this MotionBuilder builder, TMP_Text text)
where TOptions : unmanaged, IMotionOptions
where TAdapter : unmanaged, IMotionAdapter
{
Error.IsNull(text);
return builder.Bind(text, static (x, target) =>
{
var buffer = ArrayPool.Shared.Rent(128);
var bufferOffset = 0;
Utf16StringHelper.WriteInt32(ref buffer, ref bufferOffset, x);
target.SetText(buffer, 0, bufferOffset);
ArrayPool.Shared.Return(buffer);
});
}
///
/// Create a motion data and bind it to TMP_Text.text.
///
/// The type of special parameters given to the motion data
/// The type of adapter that support value animation
/// This builder
/// Target TMP_Text
/// Format string
/// Handle of the created motion data.
public unsafe static MotionHandle BindToText(this MotionBuilder builder, TMP_Text text, string format)
where TOptions : unmanaged, IMotionOptions
where TAdapter : unmanaged, IMotionAdapter
{
Error.IsNull(text);
return builder.Bind(text, format, static (x, text, format) =>
{
#if LITMOTION_SUPPORT_ZSTRING
text.SetTextFormat(format, x);
#else
text.text = string.Format(format, x);
#endif
});
}
///
/// Create a motion data and bind it to TMP_Text.text.
///
///
/// Note: This extension method uses TMP_Text.SetText() to achieve zero allocation, so it is recommended to use this method when binding to 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 unsafe static MotionHandle BindToText(this MotionBuilder builder, TMP_Text text)
where TOptions : unmanaged, IMotionOptions
where TAdapter : unmanaged, IMotionAdapter
{
Error.IsNull(text);
return builder.Bind(text, static (x, target) =>
{
var buffer = ArrayPool.Shared.Rent(128);
var bufferOffset = 0;
Utf16StringHelper.WriteInt64(ref buffer, ref bufferOffset, x);
target.SetText(buffer, 0, bufferOffset);
ArrayPool.Shared.Return(buffer);
});
}
///
/// Create a motion data and bind it to TMP_Text.text.
///
/// The type of special parameters given to the motion data
/// The type of adapter that support value animation
/// This builder
/// Target TMP_Text
/// Format string
/// Handle of the created motion data.
public unsafe static MotionHandle BindToText(this MotionBuilder builder, TMP_Text text, string format)
where TOptions : unmanaged, IMotionOptions
where TAdapter : unmanaged, IMotionAdapter
{
Error.IsNull(text);
return builder.Bind(text, format, static (x, text, format) =>
{
#if LITMOTION_SUPPORT_ZSTRING
text.SetTextFormat(format, x);
#else
text.text = string.Format(format, x);
#endif
});
}
///
/// Create a motion data and bind it to TMP_Text.text.
///
///
/// Note: This extension method uses TMP_Text.SetText() to achieve zero allocation, so it is recommended to use this method when binding to 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 unsafe static MotionHandle BindToText(this MotionBuilder builder, TMP_Text text)
where TOptions : unmanaged, IMotionOptions
where TAdapter : unmanaged, IMotionAdapter
{
const string format = "{0}";
Error.IsNull(text);
return builder.Bind(text, static (x, target) =>
{
#if LITMOTION_SUPPORT_ZSTRING
target.SetTextFormat(format, x);
#else
target.SetText(format, x);
#endif
});
}
///
/// Create a motion data and bind it to TMP_Text.text.
///
/// The type of special parameters given to the motion data
/// The type of adapter that support value animation
/// This builder
/// Target TMP_Text
/// Format string
/// Handle of the created motion data.
public unsafe static MotionHandle BindToText(this MotionBuilder builder, TMP_Text text, string format)
where TOptions : unmanaged, IMotionOptions
where TAdapter : unmanaged, IMotionAdapter
{
Error.IsNull(text);
return builder.Bind(text, format, static (x, text, format) =>
{
#if LITMOTION_SUPPORT_ZSTRING
text.SetTextFormat(format, x);
#else
text.text = string.Format(format, x);
#endif
});
}
///
/// Create motion data and bind it to the character color.
///
/// The type of value to animate
/// The type of special parameters given to the motion entity
/// The type of adapter that support value animation
/// This builder
/// Target TMP_Text
/// Target character index
/// Action to update the character
/// Handle of the created motion data.
public static MotionHandle BindToTMPChar(this MotionBuilder builder, TMP_Text text, int charIndex, TMPCharacterMotionUpdateAction action)
where TValue : unmanaged
where TOptions : unmanaged, IMotionOptions
where TAdapter : unmanaged, IMotionAdapter
{
Error.IsNull(text);
var animator = TextMeshProMotionAnimator.Get(text);
animator.EnsureCapacity(charIndex + 1);
var handle = builder.WithOnComplete(animator.completeAction).Bind(animator, Box.Create(charIndex), action, static (x, animator, charIndex, action) =>
{
action(x, charIndex.Value, ref animator.charInfoArray[charIndex.Value]);
animator.SetDirty();
});
return handle;
}
///
/// Create motion data and bind it to the character color.
///
/// The type of special parameters given to the motion data
/// The type of adapter that support value animation
/// This builder
/// Target TMP_Text
/// Target character index
/// Handle of the created motion data.
public static MotionHandle BindToTMPCharColor(this MotionBuilder builder, TMP_Text text, int charIndex)
where TOptions : unmanaged, IMotionOptions
where TAdapter : unmanaged, IMotionAdapter
{
return builder.BindToTMPChar(text, charIndex, static (Color x, int _, ref TMPMotionCharacter c) =>
{
c.Color = x;
});
}
///
/// Create motion data and bind it to the character color.r.
///
/// The type of special parameters given to the motion data
/// The type of adapter that support value animation
/// This builder
/// Target TMP_Text
/// Target character index
/// Handle of the created motion data.
public static MotionHandle BindToTMPCharColorR(this MotionBuilder builder, TMP_Text text, int charIndex)
where TOptions : unmanaged, IMotionOptions
where TAdapter : unmanaged, IMotionAdapter
{
return builder.BindToTMPChar(text, charIndex, static (float x, int _, ref TMPMotionCharacter c) =>
{
c.Color.r = x;
});
}
///
/// Create motion data and bind it to the character color.g.
///
/// The type of special parameters given to the motion data
/// The type of adapter that support value animation
/// This builder
/// Target TMP_Text
/// Target character index
/// Handle of the created motion data.
public static MotionHandle BindToTMPCharColorG(this MotionBuilder builder, TMP_Text text, int charIndex)
where TOptions : unmanaged, IMotionOptions
where TAdapter : unmanaged, IMotionAdapter
{
return builder.BindToTMPChar(text, charIndex, static (float x, int _, ref TMPMotionCharacter c) =>
{
c.Color.g = x;
});
}
///
/// Create motion data and bind it to the character color.b.
///
/// The type of special parameters given to the motion data
/// The type of adapter that support value animation
/// This builder
/// Target TMP_Text
/// Target character index
/// Handle of the created motion data.
public static MotionHandle BindToTMPCharColorB(this MotionBuilder builder, TMP_Text text, int charIndex)
where TOptions : unmanaged, IMotionOptions
where TAdapter : unmanaged, IMotionAdapter
{
return builder.BindToTMPChar(text, charIndex, static (float x, int _, ref TMPMotionCharacter c) =>
{
c.Color.b = x;
});
}
///
/// Create motion data and bind it to the character color.a.
///
/// The type of special parameters given to the motion data
/// The type of adapter that support value animation
/// This builder
/// Target TMP_Text
/// Target character index
/// Handle of the created motion data.
public static MotionHandle BindToTMPCharColorA(this MotionBuilder builder, TMP_Text text, int charIndex)
where TOptions : unmanaged, IMotionOptions
where TAdapter : unmanaged, IMotionAdapter
{
return builder.BindToTMPChar(text, charIndex, static (float x, int _, ref TMPMotionCharacter c) =>
{
c.Color.a = x;
});
}
///
/// Create motion data and bind it to the character position.
///
/// The type of special parameters given to the motion data
/// The type of adapter that support value animation
/// This builder
/// Target TMP_Text
/// Target character index
/// Handle of the created motion data.
public static MotionHandle BindToTMPCharPosition(this MotionBuilder builder, TMP_Text text, int charIndex)
where TOptions : unmanaged, IMotionOptions
where TAdapter : unmanaged, IMotionAdapter
{
return builder.BindToTMPChar(text, charIndex, static (Vector3 x, int _, ref TMPMotionCharacter c) =>
{
c.Position = x;
});
}
///
/// Create motion data and bind it to the character position.x.
///
/// The type of special parameters given to the motion data
/// The type of adapter that support value animation
/// This builder
/// Target TMP_Text
/// Target character index
/// Handle of the created motion data.
public static MotionHandle BindToTMPCharPositionX(this MotionBuilder builder, TMP_Text text, int charIndex)
where TOptions : unmanaged, IMotionOptions
where TAdapter : unmanaged, IMotionAdapter
{
return builder.BindToTMPChar(text, charIndex, static (float x, int _, ref TMPMotionCharacter c) =>
{
c.Position.x = x;
});
}
///
/// Create motion data and bind it to the character position.y.
///
/// The type of special parameters given to the motion data
/// The type of adapter that support value animation
/// This builder
/// Target TMP_Text
/// Target character index
/// Handle of the created motion data.
public static MotionHandle BindToTMPCharPositionY(this MotionBuilder builder, TMP_Text text, int charIndex)
where TOptions : unmanaged, IMotionOptions
where TAdapter : unmanaged, IMotionAdapter
{
return builder.BindToTMPChar(text, charIndex, static (float x, int _, ref TMPMotionCharacter c) =>
{
c.Position.y = x;
});
}
///
/// Create motion data and bind it to the character position.z.
///
/// The type of special parameters given to the motion data
/// The type of adapter that support value animation
/// This builder
/// Target TMP_Text
/// Target character index
/// Handle of the created motion data.
public static MotionHandle BindToTMPCharPositionZ(this MotionBuilder builder, TMP_Text text, int charIndex)
where TOptions : unmanaged, IMotionOptions
where TAdapter : unmanaged, IMotionAdapter
{
return builder.BindToTMPChar(text, charIndex, static (float x, int _, ref TMPMotionCharacter c) =>
{
c.Position.z = x;
});
}
///
/// Create motion data and bind it to the character position.xy.
///
/// The type of special parameters given to the motion data
/// The type of adapter that support value animation
/// This builder
/// Target TMP_Text
/// Target character index
/// Handle of the created motion data.
public static MotionHandle BindToTMPCharPositionXY(this MotionBuilder builder, TMP_Text text, int charIndex)
where TOptions : unmanaged, IMotionOptions
where TAdapter : unmanaged, IMotionAdapter
{
return builder.BindToTMPChar(text, charIndex, static (Vector2 x, int _, ref TMPMotionCharacter c) =>
{
c.Position.x = x.x;
c.Position.y = x.y;
});
}
///
/// Create motion data and bind it to the character position.yz.
///
/// The type of special parameters given to the motion data
/// The type of adapter that support value animation
/// This builder
/// Target TMP_Text
/// Target character index
/// Handle of the created motion data.
public static MotionHandle BindToTMPCharPositionYZ(this MotionBuilder builder, TMP_Text text, int charIndex)
where TOptions : unmanaged, IMotionOptions
where TAdapter : unmanaged, IMotionAdapter
{
return builder.BindToTMPChar(text, charIndex, static (Vector2 x, int _, ref TMPMotionCharacter c) =>
{
c.Position.y = x.x;
c.Position.z = x.y;
});
}
///
/// Create motion data and bind it to the character position.xz.
///
/// The type of special parameters given to the motion data
/// The type of adapter that support value animation
/// This builder
/// Target TMP_Text
/// Target character index
/// Handle of the created motion data.
public static MotionHandle BindToTMPCharPositionXZ(this MotionBuilder builder, TMP_Text text, int charIndex)
where TOptions : unmanaged, IMotionOptions
where TAdapter : unmanaged, IMotionAdapter
{
return builder.BindToTMPChar(text, charIndex, static (Vector2 x, int _, ref TMPMotionCharacter c) =>
{
c.Position.x = x.x;
c.Position.z = x.y;
});
}
///
/// Create motion data and bind it to the character rotation.
///
/// The type of special parameters given to the motion data
/// The type of adapter that support value animation
/// This builder
/// Target TMP_Text
/// Target character index
/// Handle of the created motion data.
public static MotionHandle BindToTMPCharRotation(this MotionBuilder builder, TMP_Text text, int charIndex)
where TOptions : unmanaged, IMotionOptions
where TAdapter : unmanaged, IMotionAdapter
{
return builder.BindToTMPChar(text, charIndex, static (Quaternion x, int _, ref TMPMotionCharacter c) =>
{
c.Rotation = x;
});
}
///
/// Create motion data and bind it to the character rotation (using euler angles).
///
/// The type of special parameters given to the motion data
/// The type of adapter that support value animation
/// This builder
/// Target TMP_Text
/// Target character index
/// Handle of the created motion data.
public static MotionHandle BindToTMPCharEulerAngles(this MotionBuilder builder, TMP_Text text, int charIndex)
where TOptions : unmanaged, IMotionOptions
where TAdapter : unmanaged, IMotionAdapter
{
return builder.BindToTMPChar(text, charIndex, static (Vector3 x, int _, ref TMPMotionCharacter c) =>
{
c.Rotation = Quaternion.Euler(x);
});
}
///
/// Create motion data and bind it to the character rotation (using euler angles).
///
/// The type of special parameters given to the motion data
/// The type of adapter that support value animation
/// This builder
/// Target TMP_Text
/// Target character index
/// Handle of the created motion data.
public static MotionHandle BindToTMPCharEulerAnglesX(this MotionBuilder builder, TMP_Text text, int charIndex)
where TOptions : unmanaged, IMotionOptions
where TAdapter : unmanaged, IMotionAdapter
{
return builder.BindToTMPChar(text, charIndex, static (float x, int _, ref TMPMotionCharacter c) =>
{
var eulerAngles = c.Rotation.eulerAngles;
eulerAngles.x = x;
c.Rotation = Quaternion.Euler(eulerAngles);
});
}
///
/// Create motion data and bind it to the character rotation (using euler angles).
///
/// The type of special parameters given to the motion data
/// The type of adapter that support value animation
/// This builder
/// Target TMP_Text
/// Target character index
/// Handle of the created motion data.
public static MotionHandle BindToTMPCharEulerAnglesY(this MotionBuilder builder, TMP_Text text, int charIndex)
where TOptions : unmanaged, IMotionOptions
where TAdapter : unmanaged, IMotionAdapter
{
return builder.BindToTMPChar(text, charIndex, static (float x, int _, ref TMPMotionCharacter c) =>
{
var eulerAngles = c.Rotation.eulerAngles;
eulerAngles.y = x;
c.Rotation = Quaternion.Euler(eulerAngles);
});
}
///
/// Create motion data and bind it to the character rotation (using euler angles).
///
/// The type of special parameters given to the motion data
/// The type of adapter that support value animation
/// This builder
/// Target TMP_Text
/// Target character index
/// Handle of the created motion data.
public static MotionHandle BindToTMPCharEulerAnglesZ(this MotionBuilder builder, TMP_Text text, int charIndex)
where TOptions : unmanaged, IMotionOptions
where TAdapter : unmanaged, IMotionAdapter
{
return builder.BindToTMPChar(text, charIndex, static (float x, int _, ref TMPMotionCharacter c) =>
{
var eulerAngles = c.Rotation.eulerAngles;
eulerAngles.z = x;
c.Rotation = Quaternion.Euler(eulerAngles);
});
}
///
/// Create motion data and bind it to the character rotation (using euler angles).
///
/// The type of special parameters given to the motion data
/// The type of adapter that support value animation
/// This builder
/// Target TMP_Text
/// Target character index
/// Handle of the created motion data.
public static MotionHandle BindToTMPCharEulerAnglesXY(this MotionBuilder builder, TMP_Text text, int charIndex)
where TOptions : unmanaged, IMotionOptions
where TAdapter : unmanaged, IMotionAdapter
{
return builder.BindToTMPChar(text, charIndex, static (Vector2 x, int _, ref TMPMotionCharacter c) =>
{
var eulerAngles = c.Rotation.eulerAngles;
eulerAngles.x = x.x;
eulerAngles.y = x.y;
c.Rotation = Quaternion.Euler(eulerAngles);
});
}
///
/// Create motion data and bind it to the character rotation (using euler angles).
///
/// The type of special parameters given to the motion data
/// The type of adapter that support value animation
/// This builder
/// Target TMP_Text
/// Target character index
/// Handle of the created motion data.
public static MotionHandle BindToTMPCharEulerAnglesYZ(this MotionBuilder builder, TMP_Text text, int charIndex)
where TOptions : unmanaged, IMotionOptions
where TAdapter : unmanaged, IMotionAdapter
{
return builder.BindToTMPChar(text, charIndex, static (Vector2 x, int _, ref TMPMotionCharacter c) =>
{
var eulerAngles = c.Rotation.eulerAngles;
eulerAngles.y = x.x;
eulerAngles.z = x.y;
c.Rotation = Quaternion.Euler(eulerAngles);
});
}
///
/// Create motion data and bind it to the character rotation (using euler angles).
///
/// The type of special parameters given to the motion data
/// The type of adapter that support value animation
/// This builder
/// Target TMP_Text
/// Target character index
/// Handle of the created motion data.
public static MotionHandle BindToTMPCharEulerAnglesXZ(this MotionBuilder builder, TMP_Text text, int charIndex)
where TOptions : unmanaged, IMotionOptions
where TAdapter : unmanaged, IMotionAdapter
{
return builder.BindToTMPChar(text, charIndex, static (Vector2 x, int _, ref TMPMotionCharacter c) =>
{
var eulerAngles = c.Rotation.eulerAngles;
eulerAngles.x = x.x;
eulerAngles.z = x.y;
c.Rotation = Quaternion.Euler(eulerAngles);
});
}
///
/// Create motion data and bind it to the character scale.
///
/// The type of special parameters given to the motion data
/// The type of adapter that support value animation
/// This builder
/// Target TMP_Text
/// Target character index
/// Handle of the created motion data.
public static MotionHandle BindToTMPCharScale(this MotionBuilder builder, TMP_Text text, int charIndex)
where TOptions : unmanaged, IMotionOptions
where TAdapter : unmanaged, IMotionAdapter
{
return builder.BindToTMPChar(text, charIndex, static (Vector3 x, int _, ref TMPMotionCharacter c) =>
{
c.Scale = x;
});
}
///
/// Create motion data and bind it to the character scale.x.
///
/// The type of special parameters given to the motion data
/// The type of adapter that support value animation
/// This builder
/// Target TMP_Text
/// Target character index
/// Handle of the created motion data.
public static MotionHandle BindToTMPCharScaleX(this MotionBuilder builder, TMP_Text text, int charIndex)
where TOptions : unmanaged, IMotionOptions
where TAdapter : unmanaged, IMotionAdapter
{
return builder.BindToTMPChar(text, charIndex, static (float x, int _, ref TMPMotionCharacter c) =>
{
c.Scale.x = x;
});
}
///
/// Create motion data and bind it to the character scale.y.
///
/// The type of special parameters given to the motion data
/// The type of adapter that support value animation
/// This builder
/// Target TMP_Text
/// Target character index
/// Handle of the created motion data.
public static MotionHandle BindToTMPCharScaleY(this MotionBuilder builder, TMP_Text text, int charIndex)
where TOptions : unmanaged, IMotionOptions
where TAdapter : unmanaged, IMotionAdapter
{
return builder.BindToTMPChar(text, charIndex, static (float x, int _, ref TMPMotionCharacter c) =>
{
c.Scale.y = x;
});
}
///
/// Create motion data and bind it to the character scale.z.
///
/// The type of special parameters given to the motion data
/// The type of adapter that support value animation
/// This builder
/// Target TMP_Text
/// Target character index
/// Handle of the created motion data.
public static MotionHandle BindToTMPCharScaleZ(this MotionBuilder builder, TMP_Text text, int charIndex)
where TOptions : unmanaged, IMotionOptions
where TAdapter : unmanaged, IMotionAdapter
{
return builder.BindToTMPChar(text, charIndex, static (float x, int _, ref TMPMotionCharacter c) =>
{
c.Scale.z = x;
});
}
///
/// Create motion data and bind it to the character scale.xy.
///
/// The type of special parameters given to the motion data
/// The type of adapter that support value animation
/// This builder
/// Target TMP_Text
/// Target character index
public static MotionHandle BindToTMPCharScaleXY(this MotionBuilder builder, TMP_Text text, int charIndex)
where TOptions : unmanaged, IMotionOptions
where TAdapter : unmanaged, IMotionAdapter
{
return builder.BindToTMPChar(text, charIndex, static (Vector2 x, int _, ref TMPMotionCharacter c) =>
{
c.Scale.x = x.x;
c.Scale.y = x.y;
});
}
///
/// Create motion data and bind it to the character scale.yz.
///
/// The type of special parameters given to the motion data
/// The type of adapter that support value animation
/// This builder
/// Target TMP_Text
/// Target character index
public static MotionHandle BindToTMPCharScaleYZ(this MotionBuilder builder, TMP_Text text, int charIndex)
where TOptions : unmanaged, IMotionOptions
where TAdapter : unmanaged, IMotionAdapter
{
return builder.BindToTMPChar(text, charIndex, static (Vector2 x, int _, ref TMPMotionCharacter c) =>
{
c.Scale.y = x.x;
c.Scale.z = x.y;
});
}
///
/// Create motion data and bind it to the character scale.xz.
///
/// The type of special parameters given to the motion data
/// The type of adapter that support value animation
/// This builder
/// Target TMP_Text
/// Target character index
public static MotionHandle BindToTMPCharScaleXZ(this MotionBuilder builder, TMP_Text text, int charIndex)
where TOptions : unmanaged, IMotionOptions
where TAdapter : unmanaged, IMotionAdapter
{
return builder.BindToTMPChar(text, charIndex, static (Vector2 x, int _, ref TMPMotionCharacter c) =>
{
c.Scale.x = x.x;
c.Scale.z = x.y;
});
}
///
/// Create motion data and bind it to the character scale.xyz.
///
/// The type of special parameters given to the motion data
/// The type of adapter that support value animation
/// This builder
/// Target TMP_Text
/// Target character index
/// Handle of the created motion data.
public static MotionHandle BindToTMPCharScaleXYZ(this MotionBuilder builder, TMP_Text text, int charIndex)
where TOptions : unmanaged, IMotionOptions
where TAdapter : unmanaged, IMotionAdapter
{
return builder.BindToTMPChar(text, charIndex, static (float x, int _, ref TMPMotionCharacter c) =>
{
c.Scale = new Vector3(x, x, x);
});
}
}
}
#endif