using UnityEngine;
namespace LitMotion.Extensions
{
///
/// Provides binding extension methods for Material.
///
public static class LitMotionMaterialExtensions
{
///
/// Create a motion data and bind it to a material property.
///
/// 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 BindToMaterialFloat(this MotionBuilder builder, Material material, string name)
where TOptions : unmanaged, IMotionOptions
where TAdapter : unmanaged, IMotionAdapter
{
Error.IsNull(material);
return builder.Bind(material, name, static (x, material, name) =>
{
material.SetFloat(name, x);
});
}
///
/// Create a motion data and bind it to a material property.
///
/// 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 BindToMaterialFloat(this MotionBuilder builder, Material material, int nameID)
where TOptions : unmanaged, IMotionOptions
where TAdapter : unmanaged, IMotionAdapter
{
Error.IsNull(material);
return builder.Bind(material, Box.Create(nameID), static (x, material, nameID) =>
{
material.SetFloat(nameID.Value, x);
});
}
///
/// Create a motion data and bind it to a material property.
///
/// 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 BindToMaterialInt(this MotionBuilder builder, Material material, string name)
where TOptions : unmanaged, IMotionOptions
where TAdapter : unmanaged, IMotionAdapter
{
Error.IsNull(material);
return builder.Bind(material, name, static (x, material, name) =>
{
material.SetInteger(name, x);
});
}
///
/// Create a motion data and bind it to a material property.
///
/// 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 BindToMaterialInt(this MotionBuilder builder, Material material, int nameID)
where TOptions : unmanaged, IMotionOptions
where TAdapter : unmanaged, IMotionAdapter
{
Error.IsNull(material);
return builder.Bind(material, Box.Create(nameID), static (x, material, nameID) =>
{
material.SetInteger(nameID.Value, x);
});
}
///
/// Create a motion data and bind it to a material property.
///
/// 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 BindToMaterialColor(this MotionBuilder builder, Material material, string name)
where TOptions : unmanaged, IMotionOptions
where TAdapter : unmanaged, IMotionAdapter
{
Error.IsNull(material);
return builder.Bind(material, name, static (x, material, name) =>
{
material.SetColor(name, x);
});
}
///
/// Create a motion data and bind it to a material property.
///
/// 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 BindToMaterialColor(this MotionBuilder builder, Material material, int nameID)
where TOptions : unmanaged, IMotionOptions
where TAdapter : unmanaged, IMotionAdapter
{
Error.IsNull(material);
return builder.Bind(material, Box.Create(nameID), static (x, material, nameID) =>
{
material.SetColor(nameID.Value, x);
});
}
}
}