#if LITMOTION_SUPPORT_PHYSICS_2D using UnityEngine; namespace LitMotion.Extensions { public static class LitMotionRigidbody2DExtensions { /// /// Create a motion data and bind it to Rigidbody2D.position /// /// The type of special parameters given to the motion data /// The type of adapter that support value animation /// This builder /// Target component /// Whether to use rigidbody2d.MovePosition() /// Handle of the created motion data. public static MotionHandle BindToPosition(this MotionBuilder builder, Rigidbody2D rigidbody2d, bool useMovePosition = true) where TOptions : unmanaged, IMotionOptions where TAdapter : unmanaged, IMotionAdapter { Error.IsNull(rigidbody2d); if (useMovePosition) { return builder.Bind(rigidbody2d, static (x, rigidbody2d) => { rigidbody2d.MovePosition(x); }); } else { return builder.Bind(rigidbody2d, static (x, rigidbody2d) => { rigidbody2d.position = x; }); } } /// /// Create a motion data and bind it to Rigidbody2D.position.x /// /// The type of special parameters given to the motion data /// The type of adapter that support value animation /// This builder /// Target component /// Whether to use rigidbody2d.MovePosition() /// Handle of the created motion data. public static MotionHandle BindToPositionX(this MotionBuilder builder, Rigidbody2D rigidbody2d, bool useMovePosition = true) where TOptions : unmanaged, IMotionOptions where TAdapter : unmanaged, IMotionAdapter { Error.IsNull(rigidbody2d); if (useMovePosition) { return builder.Bind(rigidbody2d, static (x, rigidbody2d) => { var p = rigidbody2d.position; p.x = x; rigidbody2d.MovePosition(p); }); } else { return builder.Bind(rigidbody2d, static (x, rigidbody2d) => { var p = rigidbody2d.position; p.x = x; rigidbody2d.position = p; }); } } /// /// Create a motion data and bind it to Rigidbody2D.position.y /// /// The type of special parameters given to the motion data /// The type of adapter that support value animation /// This builder /// Target component /// Whether to use rigidbody2d.MovePosition() /// Handle of the created motion data. public static MotionHandle BindToPositionY(this MotionBuilder builder, Rigidbody2D rigidbody2d, bool useMovePosition = true) where TOptions : unmanaged, IMotionOptions where TAdapter : unmanaged, IMotionAdapter { Error.IsNull(rigidbody2d); if (useMovePosition) { return builder.Bind(rigidbody2d, static (y, rigidbody2d) => { var p = rigidbody2d.position; p.y = y; rigidbody2d.MovePosition(p); }); } else { return builder.Bind(rigidbody2d, static (y, rigidbody2d) => { var p = rigidbody2d.position; p.y = y; rigidbody2d.position = p; }); } } /// /// Create a motion data and bind it to Rigidbody2D.rotation /// /// The type of special parameters given to the motion data /// The type of adapter that support value animation /// This builder /// Target component /// Whether to use rigidbody2d.MoveRotation() /// Handle of the created motion data. public static MotionHandle BindToRotation(this MotionBuilder builder, Rigidbody2D rigidbody2d, bool useMovePosition = true) where TOptions : unmanaged, IMotionOptions where TAdapter : unmanaged, IMotionAdapter { Error.IsNull(rigidbody2d); if (useMovePosition) { return builder.Bind(rigidbody2d, static (x, rigidbody2d) => { rigidbody2d.MoveRotation(x); }); } else { return builder.Bind(rigidbody2d, static (x, rigidbody2d) => { rigidbody2d.rotation = x; }); } } } } #endif