import { Action } from "./Action"; import { ActionWithType } from "./ActionWithType"; import { ActionWithType2 } from "./ActionWithType2"; const {ccclass, property} = cc._decorator; enum CustomType { Ex1, Ex2 } class CustomEvent extends ActionWithType {} class CustomEvent2 extends ActionWithType2 {} @ccclass export default class NewClass extends cc.Component { callback: Action = new Action(); customCallback: CustomEvent = new CustomEvent(); customCallback2: CustomEvent2 = new CustomEvent2(); private num: number = 0; start () { this.callback.AddCallback(this.CB, this); this.callback.AddCallbackOnce(this.OnceCB, this); this.customCallback.AddCallback(CustomType.Ex1, this.CBType, this); this.customCallback.AddCallbackOnce(CustomType.Ex2, this.OnceCBType, this); this.customCallback2.AddCallback(CustomType.Ex2, this.CBTypeAllin1, this); this.customCallback2.AddCallbackOnce(CustomType.Ex1, this.CBTypeAllin1, this); } DispatchClick() { this.num++; this.callback.DispatchCallback(this.num); this.customCallback.DispatchCallback(CustomType.Ex1, this.num); this.customCallback.DispatchCallback(CustomType.Ex2, this.num); this.customCallback2.DispatchCallback(CustomType.Ex1, this.num); this.customCallback2.DispatchCallback(CustomType.Ex2, this.num); } RemoveEventClick() { this.callback.RemoveByCallback(this.CB); // this.callback.RemoveByCallback(this.OnceCB); // this.callback.RemoveByBindTarget(this); // this.callback.RemoveAll(); // this.callbackWithType.RemoveByCallback(this.CBType); // this.callbackWithType.RemoveByCallback(this.OnceCBType); this.customCallback.RemoveByType(CustomType.Ex1); // this.callbackWithType.RemoveByType(CustomType.Ex2); // this.callbackWithType.RemoveByBindTarget(this); // this.callbackWithType.RemoveAll(); } OnceCB(x: number) { cc.log(`OnceCB [${this.num}]`); } CB(x: number) { cc.log(`CB [${this.num}]`); } OnceCBType(x: number) { cc.log(`OnceCBType [${this.num}]`); } CBType(x: number) { cc.log(`CBType [${this.num}]`); } CBTypeAllin1(type: CustomType,x: number) { // switch (type) { // case CustomType.Ex1: // break; // case CustomType.Ex2: // break; // } cc.log(`CBTypeAllin1 [${CustomType[type]}][${this.num}]`); } }