@galacean/engine-ui 0.0.0-experimental-1.4-small-language.3 → 0.0.0-experimental-backup.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/module.js DELETED
@@ -1,3225 +0,0 @@
1
- import { EntityModifyFlags, ignoreClone, assignmentClone, DisorderedArray, Component, deepClone, Vector2, Transform, Vector3, Matrix, Plane, ShaderProperty, dependentComponents, DependentMode, BatchUtils, ShaderMacroCollection, Renderer, Vector4, Color, RendererUpdateFlags, Script, MathUtil, 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, Shader, ShaderPass, PipelineStage, Material, BlendFactor, BlendOperation, CullMode, RenderQueueType, Entity, Loader, 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 = true, /** @internal */ _this._isGroupDirty = true, /** @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
- assignmentClone
309
- ], UIGroup.prototype, "_alpha", void 0);
310
- __decorate([
311
- assignmentClone
312
- ], UIGroup.prototype, "_interactive", void 0);
313
- __decorate([
314
- assignmentClone
315
- ], UIGroup.prototype, "_ignoreParentGroup", void 0);
316
- __decorate([
317
- ignoreClone
318
- ], UIGroup.prototype, "_rootCanvasListeningEntities", void 0);
319
- __decorate([
320
- ignoreClone
321
- ], UIGroup.prototype, "_groupListeningEntities", void 0);
322
- __decorate([
323
- ignoreClone
324
- ], UIGroup.prototype, "_isRootCanvasDirty", void 0);
325
- __decorate([
326
- ignoreClone
327
- ], UIGroup.prototype, "_isGroupDirty", void 0);
328
- __decorate([
329
- ignoreClone
330
- ], UIGroup.prototype, "_groupDirtyFlags", void 0);
331
- __decorate([
332
- ignoreClone
333
- ], UIGroup.prototype, "_groupListener", null);
334
- __decorate([
335
- ignoreClone
336
- ], UIGroup.prototype, "_rootCanvasListener", null);
337
- var GroupModifyFlags = /*#__PURE__*/ function(GroupModifyFlags) {
338
- GroupModifyFlags[GroupModifyFlags["None"] = 0] = "None";
339
- GroupModifyFlags[GroupModifyFlags["GlobalAlpha"] = 1] = "GlobalAlpha";
340
- GroupModifyFlags[GroupModifyFlags["GlobalInteractive"] = 2] = "GlobalInteractive";
341
- GroupModifyFlags[GroupModifyFlags["All"] = 3] = "All";
342
- return GroupModifyFlags;
343
- }({});
344
-
345
- var Utils = /*#__PURE__*/ function() {
346
- function Utils() {}
347
- Utils.setRootCanvasDirty = function setRootCanvasDirty(element) {
348
- if (element._isRootCanvasDirty) return;
349
- element._isRootCanvasDirty = true;
350
- this._registerRootCanvas(element, null);
351
- element._onRootCanvasModify == null ? void 0 : element._onRootCanvasModify.call(element, RootCanvasModifyFlags.All);
352
- };
353
- Utils.setRootCanvas = function setRootCanvas(element, rootCanvas) {
354
- element._isRootCanvasDirty = false;
355
- this._registerRootCanvas(element, rootCanvas);
356
- var fromEntity = _instanceof(element, UICanvas) ? element.entity.parent : element.entity;
357
- var _rootCanvas_entity_parent;
358
- var toEntity = (_rootCanvas_entity_parent = rootCanvas == null ? void 0 : rootCanvas.entity.parent) != null ? _rootCanvas_entity_parent : null;
359
- this._registerListener(fromEntity, toEntity, element._rootCanvasListener, element._rootCanvasListeningEntities);
360
- };
361
- Utils.cleanRootCanvas = function cleanRootCanvas(element) {
362
- this._registerRootCanvas(element, null);
363
- this._unRegisterListener(element._rootCanvasListener, element._rootCanvasListeningEntities);
364
- };
365
- Utils.searchRootCanvasInParents = function searchRootCanvasInParents(element) {
366
- var entity = _instanceof(element, UICanvas) ? element.entity.parent : element.entity;
367
- while(entity){
368
- // @ts-ignore
369
- var components = entity._components;
370
- for(var i = 0, n = components.length; i < n; i++){
371
- var component = components[i];
372
- if (component.enabled && _instanceof(component, UICanvas) && component._isRootCanvas) {
373
- return component;
374
- }
375
- }
376
- entity = entity.parent;
377
- }
378
- return null;
379
- };
380
- Utils.setGroupDirty = function setGroupDirty(element) {
381
- if (element._isGroupDirty) return;
382
- element._isGroupDirty = true;
383
- this._registerGroup(element, null);
384
- element._onGroupModify(GroupModifyFlags.All);
385
- };
386
- Utils.setGroup = function setGroup(element, group) {
387
- element._isGroupDirty = false;
388
- this._registerGroup(element, group);
389
- var rootCanvas = element._getRootCanvas();
390
- if (rootCanvas) {
391
- var fromEntity = _instanceof(element, UIGroup) ? element.entity.parent : element.entity;
392
- var _group_entity;
393
- var toEntity = (_group_entity = group == null ? void 0 : group.entity) != null ? _group_entity : rootCanvas.entity.parent;
394
- this._registerListener(fromEntity, toEntity, element._groupListener, element._groupListeningEntities);
395
- } else {
396
- this._unRegisterListener(element._groupListener, element._groupListeningEntities);
397
- }
398
- };
399
- Utils.cleanGroup = function cleanGroup(element) {
400
- this._registerGroup(element, null);
401
- this._unRegisterListener(element._groupListener, element._groupListeningEntities);
402
- };
403
- Utils.searchGroupInParents = function searchGroupInParents(element) {
404
- var rootCanvas = element._getRootCanvas();
405
- if (!rootCanvas) return null;
406
- var entity = _instanceof(element, UIGroup) ? element.entity.parent : element.entity;
407
- var rootCanvasParent = rootCanvas.entity.parent;
408
- while(entity && entity !== rootCanvasParent){
409
- // @ts-ignore
410
- var components = entity._components;
411
- for(var i = 0, n = components.length; i < n; i++){
412
- var component = components[i];
413
- if (component.enabled && _instanceof(component, UIGroup)) {
414
- return component;
415
- }
416
- }
417
- entity = entity.parent;
418
- }
419
- return null;
420
- };
421
- Utils._registerRootCanvas = function _registerRootCanvas(element, canvas) {
422
- var preCanvas = element._rootCanvas;
423
- if (preCanvas !== canvas) {
424
- if (preCanvas) {
425
- var replaced = preCanvas._disorderedElements.deleteByIndex(element._indexInRootCanvas);
426
- replaced && (replaced._indexInRootCanvas = element._indexInRootCanvas);
427
- element._indexInRootCanvas = -1;
428
- }
429
- if (canvas) {
430
- var disorderedElements = canvas._disorderedElements;
431
- element._indexInRootCanvas = disorderedElements.length;
432
- disorderedElements.add(element);
433
- }
434
- element._rootCanvas = canvas;
435
- }
436
- };
437
- Utils._registerGroup = function _registerGroup(element, group) {
438
- var preGroup = element._group;
439
- if (preGroup !== group) {
440
- if (preGroup) {
441
- var replaced = preGroup._disorderedElements.deleteByIndex(element._indexInGroup);
442
- replaced && (replaced._indexInGroup = element._indexInGroup);
443
- element._indexInGroup = -1;
444
- }
445
- if (group) {
446
- var disorderedElements = group._disorderedElements;
447
- element._indexInGroup = disorderedElements.length;
448
- disorderedElements.add(element);
449
- }
450
- element._group = group;
451
- element._onGroupModify(GroupModifyFlags.All);
452
- }
453
- };
454
- Utils._registerListener = function _registerListener(entity, root, listener, listeningEntities) {
455
- var count = 0;
456
- while(entity && entity !== root){
457
- var preEntity = listeningEntities[count];
458
- if (preEntity !== entity) {
459
- // @ts-ignore
460
- preEntity == null ? void 0 : preEntity._unRegisterModifyListener(listener);
461
- listeningEntities[count] = entity;
462
- // @ts-ignore
463
- entity._registerModifyListener(listener);
464
- }
465
- entity = entity.parent;
466
- count++;
467
- }
468
- listeningEntities.length = count;
469
- };
470
- Utils._unRegisterListener = function _unRegisterListener(listener, listeningEntities) {
471
- for(var i = 0, n = listeningEntities.length; i < n; i++){
472
- // @ts-ignore
473
- listeningEntities[i]._unRegisterModifyListener(listener);
474
- }
475
- listeningEntities.length = 0;
476
- };
477
- return Utils;
478
- }();
479
-
480
- /**
481
- * Render mode for ui canvas.
482
- */ var CanvasRenderMode = /*#__PURE__*/ function(CanvasRenderMode) {
483
- /**
484
- * The UI canvas will be rendered directly onto the screen and adapted to screen space,
485
- * overlaying other rendering elements in the same scene.
486
- * @remarks if the `engine.canvas` size change, the UI canvas will automatically adapt.
487
- */ CanvasRenderMode[CanvasRenderMode["ScreenSpaceOverlay"] = 0] = "ScreenSpaceOverlay";
488
- /**
489
- * The UI canvas is placed at a specified distance in front of the camera and adapted to screen space,
490
- * with all objects rendered by the camera.
491
- * @remarks if the camera's properties or the `engine.canvas` size change, the UI canvas will automatically adapt.
492
- * @remarks if set `ScreenSpaceCamera` but no corresponding camera is assigned, the actual rendering mode defaults to `ScreenSpaceOverlay`.
493
- */ CanvasRenderMode[CanvasRenderMode["ScreenSpaceCamera"] = 1] = "ScreenSpaceCamera";
494
- /**
495
- * The UI canvas is placed in the 3D world space and rendered by every camera in the same scene.
496
- */ CanvasRenderMode[CanvasRenderMode["WorldSpace"] = 2] = "WorldSpace";
497
- return CanvasRenderMode;
498
- }({});
499
-
500
- /**
501
- * Resolution adaptation mode.
502
- * @remarks Only effective in screen space.
503
- */ var ResolutionAdaptationMode = /*#__PURE__*/ function(ResolutionAdaptationMode) {
504
- /** Adapt based on width.(`referenceResolution.x`) */ ResolutionAdaptationMode[ResolutionAdaptationMode["WidthAdaptation"] = 0] = "WidthAdaptation";
505
- /** Adapt based on height.(`referenceResolution.y`) */ ResolutionAdaptationMode[ResolutionAdaptationMode["HeightAdaptation"] = 1] = "HeightAdaptation";
506
- /** Adapt based on both width and height.(`referenceResolution`) */ ResolutionAdaptationMode[ResolutionAdaptationMode["BothAdaptation"] = 2] = "BothAdaptation";
507
- /** Adapt to the side with a larger ratio. */ ResolutionAdaptationMode[ResolutionAdaptationMode["ExpandAdaptation"] = 3] = "ExpandAdaptation";
508
- /** Adapt to the side with smaller ratio. */ ResolutionAdaptationMode[ResolutionAdaptationMode["ShrinkAdaptation"] = 4] = "ShrinkAdaptation";
509
- return ResolutionAdaptationMode;
510
- }({});
511
-
512
- /**
513
- * The Transform component exclusive to the UI element.
514
- */ var UITransform = /*#__PURE__*/ function(Transform) {
515
- _inherits(UITransform, Transform);
516
- function UITransform(entity) {
517
- var _this;
518
- _this = Transform.call(this, entity) || this, _this._size = new Vector2(100, 100), _this._pivot = new Vector2(0.5, 0.5);
519
- // @ts-ignore
520
- _this._size._onValueChanged = _this._onSizeChange.bind(_this);
521
- // @ts-ignore
522
- _this._pivot._onValueChanged = _this._onPivotChange.bind(_this);
523
- return _this;
524
- }
525
- var _proto = UITransform.prototype;
526
- _proto._onSizeChange = function _onSizeChange() {
527
- // @ts-ignore
528
- this._entity._updateFlagManager.dispatch(512);
529
- };
530
- _proto._onPivotChange = function _onPivotChange() {
531
- // @ts-ignore
532
- this._entity._updateFlagManager.dispatch(1024);
533
- };
534
- _create_class(UITransform, [
535
- {
536
- key: "size",
537
- get: /**
538
- * Width and height of UI element.
539
- */ function get() {
540
- return this._size;
541
- },
542
- set: function set(value) {
543
- var _this = this, size = _this._size;
544
- if (size === value) return;
545
- (size.x !== value.x || size.y !== value.y) && size.copyFrom(value);
546
- }
547
- },
548
- {
549
- key: "pivot",
550
- get: /**
551
- * Pivot of UI element.
552
- */ function get() {
553
- return this._pivot;
554
- },
555
- set: function set(value) {
556
- var _this = this, pivot = _this._pivot;
557
- if (pivot === value) return;
558
- (pivot.x !== value.x || pivot.y !== value.y) && pivot.copyFrom(value);
559
- }
560
- }
561
- ]);
562
- return UITransform;
563
- }(Transform);
564
- __decorate([
565
- deepClone
566
- ], UITransform.prototype, "_size", void 0);
567
- __decorate([
568
- deepClone
569
- ], UITransform.prototype, "_pivot", void 0);
570
- __decorate([
571
- ignoreClone
572
- ], UITransform.prototype, "_onSizeChange", null);
573
- __decorate([
574
- ignoreClone
575
- ], UITransform.prototype, "_onPivotChange", null);
576
- /**
577
- * @internal
578
- * extends TransformModifyFlags
579
- */ var UITransformModifyFlags = /*#__PURE__*/ function(UITransformModifyFlags) {
580
- /** Size. */ UITransformModifyFlags[UITransformModifyFlags["Size"] = 512] = "Size";
581
- /** Pivot. */ UITransformModifyFlags[UITransformModifyFlags["Pivot"] = 1024] = "Pivot";
582
- return UITransformModifyFlags;
583
- }({});
584
-
585
- var UIRenderer = /*#__PURE__*/ function(Renderer) {
586
- _inherits(UIRenderer, Renderer);
587
- function UIRenderer(entity) {
588
- var _this;
589
- _this = Renderer.call(this, entity) || this, /**
590
- * Custom boundary for raycast detection.
591
- * @remarks this is based on `this.entity.transform`.
592
- */ _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);
593
- _this._dirtyUpdateFlag = RendererUpdateFlags.WorldVolume | 2;
594
- _this._onColorChanged = _this._onColorChanged.bind(_this);
595
- //@ts-ignore
596
- _this._color._onValueChanged = _this._onColorChanged;
597
- _this._groupListener = _this._groupListener.bind(_this);
598
- _this._rootCanvasListener = _this._rootCanvasListener.bind(_this);
599
- return _this;
600
- }
601
- var _proto = UIRenderer.prototype;
602
- // @ts-ignore
603
- _proto._canBatch = function _canBatch(elementA, elementB) {
604
- return BatchUtils.canBatchSprite(elementA, elementB);
605
- };
606
- // @ts-ignore
607
- _proto._batch = function _batch(elementA, elementB) {
608
- BatchUtils.batchFor2D(elementA, elementB);
609
- };
610
- // @ts-ignore
611
- _proto._updateTransformShaderData = function _updateTransformShaderData(context, onlyMVP, batched) {
612
- // @ts-ignore
613
- Renderer.prototype._updateTransformShaderData.call(this, context, onlyMVP, true);
614
- };
615
- // @ts-ignore
616
- _proto._prepareRender = function _prepareRender(context) {
617
- // Update once per frame per renderer, not influenced by batched
618
- if (this._renderFrameCount !== this.engine.time.frameCount) {
619
- this._update(context);
620
- }
621
- this._render(context);
622
- // union camera global macro and renderer macro.
623
- ShaderMacroCollection.unionCollection(context.camera._globalShaderMacro, // @ts-ignore
624
- this.shaderData._macroCollection, //@ts-ignore
625
- this._globalShaderMacro);
626
- };
627
- // @ts-ignore
628
- _proto._onEnableInScene = function _onEnableInScene() {
629
- // @ts-ignore
630
- this._overrideUpdate && this.scene._componentsManager.addOnUpdateRenderers(this);
631
- this.entity._updateUIHierarchyVersion(UICanvas._hierarchyCounter);
632
- Utils.setRootCanvasDirty(this);
633
- Utils.setGroupDirty(this);
634
- };
635
- // @ts-ignore
636
- _proto._onDisableInScene = function _onDisableInScene() {
637
- // @ts-ignore
638
- this._overrideUpdate && this.scene._componentsManager.removeOnUpdateRenderers(this);
639
- this.entity._updateUIHierarchyVersion(UICanvas._hierarchyCounter);
640
- Utils.cleanRootCanvas(this);
641
- Utils.cleanGroup(this);
642
- };
643
- /**
644
- * @internal
645
- */ _proto._getGlobalAlpha = function _getGlobalAlpha() {
646
- var _this__getGroup;
647
- var _this__getGroup__getGlobalAlpha;
648
- return (_this__getGroup__getGlobalAlpha = (_this__getGroup = this._getGroup()) == null ? void 0 : _this__getGroup._getGlobalAlpha()) != null ? _this__getGroup__getGlobalAlpha : 1;
649
- };
650
- /**
651
- * @internal
652
- */ _proto._getRootCanvas = function _getRootCanvas() {
653
- this._isRootCanvasDirty && Utils.setRootCanvas(this, Utils.searchRootCanvasInParents(this));
654
- return this._rootCanvas;
655
- };
656
- /**
657
- * @internal
658
- */ _proto._getGroup = function _getGroup() {
659
- this._isGroupDirty && Utils.setGroup(this, Utils.searchGroupInParents(this));
660
- return this._group;
661
- };
662
- /**
663
- * @internal
664
- */ _proto._groupListener = function _groupListener(flag) {
665
- if (flag === EntityModifyFlags.Parent || flag === EntityUIModifyFlags.GroupEnableInScene) {
666
- Utils.setGroupDirty(this);
667
- }
668
- };
669
- /**
670
- * @internal
671
- */ _proto._rootCanvasListener = function _rootCanvasListener(flag, entity) {
672
- switch(flag){
673
- case EntityModifyFlags.Parent:
674
- Utils.setRootCanvasDirty(this);
675
- Utils.setGroupDirty(this);
676
- case EntityModifyFlags.Child:
677
- entity._updateUIHierarchyVersion(UICanvas._hierarchyCounter);
678
- break;
679
- }
680
- };
681
- /**
682
- * @internal
683
- */ _proto._onGroupModify = function _onGroupModify(flags) {
684
- if (flags & GroupModifyFlags.GlobalAlpha) {
685
- this._dirtyUpdateFlag |= 2;
686
- }
687
- };
688
- _proto._onColorChanged = function _onColorChanged() {
689
- this._dirtyUpdateFlag |= 2;
690
- };
691
- /**
692
- * @internal
693
- */ _proto._getChunkManager = function _getChunkManager() {
694
- // @ts-ignore
695
- return this.engine._batcherManager.primitiveChunkManagerUI;
696
- };
697
- /**
698
- * @internal
699
- */ _proto._raycast = function _raycast(ray, out, distance) {
700
- if (distance === void 0) distance = Number.MAX_SAFE_INTEGER;
701
- var plane = UIRenderer._tempPlane;
702
- var transform = this._transformEntity.transform;
703
- var normal = plane.normal.copyFrom(transform.worldForward);
704
- plane.distance = -Vector3.dot(normal, transform.worldPosition);
705
- var curDistance = ray.intersectPlane(plane);
706
- if (curDistance >= 0 && curDistance < distance) {
707
- var hitPointWorld = ray.getPoint(curDistance, UIRenderer._tempVec30);
708
- var worldMatrixInv = UIRenderer._tempMat;
709
- Matrix.invert(transform.worldMatrix, worldMatrixInv);
710
- var localPosition = UIRenderer._tempVec31;
711
- Vector3.transformCoordinate(hitPointWorld, worldMatrixInv, localPosition);
712
- if (this._hitTest(localPosition)) {
713
- out.component = this;
714
- out.distance = curDistance;
715
- out.entity = this.entity;
716
- out.normal.copyFrom(normal);
717
- out.point.copyFrom(hitPointWorld);
718
- return true;
719
- }
720
- }
721
- return false;
722
- };
723
- _proto._hitTest = function _hitTest(localPosition) {
724
- var x = localPosition.x, y = localPosition.y;
725
- var uiTransform = this._transformEntity.transform;
726
- var _uiTransform_size = uiTransform.size, width = _uiTransform_size.x, height = _uiTransform_size.y;
727
- var _uiTransform_pivot = uiTransform.pivot, pivotX = _uiTransform_pivot.x, pivotY = _uiTransform_pivot.y;
728
- var _this_raycastPadding = this.raycastPadding, paddingLeft = _this_raycastPadding.x, paddingBottom = _this_raycastPadding.y, paddingRight = _this_raycastPadding.z, paddingTop = _this_raycastPadding.w;
729
- return x >= -width * pivotX + paddingLeft && x <= width * (1 - pivotX) - paddingRight && y >= -height * pivotY + paddingTop && y <= height * (1 - pivotY) - paddingBottom;
730
- };
731
- _proto._onDestroy = function _onDestroy() {
732
- if (this._subChunk) {
733
- this._getChunkManager().freeSubChunk(this._subChunk);
734
- this._subChunk = null;
735
- }
736
- Renderer.prototype._onDestroy.call(this);
737
- //@ts-ignore
738
- this._color._onValueChanged = null;
739
- this._color = null;
740
- };
741
- _create_class(UIRenderer, [
742
- {
743
- key: "color",
744
- get: /**
745
- * Rendering color for the ui renderer.
746
- */ function get() {
747
- return this._color;
748
- },
749
- set: function set(value) {
750
- if (this._color !== value) {
751
- this._color.copyFrom(value);
752
- }
753
- }
754
- },
755
- {
756
- key: "raycastEnabled",
757
- get: /**
758
- * Whether this renderer be picked up by raycast.
759
- */ function get() {
760
- return this._raycastEnabled;
761
- },
762
- set: function set(value) {
763
- this._raycastEnabled = value;
764
- }
765
- }
766
- ]);
767
- return UIRenderer;
768
- }(Renderer);
769
- /** @internal */ UIRenderer._tempVec30 = new Vector3();
770
- /** @internal */ UIRenderer._tempVec31 = new Vector3();
771
- /** @internal */ UIRenderer._tempMat = new Matrix();
772
- /** @internal */ UIRenderer._tempPlane = new Plane();
773
- /** @internal */ UIRenderer._textureProperty = ShaderProperty.getByName("renderer_UITexture");
774
- __decorate([
775
- deepClone
776
- ], UIRenderer.prototype, "raycastPadding", void 0);
777
- __decorate([
778
- ignoreClone
779
- ], UIRenderer.prototype, "_rootCanvas", void 0);
780
- __decorate([
781
- ignoreClone
782
- ], UIRenderer.prototype, "_indexInRootCanvas", void 0);
783
- __decorate([
784
- ignoreClone
785
- ], UIRenderer.prototype, "_isRootCanvasDirty", void 0);
786
- __decorate([
787
- ignoreClone
788
- ], UIRenderer.prototype, "_rootCanvasListeningEntities", void 0);
789
- __decorate([
790
- ignoreClone
791
- ], UIRenderer.prototype, "_group", void 0);
792
- __decorate([
793
- ignoreClone
794
- ], UIRenderer.prototype, "_indexInGroup", void 0);
795
- __decorate([
796
- ignoreClone
797
- ], UIRenderer.prototype, "_isGroupDirty", void 0);
798
- __decorate([
799
- ignoreClone
800
- ], UIRenderer.prototype, "_groupListeningEntities", void 0);
801
- __decorate([
802
- ignoreClone
803
- ], UIRenderer.prototype, "_subChunk", void 0);
804
- __decorate([
805
- ignoreClone
806
- ], UIRenderer.prototype, "_raycastEnabled", void 0);
807
- __decorate([
808
- deepClone
809
- ], UIRenderer.prototype, "_color", void 0);
810
- __decorate([
811
- ignoreClone
812
- ], UIRenderer.prototype, "_groupListener", null);
813
- __decorate([
814
- ignoreClone
815
- ], UIRenderer.prototype, "_rootCanvasListener", null);
816
- __decorate([
817
- ignoreClone
818
- ], UIRenderer.prototype, "_onColorChanged", null);
819
- UIRenderer = __decorate([
820
- dependentComponents(UITransform, DependentMode.AutoAdd)
821
- ], UIRenderer);
822
- /**
823
- * @remarks Extends `RendererUpdateFlags`.
824
- */ var UIRendererUpdateFlags = /*#__PURE__*/ function(UIRendererUpdateFlags) {
825
- UIRendererUpdateFlags[UIRendererUpdateFlags["Color"] = 2] = "Color";
826
- return UIRendererUpdateFlags;
827
- }({});
828
-
829
- /**
830
- * Interactive component.
831
- */ var UIInteractive = /*#__PURE__*/ function(Script) {
832
- _inherits(UIInteractive, Script);
833
- function UIInteractive(entity) {
834
- var _this;
835
- _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._interactive = true, _this._state = 0, _this._transitions = [], /** @todo Multi-touch points are not considered yet. */ _this._isPointerInside = false, _this._isPointerDragging = false;
836
- _this._groupListener = _this._groupListener.bind(_this);
837
- _this._rootCanvasListener = _this._rootCanvasListener.bind(_this);
838
- return _this;
839
- }
840
- var _proto = UIInteractive.prototype;
841
- /**
842
- * Add transition on this interactive.
843
- * @param transition - The transition
844
- */ _proto.addTransition = function addTransition(transition) {
845
- var interactive = transition._interactive;
846
- if (interactive !== this) {
847
- interactive == null ? void 0 : interactive.removeTransition(transition);
848
- this._transitions.push(transition);
849
- transition._interactive = this;
850
- transition._setState(this._state, true);
851
- }
852
- };
853
- /**
854
- * Remove a transition.
855
- * @param shape - The transition.
856
- */ _proto.removeTransition = function removeTransition(transition) {
857
- var transitions = this._transitions;
858
- var lastOneIndex = transitions.length - 1;
859
- for(var i = lastOneIndex; i >= 0; i--){
860
- if (transitions[i] === transition) {
861
- i !== lastOneIndex && (transitions[i] = transitions[lastOneIndex]);
862
- transitions.length = lastOneIndex;
863
- transition._interactive = null;
864
- break;
865
- }
866
- }
867
- };
868
- /**
869
- * Remove all transitions.
870
- */ _proto.clearTransitions = function clearTransitions() {
871
- var transitions = this._transitions;
872
- for(var i = 0, n = transitions.length; i < n; i++){
873
- transitions[i]._interactive = null;
874
- }
875
- transitions.length = 0;
876
- };
877
- _proto.onUpdate = function onUpdate(deltaTime) {
878
- if (this._getGlobalInteractive()) {
879
- var transitions = this._transitions;
880
- for(var i = 0, n = transitions.length; i < n; i++){
881
- transitions[i]._onUpdate(deltaTime);
882
- }
883
- }
884
- };
885
- _proto.onPointerBeginDrag = function onPointerBeginDrag() {
886
- this._isPointerDragging = true;
887
- this._updateState(false);
888
- };
889
- _proto.onPointerEndDrag = function onPointerEndDrag() {
890
- this._isPointerDragging = false;
891
- this._updateState(false);
892
- };
893
- _proto.onPointerEnter = function onPointerEnter() {
894
- this._isPointerInside = true;
895
- this._updateState(false);
896
- };
897
- _proto.onPointerExit = function onPointerExit() {
898
- this._isPointerInside = false;
899
- this._updateState(false);
900
- };
901
- _proto.onDestroy = function onDestroy() {
902
- Script.prototype.onDestroy.call(this);
903
- var transitions = this._transitions;
904
- for(var i = transitions.length - 1; i >= 0; i--){
905
- transitions[i].destroy();
906
- }
907
- };
908
- /**
909
- * @internal
910
- */ _proto._getRootCanvas = function _getRootCanvas() {
911
- this._isRootCanvasDirty && Utils.setRootCanvas(this, Utils.searchRootCanvasInParents(this));
912
- return this._rootCanvas;
913
- };
914
- /**
915
- * @internal
916
- */ _proto._getGroup = function _getGroup() {
917
- this._isGroupDirty && Utils.setGroup(this, Utils.searchGroupInParents(this));
918
- return this._group;
919
- };
920
- // @ts-ignore
921
- _proto._onEnableInScene = function _onEnableInScene() {
922
- // @ts-ignore
923
- Script.prototype._onEnableInScene.call(this);
924
- Utils.setRootCanvasDirty(this);
925
- Utils.setGroupDirty(this);
926
- this._updateState(true);
927
- };
928
- // @ts-ignore
929
- _proto._onDisableInScene = function _onDisableInScene() {
930
- // @ts-ignore
931
- Script.prototype._onDisableInScene.call(this);
932
- Utils.cleanRootCanvas(this);
933
- Utils.cleanGroup(this);
934
- this._isPointerInside = this._isPointerDragging = false;
935
- };
936
- /**
937
- * @internal
938
- */ _proto._groupListener = function _groupListener(flag) {
939
- if (flag === EntityModifyFlags.Parent || flag === EntityUIModifyFlags.GroupEnableInScene) {
940
- Utils.setGroupDirty(this);
941
- }
942
- };
943
- /**
944
- * @internal
945
- */ _proto._rootCanvasListener = function _rootCanvasListener(flag) {
946
- if (flag === EntityModifyFlags.Parent || flag === EntityUIModifyFlags.CanvasEnableInScene) {
947
- Utils.setRootCanvasDirty(this);
948
- Utils.setGroupDirty(this);
949
- }
950
- };
951
- /**
952
- * @internal
953
- */ _proto._onGroupModify = function _onGroupModify(flags) {
954
- if (flags & GroupModifyFlags.GlobalInteractive) {
955
- this._globalInteractiveDirty = true;
956
- }
957
- };
958
- /**
959
- * @internal
960
- */ _proto._getGlobalInteractive = function _getGlobalInteractive() {
961
- if (this._globalInteractiveDirty) {
962
- var group = this._getGroup();
963
- var globalInteractive = this._interactive && (!group || group._getGlobalInteractive());
964
- if (this._globalInteractive !== globalInteractive) {
965
- this._globalInteractive = globalInteractive;
966
- this._updateState(true);
967
- }
968
- this._globalInteractiveDirty = false;
969
- }
970
- return this._globalInteractive;
971
- };
972
- _proto._updateState = function _updateState(instant) {
973
- var state = this._getInteractiveState();
974
- if (this._state !== state) {
975
- this._state = state;
976
- var transitions = this._transitions;
977
- for(var i = 0, n = transitions.length; i < n; i++){
978
- transitions[i]._setState(state, instant);
979
- }
980
- }
981
- };
982
- _proto._getInteractiveState = function _getInteractiveState() {
983
- if (!this._getGlobalInteractive()) {
984
- return 3;
985
- }
986
- if (this._isPointerDragging) {
987
- return 1;
988
- } else {
989
- return this._isPointerInside ? 2 : 0;
990
- }
991
- };
992
- _create_class(UIInteractive, [
993
- {
994
- key: "transitions",
995
- get: /**
996
- * The transitions of this interactive.
997
- */ function get() {
998
- return this._transitions;
999
- }
1000
- },
1001
- {
1002
- key: "interactive",
1003
- get: /**
1004
- * Whether the interactive is enabled.
1005
- */ function get() {
1006
- return this._interactive;
1007
- },
1008
- set: function set(value) {
1009
- if (this._interactive !== value) {
1010
- this._interactive = value;
1011
- this._globalInteractiveDirty = true;
1012
- }
1013
- }
1014
- }
1015
- ]);
1016
- return UIInteractive;
1017
- }(Script);
1018
- __decorate([
1019
- ignoreClone
1020
- ], UIInteractive.prototype, "_rootCanvas", void 0);
1021
- __decorate([
1022
- ignoreClone
1023
- ], UIInteractive.prototype, "_indexInRootCanvas", void 0);
1024
- __decorate([
1025
- ignoreClone
1026
- ], UIInteractive.prototype, "_isRootCanvasDirty", void 0);
1027
- __decorate([
1028
- ignoreClone
1029
- ], UIInteractive.prototype, "_rootCanvasListeningEntities", void 0);
1030
- __decorate([
1031
- ignoreClone
1032
- ], UIInteractive.prototype, "_group", void 0);
1033
- __decorate([
1034
- ignoreClone
1035
- ], UIInteractive.prototype, "_indexInGroup", void 0);
1036
- __decorate([
1037
- ignoreClone
1038
- ], UIInteractive.prototype, "_isGroupDirty", void 0);
1039
- __decorate([
1040
- ignoreClone
1041
- ], UIInteractive.prototype, "_groupListeningEntities", void 0);
1042
- __decorate([
1043
- ignoreClone
1044
- ], UIInteractive.prototype, "_globalInteractive", void 0);
1045
- __decorate([
1046
- ignoreClone
1047
- ], UIInteractive.prototype, "_globalInteractiveDirty", void 0);
1048
- __decorate([
1049
- ignoreClone
1050
- ], UIInteractive.prototype, "_groupListener", null);
1051
- __decorate([
1052
- ignoreClone
1053
- ], UIInteractive.prototype, "_rootCanvasListener", null);
1054
- __decorate([
1055
- ignoreClone
1056
- ], UIInteractive.prototype, "_onGroupModify", null);
1057
- var InteractiveState = /*#__PURE__*/ function(InteractiveState) {
1058
- InteractiveState[InteractiveState["Normal"] = 0] = "Normal";
1059
- InteractiveState[InteractiveState["Pressed"] = 1] = "Pressed";
1060
- InteractiveState[InteractiveState["Hover"] = 2] = "Hover";
1061
- InteractiveState[InteractiveState["Disable"] = 3] = "Disable";
1062
- return InteractiveState;
1063
- }({});
1064
-
1065
- var UICanvas = /*#__PURE__*/ function(Component) {
1066
- _inherits(UICanvas, Component);
1067
- function UICanvas(entity) {
1068
- var _this;
1069
- _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();
1070
- _this._onCanvasSizeListener = _this._onCanvasSizeListener.bind(_this);
1071
- _this._onCameraModifyListener = _this._onCameraModifyListener.bind(_this);
1072
- _this._onCameraTransformListener = _this._onCameraTransformListener.bind(_this);
1073
- _this._onReferenceResolutionChanged = _this._onReferenceResolutionChanged.bind(_this);
1074
- // @ts-ignore
1075
- _this._referenceResolution._onValueChanged = _this._onReferenceResolutionChanged;
1076
- _this._rootCanvasListener = _this._rootCanvasListener.bind(_this);
1077
- _this._centerDirtyFlag = entity.registerWorldChangeFlag();
1078
- return _this;
1079
- }
1080
- var _proto = UICanvas.prototype;
1081
- /**
1082
- * @internal
1083
- */ _proto._raycast = function _raycast(ray, out, distance) {
1084
- if (distance === void 0) distance = Number.MAX_SAFE_INTEGER;
1085
- var renderers = this._getRenderers();
1086
- for(var i = renderers.length - 1; i >= 0; i--){
1087
- var element = renderers[i];
1088
- if (element.raycastEnabled && element._raycast(ray, out, distance)) {
1089
- return true;
1090
- }
1091
- }
1092
- out.component = null;
1093
- out.entity = null;
1094
- out.distance = 0;
1095
- out.point.set(0, 0, 0);
1096
- out.normal.set(0, 0, 0);
1097
- return false;
1098
- };
1099
- /**
1100
- * @internal
1101
- */ _proto._getRootCanvas = function _getRootCanvas() {
1102
- return this._rootCanvas;
1103
- };
1104
- /**
1105
- * @internal
1106
- */ _proto._canRender = function _canRender(camera) {
1107
- return this._renderMode !== CanvasRenderMode.ScreenSpaceCamera || this._renderCamera === camera;
1108
- };
1109
- /**
1110
- * @internal
1111
- */ _proto._prepareRender = function _prepareRender(context) {
1112
- var _this = this, engine = _this.engine, mode = _this._realRenderMode;
1113
- var _context_camera = context.camera, enableFrustumCulling = _context_camera.enableFrustumCulling, cullingMask = _context_camera.cullingMask, frustum = _context_camera._frustum;
1114
- var frameCount = engine.time.frameCount;
1115
- // @ts-ignore
1116
- var renderElement = this._renderElement = engine._renderElementPool.get();
1117
- var virtualCamera = context.virtualCamera;
1118
- this._updateSortDistance(virtualCamera.isOrthographic, virtualCamera.position, virtualCamera.forward);
1119
- renderElement.set(this.sortOrder, this._sortDistance);
1120
- var _engine_canvas = engine.canvas, width = _engine_canvas.width, height = _engine_canvas.height;
1121
- var renderers = this._getRenderers();
1122
- for(var i = 0, n = renderers.length; i < n; i++){
1123
- var renderer = renderers[i];
1124
- // Filter by camera culling mask
1125
- if (!(cullingMask & renderer.entity.layer)) {
1126
- continue;
1127
- }
1128
- // Filter by camera frustum
1129
- if (enableFrustumCulling) {
1130
- switch(mode){
1131
- case CanvasRenderMode.ScreenSpaceOverlay:
1132
- var _renderer_bounds = renderer.bounds, min = _renderer_bounds.min, max = _renderer_bounds.max;
1133
- if (min.x > width || max.x < 0 || min.y > height || max.y < 0) {
1134
- continue;
1135
- }
1136
- break;
1137
- case CanvasRenderMode.ScreenSpaceCamera:
1138
- case CanvasRenderMode.WorldSpace:
1139
- if (!frustum.intersectsBox(renderer.bounds)) {
1140
- continue;
1141
- }
1142
- break;
1143
- }
1144
- }
1145
- renderer._prepareRender(context);
1146
- renderer._renderFrameCount = frameCount;
1147
- }
1148
- };
1149
- /**
1150
- * @internal
1151
- */ _proto._updateSortDistance = function _updateSortDistance(isOrthographic, cameraPosition, cameraForward) {
1152
- switch(this._realRenderMode){
1153
- case CanvasRenderMode.ScreenSpaceOverlay:
1154
- this._sortDistance = 0;
1155
- break;
1156
- case CanvasRenderMode.ScreenSpaceCamera:
1157
- this._sortDistance = this._distance;
1158
- break;
1159
- case CanvasRenderMode.WorldSpace:
1160
- var boundsCenter = this._getCenter();
1161
- if (isOrthographic) {
1162
- var distance = UICanvas._tempVec3;
1163
- Vector3.subtract(boundsCenter, cameraPosition, distance);
1164
- this._sortDistance = Vector3.dot(distance, cameraForward);
1165
- } else {
1166
- this._sortDistance = Vector3.distanceSquared(boundsCenter, cameraPosition);
1167
- }
1168
- break;
1169
- }
1170
- };
1171
- // @ts-ignore
1172
- _proto._onEnableInScene = function _onEnableInScene() {
1173
- var entity = this.entity;
1174
- // @ts-ignore
1175
- entity._dispatchModify(4, this);
1176
- var rootCanvas = Utils.searchRootCanvasInParents(this);
1177
- this._setIsRootCanvas(!rootCanvas);
1178
- Utils.setRootCanvas(this, rootCanvas);
1179
- };
1180
- // @ts-ignore
1181
- _proto._onDisableInScene = function _onDisableInScene() {
1182
- this._setIsRootCanvas(false);
1183
- Utils.cleanRootCanvas(this);
1184
- };
1185
- /**
1186
- * @internal
1187
- */ _proto._rootCanvasListener = function _rootCanvasListener(flag, param) {
1188
- if (this._isRootCanvas) {
1189
- if (flag === EntityModifyFlags.Parent) {
1190
- var rootCanvas = Utils.searchRootCanvasInParents(this);
1191
- this._setIsRootCanvas(!rootCanvas);
1192
- Utils.setRootCanvas(this, rootCanvas);
1193
- } else if (flag === 4) {
1194
- this._setIsRootCanvas(false);
1195
- Utils.setRootCanvas(this, param);
1196
- }
1197
- } else {
1198
- if (flag === EntityModifyFlags.Parent) {
1199
- var rootCanvas1 = Utils.searchRootCanvasInParents(this);
1200
- this._setIsRootCanvas(!rootCanvas1);
1201
- Utils.setRootCanvas(this, rootCanvas1);
1202
- }
1203
- }
1204
- };
1205
- /**
1206
- * @internal
1207
- */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
1208
- target.renderMode = this._renderMode;
1209
- };
1210
- _proto._getRenderers = function _getRenderers() {
1211
- var _this = this, renderers = _this._orderedRenderers, entity = _this.entity;
1212
- var uiHierarchyVersion = entity._uiHierarchyVersion;
1213
- if (this._hierarchyVersion !== uiHierarchyVersion) {
1214
- renderers.length = this._walk(this.entity, renderers);
1215
- UICanvas._tempGroupAbleList.length = 0;
1216
- this._hierarchyVersion = uiHierarchyVersion;
1217
- ++UICanvas._hierarchyCounter;
1218
- }
1219
- return renderers;
1220
- };
1221
- _proto._adapterPoseInScreenSpace = function _adapterPoseInScreenSpace() {
1222
- var transform = this.entity.transform;
1223
- var realRenderMode = this._realRenderMode;
1224
- if (realRenderMode === CanvasRenderMode.ScreenSpaceCamera) {
1225
- var cameraEntity = this._renderCamera.entity;
1226
- if (!this._isSameOrChildEntity(cameraEntity)) {
1227
- var cameraTransform = cameraEntity.transform;
1228
- var cameraWorldPosition = cameraTransform.worldPosition, cameraWorldForward = cameraTransform.worldForward;
1229
- var distance = this._distance;
1230
- transform.setWorldPosition(cameraWorldPosition.x + cameraWorldForward.x * distance, cameraWorldPosition.y + cameraWorldForward.y * distance, cameraWorldPosition.z + cameraWorldForward.z * distance);
1231
- transform.worldRotationQuaternion.copyFrom(cameraTransform.worldRotationQuaternion);
1232
- }
1233
- } else {
1234
- var canvas = this.engine.canvas;
1235
- transform.setWorldPosition(canvas.width * 0.5, canvas.height * 0.5, 0);
1236
- transform.worldRotationQuaternion.set(0, 0, 0, 1);
1237
- }
1238
- };
1239
- _proto._adapterSizeInScreenSpace = function _adapterSizeInScreenSpace() {
1240
- var transform = this.entity.transform;
1241
- var realRenderMode = this._realRenderMode;
1242
- var _this__referenceResolution = this._referenceResolution, width = _this__referenceResolution.x, height = _this__referenceResolution.y;
1243
- var curWidth;
1244
- var curHeight;
1245
- if (realRenderMode === CanvasRenderMode.ScreenSpaceCamera) {
1246
- var renderCamera = this._renderCamera;
1247
- curHeight = renderCamera.isOrthographic ? renderCamera.orthographicSize * 2 : 2 * (Math.tan(MathUtil.degreeToRadian(renderCamera.fieldOfView * 0.5)) * this._distance);
1248
- curWidth = renderCamera.aspectRatio * curHeight;
1249
- } else {
1250
- var canvas = this.engine.canvas;
1251
- curHeight = canvas.height;
1252
- curWidth = canvas.width;
1253
- }
1254
- var expectX, expectY, expectZ;
1255
- switch(this._resolutionAdaptationMode){
1256
- case ResolutionAdaptationMode.WidthAdaptation:
1257
- expectX = expectY = expectZ = curWidth / width;
1258
- break;
1259
- case ResolutionAdaptationMode.HeightAdaptation:
1260
- expectX = expectY = expectZ = curHeight / height;
1261
- break;
1262
- case ResolutionAdaptationMode.BothAdaptation:
1263
- expectX = curWidth / width;
1264
- expectY = curHeight / height;
1265
- expectZ = (expectX + expectY) * 0.5;
1266
- break;
1267
- case ResolutionAdaptationMode.ExpandAdaptation:
1268
- expectX = expectY = expectZ = Math.min(curWidth / width, curHeight / height);
1269
- break;
1270
- case ResolutionAdaptationMode.ShrinkAdaptation:
1271
- expectX = expectY = expectZ = Math.max(curWidth / width, curHeight / height);
1272
- break;
1273
- }
1274
- var worldMatrix = UICanvas._tempMat;
1275
- Matrix.affineTransformation(UICanvas._tempVec3.set(expectX, expectY, expectZ), transform.worldRotationQuaternion, transform.worldPosition, worldMatrix);
1276
- transform.worldMatrix = worldMatrix;
1277
- transform.size.set(curWidth / expectX, curHeight / expectY);
1278
- };
1279
- _proto._walk = function _walk(entity, renderers, depth, group) {
1280
- if (depth === void 0) depth = 0;
1281
- if (group === void 0) group = null;
1282
- // @ts-ignore
1283
- var components = entity._components;
1284
- var tempGroupAbleList = UICanvas._tempGroupAbleList;
1285
- var groupAbleCount = 0;
1286
- for(var i = 0, n = components.length; i < n; i++){
1287
- var component = components[i];
1288
- if (!component.enabled) continue;
1289
- if (_instanceof(component, UIRenderer)) {
1290
- renderers[depth] = component;
1291
- ++depth;
1292
- component._isRootCanvasDirty && Utils.setRootCanvas(component, this);
1293
- if (component._isGroupDirty) {
1294
- tempGroupAbleList[groupAbleCount++] = component;
1295
- }
1296
- } else if (_instanceof(component, UIInteractive)) {
1297
- component._isRootCanvasDirty && Utils.setRootCanvas(component, this);
1298
- if (component._isGroupDirty) {
1299
- tempGroupAbleList[groupAbleCount++] = component;
1300
- }
1301
- } else if (_instanceof(component, UIGroup)) {
1302
- component._isRootCanvasDirty && Utils.setRootCanvas(component, this);
1303
- component._isGroupDirty && Utils.setGroup(component, group);
1304
- group = component;
1305
- }
1306
- }
1307
- for(var i1 = 0; i1 < groupAbleCount; i1++){
1308
- Utils.setGroup(tempGroupAbleList[i1], group);
1309
- }
1310
- var children = entity.children;
1311
- for(var i2 = 0, n1 = children.length; i2 < n1; i2++){
1312
- var child = children[i2];
1313
- child.isActive && (depth = this._walk(child, renderers, depth, group));
1314
- }
1315
- return depth;
1316
- };
1317
- _proto._updateCameraObserver = function _updateCameraObserver() {
1318
- var camera = this._isRootCanvas && this._renderMode === CanvasRenderMode.ScreenSpaceCamera ? this._renderCamera : null;
1319
- var preCamera = this._cameraObserver;
1320
- if (preCamera !== camera) {
1321
- this._cameraObserver = camera;
1322
- if (preCamera) {
1323
- // @ts-ignore
1324
- preCamera.entity._updateFlagManager.removeListener(this._onCameraTransformListener);
1325
- // @ts-ignore
1326
- preCamera._unRegisterModifyListener(this._onCameraModifyListener);
1327
- }
1328
- if (camera) {
1329
- // @ts-ignore
1330
- camera.entity._updateFlagManager.addListener(this._onCameraTransformListener);
1331
- // @ts-ignore
1332
- camera._registerModifyListener(this._onCameraModifyListener);
1333
- }
1334
- }
1335
- };
1336
- _proto._onCameraModifyListener = function _onCameraModifyListener(flag) {
1337
- if (this._realRenderMode === CanvasRenderMode.ScreenSpaceCamera) {
1338
- switch(flag){
1339
- case CameraModifyFlags.ProjectionType:
1340
- case CameraModifyFlags.AspectRatio:
1341
- this._adapterSizeInScreenSpace();
1342
- break;
1343
- case CameraModifyFlags.FieldOfView:
1344
- !this._renderCamera.isOrthographic && this._adapterSizeInScreenSpace();
1345
- break;
1346
- case CameraModifyFlags.OrthographicSize:
1347
- this._renderCamera.isOrthographic && this._adapterSizeInScreenSpace();
1348
- break;
1349
- case CameraModifyFlags.DisableInScene:
1350
- this._setRealRenderMode(CanvasRenderMode.ScreenSpaceOverlay);
1351
- break;
1352
- }
1353
- } else {
1354
- flag === CameraModifyFlags.EnableInScene && this._setRealRenderMode(CanvasRenderMode.ScreenSpaceCamera);
1355
- }
1356
- };
1357
- _proto._onCameraTransformListener = function _onCameraTransformListener() {
1358
- this._realRenderMode === CanvasRenderMode.ScreenSpaceCamera && this._adapterPoseInScreenSpace();
1359
- };
1360
- _proto._addCanvasListener = function _addCanvasListener() {
1361
- // @ts-ignore
1362
- this.engine.canvas._sizeUpdateFlagManager.addListener(this._onCanvasSizeListener);
1363
- };
1364
- _proto._removeCanvasListener = function _removeCanvasListener() {
1365
- // @ts-ignore
1366
- this.engine.canvas._sizeUpdateFlagManager.removeListener(this._onCanvasSizeListener);
1367
- };
1368
- _proto._onCanvasSizeListener = function _onCanvasSizeListener() {
1369
- var canvas = this.engine.canvas;
1370
- this.entity.transform.setWorldPosition(canvas.width * 0.5, canvas.height * 0.5, 0);
1371
- this._adapterSizeInScreenSpace();
1372
- };
1373
- _proto._onReferenceResolutionChanged = function _onReferenceResolutionChanged() {
1374
- var realRenderMode = this._realRenderMode;
1375
- if (realRenderMode === CanvasRenderMode.ScreenSpaceOverlay || realRenderMode === CanvasRenderMode.ScreenSpaceCamera) {
1376
- this._adapterSizeInScreenSpace();
1377
- }
1378
- };
1379
- _proto._setIsRootCanvas = function _setIsRootCanvas(isRootCanvas) {
1380
- var _this = this;
1381
- if (this._isRootCanvas !== isRootCanvas) {
1382
- this._isRootCanvas = isRootCanvas;
1383
- this._updateCameraObserver();
1384
- this._setRealRenderMode(this._getRealRenderMode());
1385
- if (isRootCanvas) {
1386
- this.entity._updateUIHierarchyVersion(UICanvas._hierarchyCounter);
1387
- } else {
1388
- var _this1 = this, disorderedElements = _this1._disorderedElements;
1389
- disorderedElements.forEach(function(element) {
1390
- if (_instanceof(element, UICanvas)) {
1391
- var rootCanvas = Utils.searchRootCanvasInParents(element);
1392
- element._setIsRootCanvas(!rootCanvas);
1393
- Utils.setRootCanvas(element, rootCanvas);
1394
- } else {
1395
- Utils.setRootCanvasDirty(_this);
1396
- Utils.setGroupDirty(element);
1397
- }
1398
- });
1399
- disorderedElements.length = 0;
1400
- disorderedElements.garbageCollection();
1401
- this._orderedRenderers.length = 0;
1402
- }
1403
- }
1404
- };
1405
- _proto._getCenter = function _getCenter() {
1406
- if (this._centerDirtyFlag.flag) {
1407
- var center = this._center;
1408
- var uiTransform = this.entity.transform;
1409
- var pivot = uiTransform.pivot, size = uiTransform.size;
1410
- center.set((0.5 - pivot.x) * size.x, (0.5 - pivot.y) * size.y, 0);
1411
- Vector3.transformCoordinate(center, uiTransform.worldMatrix, center);
1412
- this._centerDirtyFlag.flag = false;
1413
- }
1414
- return this._center;
1415
- };
1416
- _proto._getRealRenderMode = function _getRealRenderMode() {
1417
- if (this._isRootCanvas) {
1418
- var _this__renderCamera;
1419
- var mode = this._renderMode;
1420
- if (mode === CanvasRenderMode.ScreenSpaceCamera && !((_this__renderCamera = this._renderCamera) == null ? void 0 : _this__renderCamera.enabled)) {
1421
- return CanvasRenderMode.ScreenSpaceOverlay;
1422
- } else {
1423
- return mode;
1424
- }
1425
- } else {
1426
- return 4;
1427
- }
1428
- };
1429
- _proto._setRealRenderMode = function _setRealRenderMode(curRealMode) {
1430
- var preRealMode = this._realRenderMode;
1431
- if (preRealMode !== curRealMode) {
1432
- this._realRenderMode = curRealMode;
1433
- // @ts-ignore
1434
- var componentsManager = this.scene._componentsManager;
1435
- switch(preRealMode){
1436
- case CanvasRenderMode.ScreenSpaceOverlay:
1437
- this._removeCanvasListener();
1438
- case CanvasRenderMode.ScreenSpaceCamera:
1439
- case CanvasRenderMode.WorldSpace:
1440
- componentsManager.removeUICanvas(this, preRealMode === CanvasRenderMode.ScreenSpaceOverlay);
1441
- break;
1442
- }
1443
- switch(curRealMode){
1444
- case CanvasRenderMode.ScreenSpaceOverlay:
1445
- this._addCanvasListener();
1446
- case CanvasRenderMode.ScreenSpaceCamera:
1447
- this._adapterPoseInScreenSpace();
1448
- this._adapterSizeInScreenSpace();
1449
- case CanvasRenderMode.WorldSpace:
1450
- componentsManager.addUICanvas(this, curRealMode === CanvasRenderMode.ScreenSpaceOverlay);
1451
- break;
1452
- }
1453
- }
1454
- };
1455
- _proto._isSameOrChildEntity = function _isSameOrChildEntity(cameraEntity) {
1456
- var canvasEntity = this.entity;
1457
- while(cameraEntity){
1458
- if (cameraEntity === canvasEntity) return true;
1459
- cameraEntity = cameraEntity.parent;
1460
- }
1461
- return false;
1462
- };
1463
- _create_class(UICanvas, [
1464
- {
1465
- key: "referenceResolutionPerUnit",
1466
- get: /**
1467
- * The conversion ratio between reference resolution and unit for UI elements in this canvas.
1468
- */ function get() {
1469
- return this._referenceResolutionPerUnit;
1470
- },
1471
- set: function set(value) {
1472
- if (this._referenceResolutionPerUnit !== value) {
1473
- this._referenceResolutionPerUnit = value;
1474
- this._disorderedElements.forEach(function(element) {
1475
- element._onRootCanvasModify == null ? void 0 : element._onRootCanvasModify.call(element, 1);
1476
- });
1477
- }
1478
- }
1479
- },
1480
- {
1481
- key: "referenceResolution",
1482
- get: /**
1483
- * The reference resolution of the UI canvas in `ScreenSpaceCamera` and `ScreenSpaceOverlay` mode.
1484
- */ function get() {
1485
- return this._referenceResolution;
1486
- },
1487
- set: function set(value) {
1488
- var referenceResolution = this._referenceResolution;
1489
- if (referenceResolution === value) return;
1490
- (referenceResolution.x !== value.x || referenceResolution.y !== value.y) && referenceResolution.copyFrom(value);
1491
- }
1492
- },
1493
- {
1494
- key: "renderMode",
1495
- get: /**
1496
- * The rendering mode of the UI canvas.
1497
- */ function get() {
1498
- return this._renderMode;
1499
- },
1500
- set: function set(mode) {
1501
- var preMode = this._renderMode;
1502
- if (preMode !== mode) {
1503
- this._renderMode = mode;
1504
- this._updateCameraObserver();
1505
- this._setRealRenderMode(this._getRealRenderMode());
1506
- }
1507
- }
1508
- },
1509
- {
1510
- key: "renderCamera",
1511
- get: /**
1512
- * The camera used to render the UI canvas in `ScreenSpaceCamera` mode.
1513
- * @remarks If set `ScreenSpaceCamera` but no corresponding camera is assigned, the actual rendering mode defaults to `ScreenSpaceOverlay`.
1514
- */ function get() {
1515
- return this._renderCamera;
1516
- },
1517
- set: function set(value) {
1518
- var preCamera = this._renderCamera;
1519
- if (preCamera !== value) {
1520
- value && this._isSameOrChildEntity(value.entity) && Logger.warn("Camera entity matching or nested within the canvas entity disables canvas auto-adaptation in ScreenSpaceCamera mode.");
1521
- this._renderCamera = value;
1522
- this._updateCameraObserver();
1523
- var preRenderMode = this._realRenderMode;
1524
- var curRenderMode = this._getRealRenderMode();
1525
- if (preRenderMode === curRenderMode) {
1526
- if (curRenderMode === CanvasRenderMode.ScreenSpaceCamera) {
1527
- this._adapterPoseInScreenSpace();
1528
- this._adapterSizeInScreenSpace();
1529
- }
1530
- } else {
1531
- this._setRealRenderMode(curRenderMode);
1532
- }
1533
- }
1534
- }
1535
- },
1536
- {
1537
- key: "resolutionAdaptationMode",
1538
- get: /**
1539
- * The screen resolution adaptation mode of the UI canvas in `ScreenSpaceCamera` and `ScreenSpaceOverlay` mode.
1540
- */ function get() {
1541
- return this._resolutionAdaptationMode;
1542
- },
1543
- set: function set(value) {
1544
- if (this._resolutionAdaptationMode !== value) {
1545
- this._resolutionAdaptationMode = value;
1546
- var realRenderMode = this._realRenderMode;
1547
- if (realRenderMode === CanvasRenderMode.ScreenSpaceCamera || realRenderMode === CanvasRenderMode.ScreenSpaceOverlay) {
1548
- this._adapterSizeInScreenSpace();
1549
- }
1550
- }
1551
- }
1552
- },
1553
- {
1554
- key: "sortOrder",
1555
- get: /**
1556
- * The rendering order priority of the UI canvas in `ScreenSpaceOverlay` mode.
1557
- */ function get() {
1558
- return this._sortOrder;
1559
- },
1560
- set: function set(value) {
1561
- if (this._sortOrder !== value) {
1562
- this._sortOrder = value;
1563
- this._realRenderMode === CanvasRenderMode.ScreenSpaceOverlay && // @ts-ignore
1564
- (this.scene._componentsManager._overlayCanvasesSortingFlag = true);
1565
- }
1566
- }
1567
- },
1568
- {
1569
- key: "distance",
1570
- get: /**
1571
- * The distance between the UI canvas and the camera in `ScreenSpaceCamera` mode.
1572
- */ function get() {
1573
- return this._distance;
1574
- },
1575
- set: function set(value) {
1576
- if (this._distance !== value) {
1577
- this._distance = value;
1578
- if (this._realRenderMode === CanvasRenderMode.ScreenSpaceCamera) {
1579
- this._adapterPoseInScreenSpace();
1580
- this._adapterSizeInScreenSpace();
1581
- }
1582
- }
1583
- }
1584
- }
1585
- ]);
1586
- return UICanvas;
1587
- }(Component);
1588
- /** @internal */ UICanvas._hierarchyCounter = 1;
1589
- UICanvas._tempGroupAbleList = [];
1590
- UICanvas._tempVec3 = new Vector3();
1591
- UICanvas._tempMat = new Matrix();
1592
- __decorate([
1593
- ignoreClone
1594
- ], UICanvas.prototype, "_canvasIndex", void 0);
1595
- __decorate([
1596
- ignoreClone
1597
- ], UICanvas.prototype, "_rootCanvas", void 0);
1598
- __decorate([
1599
- ignoreClone
1600
- ], UICanvas.prototype, "_indexInRootCanvas", void 0);
1601
- __decorate([
1602
- ignoreClone
1603
- ], UICanvas.prototype, "_isRootCanvasDirty", void 0);
1604
- __decorate([
1605
- ignoreClone
1606
- ], UICanvas.prototype, "_rootCanvasListeningEntities", void 0);
1607
- __decorate([
1608
- ignoreClone
1609
- ], UICanvas.prototype, "_isRootCanvas", void 0);
1610
- __decorate([
1611
- ignoreClone
1612
- ], UICanvas.prototype, "_renderElement", void 0);
1613
- __decorate([
1614
- ignoreClone
1615
- ], UICanvas.prototype, "_sortDistance", void 0);
1616
- __decorate([
1617
- ignoreClone
1618
- ], UICanvas.prototype, "_orderedRenderers", void 0);
1619
- __decorate([
1620
- ignoreClone
1621
- ], UICanvas.prototype, "_realRenderMode", void 0);
1622
- __decorate([
1623
- ignoreClone
1624
- ], UICanvas.prototype, "_disorderedElements", void 0);
1625
- __decorate([
1626
- ignoreClone
1627
- ], UICanvas.prototype, "_renderMode", void 0);
1628
- __decorate([
1629
- assignmentClone
1630
- ], UICanvas.prototype, "_renderCamera", void 0);
1631
- __decorate([
1632
- ignoreClone
1633
- ], UICanvas.prototype, "_cameraObserver", void 0);
1634
- __decorate([
1635
- assignmentClone
1636
- ], UICanvas.prototype, "_resolutionAdaptationMode", void 0);
1637
- __decorate([
1638
- assignmentClone
1639
- ], UICanvas.prototype, "_sortOrder", void 0);
1640
- __decorate([
1641
- assignmentClone
1642
- ], UICanvas.prototype, "_distance", void 0);
1643
- __decorate([
1644
- deepClone
1645
- ], UICanvas.prototype, "_referenceResolution", void 0);
1646
- __decorate([
1647
- assignmentClone
1648
- ], UICanvas.prototype, "_referenceResolutionPerUnit", void 0);
1649
- __decorate([
1650
- ignoreClone
1651
- ], UICanvas.prototype, "_hierarchyVersion", void 0);
1652
- __decorate([
1653
- ignoreClone
1654
- ], UICanvas.prototype, "_center", void 0);
1655
- __decorate([
1656
- ignoreClone
1657
- ], UICanvas.prototype, "_centerDirtyFlag", void 0);
1658
- __decorate([
1659
- ignoreClone
1660
- ], UICanvas.prototype, "_rootCanvasListener", null);
1661
- __decorate([
1662
- ignoreClone
1663
- ], UICanvas.prototype, "_onCameraModifyListener", null);
1664
- __decorate([
1665
- ignoreClone
1666
- ], UICanvas.prototype, "_onCameraTransformListener", null);
1667
- __decorate([
1668
- ignoreClone
1669
- ], UICanvas.prototype, "_onCanvasSizeListener", null);
1670
- __decorate([
1671
- ignoreClone
1672
- ], UICanvas.prototype, "_onReferenceResolutionChanged", null);
1673
- UICanvas = __decorate([
1674
- dependentComponents(UITransform, DependentMode.AutoAdd)
1675
- ], UICanvas);
1676
- /**
1677
- * @remarks Extends `EntityModifyFlags`.
1678
- */ var EntityUIModifyFlags = /*#__PURE__*/ function(EntityUIModifyFlags) {
1679
- EntityUIModifyFlags[EntityUIModifyFlags["CanvasEnableInScene"] = 4] = "CanvasEnableInScene";
1680
- EntityUIModifyFlags[EntityUIModifyFlags["GroupEnableInScene"] = 8] = "GroupEnableInScene";
1681
- return EntityUIModifyFlags;
1682
- }({});
1683
- var RootCanvasModifyFlags = /*#__PURE__*/ function(RootCanvasModifyFlags) {
1684
- RootCanvasModifyFlags[RootCanvasModifyFlags["None"] = 0] = "None";
1685
- RootCanvasModifyFlags[RootCanvasModifyFlags["ReferenceResolutionPerUnit"] = 1] = "ReferenceResolutionPerUnit";
1686
- RootCanvasModifyFlags[RootCanvasModifyFlags["All"] = 1] = "All";
1687
- return RootCanvasModifyFlags;
1688
- }({});
1689
-
1690
- var Button = /*#__PURE__*/ function(UIInteractive) {
1691
- _inherits(Button, UIInteractive);
1692
- function Button() {
1693
- var _this;
1694
- _this = UIInteractive.apply(this, arguments) || this, _this._listeners = new SafeLoopArray();
1695
- return _this;
1696
- }
1697
- var _proto = Button.prototype;
1698
- /**
1699
- * Add a listening function for click.
1700
- * @param listener - The listening function
1701
- */ _proto.addClicked = function addClicked(listener) {
1702
- this._listeners.push({
1703
- fn: listener
1704
- });
1705
- };
1706
- /**
1707
- * Remove a listening function of click.
1708
- * @param listener - The listening function
1709
- */ _proto.removeClicked = function removeClicked(listener) {
1710
- this._listeners.findAndRemove(function(value) {
1711
- return value.fn === listener ? value.destroyed = true : false;
1712
- });
1713
- };
1714
- _proto.onPointerClick = function onPointerClick(event) {
1715
- if (!this._getGlobalInteractive()) return;
1716
- var listeners = this._listeners.getLoopArray();
1717
- for(var i = 0, n = listeners.length; i < n; i++){
1718
- var listener = listeners[i];
1719
- !listener.destroyed && listener.fn(event);
1720
- }
1721
- };
1722
- _proto.onDestroy = function onDestroy() {
1723
- UIInteractive.prototype.onDestroy.call(this);
1724
- this._listeners.findAndRemove(function(value) {
1725
- return value.destroyed = true;
1726
- });
1727
- };
1728
- return Button;
1729
- }(UIInteractive);
1730
-
1731
- /**
1732
- * UI element that renders an image.
1733
- */ var Image = /*#__PURE__*/ function(UIRenderer1) {
1734
- _inherits(Image, UIRenderer1);
1735
- function Image(entity) {
1736
- var _this;
1737
- _this = UIRenderer1.call(this, entity) || this, _this._sprite = null, _this._tileMode = SpriteTileMode.Continuous, _this._tiledAdaptiveThreshold = 0.5;
1738
- _this.drawMode = SpriteDrawMode.Simple;
1739
- _this.setMaterial(_this._engine._getUIDefaultMaterial());
1740
- _this._onSpriteChange = _this._onSpriteChange.bind(_this);
1741
- return _this;
1742
- }
1743
- var _proto = Image.prototype;
1744
- /**
1745
- * @internal
1746
- */ _proto._onRootCanvasModify = function _onRootCanvasModify(flag) {
1747
- if (flag & RootCanvasModifyFlags.ReferenceResolutionPerUnit) {
1748
- var drawMode = this._drawMode;
1749
- if (drawMode === SpriteDrawMode.Tiled) {
1750
- this._dirtyUpdateFlag |= 15;
1751
- } else if (drawMode === SpriteDrawMode.Sliced) {
1752
- this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
1753
- }
1754
- }
1755
- };
1756
- /**
1757
- * @internal
1758
- */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
1759
- // @ts-ignore
1760
- UIRenderer1.prototype._cloneTo.call(this, target, srcRoot, targetRoot);
1761
- target.sprite = this._sprite;
1762
- target.drawMode = this._drawMode;
1763
- };
1764
- _proto._updateBounds = function _updateBounds(worldBounds) {
1765
- var sprite = this._sprite;
1766
- var rootCanvas = this._getRootCanvas();
1767
- if (sprite && rootCanvas) {
1768
- var transform = this._transformEntity.transform;
1769
- var size = transform.size;
1770
- this._assembler.updatePositions(this, transform.worldMatrix, size.x, size.y, transform.pivot, false, false, rootCanvas.referenceResolutionPerUnit);
1771
- } else {
1772
- var worldPosition = this._transformEntity.transform.worldPosition;
1773
- worldBounds.min.copyFrom(worldPosition);
1774
- worldBounds.max.copyFrom(worldPosition);
1775
- }
1776
- };
1777
- _proto._render = function _render(context) {
1778
- var _this = this, sprite = _this._sprite;
1779
- var transform = this._transformEntity.transform;
1780
- var _transform_size = transform.size, width = _transform_size.x, height = _transform_size.y;
1781
- if (!(sprite == null ? void 0 : sprite.texture) || !width || !height) {
1782
- return;
1783
- }
1784
- var material = this.getMaterial();
1785
- if (!material) {
1786
- return;
1787
- }
1788
- // @todo: This question needs to be raised rather than hidden.
1789
- if (material.destroyed) {
1790
- material = this._engine._getUIDefaultMaterial();
1791
- }
1792
- var alpha = this._getGlobalAlpha();
1793
- if (this._color.a * alpha <= 0) {
1794
- return;
1795
- }
1796
- var _this1 = this, dirtyUpdateFlag = _this1._dirtyUpdateFlag;
1797
- var canvas = this._getRootCanvas();
1798
- // Update position
1799
- if (dirtyUpdateFlag & RendererUpdateFlags.WorldVolume) {
1800
- this._assembler.updatePositions(this, transform.worldMatrix, width, height, transform.pivot, false, false, canvas.referenceResolutionPerUnit);
1801
- dirtyUpdateFlag &= ~RendererUpdateFlags.WorldVolume;
1802
- }
1803
- // Update uv
1804
- if (dirtyUpdateFlag & 4) {
1805
- this._assembler.updateUVs(this);
1806
- dirtyUpdateFlag &= ~4;
1807
- }
1808
- // Update color
1809
- if (dirtyUpdateFlag & UIRendererUpdateFlags.Color) {
1810
- this._assembler.updateColor(this, alpha);
1811
- dirtyUpdateFlag &= ~UIRendererUpdateFlags.Color;
1812
- }
1813
- this._dirtyUpdateFlag = dirtyUpdateFlag;
1814
- // Init sub render element.
1815
- var engine = context.camera.engine;
1816
- var subRenderElement = engine._subRenderElementPool.get();
1817
- var subChunk = this._subChunk;
1818
- subRenderElement.set(this, material, subChunk.chunk.primitive, subChunk.subMesh, this.sprite.texture, subChunk);
1819
- if (canvas._realRenderMode === CanvasRenderMode.ScreenSpaceOverlay) {
1820
- subRenderElement.shaderPasses = material.shader.subShaders[0].passes;
1821
- subRenderElement.renderQueueFlags = RenderQueueFlags.All;
1822
- }
1823
- canvas._renderElement.addSubRenderElement(subRenderElement);
1824
- };
1825
- _proto._onTransformChanged = function _onTransformChanged(type) {
1826
- if (type & UITransformModifyFlags.Size && this._drawMode === SpriteDrawMode.Tiled) {
1827
- this._dirtyUpdateFlag |= 15;
1828
- }
1829
- this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
1830
- };
1831
- _proto._onDestroy = function _onDestroy() {
1832
- var sprite = this._sprite;
1833
- if (sprite) {
1834
- this._addResourceReferCount(sprite, -1);
1835
- // @ts-ignore
1836
- sprite._updateFlagManager.removeListener(this._onSpriteChange);
1837
- this._sprite = null;
1838
- }
1839
- UIRenderer1.prototype._onDestroy.call(this);
1840
- };
1841
- _proto._onSpriteChange = function _onSpriteChange(type) {
1842
- switch(type){
1843
- case SpriteModifyFlags.texture:
1844
- this.shaderData.setTexture(UIRenderer._textureProperty, this.sprite.texture);
1845
- break;
1846
- case SpriteModifyFlags.size:
1847
- switch(this._drawMode){
1848
- case SpriteDrawMode.Sliced:
1849
- this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
1850
- break;
1851
- case SpriteDrawMode.Tiled:
1852
- this._dirtyUpdateFlag |= 7;
1853
- break;
1854
- }
1855
- break;
1856
- case SpriteModifyFlags.border:
1857
- switch(this._drawMode){
1858
- case SpriteDrawMode.Sliced:
1859
- this._dirtyUpdateFlag |= 5;
1860
- break;
1861
- case SpriteDrawMode.Tiled:
1862
- this._dirtyUpdateFlag |= 7;
1863
- break;
1864
- }
1865
- break;
1866
- case SpriteModifyFlags.region:
1867
- case SpriteModifyFlags.atlasRegionOffset:
1868
- this._dirtyUpdateFlag |= 5;
1869
- break;
1870
- case SpriteModifyFlags.atlasRegion:
1871
- this._dirtyUpdateFlag |= 4;
1872
- break;
1873
- case SpriteModifyFlags.destroy:
1874
- this.sprite = null;
1875
- break;
1876
- }
1877
- };
1878
- _create_class(Image, [
1879
- {
1880
- key: "drawMode",
1881
- get: /**
1882
- * The draw mode of the image.
1883
- */ function get() {
1884
- return this._drawMode;
1885
- },
1886
- set: function set(value) {
1887
- if (this._drawMode !== value) {
1888
- this._drawMode = value;
1889
- switch(value){
1890
- case SpriteDrawMode.Simple:
1891
- this._assembler = SimpleSpriteAssembler;
1892
- break;
1893
- case SpriteDrawMode.Sliced:
1894
- this._assembler = SlicedSpriteAssembler;
1895
- break;
1896
- case SpriteDrawMode.Tiled:
1897
- this._assembler = TiledSpriteAssembler;
1898
- break;
1899
- }
1900
- this._assembler.resetData(this);
1901
- this._dirtyUpdateFlag |= 7;
1902
- }
1903
- }
1904
- },
1905
- {
1906
- key: "tileMode",
1907
- get: /**
1908
- * The tiling mode of the image. (Only works in tiled mode.)
1909
- */ function get() {
1910
- return this._tileMode;
1911
- },
1912
- set: function set(value) {
1913
- if (this._tileMode !== value) {
1914
- this._tileMode = value;
1915
- if (this.drawMode === SpriteDrawMode.Tiled) {
1916
- this._dirtyUpdateFlag |= 7;
1917
- }
1918
- }
1919
- }
1920
- },
1921
- {
1922
- key: "tiledAdaptiveThreshold",
1923
- get: /**
1924
- * Stretch Threshold in Tile Adaptive Mode, specified in normalized. (Only works in tiled adaptive mode.)
1925
- */ function get() {
1926
- return this._tiledAdaptiveThreshold;
1927
- },
1928
- set: function set(value) {
1929
- if (value !== this._tiledAdaptiveThreshold) {
1930
- value = MathUtil.clamp(value, 0, 1);
1931
- this._tiledAdaptiveThreshold = value;
1932
- if (this.drawMode === SpriteDrawMode.Tiled) {
1933
- this._dirtyUpdateFlag |= 7;
1934
- }
1935
- }
1936
- }
1937
- },
1938
- {
1939
- key: "sprite",
1940
- get: /**
1941
- * The Sprite to render.
1942
- */ function get() {
1943
- return this._sprite;
1944
- },
1945
- set: function set(value) {
1946
- var lastSprite = this._sprite;
1947
- if (lastSprite !== value) {
1948
- if (lastSprite) {
1949
- this._addResourceReferCount(lastSprite, -1);
1950
- // @ts-ignore
1951
- lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
1952
- }
1953
- this._dirtyUpdateFlag |= 7;
1954
- if (value) {
1955
- this._addResourceReferCount(value, 1);
1956
- // @ts-ignore
1957
- value._updateFlagManager.addListener(this._onSpriteChange);
1958
- this.shaderData.setTexture(UIRenderer._textureProperty, value.texture);
1959
- } else {
1960
- this.shaderData.setTexture(UIRenderer._textureProperty, null);
1961
- }
1962
- this._sprite = value;
1963
- }
1964
- }
1965
- }
1966
- ]);
1967
- return Image;
1968
- }(UIRenderer);
1969
- __decorate([
1970
- ignoreClone
1971
- ], Image.prototype, "_sprite", void 0);
1972
- __decorate([
1973
- ignoreClone
1974
- ], Image.prototype, "_drawMode", void 0);
1975
- __decorate([
1976
- ignoreClone
1977
- ], Image.prototype, "_assembler", void 0);
1978
- __decorate([
1979
- assignmentClone
1980
- ], Image.prototype, "_tileMode", void 0);
1981
- __decorate([
1982
- assignmentClone
1983
- ], Image.prototype, "_tiledAdaptiveThreshold", void 0);
1984
- __decorate([
1985
- ignoreClone
1986
- ], Image.prototype, "_onTransformChanged", null);
1987
- __decorate([
1988
- ignoreClone
1989
- ], Image.prototype, "_onSpriteChange", null);
1990
-
1991
- /**
1992
- * UI component used to render text.
1993
- */ var Text = /*#__PURE__*/ function(UIRenderer1) {
1994
- _inherits(Text, UIRenderer1);
1995
- function Text(entity) {
1996
- var _this;
1997
- _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;
1998
- var engine = _this.engine;
1999
- // @ts-ignore
2000
- _this.font = engine._textDefaultFont;
2001
- _this.raycastEnabled = false;
2002
- // @ts-ignore
2003
- _this.setMaterial(engine._basicResources.textDefaultMaterial);
2004
- return _this;
2005
- }
2006
- var _proto = Text.prototype;
2007
- /**
2008
- * @internal
2009
- */ _proto._onDestroy = function _onDestroy() {
2010
- if (this._font) {
2011
- this._addResourceReferCount(this._font, -1);
2012
- this._font = null;
2013
- }
2014
- UIRenderer1.prototype._onDestroy.call(this);
2015
- this._freeTextChunks();
2016
- this._textChunks = null;
2017
- this._subFont && (this._subFont = null);
2018
- };
2019
- // @ts-ignore
2020
- _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
2021
- // @ts-ignore
2022
- UIRenderer1.prototype._cloneTo.call(this, target, srcRoot, targetRoot);
2023
- target.font = this._font;
2024
- target._subFont = this._subFont;
2025
- };
2026
- /**
2027
- * @internal
2028
- */ _proto._isContainDirtyFlag = function _isContainDirtyFlag(type) {
2029
- return (this._dirtyUpdateFlag & type) != 0;
2030
- };
2031
- /**
2032
- * @internal
2033
- */ _proto._setDirtyFlagTrue = function _setDirtyFlagTrue(type) {
2034
- this._dirtyUpdateFlag |= type;
2035
- };
2036
- /**
2037
- * @internal
2038
- */ _proto._setDirtyFlagFalse = function _setDirtyFlagFalse(type) {
2039
- this._dirtyUpdateFlag &= ~type;
2040
- };
2041
- /**
2042
- * @internal
2043
- */ _proto._getSubFont = function _getSubFont() {
2044
- if (!this._subFont) {
2045
- this._resetSubFont();
2046
- }
2047
- return this._subFont;
2048
- };
2049
- /**
2050
- * @internal
2051
- */ _proto._onRootCanvasModify = function _onRootCanvasModify(flag) {
2052
- if (flag === RootCanvasModifyFlags.ReferenceResolutionPerUnit) {
2053
- this._setDirtyFlagTrue(8);
2054
- }
2055
- };
2056
- _proto._updateBounds = function _updateBounds(worldBounds) {
2057
- var transform = this._transformEntity.transform;
2058
- var _transform_size = transform.size, width = _transform_size.x, height = _transform_size.y;
2059
- var _transform_pivot = transform.pivot, pivotX = _transform_pivot.x, pivotY = _transform_pivot.y;
2060
- worldBounds.min.set(-width * pivotX, -height * pivotY, 0);
2061
- worldBounds.max.set(width * (1 - pivotX), height * (1 - pivotY), 0);
2062
- BoundingBox.transform(worldBounds, this._transformEntity.transform.worldMatrix, worldBounds);
2063
- };
2064
- _proto._render = function _render(context) {
2065
- if (this._isTextNoVisible()) {
2066
- return;
2067
- }
2068
- if (this._isContainDirtyFlag(4)) {
2069
- this._resetSubFont();
2070
- this._setDirtyFlagFalse(4);
2071
- }
2072
- var canvas = this._getRootCanvas();
2073
- if (this._isContainDirtyFlag(8)) {
2074
- this._updateLocalData();
2075
- this._setDirtyFlagTrue(8);
2076
- }
2077
- if (this._isContainDirtyFlag(16)) {
2078
- this._updatePosition();
2079
- this._setDirtyFlagFalse(16);
2080
- }
2081
- if (this._isContainDirtyFlag(UIRendererUpdateFlags.Color)) {
2082
- this._updateColor();
2083
- this._setDirtyFlagFalse(UIRendererUpdateFlags.Color);
2084
- }
2085
- var engine = context.camera.engine;
2086
- var textSubRenderElementPool = engine._textSubRenderElementPool;
2087
- var material = this.getMaterial();
2088
- var renderElement = canvas._renderElement;
2089
- var textChunks = this._textChunks;
2090
- var isOverlay = canvas._realRenderMode === CanvasRenderMode.ScreenSpaceOverlay;
2091
- for(var i = 0, n = textChunks.length; i < n; ++i){
2092
- var // @ts-ignore
2093
- _subRenderElement;
2094
- var _textChunks_i = textChunks[i], subChunk = _textChunks_i.subChunk, texture = _textChunks_i.texture;
2095
- var subRenderElement = textSubRenderElementPool.get();
2096
- subRenderElement.set(this, material, subChunk.chunk.primitive, subChunk.subMesh, texture, subChunk);
2097
- (_subRenderElement = subRenderElement).shaderData || (_subRenderElement.shaderData = new ShaderData(ShaderDataGroup.RenderElement));
2098
- subRenderElement.shaderData.setTexture(Text._textTextureProperty, texture);
2099
- if (isOverlay) {
2100
- subRenderElement.shaderPasses = material.shader.subShaders[0].passes;
2101
- subRenderElement.renderQueueFlags = RenderQueueFlags.All;
2102
- }
2103
- renderElement.addSubRenderElement(subRenderElement);
2104
- }
2105
- };
2106
- _proto._resetSubFont = function _resetSubFont() {
2107
- var font = this._font;
2108
- // @ts-ignore
2109
- this._subFont = font._getSubFont(this.fontSize, this.fontStyle);
2110
- this._subFont.nativeFontString = TextUtils.getNativeFontString(font.name, this.fontSize, this.fontStyle);
2111
- };
2112
- _proto._updatePosition = function _updatePosition() {
2113
- var e = this._transformEntity.transform.worldMatrix.elements;
2114
- // prettier-ignore
2115
- 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];
2116
- var up = UIRenderer._tempVec31.set(e4, e5, e6);
2117
- var right = UIRenderer._tempVec30.set(e0, e1, e2);
2118
- var worldPositions = Text._worldPositions;
2119
- var worldPosition0 = worldPositions[0], worldPosition1 = worldPositions[1], worldPosition2 = worldPositions[2], worldPosition3 = worldPositions[3];
2120
- var textChunks = this._textChunks;
2121
- for(var i = 0, n = textChunks.length; i < n; ++i){
2122
- var _textChunks_i = textChunks[i], subChunk = _textChunks_i.subChunk, charRenderInfos = _textChunks_i.charRenderInfos;
2123
- for(var j = 0, m = charRenderInfos.length; j < m; ++j){
2124
- var charRenderInfo = charRenderInfos[j];
2125
- var localPositions = charRenderInfo.localPositions;
2126
- var topLeftX = localPositions.x, topLeftY = localPositions.y;
2127
- // Top-Left
2128
- worldPosition0.set(topLeftX * e0 + topLeftY * e4 + e12, topLeftX * e1 + topLeftY * e5 + e13, topLeftX * e2 + topLeftY * e6 + e14);
2129
- // Right offset
2130
- Vector3.scale(right, localPositions.z - topLeftX, worldPosition1);
2131
- // Top-Right
2132
- Vector3.add(worldPosition0, worldPosition1, worldPosition1);
2133
- // Up offset
2134
- Vector3.scale(up, localPositions.w - topLeftY, worldPosition2);
2135
- // Bottom-Left
2136
- Vector3.add(worldPosition0, worldPosition2, worldPosition3);
2137
- // Bottom-Right
2138
- Vector3.add(worldPosition1, worldPosition2, worldPosition2);
2139
- var vertices = subChunk.chunk.vertices;
2140
- for(var k = 0, o = subChunk.vertexArea.start + charRenderInfo.indexInChunk * 36; k < 4; ++k, o += 9){
2141
- worldPositions[k].copyToArray(vertices, o);
2142
- }
2143
- }
2144
- }
2145
- };
2146
- _proto._updateColor = function _updateColor() {
2147
- var _this__color = this._color, r = _this__color.r, g = _this__color.g, b = _this__color.b, a = _this__color.a;
2148
- var finalAlpha = a * this._getGlobalAlpha();
2149
- var textChunks = this._textChunks;
2150
- for(var i = 0, n = textChunks.length; i < n; ++i){
2151
- var subChunk = textChunks[i].subChunk;
2152
- var vertexArea = subChunk.vertexArea;
2153
- var vertexCount = vertexArea.size / 9;
2154
- var vertices = subChunk.chunk.vertices;
2155
- for(var j = 0, o = vertexArea.start + 5; j < vertexCount; ++j, o += 9){
2156
- vertices[o] = r;
2157
- vertices[o + 1] = g;
2158
- vertices[o + 2] = b;
2159
- vertices[o + 3] = finalAlpha;
2160
- }
2161
- }
2162
- };
2163
- _proto._updateLocalData = function _updateLocalData() {
2164
- // @ts-ignore
2165
- var pixelsPerResolution = Engine._pixelsPerUnit / this._getRootCanvas().referenceResolutionPerUnit;
2166
- var _this__localBounds = this._localBounds, min = _this__localBounds.min, max = _this__localBounds.max;
2167
- var charRenderInfos = Text._charRenderInfos;
2168
- var charFont = this._getSubFont();
2169
- var _this__transformEntity_transform = this._transformEntity.transform, size = _this__transformEntity_transform.size, pivot = _this__transformEntity_transform.pivot;
2170
- var rendererWidth = size.x;
2171
- var rendererHeight = size.y;
2172
- var offsetWidth = rendererWidth * (0.5 - pivot.x);
2173
- var offsetHeight = rendererHeight * (0.5 - pivot.y);
2174
- var textMetrics = this.enableWrapping ? TextUtils.measureTextWithWrap(this, rendererWidth * pixelsPerResolution, rendererHeight * pixelsPerResolution, this._lineSpacing * pixelsPerResolution) : TextUtils.measureTextWithoutWrap(this, rendererHeight * pixelsPerResolution, this._lineSpacing * pixelsPerResolution);
2175
- var height = textMetrics.height, lines = textMetrics.lines, lineWidths = textMetrics.lineWidths, lineHeight = textMetrics.lineHeight, lineMaxSizes = textMetrics.lineMaxSizes;
2176
- // @ts-ignore
2177
- var charRenderInfoPool = this.engine._charRenderInfoPool;
2178
- var linesLen = lines.length;
2179
- var renderElementCount = 0;
2180
- if (linesLen > 0) {
2181
- var horizontalAlignment = this.horizontalAlignment;
2182
- var pixelsPerUnitReciprocal = 1.0 / pixelsPerResolution;
2183
- rendererWidth *= pixelsPerResolution;
2184
- rendererHeight *= pixelsPerResolution;
2185
- var halfRendererWidth = rendererWidth * 0.5;
2186
- var halfLineHeight = lineHeight * 0.5;
2187
- var startY = 0;
2188
- var topDiff = lineHeight * 0.5 - lineMaxSizes[0].ascent;
2189
- var bottomDiff = lineHeight * 0.5 - lineMaxSizes[linesLen - 1].descent - 1;
2190
- switch(this.verticalAlignment){
2191
- case TextVerticalAlignment.Top:
2192
- startY = rendererHeight * 0.5 - halfLineHeight + topDiff;
2193
- break;
2194
- case TextVerticalAlignment.Center:
2195
- startY = height * 0.5 - halfLineHeight - (bottomDiff - topDiff) * 0.5;
2196
- break;
2197
- case TextVerticalAlignment.Bottom:
2198
- startY = height - rendererHeight * 0.5 - halfLineHeight - bottomDiff;
2199
- break;
2200
- }
2201
- var firstLine = -1;
2202
- var minX = Number.MAX_SAFE_INTEGER;
2203
- var minY = Number.MAX_SAFE_INTEGER;
2204
- var maxX = Number.MIN_SAFE_INTEGER;
2205
- var maxY = Number.MIN_SAFE_INTEGER;
2206
- for(var i = 0; i < linesLen; ++i){
2207
- var lineWidth = lineWidths[i];
2208
- if (lineWidth > 0) {
2209
- var line = lines[i];
2210
- var startX = 0;
2211
- var firstRow = -1;
2212
- if (firstLine < 0) {
2213
- firstLine = i;
2214
- }
2215
- switch(horizontalAlignment){
2216
- case TextHorizontalAlignment.Left:
2217
- startX = -halfRendererWidth;
2218
- break;
2219
- case TextHorizontalAlignment.Center:
2220
- startX = -lineWidth * 0.5;
2221
- break;
2222
- case TextHorizontalAlignment.Right:
2223
- startX = halfRendererWidth - lineWidth;
2224
- break;
2225
- }
2226
- for(var j = 0, n = line.length; j < n; ++j){
2227
- var char = line[j];
2228
- var charInfo = charFont._getCharInfo(char);
2229
- if (charInfo.h > 0) {
2230
- firstRow < 0 && (firstRow = j);
2231
- var charRenderInfo = charRenderInfos[renderElementCount++] = charRenderInfoPool.get();
2232
- var localPositions = charRenderInfo.localPositions;
2233
- charRenderInfo.texture = charFont._getTextureByIndex(charInfo.index);
2234
- charRenderInfo.uvs = charInfo.uvs;
2235
- var w = charInfo.w, ascent = charInfo.ascent, descent = charInfo.descent;
2236
- var left = (startX + offsetWidth) * pixelsPerUnitReciprocal;
2237
- var right = (startX + w + offsetWidth) * pixelsPerUnitReciprocal;
2238
- var top = (startY + ascent + offsetHeight) * pixelsPerUnitReciprocal;
2239
- var bottom = (startY - descent + offsetHeight) * pixelsPerUnitReciprocal;
2240
- localPositions.set(left, top, right, bottom);
2241
- i === firstLine && (maxY = Math.max(maxY, top));
2242
- minY = Math.min(minY, bottom);
2243
- j === firstRow && (minX = Math.min(minX, left));
2244
- maxX = Math.max(maxX, right);
2245
- }
2246
- startX += charInfo.xAdvance + charInfo.offsetX;
2247
- }
2248
- }
2249
- startY -= lineHeight;
2250
- }
2251
- if (firstLine < 0) {
2252
- min.set(0, 0, 0);
2253
- max.set(0, 0, 0);
2254
- } else {
2255
- min.set(minX, minY, 0);
2256
- max.set(maxX, maxY, 0);
2257
- }
2258
- } else {
2259
- min.set(0, 0, 0);
2260
- max.set(0, 0, 0);
2261
- }
2262
- charFont._getLastIndex() > 0 && charRenderInfos.sort(function(a, b) {
2263
- return a.texture.instanceId - b.texture.instanceId;
2264
- });
2265
- this._freeTextChunks();
2266
- if (renderElementCount === 0) {
2267
- return;
2268
- }
2269
- var textChunks = this._textChunks;
2270
- var curTextChunk = new TextChunk();
2271
- textChunks.push(curTextChunk);
2272
- var chunkMaxVertexCount = this._getChunkManager().maxVertexCount;
2273
- var curCharRenderInfo = charRenderInfos[0];
2274
- var curTexture = curCharRenderInfo.texture;
2275
- curTextChunk.texture = curTexture;
2276
- var curCharInfos = curTextChunk.charRenderInfos;
2277
- curCharInfos.push(curCharRenderInfo);
2278
- for(var i1 = 1; i1 < renderElementCount; ++i1){
2279
- var charRenderInfo1 = charRenderInfos[i1];
2280
- var texture = charRenderInfo1.texture;
2281
- if (curTexture !== texture || curCharInfos.length * 4 + 4 > chunkMaxVertexCount) {
2282
- this._buildChunk(curTextChunk, curCharInfos.length);
2283
- curTextChunk = new TextChunk();
2284
- textChunks.push(curTextChunk);
2285
- curTexture = texture;
2286
- curTextChunk.texture = texture;
2287
- curCharInfos = curTextChunk.charRenderInfos;
2288
- }
2289
- curCharInfos.push(charRenderInfo1);
2290
- }
2291
- var charLength = curCharInfos.length;
2292
- if (charLength > 0) {
2293
- this._buildChunk(curTextChunk, charLength);
2294
- }
2295
- charRenderInfos.length = 0;
2296
- };
2297
- _proto._onTransformChanged = function _onTransformChanged(type) {
2298
- if (type & UITransformModifyFlags.Size || type & UITransformModifyFlags.Pivot) {
2299
- this._dirtyUpdateFlag |= 8;
2300
- }
2301
- UIRenderer1.prototype._onTransformChanged.call(this, type);
2302
- this._setDirtyFlagTrue(16);
2303
- };
2304
- _proto._isTextNoVisible = function _isTextNoVisible() {
2305
- var size = this._transformEntity.transform.size;
2306
- return this._text === "" || this._fontSize === 0 || this.enableWrapping && size.x <= 0 || this.overflowMode === OverflowMode.Truncate && size.y <= 0 || !this._getRootCanvas();
2307
- };
2308
- _proto._buildChunk = function _buildChunk(textChunk, count) {
2309
- var _this_color = this.color, r = _this_color.r, g = _this_color.g, b = _this_color.b, a = _this_color.a;
2310
- var tempIndices = CharRenderInfo.triangles;
2311
- var tempIndicesLength = tempIndices.length;
2312
- var subChunk = textChunk.subChunk = this._getChunkManager().allocateSubChunk(count * 4);
2313
- var vertices = subChunk.chunk.vertices;
2314
- var indices = subChunk.indices = [];
2315
- var charRenderInfos = textChunk.charRenderInfos;
2316
- for(var i = 0, ii = 0, io = 0, vo = subChunk.vertexArea.start + 3; i < count; ++i, io += 4){
2317
- var charRenderInfo = charRenderInfos[i];
2318
- charRenderInfo.indexInChunk = i;
2319
- // Set indices
2320
- for(var j = 0; j < tempIndicesLength; ++j){
2321
- indices[ii++] = tempIndices[j] + io;
2322
- }
2323
- // Set uv and color for vertices
2324
- for(var j1 = 0; j1 < 4; ++j1, vo += 9){
2325
- var uv = charRenderInfo.uvs[j1];
2326
- uv.copyToArray(vertices, vo);
2327
- vertices[vo + 2] = r;
2328
- vertices[vo + 3] = g;
2329
- vertices[vo + 4] = b;
2330
- vertices[vo + 5] = a;
2331
- }
2332
- }
2333
- return subChunk;
2334
- };
2335
- _proto._freeTextChunks = function _freeTextChunks() {
2336
- var textChunks = this._textChunks;
2337
- // @ts-ignore
2338
- var charRenderInfoPool = this.engine._charRenderInfoPool;
2339
- var manager = this._getChunkManager();
2340
- for(var i = 0, n = textChunks.length; i < n; ++i){
2341
- var textChunk = textChunks[i];
2342
- var charRenderInfos = textChunk.charRenderInfos;
2343
- for(var j = 0, m = charRenderInfos.length; j < m; ++j){
2344
- charRenderInfoPool.return(charRenderInfos[j]);
2345
- }
2346
- charRenderInfos.length = 0;
2347
- manager.freeSubChunk(textChunk.subChunk);
2348
- textChunk.subChunk = null;
2349
- textChunk.texture = null;
2350
- }
2351
- textChunks.length = 0;
2352
- };
2353
- _create_class(Text, [
2354
- {
2355
- key: "text",
2356
- get: /**
2357
- * Rendering string for the Text.
2358
- */ function get() {
2359
- return this._text;
2360
- },
2361
- set: function set(value) {
2362
- value = value || "";
2363
- if (this._text !== value) {
2364
- this._text = value;
2365
- this._setDirtyFlagTrue(25);
2366
- }
2367
- }
2368
- },
2369
- {
2370
- key: "font",
2371
- get: /**
2372
- * The font of the Text.
2373
- */ function get() {
2374
- return this._font;
2375
- },
2376
- set: function set(value) {
2377
- var lastFont = this._font;
2378
- if (lastFont !== value) {
2379
- lastFont && this._addResourceReferCount(lastFont, -1);
2380
- value && this._addResourceReferCount(value, 1);
2381
- this._font = value;
2382
- this._setDirtyFlagTrue(29);
2383
- }
2384
- }
2385
- },
2386
- {
2387
- key: "fontSize",
2388
- get: /**
2389
- * The font size of the Text.
2390
- */ function get() {
2391
- return this._fontSize;
2392
- },
2393
- set: function set(value) {
2394
- if (this._fontSize !== value) {
2395
- this._fontSize = value;
2396
- this._setDirtyFlagTrue(29);
2397
- }
2398
- }
2399
- },
2400
- {
2401
- key: "fontStyle",
2402
- get: /**
2403
- * The style of the font.
2404
- */ function get() {
2405
- return this._fontStyle;
2406
- },
2407
- set: function set(value) {
2408
- if (this.fontStyle !== value) {
2409
- this._fontStyle = value;
2410
- this._setDirtyFlagTrue(29);
2411
- }
2412
- }
2413
- },
2414
- {
2415
- key: "lineSpacing",
2416
- get: /**
2417
- * The space between two lines (in pixels).
2418
- */ function get() {
2419
- return this._lineSpacing;
2420
- },
2421
- set: function set(value) {
2422
- if (this._lineSpacing !== value) {
2423
- this._lineSpacing = value;
2424
- this._setDirtyFlagTrue(25);
2425
- }
2426
- }
2427
- },
2428
- {
2429
- key: "horizontalAlignment",
2430
- get: /**
2431
- * The horizontal alignment.
2432
- */ function get() {
2433
- return this._horizontalAlignment;
2434
- },
2435
- set: function set(value) {
2436
- if (this._horizontalAlignment !== value) {
2437
- this._horizontalAlignment = value;
2438
- this._setDirtyFlagTrue(25);
2439
- }
2440
- }
2441
- },
2442
- {
2443
- key: "verticalAlignment",
2444
- get: /**
2445
- * The vertical alignment.
2446
- */ function get() {
2447
- return this._verticalAlignment;
2448
- },
2449
- set: function set(value) {
2450
- if (this._verticalAlignment !== value) {
2451
- this._verticalAlignment = value;
2452
- this._setDirtyFlagTrue(25);
2453
- }
2454
- }
2455
- },
2456
- {
2457
- key: "enableWrapping",
2458
- get: /**
2459
- * Whether wrap text to next line when exceeds the width of the container.
2460
- */ function get() {
2461
- return this._enableWrapping;
2462
- },
2463
- set: function set(value) {
2464
- if (this._enableWrapping !== value) {
2465
- this._enableWrapping = value;
2466
- this._setDirtyFlagTrue(25);
2467
- }
2468
- }
2469
- },
2470
- {
2471
- key: "overflowMode",
2472
- get: /**
2473
- * The overflow mode.
2474
- */ function get() {
2475
- return this._overflowMode;
2476
- },
2477
- set: function set(value) {
2478
- if (this._overflowMode !== value) {
2479
- this._overflowMode = value;
2480
- this._setDirtyFlagTrue(25);
2481
- }
2482
- }
2483
- },
2484
- {
2485
- key: "maskLayer",
2486
- get: /**
2487
- * The mask layer the sprite renderer belongs to.
2488
- */ function get() {
2489
- return this._maskLayer;
2490
- },
2491
- set: function set(value) {
2492
- this._maskLayer = value;
2493
- }
2494
- },
2495
- {
2496
- key: "bounds",
2497
- get: /**
2498
- * The bounding volume of the TextRenderer.
2499
- */ function get() {
2500
- if (this._isTextNoVisible()) {
2501
- if (this._isContainDirtyFlag(RendererUpdateFlags.WorldVolume)) {
2502
- var localBounds = this._localBounds;
2503
- localBounds.min.set(0, 0, 0);
2504
- localBounds.max.set(0, 0, 0);
2505
- this._updateBounds(this._bounds);
2506
- this._setDirtyFlagFalse(RendererUpdateFlags.WorldVolume);
2507
- }
2508
- return this._bounds;
2509
- }
2510
- this._isContainDirtyFlag(4) && this._resetSubFont();
2511
- this._isContainDirtyFlag(8) && this._updateLocalData();
2512
- this._isContainDirtyFlag(16) && this._updatePosition();
2513
- this._isContainDirtyFlag(RendererUpdateFlags.WorldVolume) && this._updateBounds(this._bounds);
2514
- this._setDirtyFlagFalse(29);
2515
- return this._bounds;
2516
- }
2517
- }
2518
- ]);
2519
- return Text;
2520
- }(UIRenderer);
2521
- Text._textTextureProperty = ShaderProperty.getByName("renderElement_TextTexture");
2522
- Text._worldPositions = [
2523
- new Vector3(),
2524
- new Vector3(),
2525
- new Vector3(),
2526
- new Vector3()
2527
- ];
2528
- Text._charRenderInfos = [];
2529
- __decorate([
2530
- ignoreClone
2531
- ], Text.prototype, "_textChunks", void 0);
2532
- __decorate([
2533
- ignoreClone
2534
- ], Text.prototype, "_subFont", void 0);
2535
- __decorate([
2536
- assignmentClone
2537
- ], Text.prototype, "_text", void 0);
2538
- __decorate([
2539
- ignoreClone
2540
- ], Text.prototype, "_localBounds", void 0);
2541
- __decorate([
2542
- assignmentClone
2543
- ], Text.prototype, "_font", void 0);
2544
- __decorate([
2545
- assignmentClone
2546
- ], Text.prototype, "_fontSize", void 0);
2547
- __decorate([
2548
- assignmentClone
2549
- ], Text.prototype, "_fontStyle", void 0);
2550
- __decorate([
2551
- assignmentClone
2552
- ], Text.prototype, "_lineSpacing", void 0);
2553
- __decorate([
2554
- assignmentClone
2555
- ], Text.prototype, "_horizontalAlignment", void 0);
2556
- __decorate([
2557
- assignmentClone
2558
- ], Text.prototype, "_verticalAlignment", void 0);
2559
- __decorate([
2560
- assignmentClone
2561
- ], Text.prototype, "_enableWrapping", void 0);
2562
- __decorate([
2563
- assignmentClone
2564
- ], Text.prototype, "_overflowMode", void 0);
2565
- __decorate([
2566
- ignoreClone
2567
- ], Text.prototype, "_onTransformChanged", null);
2568
- var TextChunk = function TextChunk() {
2569
- this.charRenderInfos = new Array();
2570
- };
2571
-
2572
- /**
2573
- * The transition behavior of UIInteractive.
2574
- */ var Transition = /*#__PURE__*/ function() {
2575
- function Transition() {
2576
- this._duration = 0;
2577
- this._countDown = 0;
2578
- this._finalState = InteractiveState.Normal;
2579
- }
2580
- var _proto = Transition.prototype;
2581
- _proto.destroy = function destroy() {
2582
- var _this__interactive;
2583
- (_this__interactive = this._interactive) == null ? void 0 : _this__interactive.removeTransition(this);
2584
- this._target = null;
2585
- };
2586
- /**
2587
- * @internal
2588
- */ _proto._setState = function _setState(state, instant) {
2589
- this._finalState = state;
2590
- var value = this._getValueByState(state);
2591
- if (instant) {
2592
- this._countDown = 0;
2593
- this._initialValue = this._finalValue = value;
2594
- } else {
2595
- this._countDown = this._duration;
2596
- this._initialValue = this._getTargetValueCopy();
2597
- this._finalValue = value;
2598
- }
2599
- this._updateValue();
2600
- };
2601
- /**
2602
- * @internal
2603
- */ _proto._onUpdate = function _onUpdate(delta) {
2604
- if (this._countDown > 0) {
2605
- this._countDown -= delta;
2606
- this._updateValue();
2607
- }
2608
- };
2609
- _proto._onStateValueDirty = function _onStateValueDirty(state, preValue, curValue) {
2610
- // @ts-ignore
2611
- _instanceof(preValue, ReferResource) && preValue._addReferCount(-1);
2612
- // @ts-ignore
2613
- _instanceof(curValue, ReferResource) && curValue._addReferCount(1);
2614
- if (this._finalState === state) {
2615
- this._finalValue = curValue;
2616
- this._updateValue();
2617
- }
2618
- };
2619
- _proto._updateValue = function _updateValue() {
2620
- var _this__target;
2621
- var weight = this._duration ? 1 - this._countDown / this._duration : 1;
2622
- this._updateCurrentValue(this._initialValue, this._finalValue, weight);
2623
- ((_this__target = this._target) == null ? void 0 : _this__target.enabled) && this._applyValue(this._currentValue);
2624
- };
2625
- _proto._getValueByState = function _getValueByState(state) {
2626
- switch(state){
2627
- case InteractiveState.Normal:
2628
- return this.normal;
2629
- case InteractiveState.Pressed:
2630
- return this.pressed;
2631
- case InteractiveState.Hover:
2632
- return this.hover;
2633
- case InteractiveState.Disable:
2634
- return this.disabled;
2635
- }
2636
- };
2637
- _create_class(Transition, [
2638
- {
2639
- key: "normal",
2640
- get: /**
2641
- * The normal state of the transition.
2642
- */ function get() {
2643
- return this._normal;
2644
- },
2645
- set: function set(value) {
2646
- var preNormal = this._normal;
2647
- if (preNormal !== value) {
2648
- this._normal = value;
2649
- this._onStateValueDirty(InteractiveState.Normal, preNormal, value);
2650
- }
2651
- }
2652
- },
2653
- {
2654
- key: "pressed",
2655
- get: /**
2656
- * The pressed state of the transition.
2657
- */ function get() {
2658
- return this._pressed;
2659
- },
2660
- set: function set(value) {
2661
- var prePressed = this._pressed;
2662
- if (prePressed !== value) {
2663
- this._pressed = value;
2664
- this._onStateValueDirty(InteractiveState.Pressed, prePressed, value);
2665
- }
2666
- }
2667
- },
2668
- {
2669
- key: "hover",
2670
- get: /**
2671
- * The hover state of the transition.
2672
- */ function get() {
2673
- return this._hover;
2674
- },
2675
- set: function set(value) {
2676
- var preHover = this._hover;
2677
- if (preHover !== value) {
2678
- this._hover = value;
2679
- this._onStateValueDirty(InteractiveState.Hover, preHover, value);
2680
- }
2681
- }
2682
- },
2683
- {
2684
- key: "disabled",
2685
- get: /**
2686
- * The disabled state of the transition.
2687
- */ function get() {
2688
- return this._disabled;
2689
- },
2690
- set: function set(value) {
2691
- var preDisabled = this._disabled;
2692
- if (preDisabled !== value) {
2693
- this._disabled = value;
2694
- this._onStateValueDirty(InteractiveState.Disable, preDisabled, value);
2695
- }
2696
- }
2697
- },
2698
- {
2699
- key: "target",
2700
- get: /**
2701
- * The target of the transition.
2702
- */ function get() {
2703
- return this._target;
2704
- },
2705
- set: function set(value) {
2706
- if (this._target !== value) {
2707
- this._target = value;
2708
- (value == null ? void 0 : value.enabled) && this._applyValue(this._currentValue);
2709
- }
2710
- }
2711
- },
2712
- {
2713
- key: "duration",
2714
- get: /**
2715
- * The duration of the transition.
2716
- */ function get() {
2717
- return this._duration;
2718
- },
2719
- set: function set(value) {
2720
- if (value < 0) value = 0;
2721
- var preDuration = this._duration;
2722
- if (preDuration !== value) {
2723
- this._duration = value;
2724
- if (this._countDown > 0) {
2725
- this._countDown = value * (1 - this._countDown / preDuration);
2726
- this._updateValue();
2727
- }
2728
- }
2729
- }
2730
- }
2731
- ]);
2732
- return Transition;
2733
- }();
2734
-
2735
- /**
2736
- * Color transition.
2737
- */ var ColorTransition = /*#__PURE__*/ function(Transition) {
2738
- _inherits(ColorTransition, Transition);
2739
- function ColorTransition() {
2740
- var _this;
2741
- _this = Transition.call(this) || this, _this._color = new Color();
2742
- _this._normal = new Color(1, 1, 1, 1);
2743
- _this._hover = new Color(245 / 255, 245 / 255, 245 / 255, 1);
2744
- _this._pressed = new Color(200 / 255, 200 / 255, 200 / 255, 1);
2745
- _this._disabled = new Color(200 / 255, 200 / 255, 200 / 255, 1);
2746
- _this._duration = 0.1;
2747
- _this._currentValue = new Color();
2748
- _this._onNormalValueChanged = _this._onNormalValueChanged.bind(_this);
2749
- _this._onHoverValueChanged = _this._onHoverValueChanged.bind(_this);
2750
- _this._onPressedValueChanged = _this._onPressedValueChanged.bind(_this);
2751
- _this._onDisabledValueChanged = _this._onDisabledValueChanged.bind(_this);
2752
- // @ts-ignore
2753
- _this._normal._onValueChanged = _this._onNormalValueChanged;
2754
- // @ts-ignore
2755
- _this._hover._onValueChanged = _this._onHoverValueChanged;
2756
- // @ts-ignore
2757
- _this._pressed._onValueChanged = _this._onPressedValueChanged;
2758
- // @ts-ignore
2759
- _this._disabled._onValueChanged = _this._onDisabledValueChanged;
2760
- return _this;
2761
- }
2762
- var _proto = ColorTransition.prototype;
2763
- _proto._onNormalValueChanged = function _onNormalValueChanged() {
2764
- if (this._finalState === InteractiveState.Normal) {
2765
- this._finalValue = this._normal;
2766
- this._updateValue();
2767
- }
2768
- };
2769
- _proto._onHoverValueChanged = function _onHoverValueChanged() {
2770
- if (this._finalState === InteractiveState.Hover) {
2771
- this._finalValue = this._hover;
2772
- this._updateValue();
2773
- }
2774
- };
2775
- _proto._onPressedValueChanged = function _onPressedValueChanged() {
2776
- if (this._finalState === InteractiveState.Pressed) {
2777
- this._finalValue = this._pressed;
2778
- this._updateValue();
2779
- }
2780
- };
2781
- _proto._onDisabledValueChanged = function _onDisabledValueChanged() {
2782
- if (this._finalState === InteractiveState.Disable) {
2783
- this._finalValue = this._disabled;
2784
- this._updateValue();
2785
- }
2786
- };
2787
- _proto._getTargetValueCopy = function _getTargetValueCopy() {
2788
- var _this__target;
2789
- var color = this._color;
2790
- color.copyFrom(((_this__target = this._target) == null ? void 0 : _this__target.color) || this._normal);
2791
- return color;
2792
- };
2793
- _proto._updateCurrentValue = function _updateCurrentValue(srcValue, destValue, weight) {
2794
- if (weight >= 1) {
2795
- this._currentValue.copyFrom(destValue);
2796
- } else {
2797
- Color.lerp(srcValue, destValue, weight, this._currentValue);
2798
- }
2799
- };
2800
- _proto._applyValue = function _applyValue(value) {
2801
- this._target.color = value;
2802
- };
2803
- return ColorTransition;
2804
- }(Transition);
2805
-
2806
- /**
2807
- * Scale transition.
2808
- */ var ScaleTransition = /*#__PURE__*/ function(Transition) {
2809
- _inherits(ScaleTransition, Transition);
2810
- function ScaleTransition() {
2811
- var _this;
2812
- _this = Transition.call(this) || this;
2813
- _this._normal = 1;
2814
- _this._hover = 1;
2815
- _this._pressed = 1.2;
2816
- _this._disabled = 1;
2817
- _this._duration = 0.1;
2818
- return _this;
2819
- }
2820
- var _proto = ScaleTransition.prototype;
2821
- _proto._getTargetValueCopy = function _getTargetValueCopy() {
2822
- var _this__target;
2823
- return ((_this__target = this._target) == null ? void 0 : _this__target.entity.transform.scale.x) || this._normal;
2824
- };
2825
- _proto._updateCurrentValue = function _updateCurrentValue(srcValue, destValue, weight) {
2826
- this._currentValue = weight >= 1 ? destValue : (destValue - srcValue) * weight + srcValue;
2827
- };
2828
- _proto._applyValue = function _applyValue(value) {
2829
- this._target.entity.transform.setScale(value, value, value);
2830
- };
2831
- return ScaleTransition;
2832
- }(Transition);
2833
-
2834
- /**
2835
- * Sprite transition.
2836
- */ var SpriteTransition = /*#__PURE__*/ function(Transition) {
2837
- _inherits(SpriteTransition, Transition);
2838
- function SpriteTransition() {
2839
- return Transition.apply(this, arguments) || this;
2840
- }
2841
- var _proto = SpriteTransition.prototype;
2842
- /**
2843
- * @internal
2844
- */ _proto.destroy = function destroy() {
2845
- Transition.prototype.destroy.call(this);
2846
- if (this._normal) {
2847
- // @ts-ignore
2848
- this._normal._addReferCount(-1);
2849
- this._normal = null;
2850
- }
2851
- if (this._hover) {
2852
- // @ts-ignore
2853
- this._hover._addReferCount(-1);
2854
- this._hover = null;
2855
- }
2856
- if (this._pressed) {
2857
- // @ts-ignore
2858
- this._pressed._addReferCount(-1);
2859
- this._pressed = null;
2860
- }
2861
- if (this._disabled) {
2862
- // @ts-ignore
2863
- this._disabled._addReferCount(-1);
2864
- this._disabled = null;
2865
- }
2866
- this._initialValue = this._currentValue = this._finalValue = null;
2867
- this._target = null;
2868
- };
2869
- _proto._getTargetValueCopy = function _getTargetValueCopy() {
2870
- var _this__target;
2871
- return (_this__target = this._target) == null ? void 0 : _this__target.sprite;
2872
- };
2873
- _proto._updateCurrentValue = function _updateCurrentValue(srcValue, destValue, weight) {
2874
- this._currentValue = weight >= 1 ? destValue : srcValue;
2875
- };
2876
- _proto._applyValue = function _applyValue(value) {
2877
- this._target.sprite = value;
2878
- };
2879
- return SpriteTransition;
2880
- }(Transition);
2881
-
2882
- var GUIComponent = /*#__PURE__*/Object.freeze({
2883
- __proto__: null,
2884
- get UICanvas () { return UICanvas; },
2885
- UIGroup: UIGroup,
2886
- get UIRenderer () { return UIRenderer; },
2887
- UITransform: UITransform,
2888
- Button: Button,
2889
- Image: Image,
2890
- Text: Text,
2891
- ColorTransition: ColorTransition,
2892
- ScaleTransition: ScaleTransition,
2893
- SpriteTransition: SpriteTransition,
2894
- Transition: Transition
2895
- });
2896
-
2897
- var uiDefaultFs = "#define GLSLIFY 1\nuniform sampler2D renderer_UITexture;\n\nvarying vec2 v_uv;\nvarying vec4 v_color;\n\nvoid main() {\n vec4 baseColor = texture2D(renderer_UITexture, v_uv);\n gl_FragColor = baseColor * v_color;\n}\n"; // eslint-disable-line
2898
-
2899
- var uiDefaultVs = "#define GLSLIFY 1\nuniform 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
2900
-
2901
- /**
2902
- * @internal
2903
- */ var UIHitResult = function UIHitResult() {
2904
- this.entity = null;
2905
- this.distance = 0;
2906
- this.point = new Vector3();
2907
- this.normal = new Vector3();
2908
- this.component = null;
2909
- };
2910
-
2911
- var UIPointerEventEmitter = /*#__PURE__*/ function(PointerEventEmitter1) {
2912
- _inherits(UIPointerEventEmitter, PointerEventEmitter1);
2913
- function UIPointerEventEmitter() {
2914
- var _this;
2915
- _this = PointerEventEmitter1.apply(this, arguments) || this, _this._enteredPath = [], _this._pressedPath = [], _this._draggedPath = [];
2916
- return _this;
2917
- }
2918
- var _proto = UIPointerEventEmitter.prototype;
2919
- _proto._init = function _init() {
2920
- this._hitResult = new UIHitResult();
2921
- };
2922
- _proto.processRaycast = function processRaycast(scenes, pointer) {
2923
- var ray = PointerEventEmitter._tempRay;
2924
- var hitResult = this._hitResult;
2925
- var position = pointer.position;
2926
- var x = position.x, y = position.y;
2927
- for(var i = scenes.length - 1; i >= 0; i--){
2928
- var scene = scenes[i];
2929
- if (!scene.isActive || scene.destroyed) continue;
2930
- // @ts-ignore
2931
- var componentsManager = scene._componentsManager;
2932
- // Overlay Canvas
2933
- var canvasElements = componentsManager._overlayCanvases;
2934
- // Screen to world ( Assume that world units have a one-to-one relationship with pixel units )
2935
- ray.origin.set(position.x, scene.engine.canvas.height - position.y, 1);
2936
- ray.direction.set(0, 0, -1);
2937
- for(var j = canvasElements.length - 1; j >= 0; j--){
2938
- if (canvasElements.get(j)._raycast(ray, hitResult)) {
2939
- this._updateRaycast(hitResult.component, pointer);
2940
- return;
2941
- }
2942
- }
2943
- var cameras = componentsManager._activeCameras;
2944
- for(var j1 = cameras.length - 1; j1 >= 0; j1--){
2945
- var camera = cameras.get(j1);
2946
- if (camera.renderTarget) continue;
2947
- var pixelViewport = camera.pixelViewport;
2948
- if (x < pixelViewport.x || y < pixelViewport.y || x > pixelViewport.x + pixelViewport.width || y > pixelViewport.y + pixelViewport.height) {
2949
- continue;
2950
- }
2951
- camera.screenPointToRay(pointer.position, ray);
2952
- // Other canvases
2953
- var isOrthographic = camera.isOrthographic;
2954
- var _camera_entity_transform = camera.entity.transform, cameraPosition = _camera_entity_transform.worldPosition, cameraForward = _camera_entity_transform.worldForward;
2955
- // Sort by rendering order
2956
- canvasElements = componentsManager._canvases;
2957
- for(var k = 0, n = canvasElements.length; k < n; k++){
2958
- canvasElements.get(k)._updateSortDistance(isOrthographic, cameraPosition, cameraForward);
2959
- }
2960
- canvasElements.sort(function(a, b) {
2961
- return a.sortOrder - b.sortOrder || a._sortDistance - b._sortDistance;
2962
- });
2963
- for(var k1 = 0, n1 = canvasElements.length; k1 < n1; k1++){
2964
- canvasElements.get(k1)._canvasIndex = k1;
2965
- }
2966
- var farClipPlane = camera.farClipPlane;
2967
- // Post-rendering first detection
2968
- for(var k2 = 0, n2 = canvasElements.length; k2 < n2; k2++){
2969
- var canvas = canvasElements.get(k2);
2970
- if (!canvas._canRender(camera)) continue;
2971
- if (canvas._raycast(ray, hitResult, farClipPlane)) {
2972
- this._updateRaycast(hitResult.component, pointer);
2973
- return;
2974
- }
2975
- }
2976
- if (camera.clearFlags & CameraClearFlags.Color) {
2977
- this._updateRaycast(null);
2978
- return;
2979
- }
2980
- }
2981
- this._updateRaycast(null);
2982
- }
2983
- };
2984
- _proto.processDrag = function processDrag(pointer) {
2985
- var draggedPath = this._draggedPath;
2986
- if (draggedPath.length > 0) {
2987
- this._bubble(draggedPath, pointer, this._fireDrag);
2988
- }
2989
- };
2990
- _proto.processDown = function processDown(pointer) {
2991
- var enteredPath = this._enteredPath;
2992
- var pressedPath = this._pressedPath;
2993
- var draggedPath = this._draggedPath;
2994
- var length = draggedPath.length = pressedPath.length = enteredPath.length;
2995
- if (length > 0) {
2996
- for(var i = 0; i < length; i++){
2997
- pressedPath[i] = draggedPath[i] = enteredPath[i];
2998
- }
2999
- this._bubble(pressedPath, pointer, this._fireDown);
3000
- this._bubble(draggedPath, pointer, this._fireBeginDrag);
3001
- }
3002
- };
3003
- _proto.processUp = function processUp(pointer) {
3004
- var enteredPath = this._enteredPath;
3005
- var pressedPath = this._pressedPath;
3006
- if (enteredPath.length > 0) {
3007
- this._bubble(enteredPath, pointer, this._fireUp);
3008
- if (pressedPath.length > 0) {
3009
- var common = UIPointerEventEmitter._tempArray0;
3010
- if (this._findCommonInPath(enteredPath, pressedPath, common)) {
3011
- var eventData = this._createEventData(pointer);
3012
- for(var i = 0, n = common.length; i < n; i++){
3013
- this._fireClick(common[i], eventData);
3014
- }
3015
- common.length = 0;
3016
- }
3017
- }
3018
- }
3019
- pressedPath.length = 0;
3020
- var draggedPath = this._draggedPath;
3021
- if (draggedPath.length > 0) {
3022
- this._bubble(draggedPath, pointer, this._fireEndDrag);
3023
- draggedPath.length = 0;
3024
- }
3025
- if (enteredPath.length > 0) {
3026
- this._bubble(enteredPath, pointer, this._fireDrop);
3027
- }
3028
- };
3029
- _proto.processLeave = function processLeave(pointer) {
3030
- var enteredPath = this._enteredPath;
3031
- if (enteredPath.length > 0) {
3032
- this._bubble(enteredPath, pointer, this._fireExit);
3033
- enteredPath.length = 0;
3034
- }
3035
- var draggedPath = this._draggedPath;
3036
- if (draggedPath.length > 0) {
3037
- this._bubble(draggedPath, pointer, this._fireEndDrag);
3038
- draggedPath.length = 0;
3039
- }
3040
- this._pressedPath.length = 0;
3041
- };
3042
- _proto.dispose = function dispose() {
3043
- this._enteredPath.length = this._pressedPath.length = this._draggedPath.length = 0;
3044
- };
3045
- _proto._updateRaycast = function _updateRaycast(element, pointer) {
3046
- if (pointer === void 0) pointer = null;
3047
- var enteredPath = this._enteredPath;
3048
- var curPath = this._composedPath(element, UIPointerEventEmitter._path);
3049
- var add = UIPointerEventEmitter._tempArray0;
3050
- var del = UIPointerEventEmitter._tempArray1;
3051
- if (this._findDiffInPath(enteredPath, curPath, add, del)) {
3052
- var eventData = this._createEventData(pointer);
3053
- for(var i = 0, n = add.length; i < n; i++){
3054
- this._fireEnter(add[i], eventData);
3055
- }
3056
- for(var i1 = 0, n1 = del.length; i1 < n1; i1++){
3057
- this._fireExit(del[i1], eventData);
3058
- }
3059
- var length = enteredPath.length = curPath.length;
3060
- for(var i2 = 0; i2 < length; i2++){
3061
- enteredPath[i2] = curPath[i2];
3062
- }
3063
- add.length = del.length = 0;
3064
- }
3065
- curPath.length = 0;
3066
- };
3067
- _proto._composedPath = function _composedPath(element, path) {
3068
- if (!element) {
3069
- path.length = 0;
3070
- return path;
3071
- }
3072
- var entity = path[0] = element.entity;
3073
- var i = 1;
3074
- var rootEntity = element._getRootCanvas().entity;
3075
- for(; i < UIPointerEventEmitter._MAX_PATH_DEPTH && !!entity && entity !== rootEntity; i++){
3076
- entity = path[i] = entity.parent;
3077
- }
3078
- path.length = i;
3079
- return path;
3080
- };
3081
- _proto._findCommonInPath = function _findCommonInPath(prePath, curPath, common) {
3082
- var idSet = UIPointerEventEmitter._tempSet;
3083
- idSet.clear();
3084
- for(var i = 0, n = prePath.length; i < n; i++){
3085
- idSet.add(prePath[i].instanceId);
3086
- }
3087
- var hasCommon = false;
3088
- for(var i1 = 0, n1 = curPath.length; i1 < n1; i1++){
3089
- var entity = curPath[i1];
3090
- if (idSet.has(entity.instanceId)) {
3091
- common.push(entity);
3092
- hasCommon = true;
3093
- }
3094
- }
3095
- return hasCommon;
3096
- };
3097
- _proto._findDiffInPath = function _findDiffInPath(prePath, curPath, add, del) {
3098
- var idSet = UIPointerEventEmitter._tempSet;
3099
- idSet.clear();
3100
- var changed = false;
3101
- for(var i = 0, n = prePath.length; i < n; i++){
3102
- idSet.add(prePath[i].instanceId);
3103
- }
3104
- for(var i1 = 0, n1 = curPath.length; i1 < n1; i1++){
3105
- var entity = curPath[i1];
3106
- if (!idSet.has(entity.instanceId)) {
3107
- add.push(entity);
3108
- changed = true;
3109
- }
3110
- }
3111
- idSet.clear();
3112
- for(var i2 = 0, n2 = curPath.length; i2 < n2; i2++){
3113
- idSet.add(curPath[i2].instanceId);
3114
- }
3115
- for(var i3 = 0, n3 = prePath.length; i3 < n3; i3++){
3116
- var entity1 = prePath[i3];
3117
- if (!idSet.has(entity1.instanceId)) {
3118
- del.push(entity1);
3119
- changed = true;
3120
- }
3121
- }
3122
- return changed;
3123
- };
3124
- _proto._bubble = function _bubble(path, pointer, fireEvent) {
3125
- var length = path.length;
3126
- if (length <= 0) return;
3127
- var eventData = this._createEventData(pointer);
3128
- for(var i = 0; i < length; i++){
3129
- fireEvent(path[i], eventData);
3130
- }
3131
- };
3132
- return UIPointerEventEmitter;
3133
- }(PointerEventEmitter);
3134
- UIPointerEventEmitter._MAX_PATH_DEPTH = 2048;
3135
- UIPointerEventEmitter._tempSet = new Set();
3136
- UIPointerEventEmitter._path = [];
3137
- UIPointerEventEmitter._tempArray0 = [];
3138
- UIPointerEventEmitter._tempArray1 = [];
3139
- UIPointerEventEmitter = __decorate([
3140
- registerPointerEventEmitter()
3141
- ], UIPointerEventEmitter);
3142
-
3143
- var EngineExtension = /*#__PURE__*/ function() {
3144
- function EngineExtension() {}
3145
- var _proto = EngineExtension.prototype;
3146
- _proto._getUIDefaultMaterial = function _getUIDefaultMaterial() {
3147
- if (!this._uiDefaultMaterial) {
3148
- var _Shader_find;
3149
- var shader = (_Shader_find = Shader.find("ui")) != null ? _Shader_find : Shader.create("ui", [
3150
- new ShaderPass("Forward", uiDefaultVs, uiDefaultFs, {
3151
- pipelineStage: PipelineStage.Forward
3152
- })
3153
- ]);
3154
- // @ts-ignore
3155
- var material = new Material(this, shader);
3156
- var renderState = material.renderState;
3157
- var target = renderState.blendState.targetBlendState;
3158
- target.enabled = true;
3159
- target.sourceColorBlendFactor = BlendFactor.SourceAlpha;
3160
- target.destinationColorBlendFactor = BlendFactor.OneMinusSourceAlpha;
3161
- target.sourceAlphaBlendFactor = BlendFactor.One;
3162
- target.destinationAlphaBlendFactor = BlendFactor.OneMinusSourceAlpha;
3163
- target.colorBlendOperation = target.alphaBlendOperation = BlendOperation.Add;
3164
- renderState.depthState.writeEnabled = false;
3165
- renderState.rasterState.cullMode = CullMode.Off;
3166
- renderState.renderQueueType = RenderQueueType.Transparent;
3167
- material.isGCIgnored = true;
3168
- this._uiDefaultMaterial = material;
3169
- }
3170
- return this._uiDefaultMaterial;
3171
- };
3172
- return EngineExtension;
3173
- }();
3174
- var EntityExtension = /*#__PURE__*/ function() {
3175
- function EntityExtension() {
3176
- this._uiHierarchyVersion = 0;
3177
- }
3178
- var _proto = EntityExtension.prototype;
3179
- _proto._updateUIHierarchyVersion = function _updateUIHierarchyVersion(version) {
3180
- if (this._uiHierarchyVersion !== version) {
3181
- var // @ts-ignore
3182
- _this_parent;
3183
- this._uiHierarchyVersion = version;
3184
- (_this_parent = this.parent) == null ? void 0 : _this_parent._updateUIHierarchyVersion(version);
3185
- }
3186
- };
3187
- return EntityExtension;
3188
- }();
3189
- function ApplyMixins(derivedCtor, baseCtors) {
3190
- baseCtors.forEach(function(baseCtor) {
3191
- Object.getOwnPropertyNames(baseCtor.prototype).forEach(function(name) {
3192
- Object.defineProperty(derivedCtor.prototype, name, Object.getOwnPropertyDescriptor(baseCtor.prototype, name) || Object.create(null));
3193
- });
3194
- });
3195
- }
3196
- ApplyMixins(Engine, [
3197
- EngineExtension
3198
- ]);
3199
- ApplyMixins(Entity, [
3200
- EntityExtension
3201
- ]);
3202
- ReflectionParser.registerCustomParseComponent("Text", /*#__PURE__*/ _async_to_generator(function(instance, item) {
3203
- var props;
3204
- return __generator(this, function(_state) {
3205
- props = item.props;
3206
- if (!props.font) {
3207
- // @ts-ignore
3208
- instance.font = Font.createFromOS(instance.engine, props.fontFamily || "Arial");
3209
- }
3210
- return [
3211
- 2,
3212
- instance
3213
- ];
3214
- });
3215
- }));
3216
- /**
3217
- * Register GUI components for the editor.
3218
- */ function registerGUI() {
3219
- for(var key in GUIComponent){
3220
- Loader.registerClass(key, GUIComponent[key]);
3221
- }
3222
- }
3223
-
3224
- export { Button, CanvasRenderMode, ColorTransition, EngineExtension, EntityExtension, Image, ResolutionAdaptationMode, ScaleTransition, SpriteTransition, Text, Transition, UICanvas, UIGroup, UIPointerEventEmitter, UIRenderer, UITransform, registerGUI };
3225
- //# sourceMappingURL=module.js.map