Tuesday, October 18, 2022
HomeGame DevelopmentConstruct Extension, Catch Construct Fail - Cocos Creator

Construct Extension, Catch Construct Fail – Cocos Creator


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

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

Looking 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 immediately via right here immediately

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 knowledge: { [path: string]: { contents: string; meta: string } } = {};

async operate take away(path: string): Promise<{ contents: string; meta: string }> {
    let full_path = path.change('db://', Editor.Mission.path + "https://talk about.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 operate create(path: string, knowledge: { contents: string; meta: string }) {
    console.log(`create the ${path}`);
    let full_path = path.change('db://', Editor.Mission.path + "https://talk about.cocos2d-x.org/");
    await Editor.Message.request('asset-db', 'create-asset', path, knowledge.contents);
    fs.writeFileSync(full_path + '.meta', knowledge.meta);
}

export async operate onBeforeBuild(choices) {
    knowledge = {};
    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.change('db://', Editor.Mission.path + "https://talk about.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);
        knowledge[path] = contents;
    }
}

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

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

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

that is full hooks code

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments