diff --git a/assets/Scene/Test.fire b/assets/Scene/Test.fire index ecf1c56..60c89cd 100644 --- a/assets/Scene/Test.fire +++ b/assets/Scene/Test.fire @@ -78,10 +78,10 @@ "_active": true, "_components": [ { - "__id__": 17 + "__id__": 19 }, { - "__id__": 18 + "__id__": 20 } ], "_prefab": null, @@ -251,10 +251,13 @@ "__id__": 13 }, { - "__id__": 14 + "__id__": 15 }, { - "__id__": 15 + "__id__": 16 + }, + { + "__id__": 18 } ], "_prefab": null, @@ -665,7 +668,11 @@ "_grayMaterial": null, "duration": 0.1, "zoomScale": 0.9, - "clickEvents": [], + "clickEvents": [ + { + "__id__": 14 + } + ], "_N$interactable": true, "_N$enableAutoGrayEffect": false, "_N$transition": 1, @@ -725,6 +732,16 @@ }, "_id": "b1JdTzpetM5Y2+ajB7CgHk" }, + { + "__type__": "cc.ClickEvent", + "target": { + "__id__": 5 + }, + "component": "", + "_componentId": "cf85bcS8qVLQ5grFSK4g1D6", + "handler": "Log", + "customEventData": "5555" + }, { "__type__": "cc.Sprite", "_name": "", @@ -778,7 +795,7 @@ }, "OnInvoke": [ { - "__id__": 16 + "__id__": 17 } ], "_id": "42FPUDXnROx55pRRLBeL22" @@ -786,12 +803,22 @@ { "__type__": "cc.ClickEvent", "target": { - "__id__": 6 + "__id__": 5 }, "component": "", - "_componentId": "cc.Label", - "handler": "destroy", - "customEventData": "false" + "_componentId": "cf85bcS8qVLQ5grFSK4g1D6", + "handler": "Log", + "customEventData": "6666" + }, + { + "__type__": "cf85bcS8qVLQ5grFSK4g1D6", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 5 + }, + "_enabled": true, + "_id": "59e/1WbXJCBrpkHVzwqEeX" }, { "__type__": "cc.Canvas", diff --git a/assets/Script/Badminton/Badminton.ts b/assets/Script/Badminton/Badminton.ts index 73e2325..76010f6 100644 --- a/assets/Script/Badminton/Badminton.ts +++ b/assets/Script/Badminton/Badminton.ts @@ -113,7 +113,6 @@ 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(); @@ -173,14 +172,13 @@ 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); - 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); }); + // 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.on("click", () => { item.isChecked = !item.isChecked; }, this); } this._m_toggleList.push(item); diff --git a/assets/Script/Engine/Component/Button/HoldButton.ts b/assets/Script/Engine/Component/Button/HoldButton.ts index fcd3ec0..3b9f7c6 100644 --- a/assets/Script/Engine/Component/Button/HoldButton.ts +++ b/assets/Script/Engine/Component/Button/HoldButton.ts @@ -30,6 +30,11 @@ export default class HoldButton extends cc.Component { //#region private + /** 按钮的点击事件列表 */ + private _clickEvents: cc.Component.EventHandler[] = []; + + private _isOnInvoke: boolean = false; + private _m_isMouseDown: boolean = false; private _m_pressDeltaTime: number = 0; @@ -39,6 +44,8 @@ export default class HoldButton extends cc.Component { //#region Lifecycle protected start(): void { + this._clickEvents = this.getComponent(cc.Button).clickEvents.slice(0); + this.getComponent(cc.Button).clickEvents.Clear(); if (this.HoldLine != null) { this.HoldLine.active = false; } @@ -79,6 +86,7 @@ export default class HoldButton extends cc.Component { } if (this._m_pressDeltaTime > this.MaxTime) { + this._isOnInvoke = true; this._m_isMouseDown = false; if (this.IsHaveHoldLine) { this.HoldLine.active = false; @@ -116,6 +124,12 @@ export default class HoldButton extends cc.Component { if (this.IsHaveHoldLine) { this.HoldLine.active = false; } + if (!this._isOnInvoke) { + this._clickEvents.forEach((eventHandler: cc.Component.EventHandler) => { + eventHandler.emit([this.node.getComponent(cc.Button)]); + }); + } + this._isOnInvoke = false; this._checkHoldAutoStart(0); } @@ -125,6 +139,12 @@ export default class HoldButton extends cc.Component { if (this.IsHaveHoldLine) { this.HoldLine.active = false; } + if (!this._isOnInvoke) { + this._clickEvents.forEach((eventHandler: cc.Component.EventHandler) => { + eventHandler.emit([this.node.getComponent(cc.Button)]); + }); + } + this._isOnInvoke = false; this._checkHoldAutoStart(0); } diff --git a/assets/Script/Engine/Utils/CCExtensions/ArrayExtension.ts b/assets/Script/Engine/Utils/CCExtensions/ArrayExtension.ts index 60838cc..00263fd 100644 --- a/assets/Script/Engine/Utils/CCExtensions/ArrayExtension.ts +++ b/assets/Script/Engine/Utils/CCExtensions/ArrayExtension.ts @@ -15,7 +15,7 @@ declare interface Array { */ ObjectSort(asc?: boolean[], key?: string[]): any[]; /** - * 設計給Array使用 + * 設計給ArrayforHoldButton使用 * Add a non persistent listener to the UnityEvent. * @param call Callback function. */ diff --git a/assets/Script/Test.ts b/assets/Script/Test.ts new file mode 100644 index 0000000..19be0d8 --- /dev/null +++ b/assets/Script/Test.ts @@ -0,0 +1,19 @@ +// 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 + +const { ccclass, property } = cc._decorator; + +@ccclass +export default class Test extends cc.Component { + + /** + * name + */ + public Log(a, b): void { + cc.log(b); + } +} diff --git a/assets/Script/Test.ts.meta b/assets/Script/Test.ts.meta new file mode 100644 index 0000000..ea8d505 --- /dev/null +++ b/assets/Script/Test.ts.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.8", + "uuid": "cf85b712-f2a5-4b43-982b-1522b88350fa", + "isPlugin": false, + "loadPluginInWeb": true, + "loadPluginInNative": true, + "loadPluginInEditor": false, + "subMetas": {} +} \ No newline at end of file