请问怎么导出eventemitter3给Cocos Creator 3.0做插件用? #11
Unanswered
lostsailboard
asked this question in
Q&A
Replies: 1 comment 1 reply
-
//index.ts import * as Emitter3 from "eventemitter3"
import {
EventArgs, EventListener, EventNames,
ValidEventTypes, ArgumentMap, ListenerFn,
EventEmitterStatic,
EventEmitter,
} from "eventemitter3";
const EventEmitter3 = Emitter3.default;
export {
EventEmitter3,
EventArgs,
EventListener,
EventNames,
ValidEventTypes,
ArgumentMap,
ListenerFn,
EventEmitterStatic,
}; 在使用的时候,需要安装npm i eventemitter3 (获得类型提示),但在使用的时候,不要引入任何这个包的类型提示 // Learn TypeScript:
// - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
// - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
// - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
import { ArgumentMap, EventEmitter3, EventNames } from '@ailhc/emitter3';
import { _decorator, Component, Node } from 'cc';
const { ccclass, property } = _decorator;
@ccclass('TestEmitter3')
export class TestEmitter3 extends Component {
/* class member could be defined like this */
// dummy = '';
/* use `property` decorator if your want the member to be serializable */
// @property
// serializableDummy = 0;
start() {
const emitter3 = new EventEmitter3();
emitter3.addListener("haha", function (arg) {
console.log("haha");
})
emitter3.emit("haha");
}
// update (deltaTime: number) {
// // Your update function goes here.
// }
}
如果觉得好用,其实这个库,不需要这么麻烦的。
解决方案2:
将npm包里的umd文件夹的文件拿出,设置为全局的插件
然后修改index.d.ts的声明为全局声明,去掉export之类的
如果觉得好用,可以给个star哦 |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
在index.ts里写export * from 'eventemitter3'会报错,请问应该怎么导出?
链接: https://pan.baidu.com/s/15th-VeS5pO4a3oT32MVTMw
提取码: cc75
这里是我要导出的例子
Beta Was this translation helpful? Give feedback.
All reactions