TimerSequenceParallel.md

May 23, 2024 · View on GitHub

Home | Life Cycle | Setter | Easing | Callbacks | Playback | Relative Values | ▸Timer, Sequence, and Parallel◂ | Anonymous Playback | Shared Assets | Batch Operations |

The Other Objects: Timer, Sequence, Parallel

The MotionKit has other objects that allow to build complex animation composites: Timer, Sequence and Parallel. These 3 objects and the Motion objects are referred to as Playback objects.

Here is a table of the 4 of them:

ObjectDescriptionFeatures
MotionAnimates any property.owner and reuseID, setter, easing, callbacks, playback methods
TimerWaits for a duration and then ends.owner and reuseID, callbacks, playback methods
SequencePlays the contained Playbacks in sequence.owner and reuseID, easing, callbacks, playback methods
ParallelPlays the contained Playbacks in parallel.owner and reuseID, easing, callbacks, playback methods

Example of a sequence:

Example of a Parallel:

Example of a more complex composite:

C#

Timer Example:

MotionKit.GetTimer(this, "SomeTimer").Play(5)
	.SetOnComplete(() => Debug.Log("Timer completed after 5 seconds"));

Sequence Example:

// The nested Motion objects will play one after the other.
MotionKit.GetSequence(this, "SomeSequence",
	MotionKit.GetMotion(this, "MoveBall", p => m_Ball.localPosition = p).SetValuesAndDuration(new Vector3(0, 0, 0), new Vector3(3, 0, 0), 2),
	MotionKit.GetMotion(this, "FadeInCanvas", a => m_CanvasRenderer.SetAlpha(a)).SetValuesAndDuration(0, 1, 2),
	MotionKit.GetTimer(this, "Pause").SetDuration(5), // Make a 5 seconds pause here
	MotionKit.GetMotion(this, "MakeRed", c => m_Image.color = c).SetValuesAndDuration(Color.black, Color.red, 2)
).SetEasing(MotionKitEasing.QuadInOut) // Easing will be applied to the sequence as a whole
.Play(); 

Parallel Example:

// The nested Motion objects will play starting at the same time.
MotionKit.GetParallel(this, "SomeParallel",
	MotionKit.GetMotion(this, "MoveBall", p => m_Ball.localPosition = p).SetValuesAndDuration(Vector3.zero, Vector3.right * 3, 2),
	MotionKit.GetMotion(this, "FadeInCanvas", a => m_CanvasRenderer.SetAlpha(a)).SetValuesAndDuration(0, 1, 2),
	MotionKit.GetMotion(this, "MakeRed", c => m_Image.color = c).SetValuesAndDuration(Color.black, Color.red, 2)
).SetEasing(MotionKitEasing.QuadInOut)
.Play();

Inspector

When creating nested MotionKit animations in the Unity inspector, there is no limit. You can create any composite structure that suits your animation needs. This is an example of an MotionKitComponent that has many nested MotionKitBlocks:

In the top area you will find a very powerful breadcrumb navigation system where you can go to any parent in the hierarchy and also choose any sibling of the currently selected MotionKitBlock.

In this example, we are seeing the editor of a ParallelBlock, which contain 7 child sequences. Whenever you click Edit on any of those, you'll navigate deeper in the hierarchy.

In the bottom part of the image, you can see a section called Batch Operations which are some editing actions that can be performed in all children MotionKitBlocks with one click. For example, setting an incremental duration. More documentation on this will come later!