龙骨官网
http://dragonbones.com/cn/index.html
unity 龙骨插件
https://github.com/DragonBones/DragonBoneToUnity
龙骨封装
private readonly string logoPath = "DB_Anim/";
public GameObject Play( string bonesData, string atlasData, string animation, int times = 1 ) {
TextAsset dragonText = Resources.Load(( this.logoPath + bonesData ),typeof(TextAsset)) as TextAsset;
TextAsset atlasText = Resources.Load(( this.logoPath + atlasData ), typeof(TextAsset) ) as TextAsset;
Texture2D texture = Resources.Load(( this.logoPath + atlasData ), typeof(Texture2D)) as Texture2D;
UnityFactory.factory.LoadDragonBonesData(dragonText);
UnityFactory.factory.LoadTextureAtlasData(atlasText, texture);
this.armatureComponent = UnityFactory.factory.BuildArmatureComponent("Armature");
this.armatureComponent.animation.Play(animation, times);
InvokeRepeating("ReleaseDragon", 3f, 1);
return this.armatureComponent.gameObject;
}
public void ReleaseDragon() {
if (this.armatureComponent == null) {
return;
}
if (!this.armatureComponent.animation.isPlaying) {
DestroyImmediate(this.armatureComponent.gameObject);
UnityFactory.factory.Clear();
this.armatureComponent = null;
}
}
参数解读:
string bonesData 龙骨的json数据
string atlasData 图集数据
string animation 动画数据名称。 (如果未设置,则播放默认动画,或将暂停状态切换为播放状态,或重新播放之前播放的动画)
int times 循环播放次数。 [-1: 使用动画数据默认值, 0: 无限循环播放, [1~N]: 循环播放 N 次] (默认: -1)
UnityFactory.factory.BuildArmatureComponent("Armature")
"Armature" 编辑器里骨架名称
FairyGUI:
GGraph gr = btn.GetChild("mask").asGraph;
GameObject go = PlayLocalPlatform("DB_ske", "DB_tex", "start", 0);
gr.SetNativeObject(new GoWrapper(go));
gr.SetScale(100, 100);
gr.SetXY(194f, 311f);
UGUI待测。。。
附:
在Unity中使用龙骨动画
终于回到正题了,首先在场景中创建一个DragonBones Armature Object, 导入龙骨的插件后可以在Hierarchy视图中右键看到DragonkBones这个选项,点击Armature Object
创建成功,选中这个Armature对象,查看Inspector视图
这个对象自带一个UnityArmatureComponent组件,这个组件下有一个叫做龙骨数据(DragonBonesData)的属性,我们刚刚导出到项目里的龙骨动画明明是三个文件,这要怎么办呢?
在Unity的文件管理器中找到我们导出的龙骨动画的三个文件,将三个文件选中,右键Create->DragonBones->Create Unity Date
龙骨动画相关链接