[add] Array<cc.Component.EventHandler> AddListener
This commit is contained in:
@@ -113,6 +113,7 @@ export class Badminton extends cc.Component {
|
||||
//#region 初始化
|
||||
|
||||
protected onLoad(): void {
|
||||
// this.node.getChildByName("Test").getComponent(HoldButton).OnInvoke.AddListener(() => { this.OnChangeAvatar(666); });
|
||||
Badminton._instance = this;
|
||||
new LocalStorageData();
|
||||
this.config.Init();
|
||||
@@ -172,13 +173,14 @@ export class Badminton extends cc.Component {
|
||||
let picObj: cc.Node = item.node.getChildByName("Avatar").getChildByName("Pic");
|
||||
if (picObj != null) {
|
||||
picObj.getComponent(cc.Sprite).spriteFrame = this.config.GetAvatarPicById(this.TeamMemberList[idx].AvatarId);
|
||||
// picObj.GetComponent<HoldButton>().OnInvoke.AddListener(this.OnChangeAvatar(idx));
|
||||
let EventHandler: cc.Component.EventHandler = new cc.Component.EventHandler();
|
||||
EventHandler.target = this.node;
|
||||
EventHandler.component = this.name.split("<")[1].split(">")[0];
|
||||
EventHandler.handler = "OnChangeAvatar";
|
||||
EventHandler.customEventData = idx.toString();
|
||||
picObj.getComponent(HoldButton).OnInvoke.push(EventHandler);
|
||||
// picObj.getComponent(HoldButton).OnInvoke.AddListener(this.OnChangeAvatar(idx));
|
||||
// picObj.getComponent(HoldButton).OnInvoke.AddListener(() => { this.OnChangeAvatar(idx); });
|
||||
picObj.on("click", () => { item.isChecked = !item.isChecked; }, this);
|
||||
}
|
||||
this._m_toggleList.push(item);
|
||||
@@ -347,10 +349,6 @@ export class Badminton extends cc.Component {
|
||||
// this.AvatarPanel.OpenChange(teamMemberList[index]);
|
||||
}
|
||||
|
||||
public Log(a, b): void {
|
||||
console.log("Log");
|
||||
}
|
||||
|
||||
//#endregion
|
||||
}
|
||||
|
||||
|
||||
@@ -86,7 +86,11 @@ export default class HoldButton extends cc.Component {
|
||||
this._m_pressDeltaTime = 0;
|
||||
if (this.OnInvoke != null) {
|
||||
this.OnInvoke.forEach((eventHandler: cc.Component.EventHandler) => {
|
||||
eventHandler.emit([this.node.getComponent(cc.Button)]);
|
||||
if (eventHandler.target === <any>"AddListener" && eventHandler.component === "AddListener" && eventHandler.handler) {
|
||||
(<Function><unknown>eventHandler.handler)();
|
||||
} else {
|
||||
eventHandler.emit([this.node.getComponent(cc.Button)]);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,8 +14,26 @@ declare interface Array<T> {
|
||||
* @param key 需排序的key(優先順序左到右)(沒有就放空)
|
||||
*/
|
||||
ObjectSort(asc?: boolean[], key?: string[]): any[];
|
||||
/**
|
||||
* 設計給Array<cc.Component.EventHandler>使用
|
||||
* Add a non persistent listener to the UnityEvent.
|
||||
* @param call Callback function.
|
||||
*/
|
||||
AddListener(call: Function): void;
|
||||
}
|
||||
|
||||
Array.prototype.AddListener || Object.defineProperty(Array.prototype, "AddListener", {
|
||||
enumerable: false,
|
||||
value: function (call: Function): void {
|
||||
let EventHandler: cc.Component.EventHandler = new cc.Component.EventHandler();
|
||||
EventHandler.target = <any>"AddListener";
|
||||
EventHandler.component = "AddListener";
|
||||
EventHandler.handler = <any>call;
|
||||
this.push(EventHandler);
|
||||
console.log(`AddListener`);
|
||||
}
|
||||
});
|
||||
|
||||
Array.prototype.ExRemoveAt || Object.defineProperty(Array.prototype, "ExRemoveAt", {
|
||||
enumerable: false,
|
||||
value: function (index: number): any {
|
||||
|
||||
@@ -3,7 +3,7 @@ declare namespace cc {
|
||||
export interface Node {
|
||||
/**
|
||||
* 設定世界座標
|
||||
* @param worldPoint
|
||||
* @param worldPoint
|
||||
*/
|
||||
SetWorldPosition(worldPoint: cc.Vec2): void;
|
||||
/**
|
||||
@@ -12,7 +12,7 @@ declare namespace cc {
|
||||
GetWorldPosition(): cc.Vec2;
|
||||
/**
|
||||
* 設定長寬
|
||||
* @param size
|
||||
* @param size
|
||||
*/
|
||||
SetSizeDelta(size: cc.Vec2);
|
||||
/**
|
||||
@@ -21,7 +21,7 @@ declare namespace cc {
|
||||
GetSizeDelta(): cc.Vec2;
|
||||
/**
|
||||
* 增加一個子物件
|
||||
* @param childObj
|
||||
* @param childObj
|
||||
*/
|
||||
ExAddChild(childObj: cc.Prefab | cc.Node, childActive?: boolean): cc.Node;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user