Unity has two ways to control animations: Animation (old) and Animator (new).
Previously the developer had no other option but to use the Animation component with basic controls for playing a simple animation. This Animation component would have been exactly what we needed, if not for the fact that it does not support sprite animations!
So, the only way to run sprite animations in Unity is to use the Animator.
It does have its perks. It makes it easier to tie together a complex set of animations by creating transition rules and triggers. And if you are working with skeletal animations, you can blend them seamlessly. But for our pixel-perfect 2D game none of that mattered and creating tons of animations this way was going to be a huge burden.
All animated objects would need to have an extra Animator Controller object, each animation would require an extra variable inside the controller just to be triggered to play. Even though these could be computationally generated with little extra work using our legacy data, it was going to make animation management a drag for the future. To make the development process as easy as possible, we needed a different solution.
After lots of pondering, we finally came to the conclusion that we needed to implement our own animation player that would process a set of frames and show them one after another for a predefined duration. This approach would also make it easy to use our game commands system with animations (More about it in another post)!
First we created a data structure for sprite animations and their frames, which was simple enough. Additionally we implemented a way to trigger commands during any frame, which allows for playing sounds, events, etc. in sync with the animation.
Then we created an animation player to process the animation frames in a given order, as well as controls for stopping, pausing and continuing the animation. Our character graphics controller made sure that there was only one animation playing for the given game object at any one time. The background animations were even simpler, as they just loop the same animation repeatedly.
After the compulsory minor issues to crack, all this eventually came together. Now we have a simple and easily modifiable solution for the need of creating and playing simple sprite animations.