@galacean/engine-ui 1.6.6 → 1.6.8

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.
Files changed (33) hide show
  1. package/package.json +3 -3
  2. package/dist/browser.js +0 -3662
  3. package/dist/browser.js.map +0 -1
  4. package/dist/browser.min.js +0 -2
  5. package/dist/browser.min.js.map +0 -1
  6. package/dist/main.js +0 -3658
  7. package/dist/main.js.map +0 -1
  8. package/dist/module.js +0 -3639
  9. package/dist/module.js.map +0 -1
  10. package/types/Utils.d.ts +0 -18
  11. package/types/component/UICanvas.d.ts +0 -91
  12. package/types/component/UIGroup.d.ts +0 -37
  13. package/types/component/UIRenderer.d.ts +0 -36
  14. package/types/component/UITransform.d.ts +0 -111
  15. package/types/component/advanced/Button.d.ts +0 -21
  16. package/types/component/advanced/Image.d.ts +0 -37
  17. package/types/component/advanced/Text.d.ts +0 -88
  18. package/types/component/index.d.ts +0 -11
  19. package/types/component/interactive/UIInteractive.d.ts +0 -55
  20. package/types/component/interactive/transition/ColorTransition.d.ts +0 -17
  21. package/types/component/interactive/transition/ScaleTransition.d.ts +0 -11
  22. package/types/component/interactive/transition/SpriteTransition.d.ts +0 -11
  23. package/types/component/interactive/transition/Transition.d.ts +0 -57
  24. package/types/enums/CanvasRenderMode.d.ts +0 -22
  25. package/types/enums/HorizontalAlignmentMode.d.ts +0 -13
  26. package/types/enums/ResolutionAdaptationMode.d.ts +0 -16
  27. package/types/enums/VerticalAlignmentMode.d.ts +0 -13
  28. package/types/index.d.ts +0 -25
  29. package/types/input/UIHitResult.d.ts +0 -1
  30. package/types/input/UIPointerEventEmitter.d.ts +0 -1
  31. package/types/interface/IElement.d.ts +0 -13
  32. package/types/interface/IGraphics.d.ts +0 -8
  33. package/types/interface/IGroupAble.d.ts +0 -14
package/dist/module.js DELETED
@@ -1,3639 +0,0 @@
1
- import { EntityModifyFlags, ignoreClone, assignmentClone, DisorderedArray, Component, TransformModifyFlags, Transform, deepClone, Vector2, Rect, MathUtil, Vector3, Matrix, Plane, ShaderProperty, dependentComponents, DependentMode, BatchUtils, ShaderMacroCollection, Renderer, Vector4, Color, RendererUpdateFlags, Entity, Script, Camera, CameraModifyFlags, Logger, SafeLoopArray, SpriteDrawMode, RenderQueueFlags, SpriteModifyFlags, SpriteTileMode, TiledSpriteAssembler, SlicedSpriteAssembler, SimpleSpriteAssembler, BoundingBox, ShaderData, ShaderDataGroup, TextUtils, Engine, TextVerticalAlignment, TextHorizontalAlignment, OverflowMode, CharRenderInfo, FontStyle, ReferResource, registerPointerEventEmitter, PointerEventEmitter, CameraClearFlags, ReflectionParser, Material, BlendFactor, BlendOperation, CullMode, RenderQueueType, Loader, Shader, ShaderPass, PipelineStage, Font } from '@galacean/engine';
2
-
3
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
4
- try {
5
- var info = gen[key](arg);
6
- var value = info.value;
7
- } catch (error) {
8
- reject(error);
9
- return;
10
- }
11
- if (info.done) resolve(value);
12
- else Promise.resolve(value).then(_next, _throw);
13
- }
14
- function _async_to_generator(fn) {
15
- return function() {
16
- var self = this, args = arguments;
17
-
18
- return new Promise(function(resolve, reject) {
19
- var gen = fn.apply(self, args);
20
-
21
- function _next(value) {
22
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
23
- }
24
-
25
- function _throw(err) {
26
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
27
- }
28
-
29
- _next(undefined);
30
- });
31
- };
32
- }
33
-
34
- /******************************************************************************
35
- Copyright (c) Microsoft Corporation.
36
-
37
- Permission to use, copy, modify, and/or distribute this software for any
38
- purpose with or without fee is hereby granted.
39
-
40
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
41
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
42
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
43
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
44
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
45
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
46
- PERFORMANCE OF THIS SOFTWARE.
47
- ***************************************************************************** */
48
-
49
- function __decorate(decorators, target, key, desc) {
50
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
51
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
52
- 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;
53
- return c > 3 && r && Object.defineProperty(target, key, r), r;
54
- }
55
-
56
- function __generator(thisArg, body) {
57
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
58
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
59
- function verb(n) { return function (v) { return step([n, v]); }; }
60
- function step(op) {
61
- if (f) throw new TypeError("Generator is already executing.");
62
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
63
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
64
- if (y = 0, t) op = [op[0] & 2, t.value];
65
- switch (op[0]) {
66
- case 0: case 1: t = op; break;
67
- case 4: _.label++; return { value: op[1], done: false };
68
- case 5: _.label++; y = op[1]; op = [0]; continue;
69
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
70
- default:
71
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
72
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
73
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
74
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
75
- if (t[2]) _.ops.pop();
76
- _.trys.pop(); continue;
77
- }
78
- op = body.call(thisArg, _);
79
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
80
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
81
- }
82
- }
83
-
84
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
85
- var e = new Error(message);
86
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
87
- };
88
-
89
- function _defineProperties(target, props) {
90
- for (var i = 0; i < props.length; i++) {
91
- var descriptor = props[i];
92
- descriptor.enumerable = descriptor.enumerable || false;
93
- descriptor.configurable = true;
94
-
95
- if ("value" in descriptor) descriptor.writable = true;
96
-
97
- Object.defineProperty(target, descriptor.key, descriptor);
98
- }
99
- }
100
- function _create_class(Constructor, protoProps, staticProps) {
101
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
102
- if (staticProps) _defineProperties(Constructor, staticProps);
103
-
104
- return Constructor;
105
- }
106
-
107
- function _set_prototype_of(o, p) {
108
- _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
109
- o.__proto__ = p;
110
-
111
- return o;
112
- };
113
-
114
- return _set_prototype_of(o, p);
115
- }
116
-
117
- function _inherits(subClass, superClass) {
118
- if (typeof superClass !== "function" && superClass !== null) {
119
- throw new TypeError("Super expression must either be null or a function");
120
- }
121
-
122
- subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } });
123
-
124
- if (superClass) _set_prototype_of(subClass, superClass);
125
- }
126
-
127
- function _instanceof(left, right) {
128
- if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
129
- return !!right[Symbol.hasInstance](left);
130
- } else return left instanceof right;
131
- }
132
-
133
- var UIGroup = /*#__PURE__*/ function(Component) {
134
- _inherits(UIGroup, Component);
135
- function UIGroup(entity) {
136
- var _this;
137
- _this = Component.call(this, entity) || this, /** @internal */ _this._indexInGroup = -1, /** @internal */ _this._indexInRootCanvas = -1, /** @internal */ _this._disorderedElements = new DisorderedArray(), /** @internal */ _this._globalAlpha = 1, /** @internal */ _this._globalInteractive = true, _this._alpha = 1, _this._interactive = true, _this._ignoreParentGroup = false, /** @internal */ _this._rootCanvasListeningEntities = [], /** @internal */ _this._groupListeningEntities = [], /** @internal */ _this._isRootCanvasDirty = false, /** @internal */ _this._isGroupDirty = false, /** @internal */ _this._groupDirtyFlags = 0;
138
- _this._rootCanvasListener = _this._rootCanvasListener.bind(_this);
139
- _this._groupListener = _this._groupListener.bind(_this);
140
- return _this;
141
- }
142
- var _proto = UIGroup.prototype;
143
- /**
144
- * @internal
145
- */ _proto._getGlobalAlpha = function _getGlobalAlpha() {
146
- if (this._isContainDirtyFlag(1)) {
147
- if (this._ignoreParentGroup) {
148
- this._globalAlpha = this._alpha;
149
- } else {
150
- var parentGroup = this._getGroup();
151
- this._globalAlpha = this._alpha * (parentGroup ? parentGroup._getGlobalAlpha() : 1);
152
- }
153
- this._setDirtyFlagFalse(1);
154
- }
155
- return this._globalAlpha;
156
- };
157
- /**
158
- * @internal
159
- */ _proto._getGlobalInteractive = function _getGlobalInteractive() {
160
- if (this._isContainDirtyFlag(2)) {
161
- if (this._ignoreParentGroup) {
162
- this._globalInteractive = this._interactive;
163
- } else {
164
- var parentGroup = this._getGroup();
165
- this._globalInteractive = this._interactive && (!parentGroup || parentGroup._getGlobalInteractive());
166
- }
167
- this._setDirtyFlagFalse(2);
168
- }
169
- return this._globalInteractive;
170
- };
171
- // @ts-ignore
172
- _proto._onEnableInScene = function _onEnableInScene() {
173
- Utils.setRootCanvasDirty(this);
174
- Utils.setGroupDirty(this);
175
- // @ts-ignore
176
- this.entity._dispatchModify(EntityUIModifyFlags.GroupEnableInScene);
177
- };
178
- // @ts-ignore
179
- _proto._onDisableInScene = function _onDisableInScene() {
180
- Utils.cleanRootCanvas(this);
181
- Utils.cleanGroup(this);
182
- var disorderedElements = this._disorderedElements;
183
- disorderedElements.forEach(function(element) {
184
- Utils.setGroupDirty(element);
185
- });
186
- disorderedElements.length = 0;
187
- disorderedElements.garbageCollection();
188
- this._isRootCanvasDirty = this._isGroupDirty = false;
189
- };
190
- /**
191
- * @internal
192
- */ _proto._getRootCanvas = function _getRootCanvas() {
193
- this._isRootCanvasDirty && Utils.setRootCanvas(this, Utils.searchRootCanvasInParents(this));
194
- return this._rootCanvas;
195
- };
196
- /**
197
- * @internal
198
- */ _proto._getGroup = function _getGroup() {
199
- this._isGroupDirty && Utils.setGroup(this, Utils.searchGroupInParents(this));
200
- return this._group;
201
- };
202
- /**
203
- * @internal
204
- */ _proto._groupListener = function _groupListener(flag) {
205
- if (flag === EntityModifyFlags.Parent || flag === EntityUIModifyFlags.GroupEnableInScene) {
206
- Utils.setGroupDirty(this);
207
- }
208
- };
209
- /**
210
- * @internal
211
- */ _proto._rootCanvasListener = function _rootCanvasListener(flag) {
212
- if (flag === EntityModifyFlags.Parent || flag === EntityUIModifyFlags.CanvasEnableInScene) {
213
- Utils.setRootCanvasDirty(this);
214
- Utils.setGroupDirty(this);
215
- }
216
- };
217
- /**
218
- * @internal
219
- */ _proto._onGroupModify = function _onGroupModify(flags, isPass) {
220
- if (isPass === void 0) isPass = false;
221
- if (isPass && this._ignoreParentGroup) return;
222
- if (this._isContainDirtyFlags(flags)) return;
223
- this._setDirtyFlagTrue(flags);
224
- this._disorderedElements.forEach(function(element) {
225
- element._onGroupModify(flags, true);
226
- });
227
- };
228
- _proto._isContainDirtyFlags = function _isContainDirtyFlags(targetDirtyFlags) {
229
- return (this._groupDirtyFlags & targetDirtyFlags) === targetDirtyFlags;
230
- };
231
- _proto._isContainDirtyFlag = function _isContainDirtyFlag(type) {
232
- return (this._groupDirtyFlags & type) != 0;
233
- };
234
- _proto._setDirtyFlagTrue = function _setDirtyFlagTrue(type) {
235
- this._groupDirtyFlags |= type;
236
- };
237
- _proto._setDirtyFlagFalse = function _setDirtyFlagFalse(type) {
238
- this._groupDirtyFlags &= ~type;
239
- };
240
- _create_class(UIGroup, [
241
- {
242
- key: "ignoreParentGroup",
243
- get: /**
244
- * Whether to ignore the parent group.
245
- * @remarks If this parameter set to `true`,
246
- * all settings of the parent group will be ignored.
247
- */ function get() {
248
- return this._ignoreParentGroup;
249
- },
250
- set: function set(value) {
251
- if (this._ignoreParentGroup !== value) {
252
- this._ignoreParentGroup = value;
253
- this._onGroupModify(3);
254
- }
255
- }
256
- },
257
- {
258
- key: "interactive",
259
- get: /**
260
- * Whether the group is interactive.
261
- */ function get() {
262
- return this._interactive;
263
- },
264
- set: function set(value) {
265
- if (this._interactive !== value) {
266
- this._interactive = value;
267
- this._onGroupModify(2);
268
- }
269
- }
270
- },
271
- {
272
- key: "alpha",
273
- get: /**
274
- * The alpha value of the group.
275
- */ function get() {
276
- return this._alpha;
277
- },
278
- set: function set(value) {
279
- value = Math.max(0, Math.min(value, 1));
280
- if (this._alpha !== value) {
281
- this._alpha = value;
282
- this._onGroupModify(1);
283
- }
284
- }
285
- }
286
- ]);
287
- return UIGroup;
288
- }(Component);
289
- __decorate([
290
- ignoreClone
291
- ], UIGroup.prototype, "_indexInGroup", void 0);
292
- __decorate([
293
- ignoreClone
294
- ], UIGroup.prototype, "_indexInRootCanvas", void 0);
295
- __decorate([
296
- ignoreClone
297
- ], UIGroup.prototype, "_group", void 0);
298
- __decorate([
299
- ignoreClone
300
- ], UIGroup.prototype, "_rootCanvas", void 0);
301
- __decorate([
302
- ignoreClone
303
- ], UIGroup.prototype, "_disorderedElements", void 0);
304
- __decorate([
305
- ignoreClone
306
- ], UIGroup.prototype, "_globalAlpha", void 0);
307
- __decorate([
308
- ignoreClone
309
- ], UIGroup.prototype, "_globalInteractive", void 0);
310
- __decorate([
311
- assignmentClone
312
- ], UIGroup.prototype, "_alpha", void 0);
313
- __decorate([
314
- assignmentClone
315
- ], UIGroup.prototype, "_interactive", void 0);
316
- __decorate([
317
- assignmentClone
318
- ], UIGroup.prototype, "_ignoreParentGroup", void 0);
319
- __decorate([
320
- ignoreClone
321
- ], UIGroup.prototype, "_rootCanvasListeningEntities", void 0);
322
- __decorate([
323
- ignoreClone
324
- ], UIGroup.prototype, "_groupListeningEntities", void 0);
325
- __decorate([
326
- ignoreClone
327
- ], UIGroup.prototype, "_isRootCanvasDirty", void 0);
328
- __decorate([
329
- ignoreClone
330
- ], UIGroup.prototype, "_isGroupDirty", void 0);
331
- __decorate([
332
- ignoreClone
333
- ], UIGroup.prototype, "_groupDirtyFlags", void 0);
334
- __decorate([
335
- ignoreClone
336
- ], UIGroup.prototype, "_groupListener", null);
337
- __decorate([
338
- ignoreClone
339
- ], UIGroup.prototype, "_rootCanvasListener", null);
340
- var GroupModifyFlags = /*#__PURE__*/ function(GroupModifyFlags) {
341
- GroupModifyFlags[GroupModifyFlags["None"] = 0] = "None";
342
- GroupModifyFlags[GroupModifyFlags["GlobalAlpha"] = 1] = "GlobalAlpha";
343
- GroupModifyFlags[GroupModifyFlags["GlobalInteractive"] = 2] = "GlobalInteractive";
344
- GroupModifyFlags[GroupModifyFlags["All"] = 3] = "All";
345
- return GroupModifyFlags;
346
- }({});
347
-
348
- var Utils = /*#__PURE__*/ function() {
349
- function Utils() {}
350
- Utils.setRootCanvasDirty = function setRootCanvasDirty(element) {
351
- if (element._isRootCanvasDirty) return;
352
- element._isRootCanvasDirty = true;
353
- this._registerRootCanvas(element, null);
354
- element._onRootCanvasModify == null ? void 0 : element._onRootCanvasModify.call(element, RootCanvasModifyFlags.All);
355
- };
356
- Utils.setRootCanvas = function setRootCanvas(element, rootCanvas) {
357
- element._isRootCanvasDirty = false;
358
- this._registerRootCanvas(element, rootCanvas);
359
- var fromEntity = _instanceof(element, UICanvas) ? element.entity.parent : element.entity;
360
- var _rootCanvas_entity_parent;
361
- var toEntity = (_rootCanvas_entity_parent = rootCanvas == null ? void 0 : rootCanvas.entity.parent) != null ? _rootCanvas_entity_parent : null;
362
- this._registerListener(fromEntity, toEntity, element._rootCanvasListener, element._rootCanvasListeningEntities);
363
- };
364
- Utils.cleanRootCanvas = function cleanRootCanvas(element) {
365
- this._registerRootCanvas(element, null);
366
- this._unRegisterListener(element._rootCanvasListener, element._rootCanvasListeningEntities);
367
- };
368
- Utils.searchRootCanvasInParents = function searchRootCanvasInParents(element) {
369
- var entity = _instanceof(element, UICanvas) ? element.entity.parent : element.entity;
370
- while(entity){
371
- // @ts-ignore
372
- var components = entity._components;
373
- for(var i = 0, n = components.length; i < n; i++){
374
- var component = components[i];
375
- if (component.enabled && _instanceof(component, UICanvas) && component._isRootCanvas) {
376
- return component;
377
- }
378
- }
379
- entity = entity.parent;
380
- }
381
- return null;
382
- };
383
- Utils.setGroupDirty = function setGroupDirty(element) {
384
- if (element._isGroupDirty) return;
385
- element._isGroupDirty = true;
386
- this._registerGroup(element, null);
387
- element._onGroupModify(GroupModifyFlags.All);
388
- };
389
- Utils.setGroup = function setGroup(element, group) {
390
- element._isGroupDirty = false;
391
- this._registerGroup(element, group);
392
- var rootCanvas = element._getRootCanvas();
393
- if (rootCanvas) {
394
- var fromEntity = _instanceof(element, UIGroup) ? element.entity.parent : element.entity;
395
- var _group_entity;
396
- var toEntity = (_group_entity = group == null ? void 0 : group.entity) != null ? _group_entity : rootCanvas.entity.parent;
397
- this._registerListener(fromEntity, toEntity, element._groupListener, element._groupListeningEntities);
398
- } else {
399
- this._unRegisterListener(element._groupListener, element._groupListeningEntities);
400
- }
401
- };
402
- Utils.cleanGroup = function cleanGroup(element) {
403
- this._registerGroup(element, null);
404
- this._unRegisterListener(element._groupListener, element._groupListeningEntities);
405
- };
406
- Utils.searchGroupInParents = function searchGroupInParents(element) {
407
- var rootCanvas = element._getRootCanvas();
408
- if (!rootCanvas) return null;
409
- var entity = _instanceof(element, UIGroup) ? element.entity.parent : element.entity;
410
- var rootCanvasParent = rootCanvas.entity.parent;
411
- while(entity && entity !== rootCanvasParent){
412
- // @ts-ignore
413
- var components = entity._components;
414
- for(var i = 0, n = components.length; i < n; i++){
415
- var component = components[i];
416
- if (component.enabled && _instanceof(component, UIGroup)) {
417
- return component;
418
- }
419
- }
420
- entity = entity.parent;
421
- }
422
- return null;
423
- };
424
- Utils._registerRootCanvas = function _registerRootCanvas(element, canvas) {
425
- var preCanvas = element._rootCanvas;
426
- if (preCanvas !== canvas) {
427
- if (preCanvas) {
428
- var replaced = preCanvas._disorderedElements.deleteByIndex(element._indexInRootCanvas);
429
- replaced && (replaced._indexInRootCanvas = element._indexInRootCanvas);
430
- element._indexInRootCanvas = -1;
431
- }
432
- if (canvas) {
433
- var disorderedElements = canvas._disorderedElements;
434
- element._indexInRootCanvas = disorderedElements.length;
435
- disorderedElements.add(element);
436
- }
437
- element._rootCanvas = canvas;
438
- }
439
- };
440
- Utils._registerGroup = function _registerGroup(element, group) {
441
- var preGroup = element._group;
442
- if (preGroup !== group) {
443
- if (preGroup) {
444
- var replaced = preGroup._disorderedElements.deleteByIndex(element._indexInGroup);
445
- replaced && (replaced._indexInGroup = element._indexInGroup);
446
- element._indexInGroup = -1;
447
- }
448
- if (group) {
449
- var disorderedElements = group._disorderedElements;
450
- element._indexInGroup = disorderedElements.length;
451
- disorderedElements.add(element);
452
- }
453
- element._group = group;
454
- element._onGroupModify(GroupModifyFlags.All);
455
- }
456
- };
457
- Utils._registerListener = function _registerListener(entity, root, listener, listeningEntities) {
458
- var count = 0;
459
- while(entity && entity !== root){
460
- var preEntity = listeningEntities[count];
461
- if (preEntity !== entity) {
462
- // @ts-ignore
463
- preEntity == null ? void 0 : preEntity._unRegisterModifyListener(listener);
464
- listeningEntities[count] = entity;
465
- // @ts-ignore
466
- entity._registerModifyListener(listener);
467
- }
468
- entity = entity.parent;
469
- count++;
470
- }
471
- listeningEntities.length = count;
472
- };
473
- Utils._unRegisterListener = function _unRegisterListener(listener, listeningEntities) {
474
- for(var i = 0, n = listeningEntities.length; i < n; i++){
475
- // @ts-ignore
476
- listeningEntities[i]._unRegisterModifyListener(listener);
477
- }
478
- listeningEntities.length = 0;
479
- };
480
- return Utils;
481
- }();
482
-
483
- /**
484
- * Render mode for ui canvas.
485
- */ var CanvasRenderMode = /*#__PURE__*/ function(CanvasRenderMode) {
486
- /**
487
- * The UI canvas will be rendered directly onto the screen and adapted to screen space,
488
- * overlaying other rendering elements in the same scene.
489
- * @remarks if the `engine.canvas` size change, the UI canvas will automatically adapt.
490
- */ CanvasRenderMode[CanvasRenderMode["ScreenSpaceOverlay"] = 0] = "ScreenSpaceOverlay";
491
- /**
492
- * The UI canvas is placed at a specified distance in front of the camera and adapted to screen space,
493
- * with all objects rendered by the camera.
494
- * @remarks if the camera's properties or the `engine.canvas` size change, the UI canvas will automatically adapt.
495
- * @remarks if set `ScreenSpaceCamera` but no corresponding camera is assigned, the actual rendering mode defaults to `ScreenSpaceOverlay`.
496
- */ CanvasRenderMode[CanvasRenderMode["ScreenSpaceCamera"] = 1] = "ScreenSpaceCamera";
497
- /**
498
- * The UI canvas is placed in the 3D world space and rendered by every camera in the same scene.
499
- */ CanvasRenderMode[CanvasRenderMode["WorldSpace"] = 2] = "WorldSpace";
500
- return CanvasRenderMode;
501
- }({});
502
-
503
- /**
504
- * Resolution adaptation mode.
505
- * @remarks Only effective in screen space.
506
- */ var ResolutionAdaptationMode = /*#__PURE__*/ function(ResolutionAdaptationMode) {
507
- /** Adapt based on width.(`referenceResolution.x`) */ ResolutionAdaptationMode[ResolutionAdaptationMode["WidthAdaptation"] = 0] = "WidthAdaptation";
508
- /** Adapt based on height.(`referenceResolution.y`) */ ResolutionAdaptationMode[ResolutionAdaptationMode["HeightAdaptation"] = 1] = "HeightAdaptation";
509
- /** Adapt based on both width and height.(`referenceResolution`) */ ResolutionAdaptationMode[ResolutionAdaptationMode["BothAdaptation"] = 2] = "BothAdaptation";
510
- /** Adapt to the side with a larger ratio. */ ResolutionAdaptationMode[ResolutionAdaptationMode["ExpandAdaptation"] = 3] = "ExpandAdaptation";
511
- /** Adapt to the side with smaller ratio. */ ResolutionAdaptationMode[ResolutionAdaptationMode["ShrinkAdaptation"] = 4] = "ShrinkAdaptation";
512
- return ResolutionAdaptationMode;
513
- }({});
514
-
515
- /** Horizontal alignment mode. */ var HorizontalAlignmentMode = /*#__PURE__*/ function(HorizontalAlignmentMode) {
516
- /** No horizontal alignment. */ HorizontalAlignmentMode[HorizontalAlignmentMode["None"] = 0] = "None";
517
- /** Left-aligned, `alignLeft` drives `position.x`. */ HorizontalAlignmentMode[HorizontalAlignmentMode["Left"] = 1] = "Left";
518
- /** Right-aligned, `alignRight` drives `position.x`. */ HorizontalAlignmentMode[HorizontalAlignmentMode["Right"] = 2] = "Right";
519
- /** Horizontal stretch, `alignLeft` and `alignRight` drive `position.x` and `size.x`. */ HorizontalAlignmentMode[HorizontalAlignmentMode["LeftAndRight"] = 3] = "LeftAndRight";
520
- /** Center-aligned, `alignCenter` drives `position.x`. */ HorizontalAlignmentMode[HorizontalAlignmentMode["Center"] = 4] = "Center";
521
- return HorizontalAlignmentMode;
522
- }({});
523
-
524
- /** Vertical alignment mode. */ var VerticalAlignmentMode = /*#__PURE__*/ function(VerticalAlignmentMode) {
525
- /** No vertical alignment. */ VerticalAlignmentMode[VerticalAlignmentMode["None"] = 0] = "None";
526
- /** Top-aligned, `alignTop` drives `position.y`. */ VerticalAlignmentMode[VerticalAlignmentMode["Top"] = 1] = "Top";
527
- /** Bottom-aligned, `alignBottom` drives `position.y`. */ VerticalAlignmentMode[VerticalAlignmentMode["Bottom"] = 2] = "Bottom";
528
- /** Vertical stretch, `alignTop` and `alignBottom` drive `position.y` and `size.y`. */ VerticalAlignmentMode[VerticalAlignmentMode["TopAndBottom"] = 3] = "TopAndBottom";
529
- /** Middle-aligned, `alignMiddle` drives `position.y`. */ VerticalAlignmentMode[VerticalAlignmentMode["Middle"] = 4] = "Middle";
530
- return VerticalAlignmentMode;
531
- }({});
532
-
533
- /**
534
- * The Transform component exclusive to the UI element.
535
- */ var UITransform = /*#__PURE__*/ function(Transform) {
536
- _inherits(UITransform, Transform);
537
- function UITransform(entity) {
538
- var _this;
539
- _this = Transform.call(this, entity) || this, _this._size = new Vector2(100, 100), _this._pivot = new Vector2(0.5, 0.5), _this._rect = new Rect(-50, -50, 100, 100), _this._alignLeft = 0, _this._alignRight = 0, _this._alignCenter = 0, _this._alignTop = 0, _this._alignBottom = 0, _this._alignMiddle = 0, _this._horizontalAlignment = HorizontalAlignmentMode.None, _this._verticalAlignment = VerticalAlignmentMode.None;
540
- _this._onSizeChanged = _this._onSizeChanged.bind(_this);
541
- _this._onPivotChanged = _this._onPivotChanged.bind(_this);
542
- // @ts-ignore
543
- _this._size._onValueChanged = _this._onSizeChanged;
544
- // @ts-ignore
545
- _this._pivot._onValueChanged = _this._onPivotChanged;
546
- return _this;
547
- }
548
- var _proto = UITransform.prototype;
549
- /**
550
- * @internal
551
- */ _proto._parentChange = function _parentChange() {
552
- this._isParentDirty = true;
553
- this._updateWorldFlagWithParentRectChange(TransformModifyFlags.WmWpWeWqWsWus);
554
- };
555
- // @ts-ignore
556
- _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
557
- // @ts-ignore
558
- Transform.prototype._cloneTo.call(this, target, srcRoot, targetRoot);
559
- var size = target._size, pivot = target._pivot;
560
- // @ts-ignore
561
- size._onValueChanged = pivot._onValueChanged = null;
562
- size.copyFrom(this._size);
563
- pivot.copyFrom(this._pivot);
564
- // @ts-ignore
565
- size._onValueChanged = target._onSizeChanged;
566
- // @ts-ignore
567
- pivot._onValueChanged = target._onPivotChanged;
568
- };
569
- _proto._onLocalMatrixChanging = function _onLocalMatrixChanging() {
570
- // `super._onLocalMatrixChanging()` will set `LocalMatrix` dirty flag `false`
571
- // If there is an alignment, `position` and `localMatrix` will be reset again
572
- if (this._horizontalAlignment || this._verticalAlignment) {
573
- this._updatePositionByAlignment();
574
- this._setDirtyFlagTrue(TransformModifyFlags.LocalMatrix);
575
- } else {
576
- Transform.prototype._onLocalMatrixChanging.call(this);
577
- }
578
- };
579
- _proto._onWorldMatrixChanging = function _onWorldMatrixChanging() {
580
- // `super._onWorldMatrixChanging()` will set `WorldMatrix` dirty flag `false`
581
- // If there is an alignment, `position` and `worldMatrix` will be reset again(`worldMatrix` dirty flag is already `true`)
582
- !this._horizontalAlignment && !this._verticalAlignment && Transform.prototype._onWorldMatrixChanging.call(this);
583
- };
584
- _proto._onPositionChanged = function _onPositionChanged() {
585
- (this._horizontalAlignment || this._verticalAlignment) && this._updatePositionByAlignment();
586
- Transform.prototype._onPositionChanged.call(this);
587
- };
588
- _proto._onWorldPositionChanged = function _onWorldPositionChanged() {
589
- Transform.prototype._onWorldPositionChanged.call(this);
590
- if (this._horizontalAlignment || this._verticalAlignment) {
591
- this._setDirtyFlagTrue(TransformModifyFlags.WorldPosition);
592
- }
593
- };
594
- _proto._updatePositionByAlignment = function _updatePositionByAlignment() {
595
- var _this__getParentTransform;
596
- var parentRect = (_this__getParentTransform = this._getParentTransform()) == null ? void 0 : _this__getParentTransform._rect;
597
- if (parentRect) {
598
- var position = this.position;
599
- // @ts-ignore
600
- position._onValueChanged = null;
601
- var rect = this._rect;
602
- switch(this._horizontalAlignment){
603
- case HorizontalAlignmentMode.Left:
604
- case HorizontalAlignmentMode.LeftAndRight:
605
- position.x = parentRect.x - rect.x + this._alignLeft;
606
- break;
607
- case HorizontalAlignmentMode.Center:
608
- position.x = parentRect.x + parentRect.width * 0.5 - rect.x - rect.width * 0.5 + this._alignCenter;
609
- break;
610
- case HorizontalAlignmentMode.Right:
611
- position.x = parentRect.x + parentRect.width - rect.x - rect.width - this._alignRight;
612
- break;
613
- }
614
- switch(this._verticalAlignment){
615
- case VerticalAlignmentMode.Top:
616
- position.y = parentRect.y + parentRect.height - rect.y - rect.height - this._alignTop;
617
- break;
618
- case VerticalAlignmentMode.Middle:
619
- position.y = parentRect.y + parentRect.height * 0.5 - rect.y - rect.height * 0.5 + this._alignMiddle;
620
- break;
621
- case VerticalAlignmentMode.Bottom:
622
- case VerticalAlignmentMode.TopAndBottom:
623
- position.y = parentRect.y - rect.y + this._alignBottom;
624
- break;
625
- }
626
- // @ts-ignore
627
- position._onValueChanged = this._onPositionChanged;
628
- }
629
- };
630
- _proto._updateSizeByAlignment = function _updateSizeByAlignment() {
631
- var _this__getParentTransform;
632
- var parentRect = (_this__getParentTransform = this._getParentTransform()) == null ? void 0 : _this__getParentTransform._rect;
633
- if (parentRect) {
634
- var size = this._size;
635
- // @ts-ignore
636
- size._onValueChanged = null;
637
- // The values of size must be greater than 0
638
- if (this._horizontalAlignment === HorizontalAlignmentMode.LeftAndRight) {
639
- size.x = Math.max(parentRect.width - this._alignLeft - this._alignRight, 0);
640
- }
641
- if (this._verticalAlignment === VerticalAlignmentMode.TopAndBottom) {
642
- size.y = Math.max(parentRect.height - this._alignTop - this._alignBottom, 0);
643
- }
644
- // @ts-ignore
645
- size._onValueChanged = this._onSizeChanged;
646
- }
647
- };
648
- _proto._updateRectBySizeAndPivot = function _updateRectBySizeAndPivot() {
649
- var _this = this, size = _this.size, pivot = _this._pivot;
650
- var x = -pivot.x * size.x;
651
- var y = -pivot.y * size.y;
652
- this._rect.set(x, y, size.x, size.y);
653
- };
654
- _proto._onSizeChanged = function _onSizeChanged() {
655
- if (this._horizontalAlignment === HorizontalAlignmentMode.LeftAndRight || this._verticalAlignment === VerticalAlignmentMode.TopAndBottom) {
656
- this._updateSizeByAlignment();
657
- }
658
- this._updateRectBySizeAndPivot();
659
- this._updateWorldFlagWithSelfRectChange();
660
- // @ts-ignore
661
- this._entity._updateFlagManager.dispatch(512);
662
- };
663
- _proto._onPivotChanged = function _onPivotChanged() {
664
- this._updateRectBySizeAndPivot();
665
- this._updateWorldFlagWithSelfRectChange();
666
- // @ts-ignore
667
- this._entity._updateFlagManager.dispatch(1024);
668
- };
669
- _proto._updateWorldFlagWithSelfRectChange = function _updateWorldFlagWithSelfRectChange() {
670
- var worldFlags = 0;
671
- if (this._horizontalAlignment || this._verticalAlignment) {
672
- this._updatePositionByAlignment();
673
- this._setDirtyFlagTrue(TransformModifyFlags.LocalMatrix);
674
- worldFlags = TransformModifyFlags.WmWp;
675
- !this._isContainDirtyFlags(worldFlags) && this._worldAssociatedChange(worldFlags);
676
- }
677
- var children = this.entity.children;
678
- for(var i = 0, n = children.length; i < n; i++){
679
- var _children_i_transform__updateWorldFlagWithParentRectChange, _children_i_transform;
680
- (_children_i_transform = children[i].transform) == null ? void 0 : (_children_i_transform__updateWorldFlagWithParentRectChange = _children_i_transform._updateWorldFlagWithParentRectChange) == null ? void 0 : _children_i_transform__updateWorldFlagWithParentRectChange.call(_children_i_transform, worldFlags);
681
- }
682
- };
683
- _proto._updateWorldFlagWithParentRectChange = function _updateWorldFlagWithParentRectChange(flags, parentChange) {
684
- if (parentChange === void 0) parentChange = true;
685
- var selfChange = false;
686
- if (parentChange) {
687
- var _this = this, horizontalAlignment = _this._horizontalAlignment, verticalAlignment = _this._verticalAlignment;
688
- if (horizontalAlignment || verticalAlignment) {
689
- if (horizontalAlignment === HorizontalAlignmentMode.LeftAndRight || verticalAlignment === VerticalAlignmentMode.TopAndBottom) {
690
- this._updateSizeByAlignment();
691
- this._updateRectBySizeAndPivot();
692
- selfChange = true;
693
- }
694
- this._updatePositionByAlignment();
695
- this._setDirtyFlagTrue(TransformModifyFlags.LocalMatrix);
696
- flags |= TransformModifyFlags.WmWp;
697
- }
698
- }
699
- var containDirtyFlags = this._isContainDirtyFlags(flags);
700
- !containDirtyFlags && this._worldAssociatedChange(flags);
701
- if (selfChange || !containDirtyFlags) {
702
- var children = this.entity.children;
703
- for(var i = 0, n = children.length; i < n; i++){
704
- var _children_i_transform__updateWorldFlagWithParentRectChange, _children_i_transform;
705
- (_children_i_transform = children[i].transform) == null ? void 0 : (_children_i_transform__updateWorldFlagWithParentRectChange = _children_i_transform._updateWorldFlagWithParentRectChange) == null ? void 0 : _children_i_transform__updateWorldFlagWithParentRectChange.call(_children_i_transform, flags, selfChange);
706
- }
707
- }
708
- // @ts-ignore
709
- selfChange && this._entity._updateFlagManager.dispatch(512);
710
- };
711
- _create_class(UITransform, [
712
- {
713
- key: "size",
714
- get: /**
715
- * Width and height of UI element.
716
- */ function get() {
717
- return this._size;
718
- },
719
- set: function set(value) {
720
- var _this = this, size = _this._size;
721
- if (size === value) return;
722
- (size.x !== value.x || size.y !== value.y) && size.copyFrom(value);
723
- }
724
- },
725
- {
726
- key: "pivot",
727
- get: /**
728
- * Pivot of UI element.
729
- */ function get() {
730
- return this._pivot;
731
- },
732
- set: function set(value) {
733
- var _this = this, pivot = _this._pivot;
734
- if (pivot === value) return;
735
- (pivot.x !== value.x || pivot.y !== value.y) && pivot.copyFrom(value);
736
- }
737
- },
738
- {
739
- key: "horizontalAlignment",
740
- get: /**
741
- * Horizontal alignment mode.
742
- *
743
- * @remarks
744
- * Controls how the element aligns horizontally within its parent:
745
- * - `Left` - Align to parent's left edge
746
- * - `Center` - Align to parent's horizontal center
747
- * - `Right` - Align to parent's right edge
748
- * - `LeftAndRight` - Align to both left and right edges (stretch to fill width)
749
- */ function get() {
750
- return this._horizontalAlignment;
751
- },
752
- set: function set(value) {
753
- if (this._horizontalAlignment === value) return;
754
- this._horizontalAlignment = value;
755
- switch(value){
756
- case HorizontalAlignmentMode.Left:
757
- case HorizontalAlignmentMode.Right:
758
- case HorizontalAlignmentMode.Center:
759
- this._onPositionChanged();
760
- break;
761
- case HorizontalAlignmentMode.LeftAndRight:
762
- this._onPositionChanged();
763
- this._onSizeChanged();
764
- break;
765
- }
766
- }
767
- },
768
- {
769
- key: "alignLeft",
770
- get: /**
771
- * Left margin when horizontalAlignment is Left or LeftAndRight.
772
- *
773
- * @remarks
774
- * Only effective when horizontalAlignment includes Left mode.
775
- * Distance from the parent's left edge to the element's left edge.
776
- */ function get() {
777
- return this._alignLeft;
778
- },
779
- set: function set(value) {
780
- if (!Number.isFinite(value)) return;
781
- if (MathUtil.equals(value, this._alignLeft)) return;
782
- this._alignLeft = value;
783
- if (this._horizontalAlignment & HorizontalAlignmentMode.Left) {
784
- this._onPositionChanged();
785
- this._horizontalAlignment & HorizontalAlignmentMode.Right && this._onSizeChanged();
786
- }
787
- }
788
- },
789
- {
790
- key: "alignRight",
791
- get: /**
792
- * Right margin when horizontalAlignment is Right or LeftAndRight.
793
- *
794
- * @remarks
795
- * Only effective when horizontalAlignment includes Right mode.
796
- * Distance from the parent's right edge to the element's right edge.
797
- */ function get() {
798
- return this._alignRight;
799
- },
800
- set: function set(value) {
801
- if (!Number.isFinite(value)) return;
802
- if (MathUtil.equals(value, this._alignRight)) return;
803
- this._alignRight = value;
804
- if (this._horizontalAlignment & HorizontalAlignmentMode.Right) {
805
- this._onPositionChanged();
806
- this._horizontalAlignment & HorizontalAlignmentMode.Left && this._onSizeChanged();
807
- }
808
- }
809
- },
810
- {
811
- key: "alignCenter",
812
- get: /**
813
- * Horizontal center offset when horizontalAlignment is Center.
814
- *
815
- * @remarks
816
- * Only effective when horizontalAlignment is Center mode.
817
- * Positive values move the element to the right, negative values to the left.
818
- */ function get() {
819
- return this._alignCenter;
820
- },
821
- set: function set(value) {
822
- if (!Number.isFinite(value)) return;
823
- if (MathUtil.equals(value, this._alignCenter)) return;
824
- this._alignCenter = value;
825
- this._horizontalAlignment & HorizontalAlignmentMode.Center && this._onPositionChanged();
826
- }
827
- },
828
- {
829
- key: "verticalAlignment",
830
- get: /**
831
- * Vertical alignment mode.
832
- *
833
- * @remarks
834
- * Controls how the element aligns vertically within its parent:
835
- * - `Top` - Align to parent's top edge
836
- * - `Middle` - Align to parent's vertical center
837
- * - `Bottom` - Align to parent's bottom edge
838
- * - `TopAndBottom` - Align to both top and bottom edges (stretch to fill height)
839
- */ function get() {
840
- return this._verticalAlignment;
841
- },
842
- set: function set(value) {
843
- if (this._verticalAlignment === value) return;
844
- this._verticalAlignment = value;
845
- switch(value){
846
- case VerticalAlignmentMode.Top:
847
- case VerticalAlignmentMode.Bottom:
848
- case VerticalAlignmentMode.Middle:
849
- this._onPositionChanged();
850
- break;
851
- case VerticalAlignmentMode.TopAndBottom:
852
- this._onPositionChanged();
853
- this._onSizeChanged();
854
- break;
855
- }
856
- }
857
- },
858
- {
859
- key: "alignTop",
860
- get: /**
861
- * Top margin when verticalAlignment is Top or TopAndBottom.
862
- *
863
- * @remarks
864
- * Only effective when verticalAlignment includes Top mode.
865
- * Used to offset the element from the parent's top edge.
866
- */ function get() {
867
- return this._alignTop;
868
- },
869
- set: function set(value) {
870
- if (!Number.isFinite(value)) return;
871
- if (MathUtil.equals(value, this._alignTop)) return;
872
- this._alignTop = value;
873
- if (this._verticalAlignment & VerticalAlignmentMode.Top) {
874
- this._onPositionChanged();
875
- this._verticalAlignment & VerticalAlignmentMode.Bottom && this._onSizeChanged();
876
- }
877
- }
878
- },
879
- {
880
- key: "alignBottom",
881
- get: /**
882
- * Bottom inset used in vertical alignment formulas.
883
- */ function get() {
884
- return this._alignBottom;
885
- },
886
- set: function set(value) {
887
- if (!Number.isFinite(value)) return;
888
- if (MathUtil.equals(value, this._alignBottom)) return;
889
- this._alignBottom = value;
890
- if (this._verticalAlignment & VerticalAlignmentMode.Bottom) {
891
- this._onPositionChanged();
892
- this._verticalAlignment & VerticalAlignmentMode.Top && this._onSizeChanged();
893
- }
894
- }
895
- },
896
- {
897
- key: "alignMiddle",
898
- get: /**
899
- * Vertical middle offset relative to parent's middle.
900
- */ function get() {
901
- return this._alignMiddle;
902
- },
903
- set: function set(value) {
904
- if (!Number.isFinite(value)) return;
905
- if (MathUtil.equals(value, this._alignMiddle)) return;
906
- this._alignMiddle = value;
907
- this._verticalAlignment & VerticalAlignmentMode.Middle && this._onPositionChanged();
908
- }
909
- }
910
- ]);
911
- return UITransform;
912
- }(Transform);
913
- __decorate([
914
- ignoreClone
915
- ], UITransform.prototype, "_size", void 0);
916
- __decorate([
917
- ignoreClone
918
- ], UITransform.prototype, "_pivot", void 0);
919
- __decorate([
920
- deepClone
921
- ], UITransform.prototype, "_rect", void 0);
922
- __decorate([
923
- ignoreClone
924
- ], UITransform.prototype, "_onPositionChanged", null);
925
- __decorate([
926
- ignoreClone
927
- ], UITransform.prototype, "_onWorldPositionChanged", null);
928
- __decorate([
929
- ignoreClone
930
- ], UITransform.prototype, "_onSizeChanged", null);
931
- __decorate([
932
- ignoreClone
933
- ], UITransform.prototype, "_onPivotChanged", null);
934
- /**
935
- * @internal
936
- * extends TransformModifyFlags
937
- */ var UITransformModifyFlags = /*#__PURE__*/ function(UITransformModifyFlags) {
938
- UITransformModifyFlags[UITransformModifyFlags["Size"] = 512] = "Size";
939
- UITransformModifyFlags[UITransformModifyFlags["Pivot"] = 1024] = "Pivot";
940
- return UITransformModifyFlags;
941
- }({});
942
-
943
- var UIRenderer = /*#__PURE__*/ function(Renderer) {
944
- _inherits(UIRenderer, Renderer);
945
- function UIRenderer(entity) {
946
- var _this;
947
- _this = Renderer.call(this, entity) || this, /**
948
- * Custom boundary for raycast detection.
949
- * @remarks this is based on `this.entity.transform`.
950
- */ _this.raycastPadding = new Vector4(0, 0, 0, 0), /** @internal */ _this._indexInRootCanvas = -1, /** @internal */ _this._isRootCanvasDirty = false, /** @internal */ _this._rootCanvasListeningEntities = [], /** @internal */ _this._indexInGroup = -1, /** @internal */ _this._isGroupDirty = false, /** @internal */ _this._groupListeningEntities = [], _this._raycastEnabled = true, _this._color = new Color(1, 1, 1, 1);
951
- _this._dirtyUpdateFlag = RendererUpdateFlags.WorldVolume | 2;
952
- _this._onColorChanged = _this._onColorChanged.bind(_this);
953
- //@ts-ignore
954
- _this._color._onValueChanged = _this._onColorChanged;
955
- _this._groupListener = _this._groupListener.bind(_this);
956
- _this._rootCanvasListener = _this._rootCanvasListener.bind(_this);
957
- return _this;
958
- }
959
- var _proto = UIRenderer.prototype;
960
- // @ts-ignore
961
- _proto._canBatch = function _canBatch(elementA, elementB) {
962
- return BatchUtils.canBatchSprite(elementA, elementB);
963
- };
964
- // @ts-ignore
965
- _proto._batch = function _batch(elementA, elementB) {
966
- BatchUtils.batchFor2D(elementA, elementB);
967
- };
968
- // @ts-ignore
969
- _proto._updateTransformShaderData = function _updateTransformShaderData(context, onlyMVP, batched) {
970
- // @ts-ignore
971
- Renderer.prototype._updateTransformShaderData.call(this, context, onlyMVP, true);
972
- };
973
- // @ts-ignore
974
- _proto._prepareRender = function _prepareRender(context) {
975
- // Update once per frame per renderer, not influenced by batched
976
- if (this._renderFrameCount !== this.engine.time.frameCount) {
977
- this._update(context);
978
- }
979
- this._render(context);
980
- // union camera global macro and renderer macro.
981
- ShaderMacroCollection.unionCollection(context.camera._globalShaderMacro, // @ts-ignore
982
- this.shaderData._macroCollection, //@ts-ignore
983
- this._globalShaderMacro);
984
- };
985
- // @ts-ignore
986
- _proto._onEnableInScene = function _onEnableInScene() {
987
- // @ts-ignore
988
- this._overrideUpdate && this.scene._componentsManager.addOnUpdateRenderers(this);
989
- this.entity._updateUIHierarchyVersion(UICanvas._hierarchyCounter);
990
- Utils.setRootCanvasDirty(this);
991
- Utils.setGroupDirty(this);
992
- };
993
- // @ts-ignore
994
- _proto._onDisableInScene = function _onDisableInScene() {
995
- // @ts-ignore
996
- this._overrideUpdate && this.scene._componentsManager.removeOnUpdateRenderers(this);
997
- this.entity._updateUIHierarchyVersion(UICanvas._hierarchyCounter);
998
- Utils.cleanRootCanvas(this);
999
- Utils.cleanGroup(this);
1000
- };
1001
- /**
1002
- * @internal
1003
- */ _proto._getGlobalAlpha = function _getGlobalAlpha() {
1004
- var _this__getGroup;
1005
- var _this__getGroup__getGlobalAlpha;
1006
- return (_this__getGroup__getGlobalAlpha = (_this__getGroup = this._getGroup()) == null ? void 0 : _this__getGroup._getGlobalAlpha()) != null ? _this__getGroup__getGlobalAlpha : 1;
1007
- };
1008
- /**
1009
- * @internal
1010
- */ _proto._getRootCanvas = function _getRootCanvas() {
1011
- this._isRootCanvasDirty && Utils.setRootCanvas(this, Utils.searchRootCanvasInParents(this));
1012
- return this._rootCanvas;
1013
- };
1014
- /**
1015
- * @internal
1016
- */ _proto._getGroup = function _getGroup() {
1017
- this._isGroupDirty && Utils.setGroup(this, Utils.searchGroupInParents(this));
1018
- return this._group;
1019
- };
1020
- /**
1021
- * @internal
1022
- */ _proto._groupListener = function _groupListener(flag) {
1023
- if (flag === EntityModifyFlags.Parent || flag === EntityUIModifyFlags.GroupEnableInScene) {
1024
- Utils.setGroupDirty(this);
1025
- }
1026
- };
1027
- /**
1028
- * @internal
1029
- */ _proto._rootCanvasListener = function _rootCanvasListener(flag, entity) {
1030
- switch(flag){
1031
- case EntityModifyFlags.Parent:
1032
- Utils.setRootCanvasDirty(this);
1033
- Utils.setGroupDirty(this);
1034
- case EntityModifyFlags.Child:
1035
- entity._updateUIHierarchyVersion(UICanvas._hierarchyCounter);
1036
- break;
1037
- }
1038
- };
1039
- /**
1040
- * @internal
1041
- */ _proto._onGroupModify = function _onGroupModify(flags) {
1042
- if (flags & GroupModifyFlags.GlobalAlpha) {
1043
- this._dirtyUpdateFlag |= 2;
1044
- }
1045
- };
1046
- _proto._onColorChanged = function _onColorChanged() {
1047
- this._dirtyUpdateFlag |= 2;
1048
- };
1049
- /**
1050
- * @internal
1051
- */ _proto._getChunkManager = function _getChunkManager() {
1052
- // @ts-ignore
1053
- return this.engine._batcherManager.primitiveChunkManagerUI;
1054
- };
1055
- /**
1056
- * @internal
1057
- */ _proto._raycast = function _raycast(ray, out, distance) {
1058
- if (distance === void 0) distance = Number.MAX_SAFE_INTEGER;
1059
- var plane = UIRenderer._tempPlane;
1060
- var transform = this._transformEntity.transform;
1061
- var normal = plane.normal.copyFrom(transform.worldForward);
1062
- plane.distance = -Vector3.dot(normal, transform.worldPosition);
1063
- var curDistance = ray.intersectPlane(plane);
1064
- if (curDistance >= 0 && curDistance < distance) {
1065
- var hitPointWorld = ray.getPoint(curDistance, UIRenderer._tempVec30);
1066
- var worldMatrixInv = UIRenderer._tempMat;
1067
- Matrix.invert(transform.worldMatrix, worldMatrixInv);
1068
- var localPosition = UIRenderer._tempVec31;
1069
- Vector3.transformCoordinate(hitPointWorld, worldMatrixInv, localPosition);
1070
- if (this._hitTest(localPosition)) {
1071
- out.component = this;
1072
- out.distance = curDistance;
1073
- out.entity = this.entity;
1074
- out.normal.copyFrom(normal);
1075
- out.point.copyFrom(hitPointWorld);
1076
- return true;
1077
- }
1078
- }
1079
- return false;
1080
- };
1081
- _proto._hitTest = function _hitTest(localPosition) {
1082
- var x = localPosition.x, y = localPosition.y;
1083
- var uiTransform = this._transformEntity.transform;
1084
- var _uiTransform_size = uiTransform.size, width = _uiTransform_size.x, height = _uiTransform_size.y;
1085
- var _uiTransform_pivot = uiTransform.pivot, pivotX = _uiTransform_pivot.x, pivotY = _uiTransform_pivot.y;
1086
- var _this_raycastPadding = this.raycastPadding, paddingLeft = _this_raycastPadding.x, paddingBottom = _this_raycastPadding.y, paddingRight = _this_raycastPadding.z, paddingTop = _this_raycastPadding.w;
1087
- return x >= -width * pivotX + paddingLeft && x <= width * (1 - pivotX) - paddingRight && y >= -height * pivotY + paddingTop && y <= height * (1 - pivotY) - paddingBottom;
1088
- };
1089
- _proto._onDestroy = function _onDestroy() {
1090
- if (this._subChunk) {
1091
- this._getChunkManager().freeSubChunk(this._subChunk);
1092
- this._subChunk = null;
1093
- }
1094
- Renderer.prototype._onDestroy.call(this);
1095
- //@ts-ignore
1096
- this._color._onValueChanged = null;
1097
- this._color = null;
1098
- };
1099
- _create_class(UIRenderer, [
1100
- {
1101
- key: "color",
1102
- get: /**
1103
- * Rendering color for the ui renderer.
1104
- */ function get() {
1105
- return this._color;
1106
- },
1107
- set: function set(value) {
1108
- if (this._color !== value) {
1109
- this._color.copyFrom(value);
1110
- }
1111
- }
1112
- },
1113
- {
1114
- key: "raycastEnabled",
1115
- get: /**
1116
- * Whether this renderer be picked up by raycast.
1117
- */ function get() {
1118
- return this._raycastEnabled;
1119
- },
1120
- set: function set(value) {
1121
- this._raycastEnabled = value;
1122
- }
1123
- }
1124
- ]);
1125
- return UIRenderer;
1126
- }(Renderer);
1127
- /** @internal */ UIRenderer._tempVec30 = new Vector3();
1128
- /** @internal */ UIRenderer._tempVec31 = new Vector3();
1129
- /** @internal */ UIRenderer._tempMat = new Matrix();
1130
- /** @internal */ UIRenderer._tempPlane = new Plane();
1131
- /** @internal */ UIRenderer._textureProperty = ShaderProperty.getByName("renderer_UITexture");
1132
- __decorate([
1133
- deepClone
1134
- ], UIRenderer.prototype, "raycastPadding", void 0);
1135
- __decorate([
1136
- ignoreClone
1137
- ], UIRenderer.prototype, "_rootCanvas", void 0);
1138
- __decorate([
1139
- ignoreClone
1140
- ], UIRenderer.prototype, "_indexInRootCanvas", void 0);
1141
- __decorate([
1142
- ignoreClone
1143
- ], UIRenderer.prototype, "_isRootCanvasDirty", void 0);
1144
- __decorate([
1145
- ignoreClone
1146
- ], UIRenderer.prototype, "_rootCanvasListeningEntities", void 0);
1147
- __decorate([
1148
- ignoreClone
1149
- ], UIRenderer.prototype, "_group", void 0);
1150
- __decorate([
1151
- ignoreClone
1152
- ], UIRenderer.prototype, "_indexInGroup", void 0);
1153
- __decorate([
1154
- ignoreClone
1155
- ], UIRenderer.prototype, "_isGroupDirty", void 0);
1156
- __decorate([
1157
- ignoreClone
1158
- ], UIRenderer.prototype, "_groupListeningEntities", void 0);
1159
- __decorate([
1160
- ignoreClone
1161
- ], UIRenderer.prototype, "_subChunk", void 0);
1162
- __decorate([
1163
- assignmentClone
1164
- ], UIRenderer.prototype, "_raycastEnabled", void 0);
1165
- __decorate([
1166
- deepClone
1167
- ], UIRenderer.prototype, "_color", void 0);
1168
- __decorate([
1169
- ignoreClone
1170
- ], UIRenderer.prototype, "_groupListener", null);
1171
- __decorate([
1172
- ignoreClone
1173
- ], UIRenderer.prototype, "_rootCanvasListener", null);
1174
- __decorate([
1175
- ignoreClone
1176
- ], UIRenderer.prototype, "_onColorChanged", null);
1177
- UIRenderer = __decorate([
1178
- dependentComponents(UITransform, DependentMode.AutoAdd)
1179
- ], UIRenderer);
1180
- /**
1181
- * @remarks Extends `RendererUpdateFlags`.
1182
- */ var UIRendererUpdateFlags = /*#__PURE__*/ function(UIRendererUpdateFlags) {
1183
- UIRendererUpdateFlags[UIRendererUpdateFlags["Color"] = 2] = "Color";
1184
- return UIRendererUpdateFlags;
1185
- }({});
1186
-
1187
- /**
1188
- * Interactive component.
1189
- */ var UIInteractive = /*#__PURE__*/ function(Script) {
1190
- _inherits(UIInteractive, Script);
1191
- function UIInteractive(entity) {
1192
- var _this;
1193
- _this = Script.call(this, entity) || this, /** @internal */ _this._indexInRootCanvas = -1, /** @internal */ _this._isRootCanvasDirty = false, /** @internal */ _this._rootCanvasListeningEntities = [], /** @internal */ _this._indexInGroup = -1, /** @internal */ _this._isGroupDirty = false, /** @internal */ _this._groupListeningEntities = [], /** @internal */ _this._globalInteractive = false, /** @internal */ _this._globalInteractiveDirty = false, _this._transitions = [], _this._interactive = true, _this._state = 0, /** @todo Multi-touch points are not considered yet. */ _this._isPointerInside = false, _this._isPointerDragging = false;
1194
- _this._groupListener = _this._groupListener.bind(_this);
1195
- _this._rootCanvasListener = _this._rootCanvasListener.bind(_this);
1196
- return _this;
1197
- }
1198
- var _proto = UIInteractive.prototype;
1199
- /**
1200
- * Add transition on this interactive.
1201
- * @param transition - The transition
1202
- */ _proto.addTransition = function addTransition(transition) {
1203
- var interactive = transition._interactive;
1204
- if (interactive !== this) {
1205
- interactive == null ? void 0 : interactive.removeTransition(transition);
1206
- this._transitions.push(transition);
1207
- transition._interactive = this;
1208
- transition._setState(this._state, true);
1209
- }
1210
- };
1211
- /**
1212
- * Remove a transition.
1213
- * @param shape - The transition.
1214
- */ _proto.removeTransition = function removeTransition(transition) {
1215
- var transitions = this._transitions;
1216
- var lastOneIndex = transitions.length - 1;
1217
- for(var i = lastOneIndex; i >= 0; i--){
1218
- if (transitions[i] === transition) {
1219
- i !== lastOneIndex && (transitions[i] = transitions[lastOneIndex]);
1220
- transitions.length = lastOneIndex;
1221
- transition._interactive = null;
1222
- break;
1223
- }
1224
- }
1225
- };
1226
- /**
1227
- * Remove all transitions.
1228
- */ _proto.clearTransitions = function clearTransitions() {
1229
- var transitions = this._transitions;
1230
- for(var i = 0, n = transitions.length; i < n; i++){
1231
- transitions[i]._interactive = null;
1232
- }
1233
- transitions.length = 0;
1234
- };
1235
- _proto.onUpdate = function onUpdate(deltaTime) {
1236
- if (this._getGlobalInteractive()) {
1237
- var transitions = this._transitions;
1238
- for(var i = 0, n = transitions.length; i < n; i++){
1239
- transitions[i]._onUpdate(deltaTime);
1240
- }
1241
- }
1242
- };
1243
- _proto.onPointerBeginDrag = function onPointerBeginDrag() {
1244
- this._isPointerDragging = true;
1245
- this._updateState(false);
1246
- };
1247
- _proto.onPointerEndDrag = function onPointerEndDrag() {
1248
- this._isPointerDragging = false;
1249
- this._updateState(false);
1250
- };
1251
- _proto.onPointerEnter = function onPointerEnter() {
1252
- this._isPointerInside = true;
1253
- this._updateState(false);
1254
- };
1255
- _proto.onPointerExit = function onPointerExit() {
1256
- this._isPointerInside = false;
1257
- this._updateState(false);
1258
- };
1259
- _proto.onDestroy = function onDestroy() {
1260
- Script.prototype.onDestroy.call(this);
1261
- var transitions = this._transitions;
1262
- for(var i = transitions.length - 1; i >= 0; i--){
1263
- transitions[i].destroy();
1264
- }
1265
- };
1266
- // @ts-ignore
1267
- _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
1268
- var transitions = this._transitions;
1269
- for(var i = 0, n = transitions.length; i < n; i++){
1270
- var srcTransition = transitions[i];
1271
- var dstTransition = new transitions[i].constructor();
1272
- dstTransition.normal = srcTransition.normal;
1273
- dstTransition.pressed = srcTransition.pressed;
1274
- dstTransition.hover = srcTransition.hover;
1275
- dstTransition.disabled = srcTransition.disabled;
1276
- var transitionTarget = srcTransition.target;
1277
- if (transitionTarget) {
1278
- var paths = UIInteractive._targetTempPath;
1279
- // @ts-ignore
1280
- var success = Entity._getEntityHierarchyPath(srcRoot, transitionTarget.entity, paths);
1281
- dstTransition.target = success ? Entity._getEntityByHierarchyPath(targetRoot, paths).getComponent(transitionTarget.constructor) : transitionTarget;
1282
- }
1283
- target.addTransition(dstTransition);
1284
- }
1285
- };
1286
- /**
1287
- * @internal
1288
- */ _proto._getRootCanvas = function _getRootCanvas() {
1289
- this._isRootCanvasDirty && Utils.setRootCanvas(this, Utils.searchRootCanvasInParents(this));
1290
- return this._rootCanvas;
1291
- };
1292
- /**
1293
- * @internal
1294
- */ _proto._getGroup = function _getGroup() {
1295
- this._isGroupDirty && Utils.setGroup(this, Utils.searchGroupInParents(this));
1296
- return this._group;
1297
- };
1298
- // @ts-ignore
1299
- _proto._onEnableInScene = function _onEnableInScene() {
1300
- // @ts-ignore
1301
- Script.prototype._onEnableInScene.call(this);
1302
- Utils.setRootCanvasDirty(this);
1303
- Utils.setGroupDirty(this);
1304
- this._updateState(true);
1305
- };
1306
- // @ts-ignore
1307
- _proto._onDisableInScene = function _onDisableInScene() {
1308
- // @ts-ignore
1309
- Script.prototype._onDisableInScene.call(this);
1310
- Utils.cleanRootCanvas(this);
1311
- Utils.cleanGroup(this);
1312
- this._isPointerInside = this._isPointerDragging = false;
1313
- };
1314
- /**
1315
- * @internal
1316
- */ _proto._groupListener = function _groupListener(flag) {
1317
- if (flag === EntityModifyFlags.Parent || flag === EntityUIModifyFlags.GroupEnableInScene) {
1318
- Utils.setGroupDirty(this);
1319
- }
1320
- };
1321
- /**
1322
- * @internal
1323
- */ _proto._rootCanvasListener = function _rootCanvasListener(flag) {
1324
- if (flag === EntityModifyFlags.Parent || flag === EntityUIModifyFlags.CanvasEnableInScene) {
1325
- Utils.setRootCanvasDirty(this);
1326
- Utils.setGroupDirty(this);
1327
- }
1328
- };
1329
- /**
1330
- * @internal
1331
- */ _proto._onGroupModify = function _onGroupModify(flags) {
1332
- if (flags & GroupModifyFlags.GlobalInteractive) {
1333
- this._globalInteractiveDirty = true;
1334
- }
1335
- };
1336
- /**
1337
- * @internal
1338
- */ _proto._getGlobalInteractive = function _getGlobalInteractive() {
1339
- if (this._globalInteractiveDirty) {
1340
- var group = this._getGroup();
1341
- var globalInteractive = this._interactive && (!group || group._getGlobalInteractive());
1342
- if (this._globalInteractive !== globalInteractive) {
1343
- this._globalInteractive = globalInteractive;
1344
- this._updateState(true);
1345
- }
1346
- this._globalInteractiveDirty = false;
1347
- }
1348
- return this._globalInteractive;
1349
- };
1350
- _proto._updateState = function _updateState(instant) {
1351
- var state = this._getInteractiveState();
1352
- if (this._state !== state) {
1353
- this._state = state;
1354
- var transitions = this._transitions;
1355
- for(var i = 0, n = transitions.length; i < n; i++){
1356
- transitions[i]._setState(state, instant);
1357
- }
1358
- }
1359
- };
1360
- _proto._getInteractiveState = function _getInteractiveState() {
1361
- if (!this._getGlobalInteractive()) {
1362
- return 3;
1363
- }
1364
- if (this._isPointerDragging) {
1365
- return 1;
1366
- } else {
1367
- return this._isPointerInside ? 2 : 0;
1368
- }
1369
- };
1370
- _create_class(UIInteractive, [
1371
- {
1372
- key: "transitions",
1373
- get: /**
1374
- * The transitions of this interactive.
1375
- */ function get() {
1376
- return this._transitions;
1377
- }
1378
- },
1379
- {
1380
- key: "interactive",
1381
- get: /**
1382
- * Whether the interactive is enabled.
1383
- */ function get() {
1384
- return this._interactive;
1385
- },
1386
- set: function set(value) {
1387
- if (this._interactive !== value) {
1388
- this._interactive = value;
1389
- this._globalInteractiveDirty = true;
1390
- }
1391
- }
1392
- }
1393
- ]);
1394
- return UIInteractive;
1395
- }(Script);
1396
- UIInteractive._targetTempPath = new Array();
1397
- __decorate([
1398
- ignoreClone
1399
- ], UIInteractive.prototype, "_rootCanvas", void 0);
1400
- __decorate([
1401
- ignoreClone
1402
- ], UIInteractive.prototype, "_indexInRootCanvas", void 0);
1403
- __decorate([
1404
- ignoreClone
1405
- ], UIInteractive.prototype, "_isRootCanvasDirty", void 0);
1406
- __decorate([
1407
- ignoreClone
1408
- ], UIInteractive.prototype, "_rootCanvasListeningEntities", void 0);
1409
- __decorate([
1410
- ignoreClone
1411
- ], UIInteractive.prototype, "_group", void 0);
1412
- __decorate([
1413
- ignoreClone
1414
- ], UIInteractive.prototype, "_indexInGroup", void 0);
1415
- __decorate([
1416
- ignoreClone
1417
- ], UIInteractive.prototype, "_isGroupDirty", void 0);
1418
- __decorate([
1419
- ignoreClone
1420
- ], UIInteractive.prototype, "_groupListeningEntities", void 0);
1421
- __decorate([
1422
- ignoreClone
1423
- ], UIInteractive.prototype, "_globalInteractive", void 0);
1424
- __decorate([
1425
- ignoreClone
1426
- ], UIInteractive.prototype, "_globalInteractiveDirty", void 0);
1427
- __decorate([
1428
- ignoreClone
1429
- ], UIInteractive.prototype, "_transitions", void 0);
1430
- __decorate([
1431
- assignmentClone
1432
- ], UIInteractive.prototype, "_interactive", void 0);
1433
- __decorate([
1434
- ignoreClone
1435
- ], UIInteractive.prototype, "_state", void 0);
1436
- __decorate([
1437
- ignoreClone
1438
- ], UIInteractive.prototype, "_isPointerInside", void 0);
1439
- __decorate([
1440
- ignoreClone
1441
- ], UIInteractive.prototype, "_isPointerDragging", void 0);
1442
- __decorate([
1443
- ignoreClone
1444
- ], UIInteractive.prototype, "_groupListener", null);
1445
- __decorate([
1446
- ignoreClone
1447
- ], UIInteractive.prototype, "_rootCanvasListener", null);
1448
- __decorate([
1449
- ignoreClone
1450
- ], UIInteractive.prototype, "_onGroupModify", null);
1451
- var InteractiveState = /*#__PURE__*/ function(InteractiveState) {
1452
- InteractiveState[InteractiveState["Normal"] = 0] = "Normal";
1453
- InteractiveState[InteractiveState["Pressed"] = 1] = "Pressed";
1454
- InteractiveState[InteractiveState["Hover"] = 2] = "Hover";
1455
- InteractiveState[InteractiveState["Disable"] = 3] = "Disable";
1456
- return InteractiveState;
1457
- }({});
1458
-
1459
- var UICanvas = /*#__PURE__*/ function(Component) {
1460
- _inherits(UICanvas, Component);
1461
- function UICanvas(entity) {
1462
- var _this;
1463
- _this = Component.call(this, entity) || this, /** @internal */ _this._canvasIndex = -1, /** @internal */ _this._indexInRootCanvas = -1, /** @internal */ _this._isRootCanvasDirty = false, /** @internal */ _this._rootCanvasListeningEntities = [], /** @internal */ _this._isRootCanvas = false, /** @internal */ _this._sortDistance = 0, /** @internal */ _this._orderedRenderers = [], /** @internal */ _this._realRenderMode = 4, /** @internal */ _this._disorderedElements = new DisorderedArray(), _this._renderMode = CanvasRenderMode.WorldSpace, _this._resolutionAdaptationMode = ResolutionAdaptationMode.HeightAdaptation, _this._sortOrder = 0, _this._distance = 10, _this._referenceResolution = new Vector2(800, 600), _this._referenceResolutionPerUnit = 100, _this._hierarchyVersion = -1, _this._center = new Vector3();
1464
- _this._onCanvasSizeListener = _this._onCanvasSizeListener.bind(_this);
1465
- _this._onCameraModifyListener = _this._onCameraModifyListener.bind(_this);
1466
- _this._onCameraTransformListener = _this._onCameraTransformListener.bind(_this);
1467
- _this._onReferenceResolutionChanged = _this._onReferenceResolutionChanged.bind(_this);
1468
- // @ts-ignore
1469
- _this._referenceResolution._onValueChanged = _this._onReferenceResolutionChanged;
1470
- _this._rootCanvasListener = _this._rootCanvasListener.bind(_this);
1471
- _this._centerDirtyFlag = entity.registerWorldChangeFlag();
1472
- return _this;
1473
- }
1474
- var _proto = UICanvas.prototype;
1475
- /**
1476
- * @internal
1477
- */ _proto._raycast = function _raycast(ray, out, distance) {
1478
- if (distance === void 0) distance = Number.MAX_SAFE_INTEGER;
1479
- var renderers = this._getRenderers();
1480
- for(var i = renderers.length - 1; i >= 0; i--){
1481
- var element = renderers[i];
1482
- if (element.raycastEnabled && element._raycast(ray, out, distance)) {
1483
- return true;
1484
- }
1485
- }
1486
- out.component = null;
1487
- out.entity = null;
1488
- out.distance = 0;
1489
- out.point.set(0, 0, 0);
1490
- out.normal.set(0, 0, 0);
1491
- return false;
1492
- };
1493
- /**
1494
- * @internal
1495
- */ _proto._getRootCanvas = function _getRootCanvas() {
1496
- return this._rootCanvas;
1497
- };
1498
- /**
1499
- * @internal
1500
- */ _proto._canRender = function _canRender(camera) {
1501
- return this._renderMode !== CanvasRenderMode.ScreenSpaceCamera || this._renderCamera === camera;
1502
- };
1503
- /**
1504
- * @internal
1505
- */ _proto._prepareRender = function _prepareRender(context) {
1506
- var _this = this, engine = _this.engine, mode = _this._realRenderMode;
1507
- var _context_camera = context.camera, enableFrustumCulling = _context_camera.enableFrustumCulling, cullingMask = _context_camera.cullingMask, frustum = _context_camera._frustum;
1508
- var frameCount = engine.time.frameCount;
1509
- // @ts-ignore
1510
- var renderElement = this._renderElement = engine._renderElementPool.get();
1511
- var virtualCamera = context.virtualCamera;
1512
- this._updateSortDistance(virtualCamera.isOrthographic, virtualCamera.position, virtualCamera.forward);
1513
- renderElement.set(this.sortOrder, this._sortDistance);
1514
- var _engine_canvas = engine.canvas, width = _engine_canvas.width, height = _engine_canvas.height;
1515
- var renderers = this._getRenderers();
1516
- for(var i = 0, n = renderers.length; i < n; i++){
1517
- var renderer = renderers[i];
1518
- // Filter by camera culling mask
1519
- if (!(cullingMask & renderer.entity.layer)) {
1520
- continue;
1521
- }
1522
- // Filter by camera frustum
1523
- if (enableFrustumCulling) {
1524
- switch(mode){
1525
- case CanvasRenderMode.ScreenSpaceOverlay:
1526
- var _renderer_bounds = renderer.bounds, min = _renderer_bounds.min, max = _renderer_bounds.max;
1527
- if (min.x > width || max.x < 0 || min.y > height || max.y < 0) {
1528
- continue;
1529
- }
1530
- break;
1531
- case CanvasRenderMode.ScreenSpaceCamera:
1532
- case CanvasRenderMode.WorldSpace:
1533
- if (!frustum.intersectsBox(renderer.bounds)) {
1534
- continue;
1535
- }
1536
- break;
1537
- }
1538
- }
1539
- renderer._prepareRender(context);
1540
- renderer._renderFrameCount = frameCount;
1541
- }
1542
- };
1543
- /**
1544
- * @internal
1545
- */ _proto._updateSortDistance = function _updateSortDistance(isOrthographic, cameraPosition, cameraForward) {
1546
- switch(this._realRenderMode){
1547
- case CanvasRenderMode.ScreenSpaceOverlay:
1548
- this._sortDistance = 0;
1549
- break;
1550
- case CanvasRenderMode.ScreenSpaceCamera:
1551
- this._sortDistance = this._distance;
1552
- break;
1553
- case CanvasRenderMode.WorldSpace:
1554
- var boundsCenter = this._getCenter();
1555
- if (isOrthographic) {
1556
- var distance = UICanvas._tempVec3;
1557
- Vector3.subtract(boundsCenter, cameraPosition, distance);
1558
- this._sortDistance = Vector3.dot(distance, cameraForward);
1559
- } else {
1560
- this._sortDistance = Vector3.distanceSquared(boundsCenter, cameraPosition);
1561
- }
1562
- break;
1563
- }
1564
- };
1565
- // @ts-ignore
1566
- _proto._onEnableInScene = function _onEnableInScene() {
1567
- var entity = this.entity;
1568
- // @ts-ignore
1569
- entity._dispatchModify(4, this);
1570
- var rootCanvas = Utils.searchRootCanvasInParents(this);
1571
- this._setIsRootCanvas(!rootCanvas);
1572
- Utils.setRootCanvas(this, rootCanvas);
1573
- };
1574
- // @ts-ignore
1575
- _proto._onDisableInScene = function _onDisableInScene() {
1576
- this._setIsRootCanvas(false);
1577
- Utils.cleanRootCanvas(this);
1578
- };
1579
- /**
1580
- * @internal
1581
- */ _proto._rootCanvasListener = function _rootCanvasListener(flag, param) {
1582
- if (this._isRootCanvas) {
1583
- if (flag === EntityModifyFlags.Parent) {
1584
- var rootCanvas = Utils.searchRootCanvasInParents(this);
1585
- this._setIsRootCanvas(!rootCanvas);
1586
- Utils.setRootCanvas(this, rootCanvas);
1587
- } else if (flag === 4) {
1588
- this._setIsRootCanvas(false);
1589
- Utils.setRootCanvas(this, param);
1590
- }
1591
- } else {
1592
- if (flag === EntityModifyFlags.Parent) {
1593
- var rootCanvas1 = Utils.searchRootCanvasInParents(this);
1594
- this._setIsRootCanvas(!rootCanvas1);
1595
- Utils.setRootCanvas(this, rootCanvas1);
1596
- }
1597
- }
1598
- };
1599
- /**
1600
- * @internal
1601
- */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
1602
- target.renderMode = this._renderMode;
1603
- var renderCamera = this._renderCamera;
1604
- if (renderCamera) {
1605
- var paths = UICanvas._targetTempPath;
1606
- // @ts-ignore
1607
- var success = Entity._getEntityHierarchyPath(srcRoot, renderCamera.entity, paths);
1608
- // @ts-ignore
1609
- target.renderCamera = success ? Entity._getEntityByHierarchyPath(targetRoot, paths).getComponent(Camera) : renderCamera;
1610
- }
1611
- };
1612
- _proto._getRenderers = function _getRenderers() {
1613
- var _this = this, renderers = _this._orderedRenderers, entity = _this.entity;
1614
- var uiHierarchyVersion = entity._uiHierarchyVersion;
1615
- if (this._hierarchyVersion !== uiHierarchyVersion) {
1616
- renderers.length = this._walk(this.entity, renderers);
1617
- UICanvas._tempGroupAbleList.length = 0;
1618
- this._hierarchyVersion = uiHierarchyVersion;
1619
- ++UICanvas._hierarchyCounter;
1620
- }
1621
- return renderers;
1622
- };
1623
- _proto._adapterPoseInScreenSpace = function _adapterPoseInScreenSpace() {
1624
- var transform = this.entity.transform;
1625
- var realRenderMode = this._realRenderMode;
1626
- if (realRenderMode === CanvasRenderMode.ScreenSpaceCamera) {
1627
- var cameraEntity = this._renderCamera.entity;
1628
- if (!this._isSameOrChildEntity(cameraEntity)) {
1629
- var cameraTransform = cameraEntity.transform;
1630
- var cameraWorldPosition = cameraTransform.worldPosition, cameraWorldForward = cameraTransform.worldForward;
1631
- var distance = this._distance;
1632
- transform.setWorldPosition(cameraWorldPosition.x + cameraWorldForward.x * distance, cameraWorldPosition.y + cameraWorldForward.y * distance, cameraWorldPosition.z + cameraWorldForward.z * distance);
1633
- transform.worldRotationQuaternion.copyFrom(cameraTransform.worldRotationQuaternion);
1634
- }
1635
- } else {
1636
- var canvas = this.engine.canvas;
1637
- transform.setWorldPosition(canvas.width * 0.5, canvas.height * 0.5, 0);
1638
- transform.worldRotationQuaternion.set(0, 0, 0, 1);
1639
- }
1640
- };
1641
- _proto._adapterSizeInScreenSpace = function _adapterSizeInScreenSpace() {
1642
- var transform = this.entity.transform;
1643
- var realRenderMode = this._realRenderMode;
1644
- var _this__referenceResolution = this._referenceResolution, width = _this__referenceResolution.x, height = _this__referenceResolution.y;
1645
- var curWidth;
1646
- var curHeight;
1647
- if (realRenderMode === CanvasRenderMode.ScreenSpaceCamera) {
1648
- var renderCamera = this._renderCamera;
1649
- curHeight = renderCamera.isOrthographic ? renderCamera.orthographicSize * 2 : 2 * (Math.tan(MathUtil.degreeToRadian(renderCamera.fieldOfView * 0.5)) * this._distance);
1650
- curWidth = renderCamera.aspectRatio * curHeight;
1651
- } else {
1652
- var canvas = this.engine.canvas;
1653
- curHeight = canvas.height;
1654
- curWidth = canvas.width;
1655
- }
1656
- var expectX, expectY, expectZ;
1657
- switch(this._resolutionAdaptationMode){
1658
- case ResolutionAdaptationMode.WidthAdaptation:
1659
- expectX = expectY = expectZ = curWidth / width;
1660
- break;
1661
- case ResolutionAdaptationMode.HeightAdaptation:
1662
- expectX = expectY = expectZ = curHeight / height;
1663
- break;
1664
- case ResolutionAdaptationMode.BothAdaptation:
1665
- expectX = curWidth / width;
1666
- expectY = curHeight / height;
1667
- expectZ = (expectX + expectY) * 0.5;
1668
- break;
1669
- case ResolutionAdaptationMode.ExpandAdaptation:
1670
- expectX = expectY = expectZ = Math.min(curWidth / width, curHeight / height);
1671
- break;
1672
- case ResolutionAdaptationMode.ShrinkAdaptation:
1673
- expectX = expectY = expectZ = Math.max(curWidth / width, curHeight / height);
1674
- break;
1675
- }
1676
- var worldMatrix = UICanvas._tempMat;
1677
- Matrix.affineTransformation(UICanvas._tempVec3.set(expectX, expectY, expectZ), transform.worldRotationQuaternion, transform.worldPosition, worldMatrix);
1678
- transform.worldMatrix = worldMatrix;
1679
- transform.size.set(curWidth / expectX, curHeight / expectY);
1680
- };
1681
- _proto._walk = function _walk(entity, renderers, depth, group) {
1682
- if (depth === void 0) depth = 0;
1683
- if (group === void 0) group = null;
1684
- // @ts-ignore
1685
- var components = entity._components;
1686
- var tempGroupAbleList = UICanvas._tempGroupAbleList;
1687
- var groupAbleCount = 0;
1688
- for(var i = 0, n = components.length; i < n; i++){
1689
- var component = components[i];
1690
- if (!component.enabled) continue;
1691
- if (_instanceof(component, UIRenderer)) {
1692
- renderers[depth] = component;
1693
- ++depth;
1694
- component._isRootCanvasDirty && Utils.setRootCanvas(component, this);
1695
- if (component._isGroupDirty) {
1696
- tempGroupAbleList[groupAbleCount++] = component;
1697
- }
1698
- } else if (_instanceof(component, UIInteractive)) {
1699
- component._isRootCanvasDirty && Utils.setRootCanvas(component, this);
1700
- if (component._isGroupDirty) {
1701
- tempGroupAbleList[groupAbleCount++] = component;
1702
- }
1703
- } else if (_instanceof(component, UIGroup)) {
1704
- component._isRootCanvasDirty && Utils.setRootCanvas(component, this);
1705
- component._isGroupDirty && Utils.setGroup(component, group);
1706
- group = component;
1707
- }
1708
- }
1709
- for(var i1 = 0; i1 < groupAbleCount; i1++){
1710
- Utils.setGroup(tempGroupAbleList[i1], group);
1711
- }
1712
- var children = entity.children;
1713
- for(var i2 = 0, n1 = children.length; i2 < n1; i2++){
1714
- var child = children[i2];
1715
- child.isActive && (depth = this._walk(child, renderers, depth, group));
1716
- }
1717
- return depth;
1718
- };
1719
- _proto._updateCameraObserver = function _updateCameraObserver() {
1720
- var camera = this._isRootCanvas && this._renderMode === CanvasRenderMode.ScreenSpaceCamera ? this._renderCamera : null;
1721
- var preCamera = this._cameraObserver;
1722
- if (preCamera !== camera) {
1723
- this._cameraObserver = camera;
1724
- if (preCamera) {
1725
- // @ts-ignore
1726
- preCamera.entity._updateFlagManager.removeListener(this._onCameraTransformListener);
1727
- // @ts-ignore
1728
- preCamera._unRegisterModifyListener(this._onCameraModifyListener);
1729
- }
1730
- if (camera) {
1731
- // @ts-ignore
1732
- camera.entity._updateFlagManager.addListener(this._onCameraTransformListener);
1733
- // @ts-ignore
1734
- camera._registerModifyListener(this._onCameraModifyListener);
1735
- }
1736
- }
1737
- };
1738
- _proto._onCameraModifyListener = function _onCameraModifyListener(flag) {
1739
- if (this._realRenderMode === CanvasRenderMode.ScreenSpaceCamera) {
1740
- switch(flag){
1741
- case CameraModifyFlags.ProjectionType:
1742
- case CameraModifyFlags.AspectRatio:
1743
- this._adapterSizeInScreenSpace();
1744
- break;
1745
- case CameraModifyFlags.FieldOfView:
1746
- !this._renderCamera.isOrthographic && this._adapterSizeInScreenSpace();
1747
- break;
1748
- case CameraModifyFlags.OrthographicSize:
1749
- this._renderCamera.isOrthographic && this._adapterSizeInScreenSpace();
1750
- break;
1751
- case CameraModifyFlags.DisableInScene:
1752
- this._setRealRenderMode(CanvasRenderMode.ScreenSpaceOverlay);
1753
- break;
1754
- }
1755
- } else {
1756
- flag === CameraModifyFlags.EnableInScene && this._setRealRenderMode(CanvasRenderMode.ScreenSpaceCamera);
1757
- }
1758
- };
1759
- _proto._onCameraTransformListener = function _onCameraTransformListener() {
1760
- this._realRenderMode === CanvasRenderMode.ScreenSpaceCamera && this._adapterPoseInScreenSpace();
1761
- };
1762
- _proto._addCanvasListener = function _addCanvasListener() {
1763
- // @ts-ignore
1764
- this.engine.canvas._sizeUpdateFlagManager.addListener(this._onCanvasSizeListener);
1765
- };
1766
- _proto._removeCanvasListener = function _removeCanvasListener() {
1767
- // @ts-ignore
1768
- this.engine.canvas._sizeUpdateFlagManager.removeListener(this._onCanvasSizeListener);
1769
- };
1770
- _proto._onCanvasSizeListener = function _onCanvasSizeListener() {
1771
- var canvas = this.engine.canvas;
1772
- this.entity.transform.setWorldPosition(canvas.width * 0.5, canvas.height * 0.5, 0);
1773
- this._adapterSizeInScreenSpace();
1774
- };
1775
- _proto._onReferenceResolutionChanged = function _onReferenceResolutionChanged() {
1776
- var realRenderMode = this._realRenderMode;
1777
- if (realRenderMode === CanvasRenderMode.ScreenSpaceOverlay || realRenderMode === CanvasRenderMode.ScreenSpaceCamera) {
1778
- this._adapterSizeInScreenSpace();
1779
- }
1780
- };
1781
- _proto._setIsRootCanvas = function _setIsRootCanvas(isRootCanvas) {
1782
- var _this = this;
1783
- if (this._isRootCanvas !== isRootCanvas) {
1784
- this._isRootCanvas = isRootCanvas;
1785
- this._updateCameraObserver();
1786
- this._setRealRenderMode(this._getRealRenderMode());
1787
- if (isRootCanvas) {
1788
- this.entity._updateUIHierarchyVersion(UICanvas._hierarchyCounter);
1789
- } else {
1790
- var _this1 = this, disorderedElements = _this1._disorderedElements;
1791
- disorderedElements.forEach(function(element) {
1792
- if (_instanceof(element, UICanvas)) {
1793
- var rootCanvas = Utils.searchRootCanvasInParents(element);
1794
- element._setIsRootCanvas(!rootCanvas);
1795
- Utils.setRootCanvas(element, rootCanvas);
1796
- } else {
1797
- Utils.setRootCanvasDirty(_this);
1798
- Utils.setGroupDirty(element);
1799
- }
1800
- });
1801
- disorderedElements.length = 0;
1802
- disorderedElements.garbageCollection();
1803
- this._orderedRenderers.length = 0;
1804
- }
1805
- }
1806
- };
1807
- _proto._getCenter = function _getCenter() {
1808
- if (this._centerDirtyFlag.flag) {
1809
- var center = this._center;
1810
- var uiTransform = this.entity.transform;
1811
- var pivot = uiTransform.pivot, size = uiTransform.size;
1812
- center.set((0.5 - pivot.x) * size.x, (0.5 - pivot.y) * size.y, 0);
1813
- Vector3.transformCoordinate(center, uiTransform.worldMatrix, center);
1814
- this._centerDirtyFlag.flag = false;
1815
- }
1816
- return this._center;
1817
- };
1818
- _proto._getRealRenderMode = function _getRealRenderMode() {
1819
- if (this._isRootCanvas) {
1820
- var _this__renderCamera;
1821
- var mode = this._renderMode;
1822
- if (mode === CanvasRenderMode.ScreenSpaceCamera && !((_this__renderCamera = this._renderCamera) == null ? void 0 : _this__renderCamera.enabled)) {
1823
- return CanvasRenderMode.ScreenSpaceOverlay;
1824
- } else {
1825
- return mode;
1826
- }
1827
- } else {
1828
- return 4;
1829
- }
1830
- };
1831
- _proto._setRealRenderMode = function _setRealRenderMode(curRealMode) {
1832
- var preRealMode = this._realRenderMode;
1833
- if (preRealMode !== curRealMode) {
1834
- this._realRenderMode = curRealMode;
1835
- // @ts-ignore
1836
- var componentsManager = this.scene._componentsManager;
1837
- switch(preRealMode){
1838
- case CanvasRenderMode.ScreenSpaceOverlay:
1839
- this._removeCanvasListener();
1840
- case CanvasRenderMode.ScreenSpaceCamera:
1841
- case CanvasRenderMode.WorldSpace:
1842
- componentsManager.removeUICanvas(this, preRealMode === CanvasRenderMode.ScreenSpaceOverlay);
1843
- break;
1844
- }
1845
- switch(curRealMode){
1846
- case CanvasRenderMode.ScreenSpaceOverlay:
1847
- this._addCanvasListener();
1848
- case CanvasRenderMode.ScreenSpaceCamera:
1849
- this._adapterPoseInScreenSpace();
1850
- this._adapterSizeInScreenSpace();
1851
- case CanvasRenderMode.WorldSpace:
1852
- componentsManager.addUICanvas(this, curRealMode === CanvasRenderMode.ScreenSpaceOverlay);
1853
- break;
1854
- }
1855
- }
1856
- };
1857
- _proto._isSameOrChildEntity = function _isSameOrChildEntity(cameraEntity) {
1858
- var canvasEntity = this.entity;
1859
- while(cameraEntity){
1860
- if (cameraEntity === canvasEntity) return true;
1861
- cameraEntity = cameraEntity.parent;
1862
- }
1863
- return false;
1864
- };
1865
- _create_class(UICanvas, [
1866
- {
1867
- key: "referenceResolutionPerUnit",
1868
- get: /**
1869
- * The conversion ratio between reference resolution and unit for UI elements in this canvas.
1870
- */ function get() {
1871
- return this._referenceResolutionPerUnit;
1872
- },
1873
- set: function set(value) {
1874
- if (this._referenceResolutionPerUnit !== value) {
1875
- this._referenceResolutionPerUnit = value;
1876
- this._disorderedElements.forEach(function(element) {
1877
- element._onRootCanvasModify == null ? void 0 : element._onRootCanvasModify.call(element, 1);
1878
- });
1879
- }
1880
- }
1881
- },
1882
- {
1883
- key: "referenceResolution",
1884
- get: /**
1885
- * The reference resolution of the UI canvas in `ScreenSpaceCamera` and `ScreenSpaceOverlay` mode.
1886
- */ function get() {
1887
- return this._referenceResolution;
1888
- },
1889
- set: function set(value) {
1890
- var referenceResolution = this._referenceResolution;
1891
- if (referenceResolution === value) return;
1892
- (referenceResolution.x !== value.x || referenceResolution.y !== value.y) && referenceResolution.copyFrom(value);
1893
- }
1894
- },
1895
- {
1896
- key: "renderMode",
1897
- get: /**
1898
- * The rendering mode of the UI canvas.
1899
- */ function get() {
1900
- return this._renderMode;
1901
- },
1902
- set: function set(mode) {
1903
- var preMode = this._renderMode;
1904
- if (preMode !== mode) {
1905
- this._renderMode = mode;
1906
- this._updateCameraObserver();
1907
- this._setRealRenderMode(this._getRealRenderMode());
1908
- }
1909
- }
1910
- },
1911
- {
1912
- key: "renderCamera",
1913
- get: /**
1914
- * The camera used to render the UI canvas in `ScreenSpaceCamera` mode.
1915
- * @remarks If set `ScreenSpaceCamera` but no corresponding camera is assigned, the actual rendering mode defaults to `ScreenSpaceOverlay`.
1916
- */ function get() {
1917
- return this._renderCamera;
1918
- },
1919
- set: function set(value) {
1920
- var preCamera = this._renderCamera;
1921
- if (preCamera !== value) {
1922
- value && this._isSameOrChildEntity(value.entity) && Logger.warn("Camera entity matching or nested within the canvas entity disables canvas auto-adaptation in ScreenSpaceCamera mode.");
1923
- this._renderCamera = value;
1924
- this._updateCameraObserver();
1925
- var preRenderMode = this._realRenderMode;
1926
- var curRenderMode = this._getRealRenderMode();
1927
- if (preRenderMode === curRenderMode) {
1928
- if (curRenderMode === CanvasRenderMode.ScreenSpaceCamera) {
1929
- this._adapterPoseInScreenSpace();
1930
- this._adapterSizeInScreenSpace();
1931
- }
1932
- } else {
1933
- this._setRealRenderMode(curRenderMode);
1934
- }
1935
- }
1936
- }
1937
- },
1938
- {
1939
- key: "resolutionAdaptationMode",
1940
- get: /**
1941
- * The screen resolution adaptation mode of the UI canvas in `ScreenSpaceCamera` and `ScreenSpaceOverlay` mode.
1942
- */ function get() {
1943
- return this._resolutionAdaptationMode;
1944
- },
1945
- set: function set(value) {
1946
- if (this._resolutionAdaptationMode !== value) {
1947
- this._resolutionAdaptationMode = value;
1948
- var realRenderMode = this._realRenderMode;
1949
- if (realRenderMode === CanvasRenderMode.ScreenSpaceCamera || realRenderMode === CanvasRenderMode.ScreenSpaceOverlay) {
1950
- this._adapterSizeInScreenSpace();
1951
- }
1952
- }
1953
- }
1954
- },
1955
- {
1956
- key: "sortOrder",
1957
- get: /**
1958
- * The rendering order priority of the UI canvas in `ScreenSpaceOverlay` mode.
1959
- */ function get() {
1960
- return this._sortOrder;
1961
- },
1962
- set: function set(value) {
1963
- if (this._sortOrder !== value) {
1964
- this._sortOrder = value;
1965
- this._realRenderMode === CanvasRenderMode.ScreenSpaceOverlay && // @ts-ignore
1966
- (this.scene._componentsManager._overlayCanvasesSortingFlag = true);
1967
- }
1968
- }
1969
- },
1970
- {
1971
- key: "distance",
1972
- get: /**
1973
- * The distance between the UI canvas and the camera in `ScreenSpaceCamera` mode.
1974
- */ function get() {
1975
- return this._distance;
1976
- },
1977
- set: function set(value) {
1978
- if (this._distance !== value) {
1979
- this._distance = value;
1980
- if (this._realRenderMode === CanvasRenderMode.ScreenSpaceCamera) {
1981
- this._adapterPoseInScreenSpace();
1982
- this._adapterSizeInScreenSpace();
1983
- }
1984
- }
1985
- }
1986
- }
1987
- ]);
1988
- return UICanvas;
1989
- }(Component);
1990
- /** @internal */ UICanvas._hierarchyCounter = 1;
1991
- UICanvas._targetTempPath = [];
1992
- UICanvas._tempGroupAbleList = [];
1993
- UICanvas._tempVec3 = new Vector3();
1994
- UICanvas._tempMat = new Matrix();
1995
- __decorate([
1996
- ignoreClone
1997
- ], UICanvas.prototype, "_canvasIndex", void 0);
1998
- __decorate([
1999
- ignoreClone
2000
- ], UICanvas.prototype, "_rootCanvas", void 0);
2001
- __decorate([
2002
- ignoreClone
2003
- ], UICanvas.prototype, "_indexInRootCanvas", void 0);
2004
- __decorate([
2005
- ignoreClone
2006
- ], UICanvas.prototype, "_isRootCanvasDirty", void 0);
2007
- __decorate([
2008
- ignoreClone
2009
- ], UICanvas.prototype, "_rootCanvasListeningEntities", void 0);
2010
- __decorate([
2011
- ignoreClone
2012
- ], UICanvas.prototype, "_isRootCanvas", void 0);
2013
- __decorate([
2014
- ignoreClone
2015
- ], UICanvas.prototype, "_renderElement", void 0);
2016
- __decorate([
2017
- ignoreClone
2018
- ], UICanvas.prototype, "_sortDistance", void 0);
2019
- __decorate([
2020
- ignoreClone
2021
- ], UICanvas.prototype, "_orderedRenderers", void 0);
2022
- __decorate([
2023
- ignoreClone
2024
- ], UICanvas.prototype, "_realRenderMode", void 0);
2025
- __decorate([
2026
- ignoreClone
2027
- ], UICanvas.prototype, "_disorderedElements", void 0);
2028
- __decorate([
2029
- ignoreClone
2030
- ], UICanvas.prototype, "_renderMode", void 0);
2031
- __decorate([
2032
- ignoreClone
2033
- ], UICanvas.prototype, "_renderCamera", void 0);
2034
- __decorate([
2035
- ignoreClone
2036
- ], UICanvas.prototype, "_cameraObserver", void 0);
2037
- __decorate([
2038
- assignmentClone
2039
- ], UICanvas.prototype, "_resolutionAdaptationMode", void 0);
2040
- __decorate([
2041
- assignmentClone
2042
- ], UICanvas.prototype, "_sortOrder", void 0);
2043
- __decorate([
2044
- assignmentClone
2045
- ], UICanvas.prototype, "_distance", void 0);
2046
- __decorate([
2047
- deepClone
2048
- ], UICanvas.prototype, "_referenceResolution", void 0);
2049
- __decorate([
2050
- assignmentClone
2051
- ], UICanvas.prototype, "_referenceResolutionPerUnit", void 0);
2052
- __decorate([
2053
- ignoreClone
2054
- ], UICanvas.prototype, "_hierarchyVersion", void 0);
2055
- __decorate([
2056
- ignoreClone
2057
- ], UICanvas.prototype, "_center", void 0);
2058
- __decorate([
2059
- ignoreClone
2060
- ], UICanvas.prototype, "_centerDirtyFlag", void 0);
2061
- __decorate([
2062
- ignoreClone
2063
- ], UICanvas.prototype, "_rootCanvasListener", null);
2064
- __decorate([
2065
- ignoreClone
2066
- ], UICanvas.prototype, "_onCameraModifyListener", null);
2067
- __decorate([
2068
- ignoreClone
2069
- ], UICanvas.prototype, "_onCameraTransformListener", null);
2070
- __decorate([
2071
- ignoreClone
2072
- ], UICanvas.prototype, "_onCanvasSizeListener", null);
2073
- __decorate([
2074
- ignoreClone
2075
- ], UICanvas.prototype, "_onReferenceResolutionChanged", null);
2076
- UICanvas = __decorate([
2077
- dependentComponents(UITransform, DependentMode.AutoAdd)
2078
- ], UICanvas);
2079
- /**
2080
- * @remarks Extends `EntityModifyFlags`.
2081
- */ var EntityUIModifyFlags = /*#__PURE__*/ function(EntityUIModifyFlags) {
2082
- EntityUIModifyFlags[EntityUIModifyFlags["CanvasEnableInScene"] = 4] = "CanvasEnableInScene";
2083
- EntityUIModifyFlags[EntityUIModifyFlags["GroupEnableInScene"] = 8] = "GroupEnableInScene";
2084
- return EntityUIModifyFlags;
2085
- }({});
2086
- var RootCanvasModifyFlags = /*#__PURE__*/ function(RootCanvasModifyFlags) {
2087
- RootCanvasModifyFlags[RootCanvasModifyFlags["None"] = 0] = "None";
2088
- RootCanvasModifyFlags[RootCanvasModifyFlags["ReferenceResolutionPerUnit"] = 1] = "ReferenceResolutionPerUnit";
2089
- RootCanvasModifyFlags[RootCanvasModifyFlags["All"] = 1] = "All";
2090
- return RootCanvasModifyFlags;
2091
- }({});
2092
-
2093
- var Button = /*#__PURE__*/ function(UIInteractive) {
2094
- _inherits(Button, UIInteractive);
2095
- function Button() {
2096
- var _this;
2097
- _this = UIInteractive.apply(this, arguments) || this, _this._listeners = new SafeLoopArray();
2098
- return _this;
2099
- }
2100
- var _proto = Button.prototype;
2101
- /**
2102
- * Add a listening function for click.
2103
- * @param listener - The listening function
2104
- */ _proto.addClicked = function addClicked(listener) {
2105
- this._listeners.push({
2106
- fn: listener
2107
- });
2108
- };
2109
- /**
2110
- * Remove a listening function of click.
2111
- * @param listener - The listening function
2112
- */ _proto.removeClicked = function removeClicked(listener) {
2113
- this._listeners.findAndRemove(function(value) {
2114
- return value.fn === listener ? value.destroyed = true : false;
2115
- });
2116
- };
2117
- _proto.onPointerClick = function onPointerClick(event) {
2118
- if (!this._getGlobalInteractive()) return;
2119
- var listeners = this._listeners.getLoopArray();
2120
- for(var i = 0, n = listeners.length; i < n; i++){
2121
- var listener = listeners[i];
2122
- !listener.destroyed && listener.fn(event);
2123
- }
2124
- };
2125
- _proto.onDestroy = function onDestroy() {
2126
- UIInteractive.prototype.onDestroy.call(this);
2127
- this._listeners.findAndRemove(function(value) {
2128
- return value.destroyed = true;
2129
- });
2130
- };
2131
- return Button;
2132
- }(UIInteractive);
2133
- __decorate([
2134
- ignoreClone
2135
- ], Button.prototype, "_listeners", void 0);
2136
-
2137
- /**
2138
- * UI element that renders an image.
2139
- */ var Image = /*#__PURE__*/ function(UIRenderer1) {
2140
- _inherits(Image, UIRenderer1);
2141
- function Image(entity) {
2142
- var _this;
2143
- _this = UIRenderer1.call(this, entity) || this, _this._sprite = null, _this._tileMode = SpriteTileMode.Continuous, _this._tiledAdaptiveThreshold = 0.5;
2144
- _this.drawMode = SpriteDrawMode.Simple;
2145
- _this.setMaterial(_this._engine._getUIDefaultMaterial());
2146
- _this._onSpriteChange = _this._onSpriteChange.bind(_this);
2147
- return _this;
2148
- }
2149
- var _proto = Image.prototype;
2150
- /**
2151
- * @internal
2152
- */ _proto._onRootCanvasModify = function _onRootCanvasModify(flag) {
2153
- if (flag & RootCanvasModifyFlags.ReferenceResolutionPerUnit) {
2154
- var drawMode = this._drawMode;
2155
- if (drawMode === SpriteDrawMode.Tiled) {
2156
- this._dirtyUpdateFlag |= 15;
2157
- } else if (drawMode === SpriteDrawMode.Sliced) {
2158
- this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
2159
- }
2160
- }
2161
- };
2162
- /**
2163
- * @internal
2164
- */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
2165
- // @ts-ignore
2166
- UIRenderer1.prototype._cloneTo.call(this, target, srcRoot, targetRoot);
2167
- target.sprite = this._sprite;
2168
- target.drawMode = this._drawMode;
2169
- };
2170
- _proto._updateBounds = function _updateBounds(worldBounds) {
2171
- var sprite = this._sprite;
2172
- var rootCanvas = this._getRootCanvas();
2173
- if (sprite && rootCanvas) {
2174
- var transform = this._transformEntity.transform;
2175
- var size = transform.size;
2176
- this._assembler.updatePositions(this, transform.worldMatrix, size.x, size.y, transform.pivot, false, false, rootCanvas.referenceResolutionPerUnit);
2177
- } else {
2178
- var worldPosition = this._transformEntity.transform.worldPosition;
2179
- worldBounds.min.copyFrom(worldPosition);
2180
- worldBounds.max.copyFrom(worldPosition);
2181
- }
2182
- };
2183
- _proto._render = function _render(context) {
2184
- var _this = this, sprite = _this._sprite;
2185
- var transform = this._transformEntity.transform;
2186
- var _transform_size = transform.size, width = _transform_size.x, height = _transform_size.y;
2187
- if (!(sprite == null ? void 0 : sprite.texture) || !width || !height) {
2188
- return;
2189
- }
2190
- var material = this.getMaterial();
2191
- if (!material) {
2192
- return;
2193
- }
2194
- // @todo: This question needs to be raised rather than hidden.
2195
- if (material.destroyed) {
2196
- material = this._engine._getUIDefaultMaterial();
2197
- }
2198
- var alpha = this._getGlobalAlpha();
2199
- if (this._color.a * alpha <= 0) {
2200
- return;
2201
- }
2202
- var _this1 = this, dirtyUpdateFlag = _this1._dirtyUpdateFlag;
2203
- var canvas = this._getRootCanvas();
2204
- // Update position
2205
- if (dirtyUpdateFlag & RendererUpdateFlags.WorldVolume) {
2206
- this._assembler.updatePositions(this, transform.worldMatrix, width, height, transform.pivot, false, false, canvas.referenceResolutionPerUnit);
2207
- dirtyUpdateFlag &= ~RendererUpdateFlags.WorldVolume;
2208
- }
2209
- // Update uv
2210
- if (dirtyUpdateFlag & 4) {
2211
- this._assembler.updateUVs(this);
2212
- dirtyUpdateFlag &= ~4;
2213
- }
2214
- // Update color
2215
- if (dirtyUpdateFlag & UIRendererUpdateFlags.Color) {
2216
- this._assembler.updateColor(this, alpha);
2217
- dirtyUpdateFlag &= ~UIRendererUpdateFlags.Color;
2218
- }
2219
- this._dirtyUpdateFlag = dirtyUpdateFlag;
2220
- // Init sub render element.
2221
- var engine = context.camera.engine;
2222
- var subRenderElement = engine._subRenderElementPool.get();
2223
- var subChunk = this._subChunk;
2224
- subRenderElement.set(this, material, subChunk.chunk.primitive, subChunk.subMesh, this.sprite.texture, subChunk);
2225
- if (canvas._realRenderMode === CanvasRenderMode.ScreenSpaceOverlay) {
2226
- subRenderElement.shaderPasses = material.shader.subShaders[0].passes;
2227
- subRenderElement.renderQueueFlags = RenderQueueFlags.All;
2228
- }
2229
- canvas._renderElement.addSubRenderElement(subRenderElement);
2230
- };
2231
- _proto._onTransformChanged = function _onTransformChanged(type) {
2232
- if (type & UITransformModifyFlags.Size && this._drawMode === SpriteDrawMode.Tiled) {
2233
- this._dirtyUpdateFlag |= 15;
2234
- }
2235
- this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
2236
- };
2237
- _proto._onDestroy = function _onDestroy() {
2238
- var sprite = this._sprite;
2239
- if (sprite) {
2240
- this._addResourceReferCount(sprite, -1);
2241
- // @ts-ignore
2242
- sprite._updateFlagManager.removeListener(this._onSpriteChange);
2243
- this._sprite = null;
2244
- }
2245
- UIRenderer1.prototype._onDestroy.call(this);
2246
- };
2247
- _proto._onSpriteChange = function _onSpriteChange(type) {
2248
- switch(type){
2249
- case SpriteModifyFlags.texture:
2250
- this.shaderData.setTexture(UIRenderer._textureProperty, this.sprite.texture);
2251
- break;
2252
- case SpriteModifyFlags.size:
2253
- switch(this._drawMode){
2254
- case SpriteDrawMode.Sliced:
2255
- this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
2256
- break;
2257
- case SpriteDrawMode.Tiled:
2258
- this._dirtyUpdateFlag |= 7;
2259
- break;
2260
- }
2261
- break;
2262
- case SpriteModifyFlags.border:
2263
- switch(this._drawMode){
2264
- case SpriteDrawMode.Sliced:
2265
- this._dirtyUpdateFlag |= 5;
2266
- break;
2267
- case SpriteDrawMode.Tiled:
2268
- this._dirtyUpdateFlag |= 7;
2269
- break;
2270
- }
2271
- break;
2272
- case SpriteModifyFlags.region:
2273
- case SpriteModifyFlags.atlasRegionOffset:
2274
- this._dirtyUpdateFlag |= 5;
2275
- break;
2276
- case SpriteModifyFlags.atlasRegion:
2277
- this._dirtyUpdateFlag |= 4;
2278
- break;
2279
- case SpriteModifyFlags.destroy:
2280
- this.sprite = null;
2281
- break;
2282
- }
2283
- };
2284
- _create_class(Image, [
2285
- {
2286
- key: "drawMode",
2287
- get: /**
2288
- * The draw mode of the image.
2289
- */ function get() {
2290
- return this._drawMode;
2291
- },
2292
- set: function set(value) {
2293
- if (this._drawMode !== value) {
2294
- this._drawMode = value;
2295
- switch(value){
2296
- case SpriteDrawMode.Simple:
2297
- this._assembler = SimpleSpriteAssembler;
2298
- break;
2299
- case SpriteDrawMode.Sliced:
2300
- this._assembler = SlicedSpriteAssembler;
2301
- break;
2302
- case SpriteDrawMode.Tiled:
2303
- this._assembler = TiledSpriteAssembler;
2304
- break;
2305
- }
2306
- this._assembler.resetData(this);
2307
- this._dirtyUpdateFlag |= 7;
2308
- }
2309
- }
2310
- },
2311
- {
2312
- key: "tileMode",
2313
- get: /**
2314
- * The tiling mode of the image. (Only works in tiled mode.)
2315
- */ function get() {
2316
- return this._tileMode;
2317
- },
2318
- set: function set(value) {
2319
- if (this._tileMode !== value) {
2320
- this._tileMode = value;
2321
- if (this.drawMode === SpriteDrawMode.Tiled) {
2322
- this._dirtyUpdateFlag |= 7;
2323
- }
2324
- }
2325
- }
2326
- },
2327
- {
2328
- key: "tiledAdaptiveThreshold",
2329
- get: /**
2330
- * Stretch Threshold in Tile Adaptive Mode, specified in normalized. (Only works in tiled adaptive mode.)
2331
- */ function get() {
2332
- return this._tiledAdaptiveThreshold;
2333
- },
2334
- set: function set(value) {
2335
- if (value !== this._tiledAdaptiveThreshold) {
2336
- value = MathUtil.clamp(value, 0, 1);
2337
- this._tiledAdaptiveThreshold = value;
2338
- if (this.drawMode === SpriteDrawMode.Tiled) {
2339
- this._dirtyUpdateFlag |= 7;
2340
- }
2341
- }
2342
- }
2343
- },
2344
- {
2345
- key: "sprite",
2346
- get: /**
2347
- * The Sprite to render.
2348
- */ function get() {
2349
- return this._sprite;
2350
- },
2351
- set: function set(value) {
2352
- var lastSprite = this._sprite;
2353
- if (lastSprite !== value) {
2354
- if (lastSprite) {
2355
- this._addResourceReferCount(lastSprite, -1);
2356
- // @ts-ignore
2357
- lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
2358
- }
2359
- this._dirtyUpdateFlag |= 7;
2360
- if (value) {
2361
- this._addResourceReferCount(value, 1);
2362
- // @ts-ignore
2363
- value._updateFlagManager.addListener(this._onSpriteChange);
2364
- this.shaderData.setTexture(UIRenderer._textureProperty, value.texture);
2365
- } else {
2366
- this.shaderData.setTexture(UIRenderer._textureProperty, null);
2367
- }
2368
- this._sprite = value;
2369
- }
2370
- }
2371
- }
2372
- ]);
2373
- return Image;
2374
- }(UIRenderer);
2375
- __decorate([
2376
- ignoreClone
2377
- ], Image.prototype, "_sprite", void 0);
2378
- __decorate([
2379
- ignoreClone
2380
- ], Image.prototype, "_drawMode", void 0);
2381
- __decorate([
2382
- ignoreClone
2383
- ], Image.prototype, "_assembler", void 0);
2384
- __decorate([
2385
- assignmentClone
2386
- ], Image.prototype, "_tileMode", void 0);
2387
- __decorate([
2388
- assignmentClone
2389
- ], Image.prototype, "_tiledAdaptiveThreshold", void 0);
2390
- __decorate([
2391
- ignoreClone
2392
- ], Image.prototype, "_onTransformChanged", null);
2393
- __decorate([
2394
- ignoreClone
2395
- ], Image.prototype, "_onSpriteChange", null);
2396
-
2397
- /**
2398
- * UI component used to render text.
2399
- */ var Text = /*#__PURE__*/ function(UIRenderer1) {
2400
- _inherits(Text, UIRenderer1);
2401
- function Text(entity) {
2402
- var _this;
2403
- _this = UIRenderer1.call(this, entity) || this, _this._textChunks = Array(), _this._subFont = null, _this._text = "", _this._localBounds = new BoundingBox(), _this._font = null, _this._fontSize = 24, _this._fontStyle = FontStyle.None, _this._lineSpacing = 0, _this._horizontalAlignment = TextHorizontalAlignment.Center, _this._verticalAlignment = TextVerticalAlignment.Center, _this._enableWrapping = false, _this._overflowMode = OverflowMode.Overflow;
2404
- var engine = _this.engine;
2405
- // @ts-ignore
2406
- _this.font = engine._textDefaultFont;
2407
- _this.raycastEnabled = false;
2408
- // @ts-ignore
2409
- _this.setMaterial(engine._basicResources.textDefaultMaterial);
2410
- return _this;
2411
- }
2412
- var _proto = Text.prototype;
2413
- /**
2414
- * @internal
2415
- */ _proto._onDestroy = function _onDestroy() {
2416
- if (this._font) {
2417
- this._addResourceReferCount(this._font, -1);
2418
- this._font = null;
2419
- }
2420
- UIRenderer1.prototype._onDestroy.call(this);
2421
- this._freeTextChunks();
2422
- this._textChunks = null;
2423
- this._subFont && (this._subFont = null);
2424
- };
2425
- // @ts-ignore
2426
- _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
2427
- // @ts-ignore
2428
- UIRenderer1.prototype._cloneTo.call(this, target, srcRoot, targetRoot);
2429
- target.font = this._font;
2430
- target._subFont = this._subFont;
2431
- };
2432
- /**
2433
- * @internal
2434
- */ _proto._isContainDirtyFlag = function _isContainDirtyFlag(type) {
2435
- return (this._dirtyUpdateFlag & type) != 0;
2436
- };
2437
- /**
2438
- * @internal
2439
- */ _proto._setDirtyFlagTrue = function _setDirtyFlagTrue(type) {
2440
- this._dirtyUpdateFlag |= type;
2441
- };
2442
- /**
2443
- * @internal
2444
- */ _proto._setDirtyFlagFalse = function _setDirtyFlagFalse(type) {
2445
- this._dirtyUpdateFlag &= ~type;
2446
- };
2447
- /**
2448
- * @internal
2449
- */ _proto._getSubFont = function _getSubFont() {
2450
- if (!this._subFont) {
2451
- this._resetSubFont();
2452
- }
2453
- return this._subFont;
2454
- };
2455
- /**
2456
- * @internal
2457
- */ _proto._onRootCanvasModify = function _onRootCanvasModify(flag) {
2458
- if (flag === RootCanvasModifyFlags.ReferenceResolutionPerUnit) {
2459
- this._setDirtyFlagTrue(8);
2460
- }
2461
- };
2462
- _proto._updateBounds = function _updateBounds(worldBounds) {
2463
- var transform = this._transformEntity.transform;
2464
- var _transform_size = transform.size, width = _transform_size.x, height = _transform_size.y;
2465
- var _transform_pivot = transform.pivot, pivotX = _transform_pivot.x, pivotY = _transform_pivot.y;
2466
- worldBounds.min.set(-width * pivotX, -height * pivotY, 0);
2467
- worldBounds.max.set(width * (1 - pivotX), height * (1 - pivotY), 0);
2468
- BoundingBox.transform(worldBounds, this._transformEntity.transform.worldMatrix, worldBounds);
2469
- };
2470
- _proto._render = function _render(context) {
2471
- if (this._isTextNoVisible()) {
2472
- return;
2473
- }
2474
- if (this._isContainDirtyFlag(4)) {
2475
- this._resetSubFont();
2476
- this._setDirtyFlagFalse(4);
2477
- }
2478
- var canvas = this._getRootCanvas();
2479
- if (this._isContainDirtyFlag(8)) {
2480
- this._updateLocalData();
2481
- this._setDirtyFlagTrue(8);
2482
- }
2483
- if (this._isContainDirtyFlag(16)) {
2484
- this._updatePosition();
2485
- this._setDirtyFlagFalse(16);
2486
- }
2487
- if (this._isContainDirtyFlag(UIRendererUpdateFlags.Color)) {
2488
- this._updateColor();
2489
- this._setDirtyFlagFalse(UIRendererUpdateFlags.Color);
2490
- }
2491
- var engine = context.camera.engine;
2492
- var textSubRenderElementPool = engine._textSubRenderElementPool;
2493
- var material = this.getMaterial();
2494
- var renderElement = canvas._renderElement;
2495
- var textChunks = this._textChunks;
2496
- var isOverlay = canvas._realRenderMode === CanvasRenderMode.ScreenSpaceOverlay;
2497
- for(var i = 0, n = textChunks.length; i < n; ++i){
2498
- var // @ts-ignore
2499
- _subRenderElement;
2500
- var _textChunks_i = textChunks[i], subChunk = _textChunks_i.subChunk, texture = _textChunks_i.texture;
2501
- var subRenderElement = textSubRenderElementPool.get();
2502
- subRenderElement.set(this, material, subChunk.chunk.primitive, subChunk.subMesh, texture, subChunk);
2503
- (_subRenderElement = subRenderElement).shaderData || (_subRenderElement.shaderData = new ShaderData(ShaderDataGroup.RenderElement));
2504
- subRenderElement.shaderData.setTexture(Text._textTextureProperty, texture);
2505
- if (isOverlay) {
2506
- subRenderElement.shaderPasses = material.shader.subShaders[0].passes;
2507
- subRenderElement.renderQueueFlags = RenderQueueFlags.All;
2508
- }
2509
- renderElement.addSubRenderElement(subRenderElement);
2510
- }
2511
- };
2512
- _proto._resetSubFont = function _resetSubFont() {
2513
- var font = this._font;
2514
- // @ts-ignore
2515
- this._subFont = font._getSubFont(this.fontSize, this.fontStyle);
2516
- this._subFont.nativeFontString = TextUtils.getNativeFontString(font.name, this.fontSize, this.fontStyle);
2517
- };
2518
- _proto._updatePosition = function _updatePosition() {
2519
- var e = this._transformEntity.transform.worldMatrix.elements;
2520
- // prettier-ignore
2521
- var e0 = e[0], e1 = e[1], e2 = e[2], e4 = e[4], e5 = e[5], e6 = e[6], e12 = e[12], e13 = e[13], e14 = e[14];
2522
- var up = UIRenderer._tempVec31.set(e4, e5, e6);
2523
- var right = UIRenderer._tempVec30.set(e0, e1, e2);
2524
- var worldPositions = Text._worldPositions;
2525
- var worldPosition0 = worldPositions[0], worldPosition1 = worldPositions[1], worldPosition2 = worldPositions[2], worldPosition3 = worldPositions[3];
2526
- var textChunks = this._textChunks;
2527
- for(var i = 0, n = textChunks.length; i < n; ++i){
2528
- var _textChunks_i = textChunks[i], subChunk = _textChunks_i.subChunk, charRenderInfos = _textChunks_i.charRenderInfos;
2529
- for(var j = 0, m = charRenderInfos.length; j < m; ++j){
2530
- var charRenderInfo = charRenderInfos[j];
2531
- var localPositions = charRenderInfo.localPositions;
2532
- var topLeftX = localPositions.x, topLeftY = localPositions.y;
2533
- // Top-Left
2534
- worldPosition0.set(topLeftX * e0 + topLeftY * e4 + e12, topLeftX * e1 + topLeftY * e5 + e13, topLeftX * e2 + topLeftY * e6 + e14);
2535
- // Right offset
2536
- Vector3.scale(right, localPositions.z - topLeftX, worldPosition1);
2537
- // Top-Right
2538
- Vector3.add(worldPosition0, worldPosition1, worldPosition1);
2539
- // Up offset
2540
- Vector3.scale(up, localPositions.w - topLeftY, worldPosition2);
2541
- // Bottom-Left
2542
- Vector3.add(worldPosition0, worldPosition2, worldPosition3);
2543
- // Bottom-Right
2544
- Vector3.add(worldPosition1, worldPosition2, worldPosition2);
2545
- var vertices = subChunk.chunk.vertices;
2546
- for(var k = 0, o = subChunk.vertexArea.start + charRenderInfo.indexInChunk * 36; k < 4; ++k, o += 9){
2547
- worldPositions[k].copyToArray(vertices, o);
2548
- }
2549
- }
2550
- }
2551
- };
2552
- _proto._updateColor = function _updateColor() {
2553
- var _this__color = this._color, r = _this__color.r, g = _this__color.g, b = _this__color.b, a = _this__color.a;
2554
- var finalAlpha = a * this._getGlobalAlpha();
2555
- var textChunks = this._textChunks;
2556
- for(var i = 0, n = textChunks.length; i < n; ++i){
2557
- var subChunk = textChunks[i].subChunk;
2558
- var vertexArea = subChunk.vertexArea;
2559
- var vertexCount = vertexArea.size / 9;
2560
- var vertices = subChunk.chunk.vertices;
2561
- for(var j = 0, o = vertexArea.start + 5; j < vertexCount; ++j, o += 9){
2562
- vertices[o] = r;
2563
- vertices[o + 1] = g;
2564
- vertices[o + 2] = b;
2565
- vertices[o + 3] = finalAlpha;
2566
- }
2567
- }
2568
- };
2569
- _proto._updateLocalData = function _updateLocalData() {
2570
- // @ts-ignore
2571
- var pixelsPerResolution = Engine._pixelsPerUnit / this._getRootCanvas().referenceResolutionPerUnit;
2572
- var _this__localBounds = this._localBounds, min = _this__localBounds.min, max = _this__localBounds.max;
2573
- var charRenderInfos = Text._charRenderInfos;
2574
- var charFont = this._getSubFont();
2575
- var _this__transformEntity_transform = this._transformEntity.transform, size = _this__transformEntity_transform.size, pivot = _this__transformEntity_transform.pivot;
2576
- var rendererWidth = size.x;
2577
- var rendererHeight = size.y;
2578
- var offsetWidth = rendererWidth * (0.5 - pivot.x);
2579
- var offsetHeight = rendererHeight * (0.5 - pivot.y);
2580
- var textMetrics = this.enableWrapping ? TextUtils.measureTextWithWrap(this, rendererWidth * pixelsPerResolution, rendererHeight * pixelsPerResolution, this._lineSpacing * pixelsPerResolution) : TextUtils.measureTextWithoutWrap(this, rendererHeight * pixelsPerResolution, this._lineSpacing * pixelsPerResolution);
2581
- var height = textMetrics.height, lines = textMetrics.lines, lineWidths = textMetrics.lineWidths, lineHeight = textMetrics.lineHeight, lineMaxSizes = textMetrics.lineMaxSizes;
2582
- // @ts-ignore
2583
- var charRenderInfoPool = this.engine._charRenderInfoPool;
2584
- var linesLen = lines.length;
2585
- var renderElementCount = 0;
2586
- if (linesLen > 0) {
2587
- var horizontalAlignment = this.horizontalAlignment;
2588
- var pixelsPerUnitReciprocal = 1.0 / pixelsPerResolution;
2589
- rendererWidth *= pixelsPerResolution;
2590
- rendererHeight *= pixelsPerResolution;
2591
- var halfRendererWidth = rendererWidth * 0.5;
2592
- var halfLineHeight = lineHeight * 0.5;
2593
- var startY = 0;
2594
- var topDiff = lineHeight * 0.5 - lineMaxSizes[0].ascent;
2595
- var bottomDiff = lineHeight * 0.5 - lineMaxSizes[linesLen - 1].descent - 1;
2596
- switch(this.verticalAlignment){
2597
- case TextVerticalAlignment.Top:
2598
- startY = rendererHeight * 0.5 - halfLineHeight + topDiff;
2599
- break;
2600
- case TextVerticalAlignment.Center:
2601
- startY = height * 0.5 - halfLineHeight - (bottomDiff - topDiff) * 0.5;
2602
- break;
2603
- case TextVerticalAlignment.Bottom:
2604
- startY = height - rendererHeight * 0.5 - halfLineHeight - bottomDiff;
2605
- break;
2606
- }
2607
- var firstLine = -1;
2608
- var minX = Number.MAX_SAFE_INTEGER;
2609
- var minY = Number.MAX_SAFE_INTEGER;
2610
- var maxX = Number.MIN_SAFE_INTEGER;
2611
- var maxY = Number.MIN_SAFE_INTEGER;
2612
- for(var i = 0; i < linesLen; ++i){
2613
- var lineWidth = lineWidths[i];
2614
- if (lineWidth > 0) {
2615
- var line = lines[i];
2616
- var startX = 0;
2617
- var firstRow = -1;
2618
- if (firstLine < 0) {
2619
- firstLine = i;
2620
- }
2621
- switch(horizontalAlignment){
2622
- case TextHorizontalAlignment.Left:
2623
- startX = -halfRendererWidth;
2624
- break;
2625
- case TextHorizontalAlignment.Center:
2626
- startX = -lineWidth * 0.5;
2627
- break;
2628
- case TextHorizontalAlignment.Right:
2629
- startX = halfRendererWidth - lineWidth;
2630
- break;
2631
- }
2632
- for(var j = 0, n = line.length; j < n; ++j){
2633
- var char = line[j];
2634
- var charInfo = charFont._getCharInfo(char);
2635
- if (charInfo.h > 0) {
2636
- firstRow < 0 && (firstRow = j);
2637
- var charRenderInfo = charRenderInfos[renderElementCount++] = charRenderInfoPool.get();
2638
- var localPositions = charRenderInfo.localPositions;
2639
- charRenderInfo.texture = charFont._getTextureByIndex(charInfo.index);
2640
- charRenderInfo.uvs = charInfo.uvs;
2641
- var w = charInfo.w, ascent = charInfo.ascent, descent = charInfo.descent;
2642
- var left = (startX + offsetWidth) * pixelsPerUnitReciprocal;
2643
- var right = (startX + w + offsetWidth) * pixelsPerUnitReciprocal;
2644
- var top = (startY + ascent + offsetHeight) * pixelsPerUnitReciprocal;
2645
- var bottom = (startY - descent + offsetHeight) * pixelsPerUnitReciprocal;
2646
- localPositions.set(left, top, right, bottom);
2647
- i === firstLine && (maxY = Math.max(maxY, top));
2648
- minY = Math.min(minY, bottom);
2649
- j === firstRow && (minX = Math.min(minX, left));
2650
- maxX = Math.max(maxX, right);
2651
- }
2652
- startX += charInfo.xAdvance + charInfo.offsetX;
2653
- }
2654
- }
2655
- startY -= lineHeight;
2656
- }
2657
- if (firstLine < 0) {
2658
- min.set(0, 0, 0);
2659
- max.set(0, 0, 0);
2660
- } else {
2661
- min.set(minX, minY, 0);
2662
- max.set(maxX, maxY, 0);
2663
- }
2664
- } else {
2665
- min.set(0, 0, 0);
2666
- max.set(0, 0, 0);
2667
- }
2668
- charFont._getLastIndex() > 0 && charRenderInfos.sort(function(a, b) {
2669
- return a.texture.instanceId - b.texture.instanceId;
2670
- });
2671
- this._freeTextChunks();
2672
- if (renderElementCount === 0) {
2673
- return;
2674
- }
2675
- var textChunks = this._textChunks;
2676
- var curTextChunk = new TextChunk();
2677
- textChunks.push(curTextChunk);
2678
- var chunkMaxVertexCount = this._getChunkManager().maxVertexCount;
2679
- var curCharRenderInfo = charRenderInfos[0];
2680
- var curTexture = curCharRenderInfo.texture;
2681
- curTextChunk.texture = curTexture;
2682
- var curCharInfos = curTextChunk.charRenderInfos;
2683
- curCharInfos.push(curCharRenderInfo);
2684
- for(var i1 = 1; i1 < renderElementCount; ++i1){
2685
- var charRenderInfo1 = charRenderInfos[i1];
2686
- var texture = charRenderInfo1.texture;
2687
- if (curTexture !== texture || curCharInfos.length * 4 + 4 > chunkMaxVertexCount) {
2688
- this._buildChunk(curTextChunk, curCharInfos.length);
2689
- curTextChunk = new TextChunk();
2690
- textChunks.push(curTextChunk);
2691
- curTexture = texture;
2692
- curTextChunk.texture = texture;
2693
- curCharInfos = curTextChunk.charRenderInfos;
2694
- }
2695
- curCharInfos.push(charRenderInfo1);
2696
- }
2697
- var charLength = curCharInfos.length;
2698
- if (charLength > 0) {
2699
- this._buildChunk(curTextChunk, charLength);
2700
- }
2701
- charRenderInfos.length = 0;
2702
- };
2703
- _proto._onTransformChanged = function _onTransformChanged(type) {
2704
- if (type & UITransformModifyFlags.Size || type & UITransformModifyFlags.Pivot) {
2705
- this._dirtyUpdateFlag |= 8;
2706
- }
2707
- UIRenderer1.prototype._onTransformChanged.call(this, type);
2708
- this._setDirtyFlagTrue(16);
2709
- };
2710
- _proto._isTextNoVisible = function _isTextNoVisible() {
2711
- var size = this._transformEntity.transform.size;
2712
- return this._text === "" || this._fontSize === 0 || this.enableWrapping && size.x <= 0 || this.overflowMode === OverflowMode.Truncate && size.y <= 0 || !this._getRootCanvas();
2713
- };
2714
- _proto._buildChunk = function _buildChunk(textChunk, count) {
2715
- var _this_color = this.color, r = _this_color.r, g = _this_color.g, b = _this_color.b, a = _this_color.a;
2716
- var finalAlpha = a * this._getGlobalAlpha();
2717
- var tempIndices = CharRenderInfo.triangles;
2718
- var tempIndicesLength = tempIndices.length;
2719
- var subChunk = textChunk.subChunk = this._getChunkManager().allocateSubChunk(count * 4);
2720
- var vertices = subChunk.chunk.vertices;
2721
- var indices = subChunk.indices = [];
2722
- var charRenderInfos = textChunk.charRenderInfos;
2723
- for(var i = 0, ii = 0, io = 0, vo = subChunk.vertexArea.start + 3; i < count; ++i, io += 4){
2724
- var charRenderInfo = charRenderInfos[i];
2725
- charRenderInfo.indexInChunk = i;
2726
- // Set indices
2727
- for(var j = 0; j < tempIndicesLength; ++j){
2728
- indices[ii++] = tempIndices[j] + io;
2729
- }
2730
- // Set uv and color for vertices
2731
- for(var j1 = 0; j1 < 4; ++j1, vo += 9){
2732
- var uv = charRenderInfo.uvs[j1];
2733
- uv.copyToArray(vertices, vo);
2734
- vertices[vo + 2] = r;
2735
- vertices[vo + 3] = g;
2736
- vertices[vo + 4] = b;
2737
- vertices[vo + 5] = finalAlpha;
2738
- }
2739
- }
2740
- return subChunk;
2741
- };
2742
- _proto._freeTextChunks = function _freeTextChunks() {
2743
- var textChunks = this._textChunks;
2744
- // @ts-ignore
2745
- var charRenderInfoPool = this.engine._charRenderInfoPool;
2746
- var manager = this._getChunkManager();
2747
- for(var i = 0, n = textChunks.length; i < n; ++i){
2748
- var textChunk = textChunks[i];
2749
- var charRenderInfos = textChunk.charRenderInfos;
2750
- for(var j = 0, m = charRenderInfos.length; j < m; ++j){
2751
- charRenderInfoPool.return(charRenderInfos[j]);
2752
- }
2753
- charRenderInfos.length = 0;
2754
- manager.freeSubChunk(textChunk.subChunk);
2755
- textChunk.subChunk = null;
2756
- textChunk.texture = null;
2757
- }
2758
- textChunks.length = 0;
2759
- };
2760
- _create_class(Text, [
2761
- {
2762
- key: "text",
2763
- get: /**
2764
- * Rendering string for the Text.
2765
- */ function get() {
2766
- return this._text;
2767
- },
2768
- set: function set(value) {
2769
- value = value || "";
2770
- if (this._text !== value) {
2771
- this._text = value;
2772
- this._setDirtyFlagTrue(25);
2773
- }
2774
- }
2775
- },
2776
- {
2777
- key: "font",
2778
- get: /**
2779
- * The font of the Text.
2780
- */ function get() {
2781
- return this._font;
2782
- },
2783
- set: function set(value) {
2784
- var lastFont = this._font;
2785
- if (lastFont !== value) {
2786
- lastFont && this._addResourceReferCount(lastFont, -1);
2787
- value && this._addResourceReferCount(value, 1);
2788
- this._font = value;
2789
- this._setDirtyFlagTrue(29);
2790
- }
2791
- }
2792
- },
2793
- {
2794
- key: "fontSize",
2795
- get: /**
2796
- * The font size of the Text.
2797
- */ function get() {
2798
- return this._fontSize;
2799
- },
2800
- set: function set(value) {
2801
- if (this._fontSize !== value) {
2802
- this._fontSize = value;
2803
- this._setDirtyFlagTrue(29);
2804
- }
2805
- }
2806
- },
2807
- {
2808
- key: "fontStyle",
2809
- get: /**
2810
- * The style of the font.
2811
- */ function get() {
2812
- return this._fontStyle;
2813
- },
2814
- set: function set(value) {
2815
- if (this.fontStyle !== value) {
2816
- this._fontStyle = value;
2817
- this._setDirtyFlagTrue(29);
2818
- }
2819
- }
2820
- },
2821
- {
2822
- key: "lineSpacing",
2823
- get: /**
2824
- * The space between two lines (in pixels).
2825
- */ function get() {
2826
- return this._lineSpacing;
2827
- },
2828
- set: function set(value) {
2829
- if (this._lineSpacing !== value) {
2830
- this._lineSpacing = value;
2831
- this._setDirtyFlagTrue(25);
2832
- }
2833
- }
2834
- },
2835
- {
2836
- key: "horizontalAlignment",
2837
- get: /**
2838
- * The horizontal alignment.
2839
- */ function get() {
2840
- return this._horizontalAlignment;
2841
- },
2842
- set: function set(value) {
2843
- if (this._horizontalAlignment !== value) {
2844
- this._horizontalAlignment = value;
2845
- this._setDirtyFlagTrue(25);
2846
- }
2847
- }
2848
- },
2849
- {
2850
- key: "verticalAlignment",
2851
- get: /**
2852
- * The vertical alignment.
2853
- */ function get() {
2854
- return this._verticalAlignment;
2855
- },
2856
- set: function set(value) {
2857
- if (this._verticalAlignment !== value) {
2858
- this._verticalAlignment = value;
2859
- this._setDirtyFlagTrue(25);
2860
- }
2861
- }
2862
- },
2863
- {
2864
- key: "enableWrapping",
2865
- get: /**
2866
- * Whether wrap text to next line when exceeds the width of the container.
2867
- */ function get() {
2868
- return this._enableWrapping;
2869
- },
2870
- set: function set(value) {
2871
- if (this._enableWrapping !== value) {
2872
- this._enableWrapping = value;
2873
- this._setDirtyFlagTrue(25);
2874
- }
2875
- }
2876
- },
2877
- {
2878
- key: "overflowMode",
2879
- get: /**
2880
- * The overflow mode.
2881
- */ function get() {
2882
- return this._overflowMode;
2883
- },
2884
- set: function set(value) {
2885
- if (this._overflowMode !== value) {
2886
- this._overflowMode = value;
2887
- this._setDirtyFlagTrue(25);
2888
- }
2889
- }
2890
- },
2891
- {
2892
- key: "maskLayer",
2893
- get: /**
2894
- * The mask layer the sprite renderer belongs to.
2895
- */ function get() {
2896
- return this._maskLayer;
2897
- },
2898
- set: function set(value) {
2899
- this._maskLayer = value;
2900
- }
2901
- },
2902
- {
2903
- key: "bounds",
2904
- get: /**
2905
- * The bounding volume of the TextRenderer.
2906
- */ function get() {
2907
- if (this._isTextNoVisible()) {
2908
- if (this._isContainDirtyFlag(RendererUpdateFlags.WorldVolume)) {
2909
- var localBounds = this._localBounds;
2910
- localBounds.min.set(0, 0, 0);
2911
- localBounds.max.set(0, 0, 0);
2912
- this._updateBounds(this._bounds);
2913
- this._setDirtyFlagFalse(RendererUpdateFlags.WorldVolume);
2914
- }
2915
- return this._bounds;
2916
- }
2917
- this._isContainDirtyFlag(4) && this._resetSubFont();
2918
- this._isContainDirtyFlag(8) && this._updateLocalData();
2919
- this._isContainDirtyFlag(16) && this._updatePosition();
2920
- this._isContainDirtyFlag(RendererUpdateFlags.WorldVolume) && this._updateBounds(this._bounds);
2921
- this._setDirtyFlagFalse(29);
2922
- return this._bounds;
2923
- }
2924
- }
2925
- ]);
2926
- return Text;
2927
- }(UIRenderer);
2928
- Text._textTextureProperty = ShaderProperty.getByName("renderElement_TextTexture");
2929
- Text._worldPositions = [
2930
- new Vector3(),
2931
- new Vector3(),
2932
- new Vector3(),
2933
- new Vector3()
2934
- ];
2935
- Text._charRenderInfos = [];
2936
- __decorate([
2937
- ignoreClone
2938
- ], Text.prototype, "_textChunks", void 0);
2939
- __decorate([
2940
- ignoreClone
2941
- ], Text.prototype, "_subFont", void 0);
2942
- __decorate([
2943
- assignmentClone
2944
- ], Text.prototype, "_text", void 0);
2945
- __decorate([
2946
- ignoreClone
2947
- ], Text.prototype, "_localBounds", void 0);
2948
- __decorate([
2949
- assignmentClone
2950
- ], Text.prototype, "_font", void 0);
2951
- __decorate([
2952
- assignmentClone
2953
- ], Text.prototype, "_fontSize", void 0);
2954
- __decorate([
2955
- assignmentClone
2956
- ], Text.prototype, "_fontStyle", void 0);
2957
- __decorate([
2958
- assignmentClone
2959
- ], Text.prototype, "_lineSpacing", void 0);
2960
- __decorate([
2961
- assignmentClone
2962
- ], Text.prototype, "_horizontalAlignment", void 0);
2963
- __decorate([
2964
- assignmentClone
2965
- ], Text.prototype, "_verticalAlignment", void 0);
2966
- __decorate([
2967
- assignmentClone
2968
- ], Text.prototype, "_enableWrapping", void 0);
2969
- __decorate([
2970
- assignmentClone
2971
- ], Text.prototype, "_overflowMode", void 0);
2972
- __decorate([
2973
- ignoreClone
2974
- ], Text.prototype, "_onTransformChanged", null);
2975
- var TextChunk = function TextChunk() {
2976
- this.charRenderInfos = new Array();
2977
- };
2978
-
2979
- /**
2980
- * The transition behavior of UIInteractive.
2981
- */ var Transition = /*#__PURE__*/ function() {
2982
- function Transition() {
2983
- this._duration = 0;
2984
- this._countDown = 0;
2985
- this._finalState = InteractiveState.Normal;
2986
- }
2987
- var _proto = Transition.prototype;
2988
- _proto.destroy = function destroy() {
2989
- var _this__interactive;
2990
- (_this__interactive = this._interactive) == null ? void 0 : _this__interactive.removeTransition(this);
2991
- this._target = null;
2992
- };
2993
- /**
2994
- * @internal
2995
- */ _proto._setState = function _setState(state, instant) {
2996
- this._finalState = state;
2997
- var value = this._getValueByState(state);
2998
- if (instant) {
2999
- this._countDown = 0;
3000
- this._initialValue = this._finalValue = value;
3001
- } else {
3002
- this._countDown = this._duration;
3003
- this._initialValue = this._getTargetValueCopy();
3004
- this._finalValue = value;
3005
- }
3006
- this._updateValue();
3007
- };
3008
- /**
3009
- * @internal
3010
- */ _proto._onUpdate = function _onUpdate(delta) {
3011
- if (this._countDown > 0) {
3012
- this._countDown -= delta;
3013
- this._updateValue();
3014
- }
3015
- };
3016
- _proto._onStateValueDirty = function _onStateValueDirty(state, preValue, curValue) {
3017
- // @ts-ignore
3018
- _instanceof(preValue, ReferResource) && preValue._addReferCount(-1);
3019
- // @ts-ignore
3020
- _instanceof(curValue, ReferResource) && curValue._addReferCount(1);
3021
- if (this._finalState === state) {
3022
- this._finalValue = curValue;
3023
- this._updateValue();
3024
- }
3025
- };
3026
- _proto._updateValue = function _updateValue() {
3027
- var _this__target;
3028
- var weight = this._duration ? 1 - this._countDown / this._duration : 1;
3029
- this._updateCurrentValue(this._initialValue, this._finalValue, weight);
3030
- ((_this__target = this._target) == null ? void 0 : _this__target.enabled) && this._applyValue(this._currentValue);
3031
- };
3032
- _proto._getValueByState = function _getValueByState(state) {
3033
- switch(state){
3034
- case InteractiveState.Normal:
3035
- return this.normal;
3036
- case InteractiveState.Pressed:
3037
- return this.pressed;
3038
- case InteractiveState.Hover:
3039
- return this.hover;
3040
- case InteractiveState.Disable:
3041
- return this.disabled;
3042
- }
3043
- };
3044
- _create_class(Transition, [
3045
- {
3046
- key: "normal",
3047
- get: /**
3048
- * The normal state of the transition.
3049
- */ function get() {
3050
- return this._normal;
3051
- },
3052
- set: function set(value) {
3053
- var preNormal = this._normal;
3054
- if (preNormal !== value) {
3055
- this._normal = value;
3056
- this._onStateValueDirty(InteractiveState.Normal, preNormal, value);
3057
- }
3058
- }
3059
- },
3060
- {
3061
- key: "pressed",
3062
- get: /**
3063
- * The pressed state of the transition.
3064
- */ function get() {
3065
- return this._pressed;
3066
- },
3067
- set: function set(value) {
3068
- var prePressed = this._pressed;
3069
- if (prePressed !== value) {
3070
- this._pressed = value;
3071
- this._onStateValueDirty(InteractiveState.Pressed, prePressed, value);
3072
- }
3073
- }
3074
- },
3075
- {
3076
- key: "hover",
3077
- get: /**
3078
- * The hover state of the transition.
3079
- */ function get() {
3080
- return this._hover;
3081
- },
3082
- set: function set(value) {
3083
- var preHover = this._hover;
3084
- if (preHover !== value) {
3085
- this._hover = value;
3086
- this._onStateValueDirty(InteractiveState.Hover, preHover, value);
3087
- }
3088
- }
3089
- },
3090
- {
3091
- key: "disabled",
3092
- get: /**
3093
- * The disabled state of the transition.
3094
- */ function get() {
3095
- return this._disabled;
3096
- },
3097
- set: function set(value) {
3098
- var preDisabled = this._disabled;
3099
- if (preDisabled !== value) {
3100
- this._disabled = value;
3101
- this._onStateValueDirty(InteractiveState.Disable, preDisabled, value);
3102
- }
3103
- }
3104
- },
3105
- {
3106
- key: "target",
3107
- get: /**
3108
- * The target of the transition.
3109
- */ function get() {
3110
- return this._target;
3111
- },
3112
- set: function set(value) {
3113
- if (this._target !== value) {
3114
- this._target = value;
3115
- (value == null ? void 0 : value.enabled) && this._applyValue(this._currentValue);
3116
- }
3117
- }
3118
- },
3119
- {
3120
- key: "duration",
3121
- get: /**
3122
- * The duration of the transition.
3123
- */ function get() {
3124
- return this._duration;
3125
- },
3126
- set: function set(value) {
3127
- if (value < 0) value = 0;
3128
- var preDuration = this._duration;
3129
- if (preDuration !== value) {
3130
- this._duration = value;
3131
- if (this._countDown > 0) {
3132
- this._countDown = value * (1 - this._countDown / preDuration);
3133
- this._updateValue();
3134
- }
3135
- }
3136
- }
3137
- }
3138
- ]);
3139
- return Transition;
3140
- }();
3141
-
3142
- /**
3143
- * Color transition.
3144
- */ var ColorTransition = /*#__PURE__*/ function(Transition) {
3145
- _inherits(ColorTransition, Transition);
3146
- function ColorTransition() {
3147
- var _this;
3148
- _this = Transition.call(this) || this, _this._color = new Color();
3149
- _this._normal = new Color(1, 1, 1, 1);
3150
- _this._hover = new Color(0.9130986517934192, 0.9130986517934192, 0.9130986517934192, 1);
3151
- _this._pressed = new Color(0.5775804404296506, 0.5775804404296506, 0.5775804404296506, 1);
3152
- _this._disabled = new Color(0.5775804404296506, 0.5775804404296506, 0.5775804404296506, 1);
3153
- _this._duration = 0.1;
3154
- _this._currentValue = new Color();
3155
- _this._onNormalValueChanged = _this._onNormalValueChanged.bind(_this);
3156
- _this._onHoverValueChanged = _this._onHoverValueChanged.bind(_this);
3157
- _this._onPressedValueChanged = _this._onPressedValueChanged.bind(_this);
3158
- _this._onDisabledValueChanged = _this._onDisabledValueChanged.bind(_this);
3159
- // @ts-ignore
3160
- _this._normal._onValueChanged = _this._onNormalValueChanged;
3161
- // @ts-ignore
3162
- _this._hover._onValueChanged = _this._onHoverValueChanged;
3163
- // @ts-ignore
3164
- _this._pressed._onValueChanged = _this._onPressedValueChanged;
3165
- // @ts-ignore
3166
- _this._disabled._onValueChanged = _this._onDisabledValueChanged;
3167
- return _this;
3168
- }
3169
- var _proto = ColorTransition.prototype;
3170
- _proto._onNormalValueChanged = function _onNormalValueChanged() {
3171
- if (this._finalState === InteractiveState.Normal) {
3172
- this._finalValue = this._normal;
3173
- this._updateValue();
3174
- }
3175
- };
3176
- _proto._onHoverValueChanged = function _onHoverValueChanged() {
3177
- if (this._finalState === InteractiveState.Hover) {
3178
- this._finalValue = this._hover;
3179
- this._updateValue();
3180
- }
3181
- };
3182
- _proto._onPressedValueChanged = function _onPressedValueChanged() {
3183
- if (this._finalState === InteractiveState.Pressed) {
3184
- this._finalValue = this._pressed;
3185
- this._updateValue();
3186
- }
3187
- };
3188
- _proto._onDisabledValueChanged = function _onDisabledValueChanged() {
3189
- if (this._finalState === InteractiveState.Disable) {
3190
- this._finalValue = this._disabled;
3191
- this._updateValue();
3192
- }
3193
- };
3194
- _proto._getTargetValueCopy = function _getTargetValueCopy() {
3195
- var _this__target;
3196
- var color = this._color;
3197
- color.copyFrom(((_this__target = this._target) == null ? void 0 : _this__target.color) || this._normal);
3198
- return color;
3199
- };
3200
- _proto._updateCurrentValue = function _updateCurrentValue(srcValue, destValue, weight) {
3201
- if (weight >= 1) {
3202
- this._currentValue.copyFrom(destValue);
3203
- } else {
3204
- Color.lerp(srcValue, destValue, weight, this._currentValue);
3205
- }
3206
- };
3207
- _proto._applyValue = function _applyValue(value) {
3208
- this._target.color = value;
3209
- };
3210
- return ColorTransition;
3211
- }(Transition);
3212
-
3213
- /**
3214
- * Scale transition.
3215
- */ var ScaleTransition = /*#__PURE__*/ function(Transition) {
3216
- _inherits(ScaleTransition, Transition);
3217
- function ScaleTransition() {
3218
- var _this;
3219
- _this = Transition.call(this) || this;
3220
- _this._normal = 1;
3221
- _this._hover = 1;
3222
- _this._pressed = 1.2;
3223
- _this._disabled = 1;
3224
- _this._duration = 0.1;
3225
- return _this;
3226
- }
3227
- var _proto = ScaleTransition.prototype;
3228
- _proto._getTargetValueCopy = function _getTargetValueCopy() {
3229
- var _this__target;
3230
- return ((_this__target = this._target) == null ? void 0 : _this__target.entity.transform.scale.x) || this._normal;
3231
- };
3232
- _proto._updateCurrentValue = function _updateCurrentValue(srcValue, destValue, weight) {
3233
- this._currentValue = weight >= 1 ? destValue : (destValue - srcValue) * weight + srcValue;
3234
- };
3235
- _proto._applyValue = function _applyValue(value) {
3236
- this._target.entity.transform.setScale(value, value, value);
3237
- };
3238
- return ScaleTransition;
3239
- }(Transition);
3240
-
3241
- /**
3242
- * Sprite transition.
3243
- */ var SpriteTransition = /*#__PURE__*/ function(Transition) {
3244
- _inherits(SpriteTransition, Transition);
3245
- function SpriteTransition() {
3246
- return Transition.apply(this, arguments) || this;
3247
- }
3248
- var _proto = SpriteTransition.prototype;
3249
- /**
3250
- * @internal
3251
- */ _proto.destroy = function destroy() {
3252
- Transition.prototype.destroy.call(this);
3253
- if (this._normal) {
3254
- // @ts-ignore
3255
- this._normal._addReferCount(-1);
3256
- this._normal = null;
3257
- }
3258
- if (this._hover) {
3259
- // @ts-ignore
3260
- this._hover._addReferCount(-1);
3261
- this._hover = null;
3262
- }
3263
- if (this._pressed) {
3264
- // @ts-ignore
3265
- this._pressed._addReferCount(-1);
3266
- this._pressed = null;
3267
- }
3268
- if (this._disabled) {
3269
- // @ts-ignore
3270
- this._disabled._addReferCount(-1);
3271
- this._disabled = null;
3272
- }
3273
- this._initialValue = this._currentValue = this._finalValue = null;
3274
- this._target = null;
3275
- };
3276
- _proto._getTargetValueCopy = function _getTargetValueCopy() {
3277
- var _this__target;
3278
- return (_this__target = this._target) == null ? void 0 : _this__target.sprite;
3279
- };
3280
- _proto._updateCurrentValue = function _updateCurrentValue(srcValue, destValue, weight) {
3281
- this._currentValue = weight >= 1 ? destValue : srcValue;
3282
- };
3283
- _proto._applyValue = function _applyValue(value) {
3284
- this._target.sprite = value;
3285
- };
3286
- return SpriteTransition;
3287
- }(Transition);
3288
-
3289
- var GUIComponent = /*#__PURE__*/Object.freeze({
3290
- __proto__: null,
3291
- get UICanvas () { return UICanvas; },
3292
- UIGroup: UIGroup,
3293
- get UIRenderer () { return UIRenderer; },
3294
- UITransform: UITransform,
3295
- Button: Button,
3296
- Image: Image,
3297
- Text: Text,
3298
- ColorTransition: ColorTransition,
3299
- ScaleTransition: ScaleTransition,
3300
- SpriteTransition: SpriteTransition,
3301
- Transition: Transition
3302
- });
3303
-
3304
- var uiDefaultFs = "#include <common>\nuniform sampler2D renderer_UITexture;\n\nvarying vec2 v_uv;\nvarying vec4 v_color;\n\nvoid main() {\n vec4 baseColor = texture2DSRGB(renderer_UITexture, v_uv);\n vec4 finalColor = baseColor * v_color;\n #ifdef ENGINE_SHOULD_SRGB_CORRECT\n finalColor = outputSRGBCorrection(finalColor);\n #endif\n gl_FragColor = finalColor;\n}"; // eslint-disable-line
3305
-
3306
- var uiDefaultVs = "uniform mat4 renderer_MVPMat;\n\nattribute vec3 POSITION;\nattribute vec2 TEXCOORD_0;\nattribute vec4 COLOR_0;\n\nvarying vec2 v_uv;\nvarying vec4 v_color;\n\nvoid main() {\n gl_Position = renderer_MVPMat * vec4(POSITION, 1.0);\n\n v_uv = TEXCOORD_0;\n v_color = COLOR_0;\n}\n"; // eslint-disable-line
3307
-
3308
- /**
3309
- * @internal
3310
- */ var UIHitResult = function UIHitResult() {
3311
- this.entity = null;
3312
- this.distance = 0;
3313
- this.point = new Vector3();
3314
- this.normal = new Vector3();
3315
- this.component = null;
3316
- };
3317
-
3318
- var UIPointerEventEmitter = /*#__PURE__*/ function(PointerEventEmitter1) {
3319
- _inherits(UIPointerEventEmitter, PointerEventEmitter1);
3320
- function UIPointerEventEmitter() {
3321
- var _this;
3322
- _this = PointerEventEmitter1.apply(this, arguments) || this, _this._enteredPath = [], _this._pressedPath = [], _this._draggedPath = [];
3323
- return _this;
3324
- }
3325
- var _proto = UIPointerEventEmitter.prototype;
3326
- _proto._init = function _init() {
3327
- this._hitResult = new UIHitResult();
3328
- };
3329
- _proto.processRaycast = function processRaycast(scenes, pointer) {
3330
- var ray = PointerEventEmitter._tempRay;
3331
- var hitResult = this._hitResult;
3332
- var position = pointer.position;
3333
- var x = position.x, y = position.y;
3334
- for(var i = scenes.length - 1; i >= 0; i--){
3335
- var scene = scenes[i];
3336
- if (!scene.isActive || scene.destroyed) continue;
3337
- // @ts-ignore
3338
- var componentsManager = scene._componentsManager;
3339
- // Overlay Canvas
3340
- var canvasElements = componentsManager._overlayCanvases;
3341
- // Screen to world ( Assume that world units have a one-to-one relationship with pixel units )
3342
- ray.origin.set(position.x, scene.engine.canvas.height - position.y, 1);
3343
- ray.direction.set(0, 0, -1);
3344
- for(var j = canvasElements.length - 1; j >= 0; j--){
3345
- if (canvasElements.get(j)._raycast(ray, hitResult)) {
3346
- this._updateRaycast(hitResult.component, pointer);
3347
- return;
3348
- }
3349
- }
3350
- var cameras = componentsManager._activeCameras;
3351
- for(var j1 = cameras.length - 1; j1 >= 0; j1--){
3352
- var camera = cameras.get(j1);
3353
- if (camera.renderTarget) continue;
3354
- var pixelViewport = camera.pixelViewport;
3355
- if (x < pixelViewport.x || y < pixelViewport.y || x > pixelViewport.x + pixelViewport.width || y > pixelViewport.y + pixelViewport.height) {
3356
- continue;
3357
- }
3358
- camera.screenPointToRay(pointer.position, ray);
3359
- // Other canvases
3360
- var isOrthographic = camera.isOrthographic;
3361
- var _camera_entity_transform = camera.entity.transform, cameraPosition = _camera_entity_transform.worldPosition, cameraForward = _camera_entity_transform.worldForward;
3362
- // Sort by rendering order
3363
- canvasElements = componentsManager._canvases;
3364
- for(var k = 0, n = canvasElements.length; k < n; k++){
3365
- canvasElements.get(k)._updateSortDistance(isOrthographic, cameraPosition, cameraForward);
3366
- }
3367
- canvasElements.sort(function(a, b) {
3368
- return a.sortOrder - b.sortOrder || a._sortDistance - b._sortDistance;
3369
- });
3370
- for(var k1 = 0, n1 = canvasElements.length; k1 < n1; k1++){
3371
- canvasElements.get(k1)._canvasIndex = k1;
3372
- }
3373
- var farClipPlane = camera.farClipPlane;
3374
- // Post-rendering first detection
3375
- for(var k2 = 0, n2 = canvasElements.length; k2 < n2; k2++){
3376
- var canvas = canvasElements.get(k2);
3377
- if (!canvas._canRender(camera)) continue;
3378
- if (canvas._raycast(ray, hitResult, farClipPlane)) {
3379
- this._updateRaycast(hitResult.component, pointer);
3380
- return;
3381
- }
3382
- }
3383
- if (camera.clearFlags & CameraClearFlags.Color) {
3384
- this._updateRaycast(null);
3385
- return;
3386
- }
3387
- }
3388
- this._updateRaycast(null);
3389
- }
3390
- };
3391
- _proto.processDrag = function processDrag(pointer) {
3392
- var draggedPath = this._draggedPath;
3393
- if (draggedPath.length > 0) {
3394
- this._bubble(draggedPath, pointer, this._fireDrag);
3395
- }
3396
- };
3397
- _proto.processDown = function processDown(pointer) {
3398
- var enteredPath = this._enteredPath;
3399
- var pressedPath = this._pressedPath;
3400
- var draggedPath = this._draggedPath;
3401
- var length = draggedPath.length = pressedPath.length = enteredPath.length;
3402
- if (length > 0) {
3403
- for(var i = 0; i < length; i++){
3404
- pressedPath[i] = draggedPath[i] = enteredPath[i];
3405
- }
3406
- this._bubble(pressedPath, pointer, this._fireDown);
3407
- this._bubble(draggedPath, pointer, this._fireBeginDrag);
3408
- }
3409
- };
3410
- _proto.processUp = function processUp(pointer) {
3411
- var enteredPath = this._enteredPath;
3412
- var pressedPath = this._pressedPath;
3413
- if (enteredPath.length > 0) {
3414
- this._bubble(enteredPath, pointer, this._fireUp);
3415
- if (pressedPath.length > 0) {
3416
- var common = UIPointerEventEmitter._tempArray0;
3417
- if (this._findCommonInPath(enteredPath, pressedPath, common)) {
3418
- var eventData = this._createEventData(pointer);
3419
- for(var i = 0, n = common.length; i < n; i++){
3420
- this._fireClick(common[i], eventData);
3421
- }
3422
- common.length = 0;
3423
- }
3424
- }
3425
- }
3426
- pressedPath.length = 0;
3427
- var draggedPath = this._draggedPath;
3428
- if (draggedPath.length > 0) {
3429
- this._bubble(draggedPath, pointer, this._fireEndDrag);
3430
- draggedPath.length = 0;
3431
- }
3432
- if (enteredPath.length > 0) {
3433
- this._bubble(enteredPath, pointer, this._fireDrop);
3434
- }
3435
- };
3436
- _proto.processLeave = function processLeave(pointer) {
3437
- var enteredPath = this._enteredPath;
3438
- if (enteredPath.length > 0) {
3439
- this._bubble(enteredPath, pointer, this._fireExit);
3440
- enteredPath.length = 0;
3441
- }
3442
- var draggedPath = this._draggedPath;
3443
- if (draggedPath.length > 0) {
3444
- this._bubble(draggedPath, pointer, this._fireEndDrag);
3445
- draggedPath.length = 0;
3446
- }
3447
- this._pressedPath.length = 0;
3448
- };
3449
- _proto.dispose = function dispose() {
3450
- this._enteredPath.length = this._pressedPath.length = this._draggedPath.length = 0;
3451
- };
3452
- _proto._updateRaycast = function _updateRaycast(element, pointer) {
3453
- if (pointer === void 0) pointer = null;
3454
- var enteredPath = this._enteredPath;
3455
- var curPath = this._composedPath(element, UIPointerEventEmitter._path);
3456
- var add = UIPointerEventEmitter._tempArray0;
3457
- var del = UIPointerEventEmitter._tempArray1;
3458
- if (this._findDiffInPath(enteredPath, curPath, add, del)) {
3459
- var eventData = this._createEventData(pointer);
3460
- for(var i = 0, n = add.length; i < n; i++){
3461
- this._fireEnter(add[i], eventData);
3462
- }
3463
- for(var i1 = 0, n1 = del.length; i1 < n1; i1++){
3464
- this._fireExit(del[i1], eventData);
3465
- }
3466
- var length = enteredPath.length = curPath.length;
3467
- for(var i2 = 0; i2 < length; i2++){
3468
- enteredPath[i2] = curPath[i2];
3469
- }
3470
- add.length = del.length = 0;
3471
- }
3472
- curPath.length = 0;
3473
- };
3474
- _proto._composedPath = function _composedPath(element, path) {
3475
- if (!element) {
3476
- path.length = 0;
3477
- return path;
3478
- }
3479
- var entity = path[0] = element.entity;
3480
- var i = 1;
3481
- var rootEntity = element._getRootCanvas().entity;
3482
- for(; i < UIPointerEventEmitter._MAX_PATH_DEPTH && !!entity && entity !== rootEntity; i++){
3483
- entity = path[i] = entity.parent;
3484
- }
3485
- path.length = i;
3486
- return path;
3487
- };
3488
- _proto._findCommonInPath = function _findCommonInPath(prePath, curPath, common) {
3489
- var idSet = UIPointerEventEmitter._tempSet;
3490
- idSet.clear();
3491
- for(var i = 0, n = prePath.length; i < n; i++){
3492
- idSet.add(prePath[i].instanceId);
3493
- }
3494
- var hasCommon = false;
3495
- for(var i1 = 0, n1 = curPath.length; i1 < n1; i1++){
3496
- var entity = curPath[i1];
3497
- if (idSet.has(entity.instanceId)) {
3498
- common.push(entity);
3499
- hasCommon = true;
3500
- }
3501
- }
3502
- return hasCommon;
3503
- };
3504
- _proto._findDiffInPath = function _findDiffInPath(prePath, curPath, add, del) {
3505
- var idSet = UIPointerEventEmitter._tempSet;
3506
- idSet.clear();
3507
- var changed = false;
3508
- for(var i = 0, n = prePath.length; i < n; i++){
3509
- idSet.add(prePath[i].instanceId);
3510
- }
3511
- for(var i1 = 0, n1 = curPath.length; i1 < n1; i1++){
3512
- var entity = curPath[i1];
3513
- if (!idSet.has(entity.instanceId)) {
3514
- add.push(entity);
3515
- changed = true;
3516
- }
3517
- }
3518
- idSet.clear();
3519
- for(var i2 = 0, n2 = curPath.length; i2 < n2; i2++){
3520
- idSet.add(curPath[i2].instanceId);
3521
- }
3522
- for(var i3 = 0, n3 = prePath.length; i3 < n3; i3++){
3523
- var entity1 = prePath[i3];
3524
- if (!idSet.has(entity1.instanceId)) {
3525
- del.push(entity1);
3526
- changed = true;
3527
- }
3528
- }
3529
- return changed;
3530
- };
3531
- _proto._bubble = function _bubble(path, pointer, fireEvent) {
3532
- var length = path.length;
3533
- if (length <= 0) return;
3534
- var eventData = this._createEventData(pointer);
3535
- for(var i = 0; i < length; i++){
3536
- fireEvent(path[i], eventData);
3537
- }
3538
- };
3539
- return UIPointerEventEmitter;
3540
- }(PointerEventEmitter);
3541
- UIPointerEventEmitter._MAX_PATH_DEPTH = 2048;
3542
- UIPointerEventEmitter._tempSet = new Set();
3543
- UIPointerEventEmitter._path = [];
3544
- UIPointerEventEmitter._tempArray0 = [];
3545
- UIPointerEventEmitter._tempArray1 = [];
3546
- UIPointerEventEmitter = __decorate([
3547
- registerPointerEventEmitter()
3548
- ], UIPointerEventEmitter);
3549
-
3550
- var EngineExtension = /*#__PURE__*/ function() {
3551
- function EngineExtension() {}
3552
- var _proto = EngineExtension.prototype;
3553
- _proto._getUIDefaultMaterial = function _getUIDefaultMaterial() {
3554
- if (!this._uiDefaultMaterial) {
3555
- var shader = _getOrCreateUIShader();
3556
- // @ts-ignore
3557
- var material = new Material(this, shader);
3558
- var renderState = material.renderState;
3559
- var target = renderState.blendState.targetBlendState;
3560
- target.enabled = true;
3561
- target.sourceColorBlendFactor = BlendFactor.SourceAlpha;
3562
- target.destinationColorBlendFactor = BlendFactor.OneMinusSourceAlpha;
3563
- target.sourceAlphaBlendFactor = BlendFactor.One;
3564
- target.destinationAlphaBlendFactor = BlendFactor.OneMinusSourceAlpha;
3565
- target.colorBlendOperation = target.alphaBlendOperation = BlendOperation.Add;
3566
- renderState.depthState.writeEnabled = false;
3567
- renderState.rasterState.cullMode = CullMode.Off;
3568
- renderState.renderQueueType = RenderQueueType.Transparent;
3569
- material.isGCIgnored = true;
3570
- this._uiDefaultMaterial = material;
3571
- }
3572
- return this._uiDefaultMaterial;
3573
- };
3574
- return EngineExtension;
3575
- }();
3576
- var EntityExtension = /*#__PURE__*/ function() {
3577
- function EntityExtension() {
3578
- this._uiHierarchyVersion = 0;
3579
- }
3580
- var _proto = EntityExtension.prototype;
3581
- _proto._updateUIHierarchyVersion = function _updateUIHierarchyVersion(version) {
3582
- if (this._uiHierarchyVersion !== version) {
3583
- var // @ts-ignore
3584
- _this_parent;
3585
- this._uiHierarchyVersion = version;
3586
- (_this_parent = this.parent) == null ? void 0 : _this_parent._updateUIHierarchyVersion(version);
3587
- }
3588
- };
3589
- return EntityExtension;
3590
- }();
3591
- function ApplyMixins(derivedCtor, baseCtors) {
3592
- baseCtors.forEach(function(baseCtor) {
3593
- Object.getOwnPropertyNames(baseCtor.prototype).forEach(function(name) {
3594
- Object.defineProperty(derivedCtor.prototype, name, Object.getOwnPropertyDescriptor(baseCtor.prototype, name) || Object.create(null));
3595
- });
3596
- });
3597
- }
3598
- ApplyMixins(Engine, [
3599
- EngineExtension
3600
- ]);
3601
- ApplyMixins(Entity, [
3602
- EntityExtension
3603
- ]);
3604
- ReflectionParser.registerCustomParseComponent("Text", /*#__PURE__*/ _async_to_generator(function(instance, item) {
3605
- var props;
3606
- return __generator(this, function(_state) {
3607
- props = item.props;
3608
- if (!props.font) {
3609
- // @ts-ignore
3610
- instance.font = Font.createFromOS(instance.engine, props.fontFamily || "Arial");
3611
- }
3612
- return [
3613
- 2,
3614
- instance
3615
- ];
3616
- });
3617
- }));
3618
- /**
3619
- * Register GUI components for the editor.
3620
- */ function registerGUI() {
3621
- for(var key in GUIComponent){
3622
- Loader.registerClass(key, GUIComponent[key]);
3623
- }
3624
- _getOrCreateUIShader();
3625
- }
3626
- function _getOrCreateUIShader() {
3627
- var shader = Shader.find("ui");
3628
- if (!shader) {
3629
- shader = Shader.create("ui", [
3630
- new ShaderPass("Forward", uiDefaultVs, uiDefaultFs, {
3631
- pipelineStage: PipelineStage.Forward
3632
- })
3633
- ]);
3634
- }
3635
- return shader;
3636
- }
3637
-
3638
- export { Button, CanvasRenderMode, ColorTransition, EngineExtension, EntityExtension, HorizontalAlignmentMode, Image, ResolutionAdaptationMode, ScaleTransition, SpriteTransition, Text, Transition, UICanvas, UIGroup, UIPointerEventEmitter, UIRenderer, UITransform, VerticalAlignmentMode, registerGUI };
3639
- //# sourceMappingURL=module.js.map