If you have been having issues with skin management in Anima2D, you have found the right asset. As of today, I have not found a good solution to creating and loading skins for Anima characters on the fly, therefore, I decided to create one myself.
Anima Skin has 2 simple scripts to use:
- SkinManager: Attach this script to the root GameObject of your character.
- Skin: Attach this script to an empty GameObject as a child of your character.
The skin manager can be added to the root GameObject of the character. The manager has three visible variables:
- Current Skin: A copy of the currently set Skin.
- Skin Holder: Drag the GameObject that contains the "Skin" scripts. If you don't have / want one, leave it empty and the manager will try to find them.
- Skins: Is a list that will show the Skins identified by the manager in the object that you dragged above.
The following variables are public in the Skin Manager script instance:
- skins: The list of the current Skins.
- currentSkin: A copy of the currently set Skin.
- defSkin: The default Skin the character had when the scene started.
- skinHolder: The GameObject that contains the skins ( this is the field in the Editor we saw earlier ).
The Skin Manager has the following public functions (At the moment):
- RefreshSkins() : Refreshes the skins in the GameObject.
- RestoreBaseSkin(): Restores the character to the skin that it had when the scene started.
- LoadSkinByString(string skinName): Loads the skin with the name passed as a parameter. It will let you know if it couldn't find it. For better debugging, check the Skins list in the manager at runtime!
- LoadSkin(Skin skinToSet): Loads the skin passed as a parameter. You can use this to create Skins at runetime and set them to the character. Wow!
- SearchSkin(string skinName): Searches the skin, with the name passed as a parameter, and returns the index of it in the skins list in the Skin Manager, it will return " -1 " if it can't find it.
The skin component will be used to create the skins for the character. It has the following visible fields in the Editor:
- Skin Name: The name of the skin as a string, it will be used to load them with the Skin Manager. Do NOT REPEAT NAMES, or it won't work.
- Skin Parts: A list with references to the Sprite Mesh Instances of the character (or other object). The SpriteMesh field will determine what Sprite Mesh is loaded to the body part determined by the instance on the left. Pretty easy right?
You can add multiple Sprite Mesh Instance references to the Skin Manager by selecting the parent object that contains the Skins in the editor, then press the "+" button in the list and click on "From Selection". This will add references to all the Sprite Mesh Instances found as children of the object selected. What a great feature!