#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.BindWithState(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.BindWithState(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.BindWithState(text, static (x, target) =>
{
target.maxVisibleLines = 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.BindWithState(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.BindWithState(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.BindWithState(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.BindWithState(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.BindWithState(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.BindWithState(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.BindWithState(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.BindWithState(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.BindWithState(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.BindWithState(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.BindWithState(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.BindWithState(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.BindWithState(text, format, static (x, target, format) =>
{
#if LITMOTION_SUPPORT_ZSTRING
target.SetTextFormat(format, x);
#else
target.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.BindWithState(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.BindWithState(text, format, static (x, target, format) =>
{
#if LITMOTION_SUPPORT_ZSTRING
target.SetTextFormat(format, x);
#else
target.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.BindWithState(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.BindWithState(text, format, static (x, target, format) =>
{
#if LITMOTION_SUPPORT_ZSTRING
target.SetTextFormat(format, x);
#else
target.text = string.Format(format, x);
#endif
});
}
///
/// 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
{
Error.IsNull(text);
var animator = TextMeshProMotionAnimator.Get(text);
animator.EnsureCapacity(charIndex + 1);
var handle = builder.BindWithState(animator, (x, target) =>
{
animator.charInfoArray[charIndex].color = x;
});
animator.motionHandleList.Add(handle);
return handle;
}
///
/// 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
{
Error.IsNull(text);
var animator = TextMeshProMotionAnimator.Get(text);
animator.EnsureCapacity(charIndex + 1);
var handle = builder.BindWithState(animator, (x, target) =>
{
animator.charInfoArray[charIndex].color.r = x;
});
animator.motionHandleList.Add(handle);
return handle;
}
///
/// 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
{
Error.IsNull(text);
var animator = TextMeshProMotionAnimator.Get(text);
animator.EnsureCapacity(charIndex + 1);
var handle = builder.BindWithState(animator, (x, target) =>
{
animator.charInfoArray[charIndex].color.g = x;
});
animator.motionHandleList.Add(handle);
return handle;
}
///
/// 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
{
Error.IsNull(text);
var animator = TextMeshProMotionAnimator.Get(text);
animator.EnsureCapacity(charIndex + 1);
var handle = builder.BindWithState(animator, (x, target) =>
{
animator.charInfoArray[charIndex].color.b = x;
});
animator.motionHandleList.Add(handle);
return handle;
}
///
/// 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
{
Error.IsNull(text);
var animator = TextMeshProMotionAnimator.Get(text);
animator.EnsureCapacity(charIndex + 1);
var handle = builder.BindWithState(animator, (x, target) =>
{
animator.charInfoArray[charIndex].color.a = x;
});
animator.motionHandleList.Add(handle);
return handle;
}
///
/// 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
{
Error.IsNull(text);
var animator = TextMeshProMotionAnimator.Get(text);
animator.EnsureCapacity(charIndex + 1);
var handle = builder.BindWithState(animator, (x, target) =>
{
animator.charInfoArray[charIndex].position = x;
});
animator.motionHandleList.Add(handle);
return handle;
}
///
/// 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
{
Error.IsNull(text);
var animator = TextMeshProMotionAnimator.Get(text);
animator.EnsureCapacity(charIndex + 1);
var handle = builder.BindWithState(animator, (x, target) =>
{
animator.charInfoArray[charIndex].position.x = x;
});
animator.motionHandleList.Add(handle);
return handle;
}
///
/// 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
{
Error.IsNull(text);
var animator = TextMeshProMotionAnimator.Get(text);
animator.EnsureCapacity(charIndex + 1);
var handle = builder.BindWithState(animator, (x, target) =>
{
animator.charInfoArray[charIndex].position.y = x;
});
animator.motionHandleList.Add(handle);
return handle;
}
///
/// 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
{
Error.IsNull(text);
var animator = TextMeshProMotionAnimator.Get(text);
animator.EnsureCapacity(charIndex + 1);
var handle = builder.BindWithState(animator, (x, target) =>
{
animator.charInfoArray[charIndex].position.z = x;
});
animator.motionHandleList.Add(handle);
return handle;
}
///
/// 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
{
Error.IsNull(text);
var animator = TextMeshProMotionAnimator.Get(text);
animator.EnsureCapacity(charIndex + 1);
var handle = builder.BindWithState(animator, (x, target) =>
{
animator.charInfoArray[charIndex].rotation = x;
});
animator.motionHandleList.Add(handle);
return handle;
}
///
/// 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
{
Error.IsNull(text);
var animator = TextMeshProMotionAnimator.Get(text);
animator.EnsureCapacity(charIndex + 1);
var handle = builder.BindWithState(animator, (x, target) =>
{
animator.charInfoArray[charIndex].rotation = Quaternion.Euler(x);
});
animator.motionHandleList.Add(handle);
return handle;
}
///
/// 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
{
Error.IsNull(text);
var animator = TextMeshProMotionAnimator.Get(text);
animator.EnsureCapacity(charIndex + 1);
var handle = builder.BindWithState(animator, (x, target) =>
{
var eulerAngles = animator.charInfoArray[charIndex].rotation.eulerAngles;
eulerAngles.x = x;
animator.charInfoArray[charIndex].rotation = Quaternion.Euler(eulerAngles);
});
animator.motionHandleList.Add(handle);
return handle;
}
///
/// 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
{
Error.IsNull(text);
var animator = TextMeshProMotionAnimator.Get(text);
animator.EnsureCapacity(charIndex + 1);
var handle = builder.BindWithState(animator, (x, target) =>
{
var eulerAngles = animator.charInfoArray[charIndex].rotation.eulerAngles;
eulerAngles.y = x;
animator.charInfoArray[charIndex].rotation = Quaternion.Euler(eulerAngles);
});
animator.motionHandleList.Add(handle);
return handle;
}
///
/// 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
{
Error.IsNull(text);
var animator = TextMeshProMotionAnimator.Get(text);
animator.EnsureCapacity(charIndex + 1);
var handle = builder.BindWithState(animator, (x, target) =>
{
var eulerAngles = animator.charInfoArray[charIndex].rotation.eulerAngles;
eulerAngles.z = x;
animator.charInfoArray[charIndex].rotation = Quaternion.Euler(eulerAngles);
});
animator.motionHandleList.Add(handle);
return handle;
}
///
/// 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
{
Error.IsNull(text);
var animator = TextMeshProMotionAnimator.Get(text);
animator.EnsureCapacity(charIndex + 1);
var handle = builder.BindWithState(animator, (x, target) =>
{
animator.charInfoArray[charIndex].scale = x;
});
animator.motionHandleList.Add(handle);
return handle;
}
///
/// 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
{
Error.IsNull(text);
var animator = TextMeshProMotionAnimator.Get(text);
animator.EnsureCapacity(charIndex + 1);
var handle = builder.BindWithState(animator, (x, target) =>
{
animator.charInfoArray[charIndex].scale.x = x;
});
animator.motionHandleList.Add(handle);
return handle;
}
///
/// 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
{
Error.IsNull(text);
var animator = TextMeshProMotionAnimator.Get(text);
animator.EnsureCapacity(charIndex + 1);
var handle = builder.BindWithState(animator, (x, target) =>
{
animator.charInfoArray[charIndex].scale.y = x;
});
animator.motionHandleList.Add(handle);
return handle;
}
///
/// 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
{
Error.IsNull(text);
var animator = TextMeshProMotionAnimator.Get(text);
animator.EnsureCapacity(charIndex + 1);
var handle = builder.BindWithState(animator, (x, target) =>
{
animator.charInfoArray[charIndex].scale.z = x;
});
animator.motionHandleList.Add(handle);
return handle;
}
}
}
#endif