@eva/plugin-renderer-event 2.0.1-beta.26 → 2.0.1-beta.28
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.
|
@@ -76,6 +76,7 @@ let Event$1 = class Event extends pluginRenderer.Renderer {
|
|
|
76
76
|
component.emit('tap', {
|
|
77
77
|
stopPropagation: () => e.stopPropagation(),
|
|
78
78
|
data: {
|
|
79
|
+
// @ts-ignore
|
|
79
80
|
pointerId: e.data.pointerId,
|
|
80
81
|
position: {
|
|
81
82
|
x: e.data.global.x,
|
|
@@ -90,6 +91,7 @@ let Event$1 = class Event extends pluginRenderer.Renderer {
|
|
|
90
91
|
component.emit('touchstart', {
|
|
91
92
|
stopPropagation: () => e.stopPropagation(),
|
|
92
93
|
data: {
|
|
94
|
+
// @ts-ignore
|
|
93
95
|
pointerId: e.data.pointerId,
|
|
94
96
|
position: {
|
|
95
97
|
x: e.data.global.x,
|
|
@@ -104,6 +106,7 @@ let Event$1 = class Event extends pluginRenderer.Renderer {
|
|
|
104
106
|
component.emit('touchmove', {
|
|
105
107
|
stopPropagation: () => e.stopPropagation(),
|
|
106
108
|
data: {
|
|
109
|
+
// @ts-ignore
|
|
107
110
|
pointerId: e.data.pointerId,
|
|
108
111
|
position: {
|
|
109
112
|
x: e.data.global.x,
|
|
@@ -118,6 +121,7 @@ let Event$1 = class Event extends pluginRenderer.Renderer {
|
|
|
118
121
|
component.emit('touchend', {
|
|
119
122
|
stopPropagation: () => e.stopPropagation(),
|
|
120
123
|
data: {
|
|
124
|
+
// @ts-ignore
|
|
121
125
|
pointerId: e.data.pointerId,
|
|
122
126
|
position: {
|
|
123
127
|
x: e.data.global.x,
|
|
@@ -132,6 +136,7 @@ let Event$1 = class Event extends pluginRenderer.Renderer {
|
|
|
132
136
|
component.emit('touchendoutside', {
|
|
133
137
|
stopPropagation: () => e.stopPropagation(),
|
|
134
138
|
data: {
|
|
139
|
+
// @ts-ignore
|
|
135
140
|
pointerId: e.data.pointerId,
|
|
136
141
|
position: {
|
|
137
142
|
x: e.data.global.x,
|
|
@@ -146,6 +151,7 @@ let Event$1 = class Event extends pluginRenderer.Renderer {
|
|
|
146
151
|
component.emit('touchcancel', {
|
|
147
152
|
stopPropagation: () => e.stopPropagation(),
|
|
148
153
|
data: {
|
|
154
|
+
// @ts-ignore
|
|
149
155
|
pointerId: e.data.pointerId,
|
|
150
156
|
position: {
|
|
151
157
|
x: e.data.global.x,
|
|
@@ -209,11 +215,74 @@ exports.HIT_AREA_TYPE = void 0;
|
|
|
209
215
|
HIT_AREA_TYPE["Rect"] = "Rect";
|
|
210
216
|
HIT_AREA_TYPE["RoundedRect"] = "RoundedRect";
|
|
211
217
|
})(exports.HIT_AREA_TYPE || (exports.HIT_AREA_TYPE = {}));
|
|
218
|
+
/**
|
|
219
|
+
* 事件组件
|
|
220
|
+
*
|
|
221
|
+
* Event 组件为游戏对象添加交互能力,使其能够响应触摸和鼠标事件。
|
|
222
|
+
* 可以自定义交互热区的形状(矩形、圆形、多边形等),
|
|
223
|
+
* 适用于按钮、拖拽对象、可点击元素等交互场景。
|
|
224
|
+
*
|
|
225
|
+
* 支持的事件类型:
|
|
226
|
+
* - touchstart - 触摸/点击开始
|
|
227
|
+
* - touchmove - 触摸/鼠标移动
|
|
228
|
+
* - touchend - 触摸/点击结束
|
|
229
|
+
* - tap - 点击/轻触
|
|
230
|
+
* - touchendoutside - 在对象外部结束触摸
|
|
231
|
+
* - touchcancel - 触摸取消
|
|
232
|
+
*
|
|
233
|
+
* @example
|
|
234
|
+
* ```typescript
|
|
235
|
+
* // 基础用法 - 使用默认热区(Transform 尺寸)
|
|
236
|
+
* const button = new GameObject('button');
|
|
237
|
+
* const event = new Event();
|
|
238
|
+
* button.addComponent(event);
|
|
239
|
+
*
|
|
240
|
+
* event.on('tap', (e) => {
|
|
241
|
+
* console.log('按钮被点击', e.data.position);
|
|
242
|
+
* });
|
|
243
|
+
*
|
|
244
|
+
* // 自定义矩形热区
|
|
245
|
+
* button.addComponent(new Event({
|
|
246
|
+
* hitArea: {
|
|
247
|
+
* type: HIT_AREA_TYPE.Rect,
|
|
248
|
+
* style: { x: 0, y: 0, width: 100, height: 50 }
|
|
249
|
+
* }
|
|
250
|
+
* }));
|
|
251
|
+
*
|
|
252
|
+
* // 圆形热区
|
|
253
|
+
* button.addComponent(new Event({
|
|
254
|
+
* hitArea: {
|
|
255
|
+
* type: HIT_AREA_TYPE.Circle,
|
|
256
|
+
* style: { x: 50, y: 50, radius: 40 }
|
|
257
|
+
* }
|
|
258
|
+
* }));
|
|
259
|
+
*
|
|
260
|
+
* // 多边形热区
|
|
261
|
+
* button.addComponent(new Event({
|
|
262
|
+
* hitArea: {
|
|
263
|
+
* type: HIT_AREA_TYPE.Polygon,
|
|
264
|
+
* style: { paths: [0,0, 100,0, 50,100] }
|
|
265
|
+
* }
|
|
266
|
+
* }));
|
|
267
|
+
*
|
|
268
|
+
* // 事件处理
|
|
269
|
+
* event.on('touchstart', (e) => {
|
|
270
|
+
* console.log('触摸开始', e.data.localPosition);
|
|
271
|
+
* e.stopPropagation(); // 阻止事件冒泡
|
|
272
|
+
* });
|
|
273
|
+
* ```
|
|
274
|
+
*/
|
|
212
275
|
class Event extends eva_js.Component {
|
|
213
276
|
constructor() {
|
|
214
277
|
super(...arguments);
|
|
278
|
+
/** 交互热区配置 */
|
|
215
279
|
this.hitArea = undefined;
|
|
216
280
|
}
|
|
281
|
+
/**
|
|
282
|
+
* 初始化组件
|
|
283
|
+
* @param params - 初始化参数
|
|
284
|
+
* @param params.hitArea - 交互热区配置
|
|
285
|
+
*/
|
|
217
286
|
init(params) {
|
|
218
287
|
params && Object.assign(this, params);
|
|
219
288
|
}
|
|
@@ -227,6 +296,7 @@ class Event extends eva_js.Component {
|
|
|
227
296
|
return super.on(en, fn, context);
|
|
228
297
|
}
|
|
229
298
|
}
|
|
299
|
+
/** 组件名称 */
|
|
230
300
|
Event.componentName = 'Event';
|
|
231
301
|
|
|
232
302
|
exports.Event = Event;
|
|
@@ -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;
|
|
@@ -72,6 +72,7 @@ let Event$1 = class Event extends Renderer {
|
|
|
72
72
|
component.emit('tap', {
|
|
73
73
|
stopPropagation: () => e.stopPropagation(),
|
|
74
74
|
data: {
|
|
75
|
+
// @ts-ignore
|
|
75
76
|
pointerId: e.data.pointerId,
|
|
76
77
|
position: {
|
|
77
78
|
x: e.data.global.x,
|
|
@@ -86,6 +87,7 @@ let Event$1 = class Event extends Renderer {
|
|
|
86
87
|
component.emit('touchstart', {
|
|
87
88
|
stopPropagation: () => e.stopPropagation(),
|
|
88
89
|
data: {
|
|
90
|
+
// @ts-ignore
|
|
89
91
|
pointerId: e.data.pointerId,
|
|
90
92
|
position: {
|
|
91
93
|
x: e.data.global.x,
|
|
@@ -100,6 +102,7 @@ let Event$1 = class Event extends Renderer {
|
|
|
100
102
|
component.emit('touchmove', {
|
|
101
103
|
stopPropagation: () => e.stopPropagation(),
|
|
102
104
|
data: {
|
|
105
|
+
// @ts-ignore
|
|
103
106
|
pointerId: e.data.pointerId,
|
|
104
107
|
position: {
|
|
105
108
|
x: e.data.global.x,
|
|
@@ -114,6 +117,7 @@ let Event$1 = class Event extends Renderer {
|
|
|
114
117
|
component.emit('touchend', {
|
|
115
118
|
stopPropagation: () => e.stopPropagation(),
|
|
116
119
|
data: {
|
|
120
|
+
// @ts-ignore
|
|
117
121
|
pointerId: e.data.pointerId,
|
|
118
122
|
position: {
|
|
119
123
|
x: e.data.global.x,
|
|
@@ -128,6 +132,7 @@ let Event$1 = class Event extends Renderer {
|
|
|
128
132
|
component.emit('touchendoutside', {
|
|
129
133
|
stopPropagation: () => e.stopPropagation(),
|
|
130
134
|
data: {
|
|
135
|
+
// @ts-ignore
|
|
131
136
|
pointerId: e.data.pointerId,
|
|
132
137
|
position: {
|
|
133
138
|
x: e.data.global.x,
|
|
@@ -142,6 +147,7 @@ let Event$1 = class Event extends Renderer {
|
|
|
142
147
|
component.emit('touchcancel', {
|
|
143
148
|
stopPropagation: () => e.stopPropagation(),
|
|
144
149
|
data: {
|
|
150
|
+
// @ts-ignore
|
|
145
151
|
pointerId: e.data.pointerId,
|
|
146
152
|
position: {
|
|
147
153
|
x: e.data.global.x,
|
|
@@ -205,11 +211,74 @@ var HIT_AREA_TYPE;
|
|
|
205
211
|
HIT_AREA_TYPE["Rect"] = "Rect";
|
|
206
212
|
HIT_AREA_TYPE["RoundedRect"] = "RoundedRect";
|
|
207
213
|
})(HIT_AREA_TYPE || (HIT_AREA_TYPE = {}));
|
|
214
|
+
/**
|
|
215
|
+
* 事件组件
|
|
216
|
+
*
|
|
217
|
+
* Event 组件为游戏对象添加交互能力,使其能够响应触摸和鼠标事件。
|
|
218
|
+
* 可以自定义交互热区的形状(矩形、圆形、多边形等),
|
|
219
|
+
* 适用于按钮、拖拽对象、可点击元素等交互场景。
|
|
220
|
+
*
|
|
221
|
+
* 支持的事件类型:
|
|
222
|
+
* - touchstart - 触摸/点击开始
|
|
223
|
+
* - touchmove - 触摸/鼠标移动
|
|
224
|
+
* - touchend - 触摸/点击结束
|
|
225
|
+
* - tap - 点击/轻触
|
|
226
|
+
* - touchendoutside - 在对象外部结束触摸
|
|
227
|
+
* - touchcancel - 触摸取消
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* ```typescript
|
|
231
|
+
* // 基础用法 - 使用默认热区(Transform 尺寸)
|
|
232
|
+
* const button = new GameObject('button');
|
|
233
|
+
* const event = new Event();
|
|
234
|
+
* button.addComponent(event);
|
|
235
|
+
*
|
|
236
|
+
* event.on('tap', (e) => {
|
|
237
|
+
* console.log('按钮被点击', e.data.position);
|
|
238
|
+
* });
|
|
239
|
+
*
|
|
240
|
+
* // 自定义矩形热区
|
|
241
|
+
* button.addComponent(new Event({
|
|
242
|
+
* hitArea: {
|
|
243
|
+
* type: HIT_AREA_TYPE.Rect,
|
|
244
|
+
* style: { x: 0, y: 0, width: 100, height: 50 }
|
|
245
|
+
* }
|
|
246
|
+
* }));
|
|
247
|
+
*
|
|
248
|
+
* // 圆形热区
|
|
249
|
+
* button.addComponent(new Event({
|
|
250
|
+
* hitArea: {
|
|
251
|
+
* type: HIT_AREA_TYPE.Circle,
|
|
252
|
+
* style: { x: 50, y: 50, radius: 40 }
|
|
253
|
+
* }
|
|
254
|
+
* }));
|
|
255
|
+
*
|
|
256
|
+
* // 多边形热区
|
|
257
|
+
* button.addComponent(new Event({
|
|
258
|
+
* hitArea: {
|
|
259
|
+
* type: HIT_AREA_TYPE.Polygon,
|
|
260
|
+
* style: { paths: [0,0, 100,0, 50,100] }
|
|
261
|
+
* }
|
|
262
|
+
* }));
|
|
263
|
+
*
|
|
264
|
+
* // 事件处理
|
|
265
|
+
* event.on('touchstart', (e) => {
|
|
266
|
+
* console.log('触摸开始', e.data.localPosition);
|
|
267
|
+
* e.stopPropagation(); // 阻止事件冒泡
|
|
268
|
+
* });
|
|
269
|
+
* ```
|
|
270
|
+
*/
|
|
208
271
|
class Event extends Component {
|
|
209
272
|
constructor() {
|
|
210
273
|
super(...arguments);
|
|
274
|
+
/** 交互热区配置 */
|
|
211
275
|
this.hitArea = undefined;
|
|
212
276
|
}
|
|
277
|
+
/**
|
|
278
|
+
* 初始化组件
|
|
279
|
+
* @param params - 初始化参数
|
|
280
|
+
* @param params.hitArea - 交互热区配置
|
|
281
|
+
*/
|
|
213
282
|
init(params) {
|
|
214
283
|
params && Object.assign(this, params);
|
|
215
284
|
}
|
|
@@ -223,6 +292,7 @@ class Event extends Component {
|
|
|
223
292
|
return super.on(en, fn, context);
|
|
224
293
|
}
|
|
225
294
|
}
|
|
295
|
+
/** 组件名称 */
|
|
226
296
|
Event.componentName = 'Event';
|
|
227
297
|
|
|
228
298
|
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.1-beta.
|
|
3
|
+
"version": "2.0.1-beta.28",
|
|
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.1-beta.
|
|
22
|
-
"@eva/eva.js": "2.0.1-beta.
|
|
21
|
+
"@eva/plugin-renderer": "2.0.1-beta.28",
|
|
22
|
+
"@eva/eva.js": "2.0.1-beta.28",
|
|
23
23
|
"pixi.js": "^8.8.1"
|
|
24
24
|
}
|
|
25
25
|
}
|