Saturday, October 22, 2022
HomeGame DevelopmentConstruct Extension, Catch Construct Fail - Cocos Creator

Construct Extension, Catch Construct Fail – Cocos Creator


Hiya, I’m a Korean developer.
I created a plug-in that makes use of construct extensions to erase information when constructing a challenge after which restore them to their authentic state after the construct is full.

My drawback is, my plug-in works completely, but when the construct fails, I gained’t return the information I deleted.

Shopping the doc doesn’t present a method to deal with the construct failure.

What ought to I do?


my cocos creator model is 3.6.1

i can’t discovered onError callback

image
cocos-build-template.zip (219.4 KB)
I created the plugin instantly by way of right here instantly

yeah i do know, however, I clicked this button to create a plug-in, however there’s nonetheless no onError within the BuildHook namespace

Are you able to share a part of the code to see the place issues are tousled?

Hooks.ts

import * as fs from 'fs';

let information: { [path: string]: { contents: string; meta: string } } = {};

async perform take away(path: string): Promise<{ contents: string; meta: string }> {
    let full_path = path.exchange('db://', Editor.Undertaking.path + "https://focus on.cocos2d-x.org/");
    let str = fs.readFileSync(full_path, { encoding: 'utf8' });
    let str_meta = fs.readFileSync(full_path + '.meta', { encoding: 'utf8' });
    console.log(`take away the ${path}`);
    await Editor.Message.request('asset-db', 'delete-asset', path);

    return { contents: str, meta: str_meta };
}

async perform create(path: string, information: { contents: string; meta: string }) {
    console.log(`create the ${path}`);
    let full_path = path.exchange('db://', Editor.Undertaking.path + "https://focus on.cocos2d-x.org/");
    await Editor.Message.request('asset-db', 'create-asset', path, information.contents);
    fs.writeFileSync(full_path + '.meta', information.meta);
}

export async perform onBeforeBuild(choices) {
    information = {};
    let pack = choices['packages'] || {};
    let module = pack['build-ignore-files'] || {};
    let record = (module['ignoreList'] || '').break up(';');

    for (let path of record) {
        let exist_search_path = path.exchange('db://', Editor.Undertaking.path + "https://focus on.cocos2d-x.org/");
        let is_exist = path !== '' && fs.existsSync(exist_search_path);
        console.log(path + ' is exist : ' + is_exist.toString());
        if (!is_exist) {
            proceed;
        }
        let contents = await take away(path);
        information[path] = contents;
    }
}

export async perform onAfterBuildAssets(choices) {
    for (let path in information) {
        await create(path, information[path]);
    }
}

export perform load() {
    console.log('build-ignore-files load');
}

export perform unload() {
    console.log('build-ignore-files unload');
}

that is full hooks code


You may verify if the content material of the template file underneath the engine path is appropriate first

Oops… Im so sorry…

I believed I used to be utilizing model 3.6.1 till now, however the model I’m utilizing was model 3.5.0

I upgraded the challenge to model 3.6.0 and there’s an onError in BuildHook.

I solved my drawback utilizing this. Thanks a lot

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments