1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- // Learn TypeScript:
- // - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
- // Learn Attribute:
- // - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
- // Learn life-cycle callbacks:
- // - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html
- import { PopType } from "../EventName/EventName";
- const { ccclass, property } = cc._decorator;
- @ccclass
- export default class MyComponent extends cc.Component {
- _eventMap = [];
- onLoad() {
- // super.onLoad();
- this.devicesFit();
- this.ClickAnyClose()
- }
- //注册事件
- regEvent(type, callback, target = null, once = null) {
- cc.systemEvent.on(type, callback, target, once);
- this._eventMap.push({
- type: type,
- callback: callback,
- target: target,
- once: once
- });
- }
- regEventOnce(type, callback, target = null) {
- cc.systemEvent.once(type, callback, target);
- this._eventMap.push({
- type: type,
- callback: callback,
- target: target,
- once: null
- });
- }
- // 机型适配 子类重载
- devicesFit() {
- }
- onDestroy() {
- // super.onDestroy();
- for (let i = 0; i < this._eventMap.length; i++) {
- let data = this._eventMap[i];
- cc.systemEvent.off(data.type, data.callback, data.target);
- }
- delete this._eventMap;
- this.unscheduleAllCallbacks();
- }
- Pop(_PopType: PopType) {
- const url = "Pop/Pop"
- cc.resources.load(url, cc.Prefab, (err, Prefab) => {
- if (err) {
- return
- }
- let a = cc.instantiate(Prefab);
- a.parent = cc.Canvas.instance.node
- a.active = true
- let Title = a.getChildByName("Title").getComponent(cc.Label)
- let Label = a.getChildByName("Label").getComponent(cc.Label)
- Title.string = _PopType.Title
- Label.string = _PopType.string
- let no = a.getChildByName("no button")
- let yes = a.getChildByName("yes button")
- //添加点击事件
- no.on('touchstart', () => {
- _PopType.Fail()
- a.destroy()
- })
- //添加点击事件
- yes.on('touchstart', () => {
- _PopType.OK()
- a.destroy()
- })
- });
- }
- ClickAnyClose() {
- let Mask = this.node.getChildByName("Mask")
- Mask?.on('touchstart', () => {
- this.node.destroy()
- })
- }
- }
|