Every motion needs a setter
to apply changes to the property that we want to animate. In our example, the setter is p => m_Ball.localPosition = p
, which will animate the position of the ball:
MotionKit.GetMotion(m_Ball, "Position", p => m_Ball.localPosition = p)
.Play(new Vector3(0, 0, 0), new Vector3(3, 0, 0), 2);
It is a lamba expression that receives a Vector3
parameter and then applies it as needed. It could also be a function, but it would need more lines of code:
MotionKit.GetMotion(m_Ball, "Position", SetPosition).Play(new Vector3(0, 0, 0), new Vector3(3, 0, 0), 2);
void SetPosition(Vector3 pos) {
m_Ball.localPosition = pos;
}
The MotionKit
API is designed so that depending on the provided setter it will internally choose among Motion3D
, MotionFloat
and MotionColor
. You don't have to worry about that. For example, the following code will create a MotionFloat
object:
MotionKit.GetMotion(m_CanvasRenderer, "Alpha", a => m_CanvasRenderer.SetAlpha(a)).Play(0, 1, 2);
An this one will create a MotionColor
:
MotionKit.GetMotion(m_Image, "Color", c => m_Image.color = c).Play(Color.black, Color.red, 2);
When using the MotionKitComponent
you do have to choose which motion to use, according to the property that you want to animate:
Note that there is a Motion2D
block that is only avaliable in the inspector version.
Once the MotionKitBlock
is created, you need to assign an object in the setter field, and then the inspector will allow you to choose among all properties and methods of that object that suits the type of MotionKitBlock
. In this example, all the listed methods and properties receive a Vector3
parameter: