Using DragonBones in Unity

I recently came across this Animation tool called DragonBones. Which looks very light and easy and compatible to unity using this Unity C# Plugin. Though the plugin is really lacking documentation, it comes up with a demo project which can give you an idea about how to use it. So here I am posting a easy guide here for get started with it fast.

Creating animation

First I created parts of my character as images. And then put them together in DragonBones with a bone structure. Then created few animations, such as Walk, Jump, Run etc.

Exporting for Unity

Dragonbones saves the project as a *.dbproj file. It can be exported to a compatible for for unity plugin.

Screen Shot 2017-07-08 at 5.34.47 PM

It creates 3 files. A *_tex.png file which contains texture atlas, a *_tex.json file which contains texture information and a *_ske.json file which contains the skeleton and animation information.

Setting up DragonBones Plugin for Unity

For setting up only the DragonBones & MiniJSON has to be imported into your unity project. i.e. Just copy the DragonBonesCSharp/Unity/Demos/Assets/Scripts/DragonBones folder into your unity project Asset folder.

Importing in Unity

Put the exported json and png files under Asset/Resources in your project. Open a scene in your project. Create a new empty object. Add new component to that object as “Unity Armature Component”.

Screen Shot 2017-07-08 at 5.52.29 PM.png

Select a your *_ske.json file as DragonBones Data. A Create button would appear. Pressing that would import the model and animations.

Screen Shot 2017-07-08 at 5.56.46 PM.png

Using Plugin for Animations

Animations can be easily handled from code by accessing the UnityArmatureComponent component. Attach your C# code to the same GameObject and try adding a code similar to the following code.

 UnityArmatureComponent armatureComponent = GetComponent<UnityArmatureComponent> ();
 armatureComponent.animation.FadeIn ("Walk", 0.25f, -1);

The default animation for my “Rama” character was “Idle”. This would make the a transition to “Walk” animation in 0.25 seconds, and loop in “Walk” animation infinitely (-1).

The GotoAndStopByProgress function can be used to control an animation frame by frame. Such as moving hand of the character according to mouse movement.

public void LoadArrow(float arrowLoadProgress) {
    armatureComponent.animation.GotoAndStopByProgress (loadArrowAnimation, arrowLoadProgress);
}

And the is a few more similar functions in the library. These can be mixed to create awesome animations. The following video shows result of a small implementation.

Just for information, I have used Unity 5.3 and DragonBones Pro 3.9.

Please leave your comments if you liked my post.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s