export async function asyncLoadDragonBoneAnime(node, skeJsonDataUrl, texJsonDataUrl, texPngDataUrl,times:number = 0) {

    if (!texPngDataUrl || !texJsonDataUrl || !texPngDataUrl
        || texPngDataUrl == '' || texJsonDataUrl == '' || texPngDataUrl == '') {
        return;
    }

    return new Promise((resolve, reject) => {
        if (node.animaNode) {
            node.animaNode.removeFromParent();
        }
        const animaNode = new cc.Node();
        animaNode.name = 'animaNode';
        animaNode.parent = node;
        animaNode.active = true;
        node.animaNode = animaNode;

        const dragonDisplay = animaNode.addComponent(dragonBones.ArmatureDisplay);

        const loadTexture = new Promise((resolve, reject) => {
            cc.assetManager.loadRemote(texPngDataUrl, (error, texture) => {
                if (error) {
                    reject(error);
                }
                resolve(texture);
            });
        });

        const loadTexJsonData = new Promise((resolve, reject) => {
            cc.assetManager.loadAny({ url: texJsonDataUrl }, (error, atlasJson) => {
                if (error) {
                    reject(error);
                }
                resolve(atlasJson);
            });
        });

        const loadSkeJsonData = new Promise((resolve, reject) => {
            cc.assetManager.loadAny({ url: skeJsonDataUrl }, (error, dragonBonesJson) => {
                if (error) {
                    reject(error);
                }
                resolve(dragonBonesJson);
            });
        });

        Promise.all([loadTexture, loadTexJsonData, loadSkeJsonData]).then(([texture, atlasJson, dragonBonesJson]) => {
            const atlas = new dragonBones.DragonBonesAtlasAsset();
            atlas.atlasJson = JSON.stringify(atlasJson);
            atlas.texture = texture;

            const asset = new dragonBones.DragonBonesAsset();
            asset.dragonBonesJson = JSON.stringify(dragonBonesJson);

            dragonDisplay.dragonAtlasAsset = atlas;
            dragonDisplay.dragonAsset = asset;

            let armatureNames = dragonBonesJson.armature.map(data => data.name);

            if (armatureNames.length > 0) {
                dragonDisplay.armatureName = armatureNames[0];
                dragonDisplay.playAnimation('newAnimation',times);
            }
            resolve(animaNode);
        });
    });
}