Architectural help for 2D sprite-layered animations, re: customizable characters
I am working on a 2D pixel-art-style RPG, where the player must be able to customize their character's appearance to some degree and equip different pieces of armor. I have a very rough idea of how I think I will need to implement this, but I'm really struggling to put it all together. I would appreciate any help along these lines!
What I am trying to accomplish (for now) are Up, Down, and Left/Right Idle and Walking animations for a character made up of the following layered sprites (top to bottom):
Helmet/Hat (armor)
Hair
Facial hair
Head
Shoulders (armor)
Sleeves/Gloves (armor)
Arms
Pants/Boots (armor)
Breastplate (armor)
Torso/Legs
I've already made test assets and got them working in Unity as layered single Sprites, but I'm not sure how to go about animating them. I'm imagining I'll need to create separate animation spritesheets for each layer of each animation, but can I sync all of these spritesheets to the same Animation Clip in Unity? Would layering 10 spritesheet animations on top of each other like this be performant? And how to make each piece in the layer interchangeable?
I don't necessarily need a full source code tutorial or anything, but mainly just some broad architectural advice/suggestions for how to organize my code and files, what sort of classes I'll need and how to tie them all together, etc. I realize this is the "hard part" of programming and I am basically asking you to do my work for me, but I'm very new to OOP, so I could really use some help wrapping my brain around some of these concepts!
Answer by dannymcgee · Jan 15, 2017 at 09:09 PM
Figured I would post an update on my progress!
The first thing I tried was using a single Animator/Controller on the Character, which controlled SpriteRenderers on separate GameObjects childed to the Character. This worked, but I couldn't find a satisfactory way to dynamically swap out the child objects and have the animator start using the new sprites.
So, I got rid of the Character's Animator/Controller, and created a new Animator/Controller and set of clips for each child object. Also attached to each of the child objects is a custom CharacterComponent script, which currently just provides an easy interface for controlling the animations. So the end result is that when the Character needs to switch animations, it does so by looping through each of the child CharacterComponents and calling a method. So I can now mix and match CharacterComponents and they'll all animate in sync, using their respective spritesheets. I did see a slight performance drop after switching to separate Animators, but so far it seems manageable.