@eva/plugin-renderer-event 2.0.1-beta.9 → 2.0.2-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
function _extends(){return _extends=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var o=arguments[t];for(var a in o)({}).hasOwnProperty.call(o,a)&&(e[a]=o[a])}return e},_extends.apply(null,arguments)}globalThis.EVA=globalThis.EVA||{},globalThis.EVA.plugin=globalThis.EVA.plugin||{},globalThis.EVA.plugin.renderer=globalThis.EVA.plugin.renderer||{};var _EVA_IIFE_event=function(e,t,o,a){"use strict";const n={Circle:a.Circle,Ellipse:a.Ellipse,Polygon:a.Polygon,Rect:a.Rectangle,RoundedRect:a.RoundedRectangle},r={Circle:["x","y","radius"],Ellipse:["x","y","width","height"],Rect:["x","y","width","height"],RoundedRect:["x","y","width","height","radius"],Polygon:["paths"]};let i=class extends t.Renderer{constructor(){super(...arguments),this.name="Event"}init(){this.renderSystem=this.game.getSystem(t.RendererSystem),this.renderSystem.rendererManager.register(this)}componentChanged(e){switch(e.type){case o.OBSERVER_TYPE.ADD:this.add(e);break;case o.OBSERVER_TYPE.REMOVE:this.remove(e);break;case o.OBSERVER_TYPE.CHANGE:this.change(e)}}add(e){const t=this.containerManager.getContainer(e.gameObject.id);t.interactive=!0,t.interactiveChildren=!0;const o=e.component;o.hitArea&&this.addHitArea(e,t,o.hitArea),t.on("pointertap",
|
|
1
|
+
function _extends(){return _extends=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var o=arguments[t];for(var a in o)({}).hasOwnProperty.call(o,a)&&(e[a]=o[a])}return e},_extends.apply(null,arguments)}globalThis.EVA=globalThis.EVA||{},globalThis.EVA.plugin=globalThis.EVA.plugin||{},globalThis.EVA.plugin.renderer=globalThis.EVA.plugin.renderer||{};var _EVA_IIFE_event=function(e,t,o,a){"use strict";const n={Circle:a.Circle,Ellipse:a.Ellipse,Polygon:a.Polygon,Rect:a.Rectangle,RoundedRect:a.RoundedRectangle},r={Circle:["x","y","radius"],Ellipse:["x","y","width","height"],Rect:["x","y","width","height"],RoundedRect:["x","y","width","height","radius"],Polygon:["paths"]};let i=class extends t.Renderer{constructor(){super(...arguments),this.name="Event"}init(){this.renderSystem=this.game.getSystem(t.RendererSystem),this.renderSystem.rendererManager.register(this)}componentChanged(e){switch(e.type){case o.OBSERVER_TYPE.ADD:this.add(e);break;case o.OBSERVER_TYPE.REMOVE:this.remove(e);break;case o.OBSERVER_TYPE.CHANGE:this.change(e)}}add(e){const t=this.containerManager.getContainer(e.gameObject.id);t.interactive=!0,t.interactiveChildren=!0;const o=e.component;o.hitArea&&this.addHitArea(e,t,o.hitArea),t.on("pointertap",e=>{o.emit("tap",{stopPropagation:()=>e.stopPropagation(),data:{pointerId:e.data.pointerId,position:{x:e.data.global.x,y:e.data.global.y},localPosition:t.worldTransform.applyInverse(e.data.global)},gameObject:o.gameObject})}),t.on("pointerdown",e=>{o.emit("touchstart",{stopPropagation:()=>e.stopPropagation(),data:{pointerId:e.data.pointerId,position:{x:e.data.global.x,y:e.data.global.y},localPosition:t.worldTransform.applyInverse(e.data.global)},gameObject:o.gameObject})}),t.on("pointermove",e=>{o.emit("touchmove",{stopPropagation:()=>e.stopPropagation(),data:{pointerId:e.data.pointerId,position:{x:e.data.global.x,y:e.data.global.y},localPosition:t.worldTransform.applyInverse(e.data.global)},gameObject:o.gameObject})}),t.on("pointerup",e=>{o.emit("touchend",{stopPropagation:()=>e.stopPropagation(),data:{pointerId:e.data.pointerId,position:{x:e.data.global.x,y:e.data.global.y},localPosition:t.worldTransform.applyInverse(e.data.global)},gameObject:o.gameObject})}),t.on("pointerupoutside",e=>{o.emit("touchendoutside",{stopPropagation:()=>e.stopPropagation(),data:{pointerId:e.data.pointerId,position:{x:e.data.global.x,y:e.data.global.y},localPosition:t.worldTransform.applyInverse(e.data.global)},gameObject:o.gameObject})}),t.on("pointercancel",e=>{o.emit("touchcancel",{stopPropagation:()=>e.stopPropagation(),data:{pointerId:e.data.pointerId,position:{x:e.data.global.x,y:e.data.global.y},localPosition:t.worldTransform.applyInverse(e.data.global)},gameObject:o.gameObject})})}remove(e){const t=this.containerManager.getContainer(e.gameObject.id);t.interactive=!1,t.off("tap"),t.off("pointerdown"),t.off("pointermove"),t.off("pointerup"),t.off("pointerupoutside"),t.off("pointercancel"),e.component.removeAllListeners()}change(e){const t=this.containerManager.getContainer(e.gameObject.id);t.interactive=!0;const o=e.component;o.hitArea?this.addHitArea(e,t,o.hitArea):o.hitArea=null}addHitArea(e,t,o){const{type:a,style:i}=o;if(!n[a])return void console.error(`${e.gameObject.name}'s hitArea type is not defined`);const l=[];for(const e of r[a])l.push(i[e]);const s=new n[a](...l);t.hitArea=s}};i.systemName="Event",i=function(e,t,o,a){var n,r=arguments.length,i=r<3?t:null===a?a=Object.getOwnPropertyDescriptor(t,o):a;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(e,t,o,a);else for(var l=e.length-1;l>=0;l--)(n=e[l])&&(i=(r<3?n(i):r>3?n(t,o,i):n(t,o))||i);return r>3&&i&&Object.defineProperty(t,o,i),i}([o.decorators.componentObserver({Event:[{prop:["hitArea"],deep:!0}]})],i);var l,s=i;e.HIT_AREA_TYPE=void 0,(l=e.HIT_AREA_TYPE||(e.HIT_AREA_TYPE={})).Circle="Circle",l.Ellipse="Ellipse",l.Polygon="Polygon",l.Rect="Rect",l.RoundedRect="RoundedRect";class d extends o.Component{constructor(){super(...arguments),this.hitArea=void 0}init(e){e&&_extends(this,e)}emit(e,...t){return super.emit(e,...t)}once(e,t,o){return super.once(e,t,o)}on(e,t,o){return super.on(e,t,o)}}return d.componentName="Event",e.Event=d,e.EventSystem=s,Object.defineProperty(e,"__esModule",{value:!0}),e}({},EVA.plugin.renderer,EVA,PIXI);globalThis.EVA.plugin.renderer.event=globalThis.EVA.plugin.renderer.event||_EVA_IIFE_event;
|
|
@@ -6,19 +6,19 @@ var pluginRenderer = require('@eva/plugin-renderer');
|
|
|
6
6
|
var eva_js = require('@eva/eva.js');
|
|
7
7
|
var pixi_js = require('pixi.js');
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
Copyright (c) Microsoft Corporation.
|
|
11
|
-
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
12
|
-
this file except in compliance with the License. You may obtain a copy of the
|
|
13
|
-
License at http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
/******************************************************************************
|
|
10
|
+
Copyright (c) Microsoft Corporation.
|
|
14
11
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
|
18
|
-
MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
12
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
13
|
+
purpose with or without fee is hereby granted.
|
|
19
14
|
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
16
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
17
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
18
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
19
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
20
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
21
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
22
22
|
***************************************************************************** */
|
|
23
23
|
|
|
24
24
|
function __decorate(decorators, target, key, desc) {
|
|
@@ -26,7 +26,12 @@ function __decorate(decorators, target, key, desc) {
|
|
|
26
26
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
27
27
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
28
28
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
29
|
-
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
32
|
+
var e = new Error(message);
|
|
33
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
34
|
+
};
|
|
30
35
|
|
|
31
36
|
const hitAreaFunc = {
|
|
32
37
|
Circle: pixi_js.Circle,
|
|
@@ -76,6 +81,7 @@ let Event$1 = class Event extends pluginRenderer.Renderer {
|
|
|
76
81
|
component.emit('tap', {
|
|
77
82
|
stopPropagation: () => e.stopPropagation(),
|
|
78
83
|
data: {
|
|
84
|
+
// @ts-ignore
|
|
79
85
|
pointerId: e.data.pointerId,
|
|
80
86
|
position: {
|
|
81
87
|
x: e.data.global.x,
|
|
@@ -90,6 +96,7 @@ let Event$1 = class Event extends pluginRenderer.Renderer {
|
|
|
90
96
|
component.emit('touchstart', {
|
|
91
97
|
stopPropagation: () => e.stopPropagation(),
|
|
92
98
|
data: {
|
|
99
|
+
// @ts-ignore
|
|
93
100
|
pointerId: e.data.pointerId,
|
|
94
101
|
position: {
|
|
95
102
|
x: e.data.global.x,
|
|
@@ -104,6 +111,7 @@ let Event$1 = class Event extends pluginRenderer.Renderer {
|
|
|
104
111
|
component.emit('touchmove', {
|
|
105
112
|
stopPropagation: () => e.stopPropagation(),
|
|
106
113
|
data: {
|
|
114
|
+
// @ts-ignore
|
|
107
115
|
pointerId: e.data.pointerId,
|
|
108
116
|
position: {
|
|
109
117
|
x: e.data.global.x,
|
|
@@ -118,6 +126,7 @@ let Event$1 = class Event extends pluginRenderer.Renderer {
|
|
|
118
126
|
component.emit('touchend', {
|
|
119
127
|
stopPropagation: () => e.stopPropagation(),
|
|
120
128
|
data: {
|
|
129
|
+
// @ts-ignore
|
|
121
130
|
pointerId: e.data.pointerId,
|
|
122
131
|
position: {
|
|
123
132
|
x: e.data.global.x,
|
|
@@ -132,6 +141,7 @@ let Event$1 = class Event extends pluginRenderer.Renderer {
|
|
|
132
141
|
component.emit('touchendoutside', {
|
|
133
142
|
stopPropagation: () => e.stopPropagation(),
|
|
134
143
|
data: {
|
|
144
|
+
// @ts-ignore
|
|
135
145
|
pointerId: e.data.pointerId,
|
|
136
146
|
position: {
|
|
137
147
|
x: e.data.global.x,
|
|
@@ -146,6 +156,7 @@ let Event$1 = class Event extends pluginRenderer.Renderer {
|
|
|
146
156
|
component.emit('touchcancel', {
|
|
147
157
|
stopPropagation: () => e.stopPropagation(),
|
|
148
158
|
data: {
|
|
159
|
+
// @ts-ignore
|
|
149
160
|
pointerId: e.data.pointerId,
|
|
150
161
|
position: {
|
|
151
162
|
x: e.data.global.x,
|
|
@@ -209,11 +220,74 @@ exports.HIT_AREA_TYPE = void 0;
|
|
|
209
220
|
HIT_AREA_TYPE["Rect"] = "Rect";
|
|
210
221
|
HIT_AREA_TYPE["RoundedRect"] = "RoundedRect";
|
|
211
222
|
})(exports.HIT_AREA_TYPE || (exports.HIT_AREA_TYPE = {}));
|
|
223
|
+
/**
|
|
224
|
+
* 事件组件
|
|
225
|
+
*
|
|
226
|
+
* Event 组件为游戏对象添加交互能力,使其能够响应触摸和鼠标事件。
|
|
227
|
+
* 可以自定义交互热区的形状(矩形、圆形、多边形等),
|
|
228
|
+
* 适用于按钮、拖拽对象、可点击元素等交互场景。
|
|
229
|
+
*
|
|
230
|
+
* 支持的事件类型:
|
|
231
|
+
* - touchstart - 触摸/点击开始
|
|
232
|
+
* - touchmove - 触摸/鼠标移动
|
|
233
|
+
* - touchend - 触摸/点击结束
|
|
234
|
+
* - tap - 点击/轻触
|
|
235
|
+
* - touchendoutside - 在对象外部结束触摸
|
|
236
|
+
* - touchcancel - 触摸取消
|
|
237
|
+
*
|
|
238
|
+
* @example
|
|
239
|
+
* ```typescript
|
|
240
|
+
* // 基础用法 - 使用默认热区(Transform 尺寸)
|
|
241
|
+
* const button = new GameObject('button');
|
|
242
|
+
* const event = new Event();
|
|
243
|
+
* button.addComponent(event);
|
|
244
|
+
*
|
|
245
|
+
* event.on('tap', (e) => {
|
|
246
|
+
* console.log('按钮被点击', e.data.position);
|
|
247
|
+
* });
|
|
248
|
+
*
|
|
249
|
+
* // 自定义矩形热区
|
|
250
|
+
* button.addComponent(new Event({
|
|
251
|
+
* hitArea: {
|
|
252
|
+
* type: HIT_AREA_TYPE.Rect,
|
|
253
|
+
* style: { x: 0, y: 0, width: 100, height: 50 }
|
|
254
|
+
* }
|
|
255
|
+
* }));
|
|
256
|
+
*
|
|
257
|
+
* // 圆形热区
|
|
258
|
+
* button.addComponent(new Event({
|
|
259
|
+
* hitArea: {
|
|
260
|
+
* type: HIT_AREA_TYPE.Circle,
|
|
261
|
+
* style: { x: 50, y: 50, radius: 40 }
|
|
262
|
+
* }
|
|
263
|
+
* }));
|
|
264
|
+
*
|
|
265
|
+
* // 多边形热区
|
|
266
|
+
* button.addComponent(new Event({
|
|
267
|
+
* hitArea: {
|
|
268
|
+
* type: HIT_AREA_TYPE.Polygon,
|
|
269
|
+
* style: { paths: [0,0, 100,0, 50,100] }
|
|
270
|
+
* }
|
|
271
|
+
* }));
|
|
272
|
+
*
|
|
273
|
+
* // 事件处理
|
|
274
|
+
* event.on('touchstart', (e) => {
|
|
275
|
+
* console.log('触摸开始', e.data.localPosition);
|
|
276
|
+
* e.stopPropagation(); // 阻止事件冒泡
|
|
277
|
+
* });
|
|
278
|
+
* ```
|
|
279
|
+
*/
|
|
212
280
|
class Event extends eva_js.Component {
|
|
213
281
|
constructor() {
|
|
214
282
|
super(...arguments);
|
|
283
|
+
/** 交互热区配置 */
|
|
215
284
|
this.hitArea = undefined;
|
|
216
285
|
}
|
|
286
|
+
/**
|
|
287
|
+
* 初始化组件
|
|
288
|
+
* @param params - 初始化参数
|
|
289
|
+
* @param params.hitArea - 交互热区配置
|
|
290
|
+
*/
|
|
217
291
|
init(params) {
|
|
218
292
|
params && Object.assign(this, params);
|
|
219
293
|
}
|
|
@@ -227,6 +301,7 @@ class Event extends eva_js.Component {
|
|
|
227
301
|
return super.on(en, fn, context);
|
|
228
302
|
}
|
|
229
303
|
}
|
|
304
|
+
/** 组件名称 */
|
|
230
305
|
Event.componentName = 'Event';
|
|
231
306
|
|
|
232
307
|
exports.Event = Event;
|
|
@@ -1,16 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@eva/plugin-renderer"),t=require("@eva/eva.js"),o=require("pixi.js");const a={Circle:o.Circle,Ellipse:o.Ellipse,Polygon:o.Polygon,Rect:o.Rectangle,RoundedRect:o.RoundedRectangle},n={Circle:["x","y","radius"],Ellipse:["x","y","width","height"],Rect:["x","y","width","height"],RoundedRect:["x","y","width","height","radius"],Polygon:["paths"]};let r=class extends e.Renderer{constructor(){super(...arguments),this.name="Event"}init(){this.renderSystem=this.game.getSystem(e.RendererSystem),this.renderSystem.rendererManager.register(this)}componentChanged(e){switch(e.type){case t.OBSERVER_TYPE.ADD:this.add(e);break;case t.OBSERVER_TYPE.REMOVE:this.remove(e);break;case t.OBSERVER_TYPE.CHANGE:this.change(e)}}add(e){const t=this.containerManager.getContainer(e.gameObject.id);t.interactive=!0,t.interactiveChildren=!0;const o=e.component;o.hitArea&&this.addHitArea(e,t,o.hitArea),t.on("pointertap",
|
|
2
|
-
/*! *****************************************************************************
|
|
3
|
-
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
|
-
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
5
|
-
this file except in compliance with the License. You may obtain a copy of the
|
|
6
|
-
License at http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
-
|
|
8
|
-
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
9
|
-
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
|
10
|
-
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
|
11
|
-
MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
12
|
-
|
|
13
|
-
See the Apache Version 2.0 License for specific language governing permissions
|
|
14
|
-
and limitations under the License.
|
|
15
|
-
***************************************************************************** */
|
|
16
|
-
function(e,t,o,a){var n,r=arguments.length,i=r<3?t:null===a?a=Object.getOwnPropertyDescriptor(t,o):a;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(e,t,o,a);else for(var s=e.length-1;s>=0;s--)(n=e[s])&&(i=(r<3?n(i):r>3?n(t,o,i):n(t,o))||i);return r>3&&i&&Object.defineProperty(t,o,i),i}([t.decorators.componentObserver({Event:[{prop:["hitArea"],deep:!0}]})],r);var i,s=r;exports.HIT_AREA_TYPE=void 0,(i=exports.HIT_AREA_TYPE||(exports.HIT_AREA_TYPE={})).Circle="Circle",i.Ellipse="Ellipse",i.Polygon="Polygon",i.Rect="Rect",i.RoundedRect="RoundedRect";class p extends t.Component{constructor(){super(...arguments),this.hitArea=void 0}init(e){e&&Object.assign(this,e)}emit(e,...t){return super.emit(e,...t)}once(e,t,o){return super.once(e,t,o)}on(e,t,o){return super.on(e,t,o)}}p.componentName="Event",exports.Event=p,exports.EventSystem=s;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@eva/plugin-renderer"),t=require("@eva/eva.js"),o=require("pixi.js");"function"==typeof SuppressedError&&SuppressedError;const a={Circle:o.Circle,Ellipse:o.Ellipse,Polygon:o.Polygon,Rect:o.Rectangle,RoundedRect:o.RoundedRectangle},n={Circle:["x","y","radius"],Ellipse:["x","y","width","height"],Rect:["x","y","width","height"],RoundedRect:["x","y","width","height","radius"],Polygon:["paths"]};let r=class extends e.Renderer{constructor(){super(...arguments),this.name="Event"}init(){this.renderSystem=this.game.getSystem(e.RendererSystem),this.renderSystem.rendererManager.register(this)}componentChanged(e){switch(e.type){case t.OBSERVER_TYPE.ADD:this.add(e);break;case t.OBSERVER_TYPE.REMOVE:this.remove(e);break;case t.OBSERVER_TYPE.CHANGE:this.change(e)}}add(e){const t=this.containerManager.getContainer(e.gameObject.id);t.interactive=!0,t.interactiveChildren=!0;const o=e.component;o.hitArea&&this.addHitArea(e,t,o.hitArea),t.on("pointertap",e=>{o.emit("tap",{stopPropagation:()=>e.stopPropagation(),data:{pointerId:e.data.pointerId,position:{x:e.data.global.x,y:e.data.global.y},localPosition:t.worldTransform.applyInverse(e.data.global)},gameObject:o.gameObject})}),t.on("pointerdown",e=>{o.emit("touchstart",{stopPropagation:()=>e.stopPropagation(),data:{pointerId:e.data.pointerId,position:{x:e.data.global.x,y:e.data.global.y},localPosition:t.worldTransform.applyInverse(e.data.global)},gameObject:o.gameObject})}),t.on("pointermove",e=>{o.emit("touchmove",{stopPropagation:()=>e.stopPropagation(),data:{pointerId:e.data.pointerId,position:{x:e.data.global.x,y:e.data.global.y},localPosition:t.worldTransform.applyInverse(e.data.global)},gameObject:o.gameObject})}),t.on("pointerup",e=>{o.emit("touchend",{stopPropagation:()=>e.stopPropagation(),data:{pointerId:e.data.pointerId,position:{x:e.data.global.x,y:e.data.global.y},localPosition:t.worldTransform.applyInverse(e.data.global)},gameObject:o.gameObject})}),t.on("pointerupoutside",e=>{o.emit("touchendoutside",{stopPropagation:()=>e.stopPropagation(),data:{pointerId:e.data.pointerId,position:{x:e.data.global.x,y:e.data.global.y},localPosition:t.worldTransform.applyInverse(e.data.global)},gameObject:o.gameObject})}),t.on("pointercancel",e=>{o.emit("touchcancel",{stopPropagation:()=>e.stopPropagation(),data:{pointerId:e.data.pointerId,position:{x:e.data.global.x,y:e.data.global.y},localPosition:t.worldTransform.applyInverse(e.data.global)},gameObject:o.gameObject})})}remove(e){const t=this.containerManager.getContainer(e.gameObject.id);t.interactive=!1,t.off("tap"),t.off("pointerdown"),t.off("pointermove"),t.off("pointerup"),t.off("pointerupoutside"),t.off("pointercancel"),e.component.removeAllListeners()}change(e){const t=this.containerManager.getContainer(e.gameObject.id);t.interactive=!0;const o=e.component;o.hitArea?this.addHitArea(e,t,o.hitArea):o.hitArea=null}addHitArea(e,t,o){const{type:r,style:i}=o;if(!a[r])return void console.error(`${e.gameObject.name}'s hitArea type is not defined`);const s=[];for(const e of n[r])s.push(i[e]);const p=new a[r](...s);t.hitArea=p}};r.systemName="Event",r=function(e,t,o,a){var n,r=arguments.length,i=r<3?t:null===a?a=Object.getOwnPropertyDescriptor(t,o):a;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(e,t,o,a);else for(var s=e.length-1;s>=0;s--)(n=e[s])&&(i=(r<3?n(i):r>3?n(t,o,i):n(t,o))||i);return r>3&&i&&Object.defineProperty(t,o,i),i}([t.decorators.componentObserver({Event:[{prop:["hitArea"],deep:!0}]})],r);var i,s=r;exports.HIT_AREA_TYPE=void 0,(i=exports.HIT_AREA_TYPE||(exports.HIT_AREA_TYPE={})).Circle="Circle",i.Ellipse="Ellipse",i.Polygon="Polygon",i.Rect="Rect",i.RoundedRect="RoundedRect";class p extends t.Component{constructor(){super(...arguments),this.hitArea=void 0}init(e){e&&Object.assign(this,e)}emit(e,...t){return super.emit(e,...t)}once(e,t,o){return super.once(e,t,o)}on(e,t,o){return super.on(e,t,o)}}p.componentName="Event",exports.Event=p,exports.EventSystem=s;
|
|
@@ -6,9 +6,73 @@ import { Renderer } from '@eva/plugin-renderer';
|
|
|
6
6
|
import { RendererManager } from '@eva/plugin-renderer';
|
|
7
7
|
import { RendererSystem } from '@eva/plugin-renderer';
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* 事件组件
|
|
11
|
+
*
|
|
12
|
+
* Event 组件为游戏对象添加交互能力,使其能够响应触摸和鼠标事件。
|
|
13
|
+
* 可以自定义交互热区的形状(矩形、圆形、多边形等),
|
|
14
|
+
* 适用于按钮、拖拽对象、可点击元素等交互场景。
|
|
15
|
+
*
|
|
16
|
+
* 支持的事件类型:
|
|
17
|
+
* - touchstart - 触摸/点击开始
|
|
18
|
+
* - touchmove - 触摸/鼠标移动
|
|
19
|
+
* - touchend - 触摸/点击结束
|
|
20
|
+
* - tap - 点击/轻触
|
|
21
|
+
* - touchendoutside - 在对象外部结束触摸
|
|
22
|
+
* - touchcancel - 触摸取消
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* // 基础用法 - 使用默认热区(Transform 尺寸)
|
|
27
|
+
* const button = new GameObject('button');
|
|
28
|
+
* const event = new Event();
|
|
29
|
+
* button.addComponent(event);
|
|
30
|
+
*
|
|
31
|
+
* event.on('tap', (e) => {
|
|
32
|
+
* console.log('按钮被点击', e.data.position);
|
|
33
|
+
* });
|
|
34
|
+
*
|
|
35
|
+
* // 自定义矩形热区
|
|
36
|
+
* button.addComponent(new Event({
|
|
37
|
+
* hitArea: {
|
|
38
|
+
* type: HIT_AREA_TYPE.Rect,
|
|
39
|
+
* style: { x: 0, y: 0, width: 100, height: 50 }
|
|
40
|
+
* }
|
|
41
|
+
* }));
|
|
42
|
+
*
|
|
43
|
+
* // 圆形热区
|
|
44
|
+
* button.addComponent(new Event({
|
|
45
|
+
* hitArea: {
|
|
46
|
+
* type: HIT_AREA_TYPE.Circle,
|
|
47
|
+
* style: { x: 50, y: 50, radius: 40 }
|
|
48
|
+
* }
|
|
49
|
+
* }));
|
|
50
|
+
*
|
|
51
|
+
* // 多边形热区
|
|
52
|
+
* button.addComponent(new Event({
|
|
53
|
+
* hitArea: {
|
|
54
|
+
* type: HIT_AREA_TYPE.Polygon,
|
|
55
|
+
* style: { paths: [0,0, 100,0, 50,100] }
|
|
56
|
+
* }
|
|
57
|
+
* }));
|
|
58
|
+
*
|
|
59
|
+
* // 事件处理
|
|
60
|
+
* event.on('touchstart', (e) => {
|
|
61
|
+
* console.log('触摸开始', e.data.localPosition);
|
|
62
|
+
* e.stopPropagation(); // 阻止事件冒泡
|
|
63
|
+
* });
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
9
66
|
declare class Event_2 extends Component<EventParams> {
|
|
67
|
+
/** 组件名称 */
|
|
10
68
|
static componentName: string;
|
|
69
|
+
/** 交互热区配置 */
|
|
11
70
|
hitArea: HitArea;
|
|
71
|
+
/**
|
|
72
|
+
* 初始化组件
|
|
73
|
+
* @param params - 初始化参数
|
|
74
|
+
* @param params.hitArea - 交互热区配置
|
|
75
|
+
*/
|
|
12
76
|
init(params?: EventParams): void;
|
|
13
77
|
emit(eventName: TouchEventName, ...args: [EventParam]): boolean;
|
|
14
78
|
emit<T extends string>(eventName: Exclude<T, TouchEventName>, ...args: any[]): boolean;
|
|
@@ -27,6 +91,9 @@ declare type EventParam = {
|
|
|
27
91
|
x: number;
|
|
28
92
|
y: number;
|
|
29
93
|
};
|
|
94
|
+
/**
|
|
95
|
+
* The position related to event target gameobject
|
|
96
|
+
*/
|
|
30
97
|
localPosition: {
|
|
31
98
|
x: number;
|
|
32
99
|
y: number;
|
|
@@ -2,19 +2,19 @@ import { Renderer, RendererSystem } from '@eva/plugin-renderer';
|
|
|
2
2
|
import { OBSERVER_TYPE, decorators, Component } from '@eva/eva.js';
|
|
3
3
|
import { Circle, Ellipse, Polygon, Rectangle, RoundedRectangle } from 'pixi.js';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
Copyright (c) Microsoft Corporation.
|
|
7
|
-
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
8
|
-
this file except in compliance with the License. You may obtain a copy of the
|
|
9
|
-
License at http://www.apache.org/licenses/LICENSE-2.0
|
|
5
|
+
/******************************************************************************
|
|
6
|
+
Copyright (c) Microsoft Corporation.
|
|
10
7
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
|
14
|
-
MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
8
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
9
|
+
purpose with or without fee is hereby granted.
|
|
15
10
|
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
12
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
13
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
14
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
15
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
16
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
17
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
18
18
|
***************************************************************************** */
|
|
19
19
|
|
|
20
20
|
function __decorate(decorators, target, key, desc) {
|
|
@@ -22,7 +22,12 @@ function __decorate(decorators, target, key, desc) {
|
|
|
22
22
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
23
23
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
24
24
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
25
|
-
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
28
|
+
var e = new Error(message);
|
|
29
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
30
|
+
};
|
|
26
31
|
|
|
27
32
|
const hitAreaFunc = {
|
|
28
33
|
Circle,
|
|
@@ -72,6 +77,7 @@ let Event$1 = class Event extends Renderer {
|
|
|
72
77
|
component.emit('tap', {
|
|
73
78
|
stopPropagation: () => e.stopPropagation(),
|
|
74
79
|
data: {
|
|
80
|
+
// @ts-ignore
|
|
75
81
|
pointerId: e.data.pointerId,
|
|
76
82
|
position: {
|
|
77
83
|
x: e.data.global.x,
|
|
@@ -86,6 +92,7 @@ let Event$1 = class Event extends Renderer {
|
|
|
86
92
|
component.emit('touchstart', {
|
|
87
93
|
stopPropagation: () => e.stopPropagation(),
|
|
88
94
|
data: {
|
|
95
|
+
// @ts-ignore
|
|
89
96
|
pointerId: e.data.pointerId,
|
|
90
97
|
position: {
|
|
91
98
|
x: e.data.global.x,
|
|
@@ -100,6 +107,7 @@ let Event$1 = class Event extends Renderer {
|
|
|
100
107
|
component.emit('touchmove', {
|
|
101
108
|
stopPropagation: () => e.stopPropagation(),
|
|
102
109
|
data: {
|
|
110
|
+
// @ts-ignore
|
|
103
111
|
pointerId: e.data.pointerId,
|
|
104
112
|
position: {
|
|
105
113
|
x: e.data.global.x,
|
|
@@ -114,6 +122,7 @@ let Event$1 = class Event extends Renderer {
|
|
|
114
122
|
component.emit('touchend', {
|
|
115
123
|
stopPropagation: () => e.stopPropagation(),
|
|
116
124
|
data: {
|
|
125
|
+
// @ts-ignore
|
|
117
126
|
pointerId: e.data.pointerId,
|
|
118
127
|
position: {
|
|
119
128
|
x: e.data.global.x,
|
|
@@ -128,6 +137,7 @@ let Event$1 = class Event extends Renderer {
|
|
|
128
137
|
component.emit('touchendoutside', {
|
|
129
138
|
stopPropagation: () => e.stopPropagation(),
|
|
130
139
|
data: {
|
|
140
|
+
// @ts-ignore
|
|
131
141
|
pointerId: e.data.pointerId,
|
|
132
142
|
position: {
|
|
133
143
|
x: e.data.global.x,
|
|
@@ -142,6 +152,7 @@ let Event$1 = class Event extends Renderer {
|
|
|
142
152
|
component.emit('touchcancel', {
|
|
143
153
|
stopPropagation: () => e.stopPropagation(),
|
|
144
154
|
data: {
|
|
155
|
+
// @ts-ignore
|
|
145
156
|
pointerId: e.data.pointerId,
|
|
146
157
|
position: {
|
|
147
158
|
x: e.data.global.x,
|
|
@@ -205,11 +216,74 @@ var HIT_AREA_TYPE;
|
|
|
205
216
|
HIT_AREA_TYPE["Rect"] = "Rect";
|
|
206
217
|
HIT_AREA_TYPE["RoundedRect"] = "RoundedRect";
|
|
207
218
|
})(HIT_AREA_TYPE || (HIT_AREA_TYPE = {}));
|
|
219
|
+
/**
|
|
220
|
+
* 事件组件
|
|
221
|
+
*
|
|
222
|
+
* Event 组件为游戏对象添加交互能力,使其能够响应触摸和鼠标事件。
|
|
223
|
+
* 可以自定义交互热区的形状(矩形、圆形、多边形等),
|
|
224
|
+
* 适用于按钮、拖拽对象、可点击元素等交互场景。
|
|
225
|
+
*
|
|
226
|
+
* 支持的事件类型:
|
|
227
|
+
* - touchstart - 触摸/点击开始
|
|
228
|
+
* - touchmove - 触摸/鼠标移动
|
|
229
|
+
* - touchend - 触摸/点击结束
|
|
230
|
+
* - tap - 点击/轻触
|
|
231
|
+
* - touchendoutside - 在对象外部结束触摸
|
|
232
|
+
* - touchcancel - 触摸取消
|
|
233
|
+
*
|
|
234
|
+
* @example
|
|
235
|
+
* ```typescript
|
|
236
|
+
* // 基础用法 - 使用默认热区(Transform 尺寸)
|
|
237
|
+
* const button = new GameObject('button');
|
|
238
|
+
* const event = new Event();
|
|
239
|
+
* button.addComponent(event);
|
|
240
|
+
*
|
|
241
|
+
* event.on('tap', (e) => {
|
|
242
|
+
* console.log('按钮被点击', e.data.position);
|
|
243
|
+
* });
|
|
244
|
+
*
|
|
245
|
+
* // 自定义矩形热区
|
|
246
|
+
* button.addComponent(new Event({
|
|
247
|
+
* hitArea: {
|
|
248
|
+
* type: HIT_AREA_TYPE.Rect,
|
|
249
|
+
* style: { x: 0, y: 0, width: 100, height: 50 }
|
|
250
|
+
* }
|
|
251
|
+
* }));
|
|
252
|
+
*
|
|
253
|
+
* // 圆形热区
|
|
254
|
+
* button.addComponent(new Event({
|
|
255
|
+
* hitArea: {
|
|
256
|
+
* type: HIT_AREA_TYPE.Circle,
|
|
257
|
+
* style: { x: 50, y: 50, radius: 40 }
|
|
258
|
+
* }
|
|
259
|
+
* }));
|
|
260
|
+
*
|
|
261
|
+
* // 多边形热区
|
|
262
|
+
* button.addComponent(new Event({
|
|
263
|
+
* hitArea: {
|
|
264
|
+
* type: HIT_AREA_TYPE.Polygon,
|
|
265
|
+
* style: { paths: [0,0, 100,0, 50,100] }
|
|
266
|
+
* }
|
|
267
|
+
* }));
|
|
268
|
+
*
|
|
269
|
+
* // 事件处理
|
|
270
|
+
* event.on('touchstart', (e) => {
|
|
271
|
+
* console.log('触摸开始', e.data.localPosition);
|
|
272
|
+
* e.stopPropagation(); // 阻止事件冒泡
|
|
273
|
+
* });
|
|
274
|
+
* ```
|
|
275
|
+
*/
|
|
208
276
|
class Event extends Component {
|
|
209
277
|
constructor() {
|
|
210
278
|
super(...arguments);
|
|
279
|
+
/** 交互热区配置 */
|
|
211
280
|
this.hitArea = undefined;
|
|
212
281
|
}
|
|
282
|
+
/**
|
|
283
|
+
* 初始化组件
|
|
284
|
+
* @param params - 初始化参数
|
|
285
|
+
* @param params.hitArea - 交互热区配置
|
|
286
|
+
*/
|
|
213
287
|
init(params) {
|
|
214
288
|
params && Object.assign(this, params);
|
|
215
289
|
}
|
|
@@ -223,6 +297,7 @@ class Event extends Component {
|
|
|
223
297
|
return super.on(en, fn, context);
|
|
224
298
|
}
|
|
225
299
|
}
|
|
300
|
+
/** 组件名称 */
|
|
226
301
|
Event.componentName = 'Event';
|
|
227
302
|
|
|
228
303
|
export { Event, Event$2 as EventSystem, HIT_AREA_TYPE };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eva/plugin-renderer-event",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2-beta.0",
|
|
4
4
|
"description": "@eva/plugin-renderer-event",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "dist/plugin-renderer-event.esm.js",
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"homepage": "https://eva.js.org",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@eva/plugin-renderer": "2.0.
|
|
22
|
-
"@eva/eva.js": "2.0.
|
|
23
|
-
"pixi.js": "^8.
|
|
21
|
+
"@eva/plugin-renderer": "2.0.2-beta.0",
|
|
22
|
+
"@eva/eva.js": "2.0.2-beta.0",
|
|
23
|
+
"pixi.js": "^8.17.0"
|
|
24
24
|
}
|
|
25
25
|
}
|