The MSCA is a product of my need to find a way to animate the ManaSeed Character Base.
It has a huge amount of different animations and there even are combat animation expansions for it. The process of creating each single animation for each direction per hand, setting it into the animcontroller and keeping the layers provided by Seliel was a HUGE amount of work. So i wanted to have a way to „just create them per one click“.
It took some time to work out how and where to do what. Since i still wanted to be able to let the player swap outfits and stuff like hats during runtime (yeah why keep a low profile???) i needed some way to swap textures… keeping the animations intact, inside these tons of animController…
I wanted a system where i could change an animation timing at one point and it would change all animations and controller on each layer. Since i love ManaSeed and think this problem may be there for others too, i thought about creating an editor and example for others to use too.
If you don’t want to buy the MSCA you can use the ideas i provide in this explanations to create you own system.
The following problems were to be solved:
- How to create the animations from code
- How to create the animationController from code, so you don’t have to have to create and maintain one for each layer
- How to swap textures
Actually 3 and 1 are more connected than i thought at first. A huge hurdle was my first idea: how to change the used sprite in an animation during runtime?
I searched a bit but wasn’t able to find a really good and practicable solution, so i searched for another way.
It is fairly easy to swap textures during runtime in unity… so you cannot change the used sprites in the animation but you can change the texture itself the sprite uses that is used in an animation.
So the solution was to create empty textures, the animations use for the character and then set the correct pixeld in the used texture.
Notice: I won’t post my exact code here just the way how i do it in the MSCA
Now back to:
1. How to create animations from code
What needs to be done:
- Create a fresh animation clip (AnimationClip)
- Create the sprite binding (EditorCurveBinding) with propertyName „m_Sprite“
- If you want to swap Layers, create a second sprite binding (EditorCurveBinding) with propertyName „m_SortingOrder“
- The use the AnimationUtility to set the ObjectReferenceCurve
- and for Layer Swapping SetEditorCurve
The animation is stored to the folders and subfolders of the animation folder set in the editor
The data like name, keys, keyTimer and such are provided by the scriptableObjects i created for the MSCA
Best friend: the AssetDatabase with CreateAsset, SaveAssets and Refresh
2. How to create the animationController from code, so you don’t have to have to create and maintain one for each layer
What needs to be done:
- Create one base animationController that will be used for each layer
- Name the states correctly: they need to be named like this: animType + animName from the scriptableObject Settings (Example: ClimbUp or WalkDown)
- The MSCA then uses the provided base AnimController to:
- Copy the base animController to a folder structure beneath the folder provided in the editor
- For each layer in the animationLayers of the MSCA it loads the animController for the layer and the corresponding animClips
- then works through the anim controller and the states in it and sets the animClip in the state to: layerName + stateName
- If there is a Player Prefab provided it searchs through the playerPrefab and sets the animController if there is a controller with the name of the layer (subobject of the player)
3. How to swap textures
Now the Player Prefab has all the animations and the animcontroller set, now you „only“ need to swap textures
in the provided Player Class you can set the textures to use on start the textures will be set
For each Layer and provided Texture you need:
- the texture basePath
- explode the texte name itself so you can get the subpaths for all the sprite pages out of it
- load the textures for each sprite page
- set the pixels on the corresponding sprite page used by the animations and created in the MSCA
If you want to really know how it is done you need to get the MSCA and look into the scripts itself.