lythreeframe 1.2.62 → 1.2.64
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.
- package/README.md +160 -1
- package/dist/bundle.cjs.js +193 -188
- package/dist/bundle.esm.js +193 -188
- package/dist/index.d.ts +1 -0
- package/dist/lythreeframe/Frame/Controller.d.ts +42 -20
- package/dist/lythreeframe/Object/Actor.d.ts +13 -20
- package/dist/lythreeframe/Object/Components/SceneComponent.d.ts +9 -0
- package/package.json +1 -1
package/dist/bundle.cjs.js
CHANGED
|
@@ -125,6 +125,30 @@ exports.AttachmentRules = void 0;
|
|
|
125
125
|
AttachmentRules[AttachmentRules["KeepRelative"] = 2] = "KeepRelative";
|
|
126
126
|
})(exports.AttachmentRules || (exports.AttachmentRules = {}));
|
|
127
127
|
|
|
128
|
+
class Delegate {
|
|
129
|
+
constructor() {
|
|
130
|
+
this.functions = [];
|
|
131
|
+
}
|
|
132
|
+
broadcast(...args) {
|
|
133
|
+
this.functions.forEach((func) => func(...args));
|
|
134
|
+
}
|
|
135
|
+
add(func) {
|
|
136
|
+
this.functions.push(func);
|
|
137
|
+
}
|
|
138
|
+
remove(func) {
|
|
139
|
+
const index = this.functions.indexOf(func);
|
|
140
|
+
if (index >= 0) {
|
|
141
|
+
this.functions.splice(index, 1);
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
console.warn("function not found");
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
clear() {
|
|
148
|
+
this.functions = [];
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
128
152
|
class SceneComponent extends Component {
|
|
129
153
|
set parentActor(value) {
|
|
130
154
|
this.childrenComponents.forEach((elem) => {
|
|
@@ -135,6 +159,11 @@ class SceneComponent extends Component {
|
|
|
135
159
|
get parentActor() {
|
|
136
160
|
return this._parentActor;
|
|
137
161
|
}
|
|
162
|
+
// Delegate getters
|
|
163
|
+
get onHoverBeginDelegate() { return this._onHoverBeginDelegate; }
|
|
164
|
+
get onHoverEndDelegate() { return this._onHoverEndDelegate; }
|
|
165
|
+
get onClickDelegate() { return this._onClickDelegate; }
|
|
166
|
+
get onDoubleClickDelegate() { return this._onDoubleClickDelegate; }
|
|
138
167
|
get world() {
|
|
139
168
|
return this.app.world;
|
|
140
169
|
}
|
|
@@ -142,6 +171,11 @@ class SceneComponent extends Component {
|
|
|
142
171
|
super(uuid);
|
|
143
172
|
this.bCanHover = false;
|
|
144
173
|
this.bCanClick = false;
|
|
174
|
+
// Component 级别事件 Delegates
|
|
175
|
+
this._onHoverBeginDelegate = new Delegate();
|
|
176
|
+
this._onHoverEndDelegate = new Delegate();
|
|
177
|
+
this._onClickDelegate = new Delegate();
|
|
178
|
+
this._onDoubleClickDelegate = new Delegate();
|
|
145
179
|
this.app = app;
|
|
146
180
|
this.name = "SceneComponent";
|
|
147
181
|
}
|
|
@@ -710,38 +744,17 @@ class SceneComponent extends Component {
|
|
|
710
744
|
return this.bCanClick;
|
|
711
745
|
}
|
|
712
746
|
onHorveringBegin() {
|
|
713
|
-
|
|
714
|
-
return;
|
|
715
|
-
}
|
|
716
|
-
if (this.parentActor) {
|
|
717
|
-
let comp = this;
|
|
718
|
-
this.parentActor.onComponentHorveringBegin(comp);
|
|
719
|
-
}
|
|
747
|
+
this._onHoverBeginDelegate.broadcast();
|
|
720
748
|
}
|
|
721
749
|
onHorveringEnd() {
|
|
722
|
-
|
|
723
|
-
return;
|
|
724
|
-
}
|
|
725
|
-
if (this.parentActor) {
|
|
726
|
-
let comp = this;
|
|
727
|
-
this.parentActor.onComponentHorveringEnd(comp);
|
|
728
|
-
}
|
|
750
|
+
this._onHoverEndDelegate.broadcast();
|
|
729
751
|
}
|
|
730
752
|
/* click */
|
|
731
753
|
onClicked() {
|
|
732
|
-
|
|
733
|
-
return;
|
|
734
|
-
}
|
|
735
|
-
if (this.parentActor) {
|
|
736
|
-
let comp = this;
|
|
737
|
-
this.parentActor.onComponentClicked(comp);
|
|
738
|
-
}
|
|
754
|
+
this._onClickDelegate.broadcast();
|
|
739
755
|
}
|
|
740
756
|
onDoubleClicked() {
|
|
741
|
-
|
|
742
|
-
let comp = this;
|
|
743
|
-
this.parentActor.onComponentDoubleClicked(comp);
|
|
744
|
-
}
|
|
757
|
+
this._onDoubleClickDelegate.broadcast();
|
|
745
758
|
}
|
|
746
759
|
}
|
|
747
760
|
|
|
@@ -1301,30 +1314,6 @@ exports.AssetType = void 0;
|
|
|
1301
1314
|
AssetType[AssetType["undefined"] = -1] = "undefined";
|
|
1302
1315
|
})(exports.AssetType || (exports.AssetType = {}));
|
|
1303
1316
|
|
|
1304
|
-
class Delegate {
|
|
1305
|
-
constructor() {
|
|
1306
|
-
this.functions = [];
|
|
1307
|
-
}
|
|
1308
|
-
broadcast(...args) {
|
|
1309
|
-
this.functions.forEach((func) => func(...args));
|
|
1310
|
-
}
|
|
1311
|
-
add(func) {
|
|
1312
|
-
this.functions.push(func);
|
|
1313
|
-
}
|
|
1314
|
-
remove(func) {
|
|
1315
|
-
const index = this.functions.indexOf(func);
|
|
1316
|
-
if (index >= 0) {
|
|
1317
|
-
this.functions.splice(index, 1);
|
|
1318
|
-
}
|
|
1319
|
-
else {
|
|
1320
|
-
console.warn("function not found");
|
|
1321
|
-
}
|
|
1322
|
-
}
|
|
1323
|
-
clear() {
|
|
1324
|
-
this.functions = [];
|
|
1325
|
-
}
|
|
1326
|
-
}
|
|
1327
|
-
|
|
1328
1317
|
const DefaultPostProcessParam = {
|
|
1329
1318
|
steps: []
|
|
1330
1319
|
};
|
|
@@ -2191,34 +2180,51 @@ class Controller {
|
|
|
2191
2180
|
get world() { return this._app.world; }
|
|
2192
2181
|
get viewPort() { return this._app.viewport; }
|
|
2193
2182
|
get app() { return this._app; }
|
|
2194
|
-
get onClickNothingDelegate() { return this._onClickNothingDelegate; }
|
|
2195
|
-
get onComponentClickDelegate() { return this._onComponentClickDelegate; }
|
|
2196
|
-
get onComponentDoubleClickDelegate() { return this._onComponentDoubleClickDelegate; }
|
|
2197
|
-
get onComponentHoverBeginDelegate() { return this._onComponentHoverBeginDelegate; }
|
|
2198
|
-
get onComponentHoverEndDelegate() { return this._onComponentHoverEndDelegate; }
|
|
2199
|
-
get onComponentPointerDownDelegate() { return this._onComponentPointerDownDelegate; }
|
|
2200
2183
|
get pawn() {
|
|
2201
2184
|
if (!this._pawn)
|
|
2202
2185
|
throw Error("pawn is null");
|
|
2203
2186
|
return this._pawn;
|
|
2204
2187
|
}
|
|
2188
|
+
// Component level delegate getters
|
|
2189
|
+
get onComponentClickDelegate() { return this._onComponentClickDelegate; }
|
|
2190
|
+
get onComponentDoubleClickDelegate() { return this._onComponentDoubleClickDelegate; }
|
|
2191
|
+
get onComponentHoverBeginDelegate() { return this._onComponentHoverBeginDelegate; }
|
|
2192
|
+
get onComponentHoverEndDelegate() { return this._onComponentHoverEndDelegate; }
|
|
2193
|
+
get onComponentPointerDownDelegate() { return this._onComponentPointerDownDelegate; }
|
|
2194
|
+
// Actor level delegate getters
|
|
2195
|
+
get onActorClickDelegate() { return this._onActorClickDelegate; }
|
|
2196
|
+
get onActorDoubleClickDelegate() { return this._onActorDoubleClickDelegate; }
|
|
2197
|
+
get onActorHoverBeginDelegate() { return this._onActorHoverBeginDelegate; }
|
|
2198
|
+
get onActorHoverEndDelegate() { return this._onActorHoverEndDelegate; }
|
|
2199
|
+
get onClickNothingDelegate() { return this._onClickNothingDelegate; }
|
|
2205
2200
|
constructor(app) {
|
|
2206
2201
|
this._pawn = null;
|
|
2202
|
+
// Component level state
|
|
2203
|
+
this.hoveringComponent = null;
|
|
2204
|
+
// Actor level state
|
|
2205
|
+
this.hoveringActor = null;
|
|
2206
|
+
// Click state
|
|
2207
2207
|
this.prepareClickComponent = null;
|
|
2208
2208
|
this.prepareClickHit = null;
|
|
2209
2209
|
this.prepareClickModifiers = { ctrlKey: false, shiftKey: false, altKey: false };
|
|
2210
|
-
this.hoveringComponent = null;
|
|
2211
2210
|
this._pointButtonIsDown = new Set();
|
|
2212
|
-
|
|
2211
|
+
// Component level delegates
|
|
2213
2212
|
this._onComponentClickDelegate = new Delegate();
|
|
2214
2213
|
this._onComponentDoubleClickDelegate = new Delegate();
|
|
2215
2214
|
this._onComponentHoverBeginDelegate = new Delegate();
|
|
2216
2215
|
this._onComponentHoverEndDelegate = new Delegate();
|
|
2217
2216
|
this._onComponentPointerDownDelegate = new Delegate();
|
|
2217
|
+
// Actor level delegates
|
|
2218
|
+
this._onActorClickDelegate = new Delegate();
|
|
2219
|
+
this._onActorDoubleClickDelegate = new Delegate();
|
|
2220
|
+
this._onActorHoverBeginDelegate = new Delegate();
|
|
2221
|
+
this._onActorHoverEndDelegate = new Delegate();
|
|
2222
|
+
// Other delegates
|
|
2223
|
+
this._onClickNothingDelegate = new Delegate();
|
|
2218
2224
|
// Pointer state
|
|
2219
2225
|
this.pointerPosition = new webgpu.Vector2();
|
|
2220
2226
|
this.pointerLeftDownPosition = new webgpu.Vector2();
|
|
2221
|
-
// Reusable objects
|
|
2227
|
+
// Reusable objects
|
|
2222
2228
|
this._tempVec2 = new webgpu.Vector2();
|
|
2223
2229
|
this._raycastVec2 = new webgpu.Vector2();
|
|
2224
2230
|
// Double click detection
|
|
@@ -2257,7 +2263,7 @@ class Controller {
|
|
|
2257
2263
|
}
|
|
2258
2264
|
destroy() {
|
|
2259
2265
|
this.clearClickTimer();
|
|
2260
|
-
this.
|
|
2266
|
+
this.clearHovering();
|
|
2261
2267
|
const canvas = this.viewPort.canvas;
|
|
2262
2268
|
if (canvas) {
|
|
2263
2269
|
canvas.removeEventListener("pointerenter", this.onPointerEnter);
|
|
@@ -2268,7 +2274,9 @@ class Controller {
|
|
|
2268
2274
|
this.pawn.destroy();
|
|
2269
2275
|
this._pawn = null;
|
|
2270
2276
|
}
|
|
2277
|
+
// ==================== Pointer Events ====================
|
|
2271
2278
|
onPointerMoveEvent(event) {
|
|
2279
|
+
var _a, _b;
|
|
2272
2280
|
const canvas = this.viewPort.canvas;
|
|
2273
2281
|
if (!canvas)
|
|
2274
2282
|
throw Error("canvas is null");
|
|
@@ -2277,47 +2285,48 @@ class Controller {
|
|
|
2277
2285
|
if (this._pointButtonIsDown.size > 0)
|
|
2278
2286
|
return;
|
|
2279
2287
|
const hits = this.getHitResultUnderCursor();
|
|
2280
|
-
const component = hits === null || hits === void 0 ? void 0 : hits.component;
|
|
2288
|
+
const component = (_a = hits === null || hits === void 0 ? void 0 : hits.component) !== null && _a !== void 0 ? _a : null;
|
|
2289
|
+
const actor = (_b = component === null || component === void 0 ? void 0 : component.parentActor) !== null && _b !== void 0 ? _b : null;
|
|
2290
|
+
// Component 级别 hover 检测
|
|
2281
2291
|
if (component !== this.hoveringComponent) {
|
|
2282
|
-
this.
|
|
2283
|
-
|
|
2284
|
-
|
|
2292
|
+
if (this.hoveringComponent) {
|
|
2293
|
+
this.fireComponentHoverEnd(this.hoveringComponent);
|
|
2294
|
+
}
|
|
2295
|
+
if (component && component.isHoverEnabled && hits) {
|
|
2296
|
+
this.fireComponentHoverBegin(component, hits.hit);
|
|
2297
|
+
}
|
|
2298
|
+
}
|
|
2299
|
+
// Actor 级别 hover 检测(独立于 Component)
|
|
2300
|
+
if (actor !== this.hoveringActor) {
|
|
2301
|
+
if (this.hoveringActor && this.hoveringComponent) {
|
|
2302
|
+
this.fireActorHoverEnd(this.hoveringActor, this.hoveringComponent);
|
|
2303
|
+
}
|
|
2304
|
+
if (actor && component && actor.isHoverEnabled && hits) {
|
|
2305
|
+
this.fireActorHoverBegin(actor, component, hits.hit);
|
|
2285
2306
|
}
|
|
2286
2307
|
}
|
|
2308
|
+
this.hoveringComponent = component;
|
|
2309
|
+
this.hoveringActor = actor;
|
|
2287
2310
|
}
|
|
2288
|
-
|
|
2311
|
+
clearHovering() {
|
|
2289
2312
|
if (this.hoveringComponent) {
|
|
2290
|
-
this.
|
|
2313
|
+
this.fireComponentHoverEnd(this.hoveringComponent);
|
|
2291
2314
|
}
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
const event = { component, hit, handled: false };
|
|
2295
|
-
if (isBegin) {
|
|
2296
|
-
this._onComponentHoverBeginDelegate.broadcast(event);
|
|
2297
|
-
if (!event.handled) {
|
|
2298
|
-
component.onHorveringBegin();
|
|
2299
|
-
}
|
|
2300
|
-
this.hoveringComponent = component;
|
|
2301
|
-
}
|
|
2302
|
-
else {
|
|
2303
|
-
this._onComponentHoverEndDelegate.broadcast(event);
|
|
2304
|
-
if (!event.handled) {
|
|
2305
|
-
component.onHorveringEnd();
|
|
2306
|
-
}
|
|
2307
|
-
this.hoveringComponent = null;
|
|
2315
|
+
if (this.hoveringActor && this.hoveringComponent) {
|
|
2316
|
+
this.fireActorHoverEnd(this.hoveringActor, this.hoveringComponent);
|
|
2308
2317
|
}
|
|
2318
|
+
this.hoveringComponent = null;
|
|
2319
|
+
this.hoveringActor = null;
|
|
2309
2320
|
}
|
|
2310
2321
|
onPointerUpEvent(event) {
|
|
2311
2322
|
this._pointButtonIsDown.delete(event.button);
|
|
2312
2323
|
if (event.button !== 0)
|
|
2313
2324
|
return;
|
|
2314
|
-
// Check if pointer moved too much (drag instead of click)
|
|
2315
2325
|
const pointerOffset = this._tempVec2.subVectors(this.pointerLeftDownPosition, this.pointerPosition).length();
|
|
2316
2326
|
if (pointerOffset > 0.005) {
|
|
2317
2327
|
this.clearClickTimer();
|
|
2318
2328
|
return;
|
|
2319
2329
|
}
|
|
2320
|
-
// 保存修饰键状态
|
|
2321
2330
|
this.prepareClickModifiers = {
|
|
2322
2331
|
ctrlKey: event.ctrlKey,
|
|
2323
2332
|
shiftKey: event.shiftKey,
|
|
@@ -2339,7 +2348,7 @@ class Controller {
|
|
|
2339
2348
|
this.leftClickTimer = window.setTimeout(() => {
|
|
2340
2349
|
this.leftClickTimer = null;
|
|
2341
2350
|
if (this.prepareClickComponent && this.prepareClickHit) {
|
|
2342
|
-
this.
|
|
2351
|
+
this.fireClickEvents(this.prepareClickComponent, this.prepareClickHit, false);
|
|
2343
2352
|
this.prepareClickComponent = null;
|
|
2344
2353
|
this.prepareClickHit = null;
|
|
2345
2354
|
}
|
|
@@ -2352,7 +2361,7 @@ class Controller {
|
|
|
2352
2361
|
handleDoubleClick() {
|
|
2353
2362
|
this.clearClickTimer();
|
|
2354
2363
|
if (this.prepareClickComponent && this.prepareClickHit) {
|
|
2355
|
-
this.
|
|
2364
|
+
this.fireClickEvents(this.prepareClickComponent, this.prepareClickHit, true);
|
|
2356
2365
|
}
|
|
2357
2366
|
else {
|
|
2358
2367
|
this._onClickNothingDelegate.broadcast();
|
|
@@ -2360,8 +2369,40 @@ class Controller {
|
|
|
2360
2369
|
this.prepareClickComponent = null;
|
|
2361
2370
|
this.prepareClickHit = null;
|
|
2362
2371
|
}
|
|
2363
|
-
|
|
2364
|
-
|
|
2372
|
+
onPointerDownEvent(event) {
|
|
2373
|
+
this._pointButtonIsDown.add(event.button);
|
|
2374
|
+
if (event.button === 0) {
|
|
2375
|
+
this.pointerLeftDownPosition.copy(this.pointerPosition);
|
|
2376
|
+
}
|
|
2377
|
+
const hit = this.getHitResultUnderCursor();
|
|
2378
|
+
const component = hit === null || hit === void 0 ? void 0 : hit.component;
|
|
2379
|
+
if (component instanceof SceneComponent && hit) {
|
|
2380
|
+
this.firePointerDownEvent(component, hit.hit, event.button);
|
|
2381
|
+
}
|
|
2382
|
+
}
|
|
2383
|
+
onPointerEnterEvent(_event) {
|
|
2384
|
+
this.addCorePointerListeners();
|
|
2385
|
+
}
|
|
2386
|
+
onPointerLeaveEvent(_event) {
|
|
2387
|
+
this.removeCorePointerListeners();
|
|
2388
|
+
}
|
|
2389
|
+
// ==================== Component Level Events ====================
|
|
2390
|
+
fireComponentHoverBegin(component, hit) {
|
|
2391
|
+
const event = { component, hit, handled: false };
|
|
2392
|
+
this._onComponentHoverBeginDelegate.broadcast(event);
|
|
2393
|
+
if (!event.handled) {
|
|
2394
|
+
component.onHorveringBegin();
|
|
2395
|
+
}
|
|
2396
|
+
}
|
|
2397
|
+
fireComponentHoverEnd(component) {
|
|
2398
|
+
const event = { component, hit: null, handled: false };
|
|
2399
|
+
this._onComponentHoverEndDelegate.broadcast(event);
|
|
2400
|
+
if (!event.handled) {
|
|
2401
|
+
component.onHorveringEnd();
|
|
2402
|
+
}
|
|
2403
|
+
}
|
|
2404
|
+
fireComponentClick(component, hit, isDoubleClick) {
|
|
2405
|
+
const event = Object.assign({ component, hit, handled: false }, this.prepareClickModifiers);
|
|
2365
2406
|
if (isDoubleClick) {
|
|
2366
2407
|
this._onComponentDoubleClickDelegate.broadcast(event);
|
|
2367
2408
|
if (!event.handled) {
|
|
@@ -2375,33 +2416,56 @@ class Controller {
|
|
|
2375
2416
|
}
|
|
2376
2417
|
}
|
|
2377
2418
|
}
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
this.leftClickTimer = null;
|
|
2382
|
-
}
|
|
2419
|
+
firePointerDownEvent(component, hit, button) {
|
|
2420
|
+
const event = { component, hit, button, handled: false };
|
|
2421
|
+
this._onComponentPointerDownDelegate.broadcast(event);
|
|
2383
2422
|
}
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2423
|
+
// ==================== Actor Level Events ====================
|
|
2424
|
+
fireActorHoverBegin(actor, component, hit) {
|
|
2425
|
+
const event = { actor, component, hit, handled: false };
|
|
2426
|
+
this._onActorHoverBeginDelegate.broadcast(event);
|
|
2427
|
+
if (!event.handled) {
|
|
2428
|
+
actor.onActorHoverBegin(component);
|
|
2388
2429
|
}
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
const
|
|
2392
|
-
|
|
2393
|
-
|
|
2430
|
+
}
|
|
2431
|
+
fireActorHoverEnd(actor, component) {
|
|
2432
|
+
const event = { actor, component, hit: null, handled: false };
|
|
2433
|
+
this._onActorHoverEndDelegate.broadcast(event);
|
|
2434
|
+
if (!event.handled) {
|
|
2435
|
+
actor.onActorHoverEnd(component);
|
|
2394
2436
|
}
|
|
2395
2437
|
}
|
|
2396
|
-
|
|
2397
|
-
const event = { component, hit,
|
|
2398
|
-
|
|
2438
|
+
fireActorClick(actor, component, hit, isDoubleClick) {
|
|
2439
|
+
const event = Object.assign({ actor, component, hit, handled: false }, this.prepareClickModifiers);
|
|
2440
|
+
if (isDoubleClick) {
|
|
2441
|
+
this._onActorDoubleClickDelegate.broadcast(event);
|
|
2442
|
+
if (!event.handled) {
|
|
2443
|
+
actor.onActorDoubleClick(component);
|
|
2444
|
+
}
|
|
2445
|
+
}
|
|
2446
|
+
else {
|
|
2447
|
+
this._onActorClickDelegate.broadcast(event);
|
|
2448
|
+
if (!event.handled) {
|
|
2449
|
+
actor.onActorClick(component);
|
|
2450
|
+
}
|
|
2451
|
+
}
|
|
2399
2452
|
}
|
|
2400
|
-
|
|
2401
|
-
|
|
2453
|
+
// ==================== Combined Events ====================
|
|
2454
|
+
fireClickEvents(component, hit, isDoubleClick) {
|
|
2455
|
+
// Component level
|
|
2456
|
+
this.fireComponentClick(component, hit, isDoubleClick);
|
|
2457
|
+
// Actor level
|
|
2458
|
+
const actor = component.parentActor;
|
|
2459
|
+
if (actor && actor.isClickEnabled) {
|
|
2460
|
+
this.fireActorClick(actor, component, hit, isDoubleClick);
|
|
2461
|
+
}
|
|
2402
2462
|
}
|
|
2403
|
-
|
|
2404
|
-
|
|
2463
|
+
// ==================== Utility ====================
|
|
2464
|
+
clearClickTimer() {
|
|
2465
|
+
if (this.leftClickTimer) {
|
|
2466
|
+
window.clearTimeout(this.leftClickTimer);
|
|
2467
|
+
this.leftClickTimer = null;
|
|
2468
|
+
}
|
|
2405
2469
|
}
|
|
2406
2470
|
addCorePointerListeners() {
|
|
2407
2471
|
const canvas = this.viewPort.canvas;
|
|
@@ -2437,17 +2501,14 @@ class Controller {
|
|
|
2437
2501
|
this._raycastVec2.set(x, y);
|
|
2438
2502
|
this.raycaster.setFromCamera(this._raycastVec2, this.camera);
|
|
2439
2503
|
const hits = this.raycaster.intersectObjects(this.world.scene.children, true);
|
|
2440
|
-
|
|
2504
|
+
const out = [];
|
|
2441
2505
|
for (const hit of hits) {
|
|
2442
2506
|
if (hit.object.userData["rayIgnored"])
|
|
2443
2507
|
continue;
|
|
2444
2508
|
const component = hit.object.userData["LYObject"];
|
|
2445
2509
|
if (!component)
|
|
2446
2510
|
continue;
|
|
2447
|
-
out.push({
|
|
2448
|
-
component: component,
|
|
2449
|
-
hit: hit
|
|
2450
|
-
});
|
|
2511
|
+
out.push({ component, hit });
|
|
2451
2512
|
}
|
|
2452
2513
|
return out;
|
|
2453
2514
|
}
|
|
@@ -2640,15 +2701,21 @@ class Actor extends BaseObject {
|
|
|
2640
2701
|
this.app.world.removeTickableActor(this);
|
|
2641
2702
|
}
|
|
2642
2703
|
}
|
|
2704
|
+
// Delegate getters
|
|
2705
|
+
get onHoverBeginDelegate() { return this._onHoverBeginDelegate; }
|
|
2706
|
+
get onHoverEndDelegate() { return this._onHoverEndDelegate; }
|
|
2707
|
+
get onClickDelegate() { return this._onClickDelegate; }
|
|
2708
|
+
get onDoubleClickDelegate() { return this._onDoubleClickDelegate; }
|
|
2643
2709
|
constructor(app, uuid) {
|
|
2644
2710
|
super(uuid);
|
|
2645
2711
|
this._name = "Actor";
|
|
2646
2712
|
this._rootComponent = null;
|
|
2647
2713
|
this._world = null;
|
|
2648
|
-
|
|
2649
|
-
this.
|
|
2650
|
-
this.
|
|
2651
|
-
this.
|
|
2714
|
+
// Actor 级别事件 Delegates
|
|
2715
|
+
this._onHoverBeginDelegate = new Delegate();
|
|
2716
|
+
this._onHoverEndDelegate = new Delegate();
|
|
2717
|
+
this._onClickDelegate = new Delegate();
|
|
2718
|
+
this._onDoubleClickDelegate = new Delegate();
|
|
2652
2719
|
this.app = app;
|
|
2653
2720
|
this.rootComponent = this.constructRootComponent();
|
|
2654
2721
|
this.rootComponent.parentActor = this;
|
|
@@ -2903,80 +2970,18 @@ class Actor extends BaseObject {
|
|
|
2903
2970
|
set isClickEnabled(bCanHorver) {
|
|
2904
2971
|
this.rootComponent.isClickEnabled = bCanHorver;
|
|
2905
2972
|
}
|
|
2906
|
-
//
|
|
2907
|
-
|
|
2908
|
-
this.
|
|
2909
|
-
}
|
|
2910
|
-
removeHoveringBeginEvent(target) {
|
|
2911
|
-
let index = this.onHoverBeginEvent.indexOf(target);
|
|
2912
|
-
if (index >= 0) {
|
|
2913
|
-
this.onHoverBeginEvent.splice(index, 1);
|
|
2914
|
-
}
|
|
2915
|
-
}
|
|
2916
|
-
clearHoveringBeginEvent() {
|
|
2917
|
-
this.onHoverBeginEvent = [];
|
|
2918
|
-
}
|
|
2919
|
-
onComponentHorveringBegin(component) {
|
|
2920
|
-
for (let i = 0; i < this.onHoverBeginEvent.length; ++i) {
|
|
2921
|
-
this.onHoverBeginEvent[i](component);
|
|
2922
|
-
}
|
|
2923
|
-
}
|
|
2924
|
-
// hovering end
|
|
2925
|
-
addHoveringEndEvent(newFunc) {
|
|
2926
|
-
this.onHoverEndEvent.push(newFunc);
|
|
2927
|
-
}
|
|
2928
|
-
removeHoveringEndEvent(target) {
|
|
2929
|
-
let index = this.onHoverEndEvent.indexOf(target);
|
|
2930
|
-
if (index >= 0) {
|
|
2931
|
-
this.onHoverEndEvent.splice(index, 1);
|
|
2932
|
-
}
|
|
2933
|
-
}
|
|
2934
|
-
clearHoveringEndEvent() {
|
|
2935
|
-
this.onHoverEndEvent = [];
|
|
2936
|
-
}
|
|
2937
|
-
onComponentHorveringEnd(component) {
|
|
2938
|
-
// console.log("onComponentHorveringEnd", this)
|
|
2939
|
-
for (let i = 0; i < this.onHoverEndEvent.length; ++i) {
|
|
2940
|
-
this.onHoverEndEvent[i](component);
|
|
2941
|
-
}
|
|
2942
|
-
}
|
|
2943
|
-
//click
|
|
2944
|
-
addClickEvent(newFunc) {
|
|
2945
|
-
this.onClickedEvent.push(newFunc);
|
|
2946
|
-
}
|
|
2947
|
-
removeClickEvent(target) {
|
|
2948
|
-
let index = this.onClickedEvent.indexOf(target);
|
|
2949
|
-
if (index >= 0) {
|
|
2950
|
-
this.onClickedEvent.splice(index, 1);
|
|
2951
|
-
}
|
|
2952
|
-
}
|
|
2953
|
-
clearClickEvent() {
|
|
2954
|
-
this.onClickedEvent = [];
|
|
2973
|
+
// ==================== Actor Events ====================
|
|
2974
|
+
onActorHoverBegin(component) {
|
|
2975
|
+
this._onHoverBeginDelegate.broadcast(component);
|
|
2955
2976
|
}
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
for (let i = 0; i < this.onClickedEvent.length; ++i) {
|
|
2959
|
-
this.onClickedEvent[i](component);
|
|
2960
|
-
}
|
|
2977
|
+
onActorHoverEnd(component) {
|
|
2978
|
+
this._onHoverEndDelegate.broadcast(component);
|
|
2961
2979
|
}
|
|
2962
|
-
|
|
2963
|
-
|
|
2964
|
-
this.onDoubleClickedEvent.push(newFunc);
|
|
2965
|
-
}
|
|
2966
|
-
removeDoubleClickEvent(target) {
|
|
2967
|
-
let index = this.onClickedEvent.indexOf(target);
|
|
2968
|
-
if (index >= 0) {
|
|
2969
|
-
this.onDoubleClickedEvent.splice(index, 1);
|
|
2970
|
-
}
|
|
2971
|
-
}
|
|
2972
|
-
onComponentDoubleClicked(component) {
|
|
2973
|
-
//console.log("onComponentClicked", this.Name, component)
|
|
2974
|
-
for (let i = 0; i < this.onDoubleClickedEvent.length; ++i) {
|
|
2975
|
-
this.onDoubleClickedEvent[i](component);
|
|
2976
|
-
}
|
|
2980
|
+
onActorClick(component) {
|
|
2981
|
+
this._onClickDelegate.broadcast(component);
|
|
2977
2982
|
}
|
|
2978
|
-
|
|
2979
|
-
this.
|
|
2983
|
+
onActorDoubleClick(component) {
|
|
2984
|
+
this._onDoubleClickDelegate.broadcast(component);
|
|
2980
2985
|
}
|
|
2981
2986
|
}
|
|
2982
2987
|
|