@galacean/engine-ui 0.0.0-experimental-2.0-migrate.6 → 0.0.0-experimental-2.0-skill.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 CHANGED
@@ -1,4 +1,22 @@
1
- import { Matrix, BoundingBox, Utils as Utils$1, Vector2, Rect, TransformModifyFlags, Transform, ignoreClone, MathUtil, Vector4, Vector3, dependentComponents, DependentMode, Component, DisorderedArray, EntityModifyFlags, Plane, ShaderProperty, Color, RendererUpdateFlags, VertexMergeBatcher, ShaderMacroCollection, SpriteMaskInteraction, Renderer, CameraModifyFlags, Logger, Ray, Script, Signal, SpriteTileMode, SpriteFilledMode, SpriteFilledOrigin, SpriteDrawMode, SpriteModifyFlags, FilledSpriteAssembler, TiledSpriteAssembler, SlicedSpriteAssembler, SimpleSpriteAssembler, MaskRenderable, FontStyle, TextHorizontalAlignment, TextVerticalAlignment, OverflowMode, ShaderData, ShaderDataGroup, TextUtils, Engine, CharRenderInfo, DataObject, ReferResource, registerPointerEventEmitter, PointerEventEmitter, CameraClearFlags, Material, Entity, Loader, Shader } from '@galacean/engine';
1
+ import { EntityModifyFlags, ignoreClone, DisorderedArray, Component, Matrix, BoundingBox, Utils as Utils$1, TransformModifyFlags, Transform, Vector2, Rect, MathUtil, Vector3, Plane, ShaderProperty, dependentComponents, DependentMode, VertexMergeBatcher, ShaderMacroCollection, Renderer, Vector4, Color, RendererUpdateFlags, Script, CameraModifyFlags, Logger, Signal, SpriteDrawMode, SpriteModifyFlags, SpriteTileMode, TiledSpriteAssembler, SlicedSpriteAssembler, SimpleSpriteAssembler, ShaderData, ShaderDataGroup, TextUtils, Engine, TextVerticalAlignment, TextHorizontalAlignment, OverflowMode, CharRenderInfo, FontStyle, ReferResource, DataObject, registerPointerEventEmitter, PointerEventEmitter, CameraClearFlags, Material, Entity, Loader, Shader } from '@galacean/engine';
2
+
3
+ function _defineProperties(target, props) {
4
+ for (var i = 0; i < props.length; i++) {
5
+ var descriptor = props[i];
6
+ descriptor.enumerable = descriptor.enumerable || false;
7
+ descriptor.configurable = true;
8
+
9
+ if ("value" in descriptor) descriptor.writable = true;
10
+
11
+ Object.defineProperty(target, descriptor.key, descriptor);
12
+ }
13
+ }
14
+ function _create_class(Constructor, protoProps, staticProps) {
15
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
16
+ if (staticProps) _defineProperties(Constructor, staticProps);
17
+
18
+ return Constructor;
19
+ }
2
20
 
3
21
  function _set_prototype_of(o, p) {
4
22
  _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
@@ -20,22 +38,10 @@ function _inherits(subClass, superClass) {
20
38
  if (superClass) _set_prototype_of(subClass, superClass);
21
39
  }
22
40
 
23
- function _defineProperties(target, props) {
24
- for (var i = 0; i < props.length; i++) {
25
- var descriptor = props[i];
26
- descriptor.enumerable = descriptor.enumerable || false;
27
- descriptor.configurable = true;
28
-
29
- if ("value" in descriptor) descriptor.writable = true;
30
-
31
- Object.defineProperty(target, descriptor.key, descriptor);
32
- }
33
- }
34
- function _create_class(Constructor, protoProps, staticProps) {
35
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
36
- if (staticProps) _defineProperties(Constructor, staticProps);
37
-
38
- return Constructor;
41
+ function _instanceof(left, right) {
42
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
43
+ return !!right[Symbol.hasInstance](left);
44
+ } else return left instanceof right;
39
45
  }
40
46
 
41
47
  /******************************************************************************
@@ -65,2424 +71,2046 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
65
71
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
66
72
  };
67
73
 
68
- function _instanceof(left, right) {
69
- if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
70
- return !!right[Symbol.hasInstance](left);
71
- } else return left instanceof right;
72
- }
73
-
74
- /**
75
- * @internal
76
- * Visual-layering driven UI batching: solve visual correctness first, batching falls out for free.
77
- *
78
- * Think of it as stacking elements onto numbered shelves (depths):
79
- * - Non-overlapping elements share shelf 0 — free to cluster regardless of material.
80
- * - Overlapping + batch-compatible — share the same shelf, still cluster.
81
- * - Overlapping + batch-incompatible — bumped one shelf higher (drawn on top).
82
- *
83
- * `depth` is a global tag, not a spatial group: distant elements at the same visual layer
84
- * share the same depth and get clustered together. Once depth is assigned, sort by
85
- * (depth, material, texture, hierarchyIndex) — visual order is locked, batching is the
86
- * by-product of materials clustering within each depth band.
87
- *
88
- * Overlap detection is accelerated by a 10×10 spatial grid. Grid origin and cell size
89
- * are derived from the union AABB of input elements (the bounds transform itself is the
90
- * work the loop must do anyway, so the union accumulation just piggybacks). This stays
91
- * correct across SS/WS canvases, any pivot, and any element distribution — no dependency
92
- * on canvas configuration.
93
- */ var UIBatchSorter = /*#__PURE__*/ function() {
94
- function UIBatchSorter() {}
74
+ var UIGroup = /*#__PURE__*/ function(Component) {
75
+ _inherits(UIGroup, Component);
76
+ function UIGroup(entity) {
77
+ var _this;
78
+ _this = Component.call(this, entity) || this, /** @internal */ _this._indexInGroup = -1, /** @internal */ _this._indexInRootCanvas = -1, /** @internal */ _this._disorderedElements = new DisorderedArray(), /** @internal */ _this._globalAlpha = 1, /** @internal */ _this._globalInteractive = true, _this._alpha = 1, _this._interactive = true, _this._ignoreParentGroup = false, /** @internal */ _this._rootCanvasListeningEntities = [], /** @internal */ _this._groupListeningEntities = [], /** @internal */ _this._isRootCanvasDirty = false, /** @internal */ _this._isGroupDirty = false, /** @internal */ _this._groupDirtyFlags = 0;
79
+ _this._rootCanvasListener = _this._rootCanvasListener.bind(_this);
80
+ _this._groupListener = _this._groupListener.bind(_this);
81
+ return _this;
82
+ }
83
+ var _proto = UIGroup.prototype;
95
84
  /**
96
- * Reorders `elements` in place for optimal batching.
97
- * @param elements - in hierarchy order (depth-first traversal); mutated in place
98
- * @param canvasWorldMatrix - reduces world bounds to canvas-local for precise overlap
99
- */ UIBatchSorter.sort = function sort(elements, canvasWorldMatrix) {
100
- var count = elements.length;
101
- if (count <= 1) return;
102
- var gridDim = this._gridDim;
103
- var entries = this._entries;
104
- var grid = this._grid;
105
- var dirtyCells = this._dirtyCells;
106
- var localBoundsPool = this._localBoundsPool;
107
- var worldToLocal = this._worldToLocal;
108
- Matrix.invert(canvasWorldMatrix, worldToLocal);
109
- while(entries.length < count)entries.push(new SortEntry());
110
- // Allocate grid once, reuse forever (each cell must be a real [], not a sparse hole)
111
- if (grid.length < gridDim) {
112
- while(grid.length < gridDim)grid.push([]);
113
- for(var i = 0; i < gridDim; i++){
114
- var row = grid[i];
115
- while(row.length < gridDim)row.push([]);
85
+ * @internal
86
+ */ _proto._getGlobalAlpha = function _getGlobalAlpha() {
87
+ if (this._isContainDirtyFlag(1)) {
88
+ if (this._ignoreParentGroup) {
89
+ this._globalAlpha = this._alpha;
90
+ } else {
91
+ var parentGroup = this._getGroup();
92
+ this._globalAlpha = this._alpha * (parentGroup ? parentGroup._getGlobalAlpha() : 1);
116
93
  }
94
+ this._setDirtyFlagFalse(1);
117
95
  }
118
- // Clear only previously-used cells (no full sweep)
119
- for(var k = 0, n = dirtyCells.length; k < n; k += 2){
120
- grid[dirtyCells[k]][dirtyCells[k + 1]].length = 0;
121
- }
122
- dirtyCells.length = 0;
123
- // Pass 1: transform world bounds to canvas-local + accumulate the union AABB.
124
- // Transform is already required to do precise overlap, so the union accumulation
125
- // is essentially free — just a few minmax compares riding on the existing pass
126
- var unionMinX = Infinity;
127
- var unionMinY = Infinity;
128
- var unionMaxX = -Infinity;
129
- var unionMaxY = -Infinity;
130
- for(var i1 = 0; i1 < count; i1++){
131
- var _localBoundsPool, _i;
132
- var localBounds = (_localBoundsPool = localBoundsPool)[_i = i1] || (_localBoundsPool[_i] = new BoundingBox());
133
- BoundingBox.transform(elements[i1].component.bounds, worldToLocal, localBounds);
134
- var min = localBounds.min, max = localBounds.max;
135
- if (min.x < unionMinX) unionMinX = min.x;
136
- if (min.y < unionMinY) unionMinY = min.y;
137
- if (max.x > unionMaxX) unionMaxX = max.x;
138
- if (max.y > unionMaxY) unionMaxY = max.y;
139
- }
140
- // Guard against a degenerate union (all elements collapsed onto a single point /
141
- // axis); the grid then collapses to cell 0 which is semantically correct
142
- var cellSizeX = Math.max(1e-6, unionMaxX - unionMinX) / gridDim;
143
- var cellSizeY = Math.max(1e-6, unionMaxY - unionMinY) / gridDim;
144
- var maxCell = gridDim - 1;
145
- // Pass 2: register each element into grid cells and compute its depth
146
- for(var i2 = 0; i2 < count; i2++){
147
- var element = elements[i2];
148
- var localBounds1 = localBoundsPool[i2];
149
- var materialId = element.material.instanceId;
150
- var textureId = element.texture ? element.texture.instanceId : 0;
151
- // Floor + clamp guards floating-point edge cases (a `max` exactly on the union
152
- // boundary would otherwise produce `gridDim`)
153
- var minCellX = Math.min(maxCell, Math.max(0, Math.floor((localBounds1.min.x - unionMinX) / cellSizeX)));
154
- var maxCellX = Math.min(maxCell, Math.max(0, Math.floor((localBounds1.max.x - unionMinX) / cellSizeX)));
155
- var minCellY = Math.min(maxCell, Math.max(0, Math.floor((localBounds1.min.y - unionMinY) / cellSizeY)));
156
- var maxCellY = Math.min(maxCell, Math.max(0, Math.floor((localBounds1.max.y - unionMinY) / cellSizeY)));
157
- // Find the deepest overlapping prior, and whether that shelf has any incompatible occupant
158
- var maxDepth = -1;
159
- var maxDepthIncompatible = false;
160
- for(var cellY = minCellY; cellY <= maxCellY; cellY++){
161
- for(var cellX = minCellX; cellX <= maxCellX; cellX++){
162
- var cell = grid[cellX][cellY];
163
- for(var j = 0, m = cell.length; j < m; j++){
164
- var other = cell[j];
165
- if (!UIBatchSorter._rectOverlap(localBounds1, other.bounds)) continue;
166
- var otherDepth = other.depth;
167
- var otherIncompatible = other.materialId !== materialId || other.textureId !== textureId;
168
- if (otherDepth > maxDepth) {
169
- maxDepth = otherDepth;
170
- maxDepthIncompatible = otherIncompatible;
171
- } else if (otherDepth === maxDepth && otherIncompatible) {
172
- maxDepthIncompatible = true;
173
- }
174
- }
175
- }
176
- }
177
- var entry = entries[i2];
178
- entry.element = element;
179
- entry.hierarchyIndex = i2;
180
- // Share the deepest shelf if compatible; bump up one if blocked by an incompatible occupant
181
- entry.depth = maxDepth < 0 ? 0 : maxDepth + (maxDepthIncompatible ? 1 : 0);
182
- entry.materialId = materialId;
183
- entry.textureId = textureId;
184
- entry.bounds = localBounds1;
185
- for(var cellY1 = minCellY; cellY1 <= maxCellY; cellY1++){
186
- for(var cellX1 = minCellX; cellX1 <= maxCellX; cellX1++){
187
- var cell1 = grid[cellX1][cellY1];
188
- if (cell1.length === 0) dirtyCells.push(cellX1, cellY1);
189
- cell1.push(entry);
190
- }
96
+ return this._globalAlpha;
97
+ };
98
+ /**
99
+ * @internal
100
+ */ _proto._getGlobalInteractive = function _getGlobalInteractive() {
101
+ if (this._isContainDirtyFlag(2)) {
102
+ if (this._ignoreParentGroup) {
103
+ this._globalInteractive = this._interactive;
104
+ } else {
105
+ var parentGroup = this._getGroup();
106
+ this._globalInteractive = this._interactive && (!parentGroup || parentGroup._getGlobalInteractive());
191
107
  }
108
+ this._setDirtyFlagFalse(2);
192
109
  }
193
- // @ts-ignore — Utils._quickSort is @internal
194
- Utils$1._quickSort(entries, 0, count, UIBatchSorter._compareEntries);
195
- for(var i3 = 0; i3 < count; i3++)elements[i3] = entries[i3].element;
110
+ return this._globalInteractive;
196
111
  };
197
- UIBatchSorter._rectOverlap = function _rectOverlap(a, b) {
198
- return a.min.x < b.max.x && a.max.x > b.min.x && a.min.y < b.max.y && a.max.y > b.min.y;
112
+ // @ts-ignore
113
+ _proto._onEnableInScene = function _onEnableInScene() {
114
+ Utils.setRootCanvasDirty(this);
115
+ Utils.setGroupDirty(this);
116
+ // @ts-ignore
117
+ this.entity._dispatchModify(EntityUIModifyFlags.GroupEnableInScene);
199
118
  };
200
- UIBatchSorter._compareEntries = function _compareEntries(a, b) {
201
- return a.depth - b.depth || a.materialId - b.materialId || a.textureId - b.textureId || a.hierarchyIndex - b.hierarchyIndex;
119
+ // @ts-ignore
120
+ _proto._onDisableInScene = function _onDisableInScene() {
121
+ Utils.cleanRootCanvas(this);
122
+ Utils.cleanGroup(this);
123
+ var disorderedElements = this._disorderedElements;
124
+ disorderedElements.forEach(function(element) {
125
+ Utils.setGroupDirty(element);
126
+ });
127
+ disorderedElements.length = 0;
128
+ disorderedElements.garbageCollection();
129
+ this._isRootCanvasDirty = this._isGroupDirty = false;
202
130
  };
203
- return UIBatchSorter;
204
- }();
205
- // Spatial-hash is fastest when cell size ≈ typical element size (one element per cell).
206
- // UI elements typically span ~10% of the canvas → 10×10 grid.
207
- UIBatchSorter._gridDim = 10;
208
- UIBatchSorter._entries = new Array();
209
- UIBatchSorter._grid = [];
210
- // Interleaved (x, y) cell coords touched in the previous frame
211
- UIBatchSorter._dirtyCells = new Array();
212
- UIBatchSorter._localBoundsPool = new Array();
213
- UIBatchSorter._worldToLocal = new Matrix();
214
- // materialId/textureId/bounds are flattened from RenderElement to avoid
215
- // multi-hop property access in the hot inner loop and the sort comparator.
216
- var SortEntry = function SortEntry() {
217
- this.hierarchyIndex = 0;
218
- this.depth = 0;
219
- this.materialId = 0;
220
- this.textureId = 0;
221
- };
222
-
223
- /**
224
- * Render mode for ui canvas.
225
- */ var CanvasRenderMode = /*#__PURE__*/ function(CanvasRenderMode) {
226
131
  /**
227
- * The UI canvas will be rendered directly onto the screen and adapted to screen space,
228
- * overlaying other rendering elements in the same scene.
229
- * @remarks if the `engine.canvas` size change, the UI canvas will automatically adapt.
230
- */ CanvasRenderMode[CanvasRenderMode["ScreenSpaceOverlay"] = 0] = "ScreenSpaceOverlay";
132
+ * @internal
133
+ */ _proto._getRootCanvas = function _getRootCanvas() {
134
+ this._isRootCanvasDirty && Utils.setRootCanvas(this, Utils.searchRootCanvasInParents(this));
135
+ return this._rootCanvas;
136
+ };
231
137
  /**
232
- * The UI canvas is placed at a specified distance in front of the camera and adapted to screen space,
233
- * with all objects rendered by the camera.
234
- * @remarks if the camera's properties or the `engine.canvas` size change, the UI canvas will automatically adapt.
235
- * @remarks if set `ScreenSpaceCamera` but no corresponding camera is assigned, the actual rendering mode defaults to `ScreenSpaceOverlay`.
236
- */ CanvasRenderMode[CanvasRenderMode["ScreenSpaceCamera"] = 1] = "ScreenSpaceCamera";
237
- /**
238
- * The UI canvas is placed in the 3D world space and rendered by every camera in the same scene.
239
- */ CanvasRenderMode[CanvasRenderMode["WorldSpace"] = 2] = "WorldSpace";
240
- return CanvasRenderMode;
241
- }({});
242
-
243
- /**
244
- * Resolution adaptation mode.
245
- * @remarks Only effective in screen space.
246
- */ var ResolutionAdaptationMode = /*#__PURE__*/ function(ResolutionAdaptationMode) {
247
- /** Adapt based on width.(`referenceResolution.x`) */ ResolutionAdaptationMode[ResolutionAdaptationMode["WidthAdaptation"] = 0] = "WidthAdaptation";
248
- /** Adapt based on height.(`referenceResolution.y`) */ ResolutionAdaptationMode[ResolutionAdaptationMode["HeightAdaptation"] = 1] = "HeightAdaptation";
249
- /** Adapt based on both width and height.(`referenceResolution`) */ ResolutionAdaptationMode[ResolutionAdaptationMode["BothAdaptation"] = 2] = "BothAdaptation";
250
- /** Adapt to the side with a larger ratio. */ ResolutionAdaptationMode[ResolutionAdaptationMode["ExpandAdaptation"] = 3] = "ExpandAdaptation";
251
- /** Adapt to the side with smaller ratio. */ ResolutionAdaptationMode[ResolutionAdaptationMode["ShrinkAdaptation"] = 4] = "ShrinkAdaptation";
252
- return ResolutionAdaptationMode;
253
- }({});
254
-
255
- /** Horizontal alignment mode. */ var HorizontalAlignmentMode = /*#__PURE__*/ function(HorizontalAlignmentMode) {
256
- /** No horizontal alignment. */ HorizontalAlignmentMode[HorizontalAlignmentMode["None"] = 0] = "None";
257
- /** Left-aligned, `alignLeft` drives `position.x`. */ HorizontalAlignmentMode[HorizontalAlignmentMode["Left"] = 1] = "Left";
258
- /** Right-aligned, `alignRight` drives `position.x`. */ HorizontalAlignmentMode[HorizontalAlignmentMode["Right"] = 2] = "Right";
259
- /** Horizontal stretch, `alignLeft` and `alignRight` drive `position.x` and `size.x`. */ HorizontalAlignmentMode[HorizontalAlignmentMode["LeftAndRight"] = 3] = "LeftAndRight";
260
- /** Center-aligned, `alignCenter` drives `position.x`. */ HorizontalAlignmentMode[HorizontalAlignmentMode["Center"] = 4] = "Center";
261
- return HorizontalAlignmentMode;
262
- }({});
263
-
264
- /** Vertical alignment mode. */ var VerticalAlignmentMode = /*#__PURE__*/ function(VerticalAlignmentMode) {
265
- /** No vertical alignment. */ VerticalAlignmentMode[VerticalAlignmentMode["None"] = 0] = "None";
266
- /** Top-aligned, `alignTop` drives `position.y`. */ VerticalAlignmentMode[VerticalAlignmentMode["Top"] = 1] = "Top";
267
- /** Bottom-aligned, `alignBottom` drives `position.y`. */ VerticalAlignmentMode[VerticalAlignmentMode["Bottom"] = 2] = "Bottom";
268
- /** Vertical stretch, `alignTop` and `alignBottom` drive `position.y` and `size.y`. */ VerticalAlignmentMode[VerticalAlignmentMode["TopAndBottom"] = 3] = "TopAndBottom";
269
- /** Middle-aligned, `alignMiddle` drives `position.y`. */ VerticalAlignmentMode[VerticalAlignmentMode["Middle"] = 4] = "Middle";
270
- return VerticalAlignmentMode;
271
- }({});
272
-
273
- /**
274
- * The Transform component exclusive to the UI element.
275
- */ var UITransform = /*#__PURE__*/ function(Transform) {
276
- _inherits(UITransform, Transform);
277
- function UITransform(entity) {
278
- var _this;
279
- _this = Transform.call(this, entity) || this, _this._size = new Vector2(100, 100), _this._pivot = new Vector2(0.5, 0.5), _this._rect = new Rect(-50, -50, 100, 100), _this._alignLeft = 0, _this._alignRight = 0, _this._alignCenter = 0, _this._alignTop = 0, _this._alignBottom = 0, _this._alignMiddle = 0, _this._horizontalAlignment = HorizontalAlignmentMode.None, _this._verticalAlignment = VerticalAlignmentMode.None;
280
- _this._onSizeChanged = _this._onSizeChanged.bind(_this);
281
- _this._onPivotChanged = _this._onPivotChanged.bind(_this);
282
- // @ts-ignore
283
- _this._size._onValueChanged = _this._onSizeChanged;
284
- // @ts-ignore
285
- _this._pivot._onValueChanged = _this._onPivotChanged;
286
- return _this;
287
- }
288
- var _proto = UITransform.prototype;
138
+ * @internal
139
+ */ _proto._getGroup = function _getGroup() {
140
+ this._isGroupDirty && Utils.setGroup(this, Utils.searchGroupInParents(this));
141
+ return this._group;
142
+ };
289
143
  /**
290
144
  * @internal
291
- */ _proto._parentChange = function _parentChange() {
292
- this._isParentDirty = true;
293
- this._updateWorldFlagWithParentRectChange(TransformModifyFlags.WmWpWeWqWsWus);
294
- };
295
- /**
296
- * @inheritdoc
297
- */ _proto._onClone = function _onClone(target) {
298
- Transform.prototype._onClone.call(this, target);
299
- var size = target._size, pivot = target._pivot;
300
- // @ts-ignore
301
- size._onValueChanged = pivot._onValueChanged = null;
302
- size.copyFrom(this._size);
303
- pivot.copyFrom(this._pivot);
304
- // @ts-ignore
305
- size._onValueChanged = target._onSizeChanged;
306
- // @ts-ignore
307
- pivot._onValueChanged = target._onPivotChanged;
308
- };
309
- _proto._onLocalMatrixChanging = function _onLocalMatrixChanging() {
310
- // `super._onLocalMatrixChanging()` will set `LocalMatrix` dirty flag `false`
311
- // If there is an alignment, `position` and `localMatrix` will be reset again
312
- if (this._horizontalAlignment || this._verticalAlignment) {
313
- this._updatePositionByAlignment();
314
- this._setDirtyFlagTrue(TransformModifyFlags.LocalMatrix);
315
- } else {
316
- Transform.prototype._onLocalMatrixChanging.call(this);
317
- }
318
- };
319
- _proto._onWorldMatrixChanging = function _onWorldMatrixChanging() {
320
- // `super._onWorldMatrixChanging()` will set `WorldMatrix` dirty flag `false`
321
- // If there is an alignment, `position` and `worldMatrix` will be reset again(`worldMatrix` dirty flag is already `true`)
322
- !this._horizontalAlignment && !this._verticalAlignment && Transform.prototype._onWorldMatrixChanging.call(this);
323
- };
324
- _proto._onPositionChanged = function _onPositionChanged() {
325
- (this._horizontalAlignment || this._verticalAlignment) && this._updatePositionByAlignment();
326
- Transform.prototype._onPositionChanged.call(this);
327
- };
328
- _proto._onWorldPositionChanged = function _onWorldPositionChanged() {
329
- Transform.prototype._onWorldPositionChanged.call(this);
330
- if (this._horizontalAlignment || this._verticalAlignment) {
331
- this._setDirtyFlagTrue(TransformModifyFlags.WorldPosition);
332
- }
333
- };
334
- _proto._updatePositionByAlignment = function _updatePositionByAlignment() {
335
- var _this__getParentTransform;
336
- var parentRect = (_this__getParentTransform = this._getParentTransform()) == null ? void 0 : _this__getParentTransform._rect;
337
- if (parentRect) {
338
- var position = this.position;
339
- // @ts-ignore
340
- position._onValueChanged = null;
341
- var rect = this._rect;
342
- switch(this._horizontalAlignment){
343
- case HorizontalAlignmentMode.Left:
344
- case HorizontalAlignmentMode.LeftAndRight:
345
- position.x = parentRect.x - rect.x + this._alignLeft;
346
- break;
347
- case HorizontalAlignmentMode.Center:
348
- position.x = parentRect.x + parentRect.width * 0.5 - rect.x - rect.width * 0.5 + this._alignCenter;
349
- break;
350
- case HorizontalAlignmentMode.Right:
351
- position.x = parentRect.x + parentRect.width - rect.x - rect.width - this._alignRight;
352
- break;
353
- }
354
- switch(this._verticalAlignment){
355
- case VerticalAlignmentMode.Top:
356
- position.y = parentRect.y + parentRect.height - rect.y - rect.height - this._alignTop;
357
- break;
358
- case VerticalAlignmentMode.Middle:
359
- position.y = parentRect.y + parentRect.height * 0.5 - rect.y - rect.height * 0.5 + this._alignMiddle;
360
- break;
361
- case VerticalAlignmentMode.Bottom:
362
- case VerticalAlignmentMode.TopAndBottom:
363
- position.y = parentRect.y - rect.y + this._alignBottom;
364
- break;
365
- }
366
- // @ts-ignore
367
- position._onValueChanged = this._onPositionChanged;
145
+ */ _proto._groupListener = function _groupListener(flag) {
146
+ if (flag === EntityModifyFlags.Parent || flag === EntityUIModifyFlags.GroupEnableInScene) {
147
+ Utils.setGroupDirty(this);
368
148
  }
369
149
  };
370
- _proto._updateSizeByAlignment = function _updateSizeByAlignment() {
371
- var _this__getParentTransform;
372
- var parentRect = (_this__getParentTransform = this._getParentTransform()) == null ? void 0 : _this__getParentTransform._rect;
373
- if (parentRect) {
374
- var size = this._size;
375
- // @ts-ignore
376
- size._onValueChanged = null;
377
- // The values of size must be greater than 0
378
- if (this._horizontalAlignment === HorizontalAlignmentMode.LeftAndRight) {
379
- size.x = Math.max(parentRect.width - this._alignLeft - this._alignRight, 0);
380
- }
381
- if (this._verticalAlignment === VerticalAlignmentMode.TopAndBottom) {
382
- size.y = Math.max(parentRect.height - this._alignTop - this._alignBottom, 0);
383
- }
384
- // @ts-ignore
385
- size._onValueChanged = this._onSizeChanged;
150
+ /**
151
+ * @internal
152
+ */ _proto._rootCanvasListener = function _rootCanvasListener(flag) {
153
+ if (flag === EntityModifyFlags.Parent || flag === EntityUIModifyFlags.CanvasEnableInScene) {
154
+ Utils.setRootCanvasDirty(this);
155
+ Utils.setGroupDirty(this);
386
156
  }
387
157
  };
388
- _proto._updateRectBySizeAndPivot = function _updateRectBySizeAndPivot() {
389
- var _this = this, size = _this.size, pivot = _this._pivot;
390
- var x = -pivot.x * size.x;
391
- var y = -pivot.y * size.y;
392
- this._rect.set(x, y, size.x, size.y);
158
+ /**
159
+ * @internal
160
+ */ _proto._onGroupModify = function _onGroupModify(flags, isPass) {
161
+ if (isPass === void 0) isPass = false;
162
+ if (isPass && this._ignoreParentGroup) return;
163
+ if (this._isContainDirtyFlags(flags)) return;
164
+ this._setDirtyFlagTrue(flags);
165
+ this._disorderedElements.forEach(function(element) {
166
+ element._onGroupModify(flags, true);
167
+ });
393
168
  };
394
- _proto._onSizeChanged = function _onSizeChanged() {
395
- if (this._horizontalAlignment === HorizontalAlignmentMode.LeftAndRight || this._verticalAlignment === VerticalAlignmentMode.TopAndBottom) {
396
- this._updateSizeByAlignment();
397
- }
398
- this._updateRectBySizeAndPivot();
399
- this._updateWorldFlagWithSelfRectChange();
400
- // @ts-ignore
401
- this._entity._updateFlagManager.dispatch(512);
169
+ _proto._isContainDirtyFlags = function _isContainDirtyFlags(targetDirtyFlags) {
170
+ return (this._groupDirtyFlags & targetDirtyFlags) === targetDirtyFlags;
402
171
  };
403
- _proto._onPivotChanged = function _onPivotChanged() {
404
- this._updateRectBySizeAndPivot();
405
- this._updateWorldFlagWithSelfRectChange();
406
- // @ts-ignore
407
- this._entity._updateFlagManager.dispatch(1024);
172
+ _proto._isContainDirtyFlag = function _isContainDirtyFlag(type) {
173
+ return (this._groupDirtyFlags & type) != 0;
408
174
  };
409
- _proto._updateWorldFlagWithSelfRectChange = function _updateWorldFlagWithSelfRectChange() {
410
- var worldFlags = 0;
411
- if (this._horizontalAlignment || this._verticalAlignment) {
412
- this._updatePositionByAlignment();
413
- this._setDirtyFlagTrue(TransformModifyFlags.LocalMatrix);
414
- worldFlags = TransformModifyFlags.WmWp;
415
- !this._isContainDirtyFlags(worldFlags) && this._worldAssociatedChange(worldFlags);
416
- }
417
- var children = this.entity.children;
418
- for(var i = 0, n = children.length; i < n; i++){
419
- var _children_i_transform__updateWorldFlagWithParentRectChange, _children_i_transform;
420
- (_children_i_transform = children[i].transform) == null ? void 0 : (_children_i_transform__updateWorldFlagWithParentRectChange = _children_i_transform._updateWorldFlagWithParentRectChange) == null ? void 0 : _children_i_transform__updateWorldFlagWithParentRectChange.call(_children_i_transform, worldFlags);
421
- }
175
+ _proto._setDirtyFlagTrue = function _setDirtyFlagTrue(type) {
176
+ this._groupDirtyFlags |= type;
422
177
  };
423
- _proto._updateWorldFlagWithParentRectChange = function _updateWorldFlagWithParentRectChange(flags, parentChange) {
424
- if (parentChange === void 0) parentChange = true;
425
- var selfChange = false;
426
- if (parentChange) {
427
- var _this = this, horizontalAlignment = _this._horizontalAlignment, verticalAlignment = _this._verticalAlignment;
428
- if (horizontalAlignment || verticalAlignment) {
429
- if (horizontalAlignment === HorizontalAlignmentMode.LeftAndRight || verticalAlignment === VerticalAlignmentMode.TopAndBottom) {
430
- this._updateSizeByAlignment();
431
- this._updateRectBySizeAndPivot();
432
- selfChange = true;
433
- }
434
- this._updatePositionByAlignment();
435
- this._setDirtyFlagTrue(TransformModifyFlags.LocalMatrix);
436
- flags |= TransformModifyFlags.WmWp;
437
- }
438
- }
439
- var containDirtyFlags = this._isContainDirtyFlags(flags);
440
- !containDirtyFlags && this._worldAssociatedChange(flags);
441
- if (selfChange || !containDirtyFlags) {
442
- var children = this.entity.children;
443
- for(var i = 0, n = children.length; i < n; i++){
444
- var _children_i_transform__updateWorldFlagWithParentRectChange, _children_i_transform;
445
- (_children_i_transform = children[i].transform) == null ? void 0 : (_children_i_transform__updateWorldFlagWithParentRectChange = _children_i_transform._updateWorldFlagWithParentRectChange) == null ? void 0 : _children_i_transform__updateWorldFlagWithParentRectChange.call(_children_i_transform, flags, selfChange);
446
- }
447
- }
448
- // @ts-ignore
449
- selfChange && this._entity._updateFlagManager.dispatch(512);
178
+ _proto._setDirtyFlagFalse = function _setDirtyFlagFalse(type) {
179
+ this._groupDirtyFlags &= ~type;
450
180
  };
451
- _create_class(UITransform, [
181
+ _create_class(UIGroup, [
452
182
  {
453
- key: "size",
183
+ key: "ignoreParentGroup",
454
184
  get: /**
455
- * Width and height of UI element.
185
+ * Whether to ignore the parent group.
186
+ * @remarks If this parameter set to `true`,
187
+ * all settings of the parent group will be ignored.
456
188
  */ function get() {
457
- return this._size;
189
+ return this._ignoreParentGroup;
458
190
  },
459
191
  set: function set(value) {
460
- var _this = this, size = _this._size;
461
- if (size === value) return;
462
- (size.x !== value.x || size.y !== value.y) && size.copyFrom(value);
192
+ if (this._ignoreParentGroup !== value) {
193
+ this._ignoreParentGroup = value;
194
+ this._onGroupModify(3);
195
+ }
463
196
  }
464
197
  },
465
198
  {
466
- key: "pivot",
199
+ key: "interactive",
467
200
  get: /**
468
- * Pivot of UI element.
201
+ * Whether the group is interactive.
469
202
  */ function get() {
470
- return this._pivot;
203
+ return this._interactive;
471
204
  },
472
205
  set: function set(value) {
473
- var _this = this, pivot = _this._pivot;
474
- if (pivot === value) return;
475
- (pivot.x !== value.x || pivot.y !== value.y) && pivot.copyFrom(value);
476
- }
477
- },
478
- {
479
- key: "horizontalAlignment",
480
- get: /**
481
- * Horizontal alignment mode.
482
- *
483
- * @remarks
484
- * Controls how the element aligns horizontally within its parent:
485
- * - `Left` - Align to parent's left edge
486
- * - `Center` - Align to parent's horizontal center
487
- * - `Right` - Align to parent's right edge
488
- * - `LeftAndRight` - Align to both left and right edges (stretch to fill width)
489
- */ function get() {
490
- return this._horizontalAlignment;
491
- },
492
- set: function set(value) {
493
- if (this._horizontalAlignment === value) return;
494
- this._horizontalAlignment = value;
495
- switch(value){
496
- case HorizontalAlignmentMode.Left:
497
- case HorizontalAlignmentMode.Right:
498
- case HorizontalAlignmentMode.Center:
499
- this._onPositionChanged();
500
- break;
501
- case HorizontalAlignmentMode.LeftAndRight:
502
- this._onPositionChanged();
503
- this._onSizeChanged();
504
- break;
505
- }
506
- }
507
- },
508
- {
509
- key: "alignLeft",
510
- get: /**
511
- * Left margin when horizontalAlignment is Left or LeftAndRight.
512
- *
513
- * @remarks
514
- * Only effective when horizontalAlignment includes Left mode.
515
- * Distance from the parent's left edge to the element's left edge.
516
- */ function get() {
517
- return this._alignLeft;
518
- },
519
- set: function set(value) {
520
- if (!Number.isFinite(value)) return;
521
- if (MathUtil.equals(value, this._alignLeft)) return;
522
- this._alignLeft = value;
523
- if (this._horizontalAlignment & HorizontalAlignmentMode.Left) {
524
- this._onPositionChanged();
525
- this._horizontalAlignment & HorizontalAlignmentMode.Right && this._onSizeChanged();
526
- }
527
- }
528
- },
529
- {
530
- key: "alignRight",
531
- get: /**
532
- * Right margin when horizontalAlignment is Right or LeftAndRight.
533
- *
534
- * @remarks
535
- * Only effective when horizontalAlignment includes Right mode.
536
- * Distance from the parent's right edge to the element's right edge.
537
- */ function get() {
538
- return this._alignRight;
539
- },
540
- set: function set(value) {
541
- if (!Number.isFinite(value)) return;
542
- if (MathUtil.equals(value, this._alignRight)) return;
543
- this._alignRight = value;
544
- if (this._horizontalAlignment & HorizontalAlignmentMode.Right) {
545
- this._onPositionChanged();
546
- this._horizontalAlignment & HorizontalAlignmentMode.Left && this._onSizeChanged();
547
- }
548
- }
549
- },
550
- {
551
- key: "alignCenter",
552
- get: /**
553
- * Horizontal center offset when horizontalAlignment is Center.
554
- *
555
- * @remarks
556
- * Only effective when horizontalAlignment is Center mode.
557
- * Positive values move the element to the right, negative values to the left.
558
- */ function get() {
559
- return this._alignCenter;
560
- },
561
- set: function set(value) {
562
- if (!Number.isFinite(value)) return;
563
- if (MathUtil.equals(value, this._alignCenter)) return;
564
- this._alignCenter = value;
565
- this._horizontalAlignment & HorizontalAlignmentMode.Center && this._onPositionChanged();
566
- }
567
- },
568
- {
569
- key: "verticalAlignment",
570
- get: /**
571
- * Vertical alignment mode.
572
- *
573
- * @remarks
574
- * Controls how the element aligns vertically within its parent:
575
- * - `Top` - Align to parent's top edge
576
- * - `Middle` - Align to parent's vertical center
577
- * - `Bottom` - Align to parent's bottom edge
578
- * - `TopAndBottom` - Align to both top and bottom edges (stretch to fill height)
579
- */ function get() {
580
- return this._verticalAlignment;
581
- },
582
- set: function set(value) {
583
- if (this._verticalAlignment === value) return;
584
- this._verticalAlignment = value;
585
- switch(value){
586
- case VerticalAlignmentMode.Top:
587
- case VerticalAlignmentMode.Bottom:
588
- case VerticalAlignmentMode.Middle:
589
- this._onPositionChanged();
590
- break;
591
- case VerticalAlignmentMode.TopAndBottom:
592
- this._onPositionChanged();
593
- this._onSizeChanged();
594
- break;
595
- }
596
- }
597
- },
598
- {
599
- key: "alignTop",
600
- get: /**
601
- * Top margin when verticalAlignment is Top or TopAndBottom.
602
- *
603
- * @remarks
604
- * Only effective when verticalAlignment includes Top mode.
605
- * Used to offset the element from the parent's top edge.
606
- */ function get() {
607
- return this._alignTop;
608
- },
609
- set: function set(value) {
610
- if (!Number.isFinite(value)) return;
611
- if (MathUtil.equals(value, this._alignTop)) return;
612
- this._alignTop = value;
613
- if (this._verticalAlignment & VerticalAlignmentMode.Top) {
614
- this._onPositionChanged();
615
- this._verticalAlignment & VerticalAlignmentMode.Bottom && this._onSizeChanged();
206
+ if (this._interactive !== value) {
207
+ this._interactive = value;
208
+ this._onGroupModify(2);
616
209
  }
617
210
  }
618
211
  },
619
212
  {
620
- key: "alignBottom",
213
+ key: "alpha",
621
214
  get: /**
622
- * Bottom inset used in vertical alignment formulas.
215
+ * The alpha value of the group.
623
216
  */ function get() {
624
- return this._alignBottom;
217
+ return this._alpha;
625
218
  },
626
219
  set: function set(value) {
627
- if (!Number.isFinite(value)) return;
628
- if (MathUtil.equals(value, this._alignBottom)) return;
629
- this._alignBottom = value;
630
- if (this._verticalAlignment & VerticalAlignmentMode.Bottom) {
631
- this._onPositionChanged();
632
- this._verticalAlignment & VerticalAlignmentMode.Top && this._onSizeChanged();
220
+ value = Math.max(0, Math.min(value, 1));
221
+ if (this._alpha !== value) {
222
+ this._alpha = value;
223
+ this._onGroupModify(1);
633
224
  }
634
225
  }
635
- },
636
- {
637
- key: "alignMiddle",
638
- get: /**
639
- * Vertical middle offset relative to parent's middle.
640
- */ function get() {
641
- return this._alignMiddle;
642
- },
643
- set: function set(value) {
644
- if (!Number.isFinite(value)) return;
645
- if (MathUtil.equals(value, this._alignMiddle)) return;
646
- this._alignMiddle = value;
647
- this._verticalAlignment & VerticalAlignmentMode.Middle && this._onPositionChanged();
648
- }
649
226
  }
650
227
  ]);
651
- return UITransform;
652
- }(Transform);
228
+ return UIGroup;
229
+ }(Component);
653
230
  __decorate([
654
231
  ignoreClone
655
- ], UITransform.prototype, "_size", void 0);
232
+ ], UIGroup.prototype, "_indexInGroup", void 0);
656
233
  __decorate([
657
234
  ignoreClone
658
- ], UITransform.prototype, "_pivot", void 0);
235
+ ], UIGroup.prototype, "_indexInRootCanvas", void 0);
659
236
  __decorate([
660
237
  ignoreClone
661
- ], UITransform.prototype, "_onPositionChanged", null);
238
+ ], UIGroup.prototype, "_globalAlpha", void 0);
662
239
  __decorate([
663
240
  ignoreClone
664
- ], UITransform.prototype, "_onWorldPositionChanged", null);
241
+ ], UIGroup.prototype, "_globalInteractive", void 0);
665
242
  __decorate([
666
243
  ignoreClone
667
- ], UITransform.prototype, "_onSizeChanged", null);
244
+ ], UIGroup.prototype, "_rootCanvasListeningEntities", void 0);
668
245
  __decorate([
669
246
  ignoreClone
670
- ], UITransform.prototype, "_onPivotChanged", null);
671
- /**
672
- * @internal
673
- * extends TransformModifyFlags
674
- */ var UITransformModifyFlags = /*#__PURE__*/ function(UITransformModifyFlags) {
675
- UITransformModifyFlags[UITransformModifyFlags["Size"] = 512] = "Size";
676
- UITransformModifyFlags[UITransformModifyFlags["Pivot"] = 1024] = "Pivot";
677
- return UITransformModifyFlags;
247
+ ], UIGroup.prototype, "_groupListeningEntities", void 0);
248
+ __decorate([
249
+ ignoreClone
250
+ ], UIGroup.prototype, "_isRootCanvasDirty", void 0);
251
+ __decorate([
252
+ ignoreClone
253
+ ], UIGroup.prototype, "_isGroupDirty", void 0);
254
+ __decorate([
255
+ ignoreClone
256
+ ], UIGroup.prototype, "_groupDirtyFlags", void 0);
257
+ __decorate([
258
+ ignoreClone
259
+ ], UIGroup.prototype, "_groupListener", null);
260
+ __decorate([
261
+ ignoreClone
262
+ ], UIGroup.prototype, "_rootCanvasListener", null);
263
+ var GroupModifyFlags = /*#__PURE__*/ function(GroupModifyFlags) {
264
+ GroupModifyFlags[GroupModifyFlags["None"] = 0] = "None";
265
+ GroupModifyFlags[GroupModifyFlags["GlobalAlpha"] = 1] = "GlobalAlpha";
266
+ GroupModifyFlags[GroupModifyFlags["GlobalInteractive"] = 2] = "GlobalInteractive";
267
+ GroupModifyFlags[GroupModifyFlags["All"] = 3] = "All";
268
+ return GroupModifyFlags;
678
269
  }({});
679
270
 
680
- var RectMask2D = /*#__PURE__*/ function(Component) {
681
- _inherits(RectMask2D, Component);
682
- function RectMask2D(entity) {
683
- var _this;
684
- _this = Component.call(this, entity) || this, _this._softness = new Vector2(0, 0), _this._alphaClip = false;
685
- _this._onSoftnessChanged = _this._onSoftnessChanged.bind(_this);
686
- // @ts-ignore
687
- _this._softness._onValueChanged = _this._onSoftnessChanged;
688
- return _this;
689
- }
690
- var _proto = RectMask2D.prototype;
691
- /**
692
- * @internal
693
- */ _proto._getWorldRect = function _getWorldRect(out) {
694
- var transform = this.entity.transform;
695
- var _transform_size = transform.size, width = _transform_size.x, height = _transform_size.y;
696
- if (!width || !height) {
697
- return false;
698
- }
699
- var _transform_pivot = transform.pivot, pivotX = _transform_pivot.x, pivotY = _transform_pivot.y;
700
- var left = -width * pivotX;
701
- var right = width * (1 - pivotX);
702
- var bottom = -height * pivotY;
703
- var top = height * (1 - pivotY);
704
- var worldMatrix = transform.worldMatrix;
705
- var corner0 = RectMask2D._tempCorner0;
706
- var corner1 = RectMask2D._tempCorner1;
707
- var corner2 = RectMask2D._tempCorner2;
708
- var corner3 = RectMask2D._tempCorner3;
709
- Vector3.transformCoordinate(corner0.set(left, bottom, 0), worldMatrix, corner0);
710
- Vector3.transformCoordinate(corner1.set(left, top, 0), worldMatrix, corner1);
711
- Vector3.transformCoordinate(corner2.set(right, bottom, 0), worldMatrix, corner2);
712
- Vector3.transformCoordinate(corner3.set(right, top, 0), worldMatrix, corner3);
713
- var minX = Math.min(corner0.x, corner1.x, corner2.x, corner3.x);
714
- var minY = Math.min(corner0.y, corner1.y, corner2.y, corner3.y);
715
- var maxX = Math.max(corner0.x, corner1.x, corner2.x, corner3.x);
716
- var maxY = Math.max(corner0.y, corner1.y, corner2.y, corner3.y);
717
- out.set(minX, minY, maxX, maxY);
718
- return true;
719
- };
720
- /**
721
- * @internal
722
- */ _proto._containsWorldPoint = function _containsWorldPoint(worldPoint) {
723
- var worldRect = RectMask2D._tempRect;
724
- if (!this._getWorldRect(worldRect)) {
725
- return false;
726
- }
727
- var x = worldPoint.x, y = worldPoint.y;
728
- return x >= worldRect.x && x <= worldRect.z && y >= worldRect.y && y <= worldRect.w;
271
+ var Utils = /*#__PURE__*/ function() {
272
+ function Utils() {}
273
+ Utils.setRootCanvasDirty = function setRootCanvasDirty(element) {
274
+ if (element._isRootCanvasDirty) return;
275
+ element._isRootCanvasDirty = true;
276
+ this._registerRootCanvas(element, null);
277
+ element._onRootCanvasModify == null ? void 0 : element._onRootCanvasModify.call(element, RootCanvasModifyFlags.All);
729
278
  };
730
- // @ts-ignore
731
- _proto._onEnableInScene = function _onEnableInScene() {
732
- this.entity._updateUIHierarchyVersion(UICanvas._hierarchyCounter);
279
+ Utils.setRootCanvas = function setRootCanvas(element, rootCanvas) {
280
+ element._isRootCanvasDirty = false;
281
+ this._registerRootCanvas(element, rootCanvas);
282
+ var fromEntity = _instanceof(element, UICanvas) ? element.entity.parent : element.entity;
283
+ var _rootCanvas_entity_parent;
284
+ var toEntity = (_rootCanvas_entity_parent = rootCanvas == null ? void 0 : rootCanvas.entity.parent) != null ? _rootCanvas_entity_parent : null;
285
+ this._registerListener(fromEntity, toEntity, element._rootCanvasListener, element._rootCanvasListeningEntities);
733
286
  };
734
- // @ts-ignore
735
- _proto._onDisableInScene = function _onDisableInScene() {
736
- this.entity._updateUIHierarchyVersion(UICanvas._hierarchyCounter);
287
+ Utils.cleanRootCanvas = function cleanRootCanvas(element) {
288
+ this._registerRootCanvas(element, null);
289
+ this._unRegisterListener(element._rootCanvasListener, element._rootCanvasListeningEntities);
737
290
  };
738
- _proto._onClone = function _onClone(target) {
739
- // RectMask2D extends Component directly, so it has no parent clone hook to call.
740
- var targetSoftness = target._softness;
741
- // @ts-ignore
742
- targetSoftness._onValueChanged = null;
743
- targetSoftness.copyFrom(this._softness);
744
- target._clampSoftness();
745
- // @ts-ignore
746
- targetSoftness._onValueChanged = target._onSoftnessChanged;
747
- };
748
- _proto._onDestroy = function _onDestroy() {
749
- // @ts-ignore
750
- this._softness._onValueChanged = null;
751
- this._softness = null;
752
- Component.prototype._onDestroy.call(this);
291
+ Utils.searchRootCanvasInParents = function searchRootCanvasInParents(element) {
292
+ var entity = _instanceof(element, UICanvas) ? element.entity.parent : element.entity;
293
+ while(entity){
294
+ // @ts-ignore
295
+ var components = entity._components;
296
+ for(var i = 0, n = components.length; i < n; i++){
297
+ var component = components[i];
298
+ if (component.enabled && _instanceof(component, UICanvas) && component._isRootCanvas) {
299
+ return component;
300
+ }
301
+ }
302
+ entity = entity.parent;
303
+ }
304
+ return null;
753
305
  };
754
- _proto._onSoftnessChanged = function _onSoftnessChanged() {
755
- this._clampSoftness();
306
+ Utils.setGroupDirty = function setGroupDirty(element) {
307
+ if (element._isGroupDirty) return;
308
+ element._isGroupDirty = true;
309
+ this._registerGroup(element, null);
310
+ element._onGroupModify(GroupModifyFlags.All);
756
311
  };
757
- _proto._clampSoftness = function _clampSoftness() {
758
- var softness = this._softness;
759
- if (softness.x < 0) {
760
- softness.x = 0;
761
- }
762
- if (softness.y < 0) {
763
- softness.y = 0;
312
+ Utils.setGroup = function setGroup(element, group) {
313
+ element._isGroupDirty = false;
314
+ this._registerGroup(element, group);
315
+ var rootCanvas = element._getRootCanvas();
316
+ if (rootCanvas) {
317
+ var fromEntity = _instanceof(element, UIGroup) ? element.entity.parent : element.entity;
318
+ var _group_entity;
319
+ var toEntity = (_group_entity = group == null ? void 0 : group.entity) != null ? _group_entity : rootCanvas.entity.parent;
320
+ this._registerListener(fromEntity, toEntity, element._groupListener, element._groupListeningEntities);
321
+ } else {
322
+ this._unRegisterListener(element._groupListener, element._groupListeningEntities);
764
323
  }
765
324
  };
766
- _create_class(RectMask2D, [
767
- {
768
- key: "softness",
769
- get: /**
770
- * Soft clipping width on X/Y axis in world space.
771
- */ function get() {
772
- return this._softness;
773
- },
774
- set: function set(value) {
775
- var softness = this._softness;
776
- if (softness === value) {
777
- return;
778
- }
779
- if (softness.x !== value.x || softness.y !== value.y) {
780
- softness.copyFrom(value);
781
- this._clampSoftness();
325
+ Utils.cleanGroup = function cleanGroup(element) {
326
+ this._registerGroup(element, null);
327
+ this._unRegisterListener(element._groupListener, element._groupListeningEntities);
328
+ };
329
+ Utils.searchGroupInParents = function searchGroupInParents(element) {
330
+ var rootCanvas = element._getRootCanvas();
331
+ if (!rootCanvas) return null;
332
+ var entity = _instanceof(element, UIGroup) ? element.entity.parent : element.entity;
333
+ var rootCanvasParent = rootCanvas.entity.parent;
334
+ while(entity && entity !== rootCanvasParent){
335
+ // @ts-ignore
336
+ var components = entity._components;
337
+ for(var i = 0, n = components.length; i < n; i++){
338
+ var component = components[i];
339
+ if (component.enabled && _instanceof(component, UIGroup)) {
340
+ return component;
782
341
  }
783
342
  }
784
- },
785
- {
786
- key: "alphaClip",
787
- get: /**
788
- * Whether to enable hard clip (discard) when outside the rect.
789
- */ function get() {
790
- return this._alphaClip;
791
- },
792
- set: function set(value) {
793
- this._alphaClip = value;
794
- }
343
+ entity = entity.parent;
795
344
  }
796
- ]);
797
- return RectMask2D;
798
- }(Component);
799
- RectMask2D._tempRect = new Vector4();
800
- RectMask2D._tempCorner0 = new Vector3();
801
- RectMask2D._tempCorner1 = new Vector3();
802
- RectMask2D._tempCorner2 = new Vector3();
803
- RectMask2D._tempCorner3 = new Vector3();
804
- RectMask2D = __decorate([
805
- dependentComponents(UITransform, DependentMode.AutoAdd)
806
- ], RectMask2D);
807
-
808
- var UIGroup = /*#__PURE__*/ function(Component) {
809
- _inherits(UIGroup, Component);
810
- function UIGroup(entity) {
811
- var _this;
812
- _this = Component.call(this, entity) || this, /** @internal */ _this._indexInGroup = -1, /** @internal */ _this._indexInRootCanvas = -1, /** @internal */ _this._disorderedElements = new DisorderedArray(), /** @internal */ _this._globalAlpha = 1, /** @internal */ _this._globalInteractive = true, _this._alpha = 1, _this._interactive = true, _this._ignoreParentGroup = false, /** @internal */ _this._rootCanvasListeningEntities = [], /** @internal */ _this._groupListeningEntities = [], /** @internal */ _this._isRootCanvasDirty = false, /** @internal */ _this._isGroupDirty = false, /** @internal */ _this._groupDirtyFlags = 0;
813
- _this._rootCanvasListener = _this._rootCanvasListener.bind(_this);
814
- _this._groupListener = _this._groupListener.bind(_this);
815
- return _this;
816
- }
817
- var _proto = UIGroup.prototype;
818
- /**
819
- * @internal
820
- */ _proto._getGlobalAlpha = function _getGlobalAlpha() {
821
- if (this._isContainDirtyFlag(1)) {
822
- if (this._ignoreParentGroup) {
823
- this._globalAlpha = this._alpha;
824
- } else {
825
- var parentGroup = this._getGroup();
826
- this._globalAlpha = this._alpha * (parentGroup ? parentGroup._getGlobalAlpha() : 1);
345
+ return null;
346
+ };
347
+ Utils._registerRootCanvas = function _registerRootCanvas(element, canvas) {
348
+ var preCanvas = element._rootCanvas;
349
+ if (preCanvas !== canvas) {
350
+ if (preCanvas) {
351
+ var replaced = preCanvas._disorderedElements.deleteByIndex(element._indexInRootCanvas);
352
+ replaced && (replaced._indexInRootCanvas = element._indexInRootCanvas);
353
+ element._indexInRootCanvas = -1;
827
354
  }
828
- this._setDirtyFlagFalse(1);
355
+ if (canvas) {
356
+ var disorderedElements = canvas._disorderedElements;
357
+ element._indexInRootCanvas = disorderedElements.length;
358
+ disorderedElements.add(element);
359
+ }
360
+ element._rootCanvas = canvas;
829
361
  }
830
- return this._globalAlpha;
831
362
  };
832
- /**
833
- * @internal
834
- */ _proto._getGlobalInteractive = function _getGlobalInteractive() {
835
- if (this._isContainDirtyFlag(2)) {
836
- if (this._ignoreParentGroup) {
837
- this._globalInteractive = this._interactive;
838
- } else {
839
- var parentGroup = this._getGroup();
840
- this._globalInteractive = this._interactive && (!parentGroup || parentGroup._getGlobalInteractive());
363
+ Utils._registerGroup = function _registerGroup(element, group) {
364
+ var preGroup = element._group;
365
+ if (preGroup !== group) {
366
+ if (preGroup) {
367
+ var replaced = preGroup._disorderedElements.deleteByIndex(element._indexInGroup);
368
+ replaced && (replaced._indexInGroup = element._indexInGroup);
369
+ element._indexInGroup = -1;
841
370
  }
842
- this._setDirtyFlagFalse(2);
371
+ if (group) {
372
+ var disorderedElements = group._disorderedElements;
373
+ element._indexInGroup = disorderedElements.length;
374
+ disorderedElements.add(element);
375
+ }
376
+ element._group = group;
377
+ element._onGroupModify(GroupModifyFlags.All);
843
378
  }
844
- return this._globalInteractive;
845
- };
846
- // @ts-ignore
847
- _proto._onEnableInScene = function _onEnableInScene() {
848
- Utils.setRootCanvasDirty(this);
849
- Utils.setGroupDirty(this);
850
- // @ts-ignore
851
- this.entity._dispatchModify(EntityUIModifyFlags.GroupEnableInScene);
852
- };
853
- // @ts-ignore
854
- _proto._onDisableInScene = function _onDisableInScene() {
855
- Utils.cleanRootCanvas(this);
856
- Utils.cleanGroup(this);
857
- var disorderedElements = this._disorderedElements;
858
- disorderedElements.forEach(function(element) {
859
- Utils.setGroupDirty(element);
860
- });
861
- disorderedElements.length = 0;
862
- disorderedElements.garbageCollection();
863
- this._isRootCanvasDirty = this._isGroupDirty = false;
864
- };
865
- /**
866
- * @internal
867
- */ _proto._getRootCanvas = function _getRootCanvas() {
868
- this._isRootCanvasDirty && Utils.setRootCanvas(this, Utils.searchRootCanvasInParents(this));
869
- return this._rootCanvas;
870
- };
871
- /**
872
- * @internal
873
- */ _proto._getGroup = function _getGroup() {
874
- this._isGroupDirty && Utils.setGroup(this, Utils.searchGroupInParents(this));
875
- return this._group;
876
379
  };
877
- /**
878
- * @internal
879
- */ _proto._groupListener = function _groupListener(flag) {
880
- if (flag === EntityModifyFlags.Parent || flag === EntityUIModifyFlags.GroupEnableInScene) {
881
- Utils.setGroupDirty(this);
380
+ Utils._registerListener = function _registerListener(entity, root, listener, listeningEntities) {
381
+ var count = 0;
382
+ while(entity && entity !== root){
383
+ var preEntity = listeningEntities[count];
384
+ if (preEntity !== entity) {
385
+ // @ts-ignore
386
+ preEntity == null ? void 0 : preEntity._unRegisterModifyListener(listener);
387
+ listeningEntities[count] = entity;
388
+ // @ts-ignore
389
+ entity._registerModifyListener(listener);
390
+ }
391
+ entity = entity.parent;
392
+ count++;
882
393
  }
394
+ listeningEntities.length = count;
883
395
  };
884
- /**
885
- * @internal
886
- */ _proto._rootCanvasListener = function _rootCanvasListener(flag) {
887
- if (flag === EntityModifyFlags.Parent || flag === EntityUIModifyFlags.CanvasEnableInScene) {
888
- Utils.setRootCanvasDirty(this);
889
- Utils.setGroupDirty(this);
396
+ Utils._unRegisterListener = function _unRegisterListener(listener, listeningEntities) {
397
+ for(var i = 0, n = listeningEntities.length; i < n; i++){
398
+ // @ts-ignore
399
+ listeningEntities[i]._unRegisterModifyListener(listener);
890
400
  }
401
+ listeningEntities.length = 0;
891
402
  };
403
+ return Utils;
404
+ }();
405
+
406
+ /**
407
+ * @internal
408
+ * Visual-layering driven UI batching: solve visual correctness first, batching falls out for free.
409
+ *
410
+ * Think of it as stacking elements onto numbered shelves (depths):
411
+ * - Non-overlapping elements share shelf 0 — free to cluster regardless of material.
412
+ * - Overlapping + batch-compatible — share the same shelf, still cluster.
413
+ * - Overlapping + batch-incompatible — bumped one shelf higher (drawn on top).
414
+ *
415
+ * `depth` is a global tag, not a spatial group: distant elements at the same visual layer
416
+ * share the same depth and get clustered together. Once depth is assigned, sort by
417
+ * (depth, material, texture, hierarchyIndex) — visual order is locked, batching is the
418
+ * by-product of materials clustering within each depth band.
419
+ *
420
+ * Overlap detection is accelerated by a 10×10 spatial grid. Grid origin and cell size
421
+ * are derived from the union AABB of input elements (the bounds transform itself is the
422
+ * work the loop must do anyway, so the union accumulation just piggybacks). This stays
423
+ * correct across SS/WS canvases, any pivot, and any element distribution — no dependency
424
+ * on canvas configuration.
425
+ */ var UIBatchSorter = /*#__PURE__*/ function() {
426
+ function UIBatchSorter() {}
892
427
  /**
893
- * @internal
894
- */ _proto._onGroupModify = function _onGroupModify(flags, isPass) {
895
- if (isPass === void 0) isPass = false;
896
- if (isPass && this._ignoreParentGroup) return;
897
- if (this._isContainDirtyFlags(flags)) return;
898
- this._setDirtyFlagTrue(flags);
899
- this._disorderedElements.forEach(function(element) {
900
- element._onGroupModify(flags, true);
901
- });
902
- };
903
- _proto._isContainDirtyFlags = function _isContainDirtyFlags(targetDirtyFlags) {
904
- return (this._groupDirtyFlags & targetDirtyFlags) === targetDirtyFlags;
905
- };
906
- _proto._isContainDirtyFlag = function _isContainDirtyFlag(type) {
907
- return (this._groupDirtyFlags & type) != 0;
908
- };
909
- _proto._setDirtyFlagTrue = function _setDirtyFlagTrue(type) {
910
- this._groupDirtyFlags |= type;
911
- };
912
- _proto._setDirtyFlagFalse = function _setDirtyFlagFalse(type) {
913
- this._groupDirtyFlags &= ~type;
914
- };
915
- _create_class(UIGroup, [
916
- {
917
- key: "ignoreParentGroup",
918
- get: /**
919
- * Whether to ignore the parent group.
920
- * @remarks If this parameter set to `true`,
921
- * all settings of the parent group will be ignored.
922
- */ function get() {
923
- return this._ignoreParentGroup;
924
- },
925
- set: function set(value) {
926
- if (this._ignoreParentGroup !== value) {
927
- this._ignoreParentGroup = value;
928
- this._onGroupModify(3);
929
- }
930
- }
931
- },
932
- {
933
- key: "interactive",
934
- get: /**
935
- * Whether the group is interactive.
936
- */ function get() {
937
- return this._interactive;
938
- },
939
- set: function set(value) {
940
- if (this._interactive !== value) {
941
- this._interactive = value;
942
- this._onGroupModify(2);
943
- }
944
- }
945
- },
946
- {
947
- key: "alpha",
948
- get: /**
949
- * The alpha value of the group.
950
- */ function get() {
951
- return this._alpha;
952
- },
953
- set: function set(value) {
954
- value = Math.max(0, Math.min(value, 1));
955
- if (this._alpha !== value) {
956
- this._alpha = value;
957
- this._onGroupModify(1);
958
- }
959
- }
960
- }
961
- ]);
962
- return UIGroup;
963
- }(Component);
964
- __decorate([
965
- ignoreClone
966
- ], UIGroup.prototype, "_indexInGroup", void 0);
967
- __decorate([
968
- ignoreClone
969
- ], UIGroup.prototype, "_indexInRootCanvas", void 0);
970
- __decorate([
971
- ignoreClone
972
- ], UIGroup.prototype, "_globalAlpha", void 0);
973
- __decorate([
974
- ignoreClone
975
- ], UIGroup.prototype, "_globalInteractive", void 0);
976
- __decorate([
977
- ignoreClone
978
- ], UIGroup.prototype, "_rootCanvasListeningEntities", void 0);
979
- __decorate([
980
- ignoreClone
981
- ], UIGroup.prototype, "_groupListeningEntities", void 0);
982
- __decorate([
983
- ignoreClone
984
- ], UIGroup.prototype, "_isRootCanvasDirty", void 0);
985
- __decorate([
986
- ignoreClone
987
- ], UIGroup.prototype, "_isGroupDirty", void 0);
988
- __decorate([
989
- ignoreClone
990
- ], UIGroup.prototype, "_groupDirtyFlags", void 0);
991
- __decorate([
992
- ignoreClone
993
- ], UIGroup.prototype, "_groupListener", null);
994
- __decorate([
995
- ignoreClone
996
- ], UIGroup.prototype, "_rootCanvasListener", null);
997
- var GroupModifyFlags = /*#__PURE__*/ function(GroupModifyFlags) {
998
- GroupModifyFlags[GroupModifyFlags["None"] = 0] = "None";
999
- GroupModifyFlags[GroupModifyFlags["GlobalAlpha"] = 1] = "GlobalAlpha";
1000
- GroupModifyFlags[GroupModifyFlags["GlobalInteractive"] = 2] = "GlobalInteractive";
1001
- GroupModifyFlags[GroupModifyFlags["All"] = 3] = "All";
1002
- return GroupModifyFlags;
1003
- }({});
1004
-
1005
- var UIRenderer = /*#__PURE__*/ function(Renderer) {
1006
- _inherits(UIRenderer, Renderer);
1007
- function UIRenderer(entity) {
1008
- var _this;
1009
- _this = Renderer.call(this, entity) || this, /**
1010
- * Custom boundary for raycast detection.
1011
- * @remarks this is based on `this.entity.transform`.
1012
- */ _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 = [], /** @internal */ _this._rectMasks = [], /** @internal */ _this._rectMaskRect = new Vector4(), /** @internal */ _this._rectMaskEnabled = false, /** @internal */ _this._rectMaskSoftness = new Vector4(), /** @internal */ _this._rectMaskHardClip = false, _this._raycastEnabled = false, _this._color = new Color(1, 1, 1, 1);
1013
- _this._dirtyUpdateFlag = RendererUpdateFlags.WorldVolume | 2;
1014
- _this._onColorChanged = _this._onColorChanged.bind(_this);
1015
- //@ts-ignore
1016
- _this._color._onValueChanged = _this._onColorChanged;
1017
- _this._groupListener = _this._groupListener.bind(_this);
1018
- _this._rootCanvasListener = _this._rootCanvasListener.bind(_this);
1019
- _this.shaderData.setFloat(UIRenderer._rectClipEnabledProperty, 0);
1020
- _this.shaderData.setVector4(UIRenderer._rectClipSoftnessProperty, _this._rectMaskSoftness);
1021
- _this.shaderData.setFloat(UIRenderer._rectClipHardClipProperty, 0);
1022
- return _this;
1023
- }
1024
- var _proto = UIRenderer.prototype;
1025
- // @ts-ignore
1026
- _proto._canBatch = function _canBatch(preElement, curElement) {
1027
- return VertexMergeBatcher.canBatchSprite(preElement, curElement);
1028
- };
1029
- // @ts-ignore
1030
- _proto._batch = function _batch(preElement, curElement) {
1031
- VertexMergeBatcher.batch(preElement, curElement);
1032
- };
1033
- // @ts-ignore
1034
- _proto._updateTransformShaderData = function _updateTransformShaderData(context, onlyMVP) {
1035
- // @ts-ignore
1036
- this._updateWorldSpaceTransformShaderData(context, onlyMVP);
1037
- };
1038
- // @ts-ignore
1039
- _proto._prepareRender = function _prepareRender(context) {
1040
- // Update once per frame per renderer, not influenced by batched
1041
- if (this._renderFrameCount !== this.engine.time.frameCount) {
1042
- this._update(context);
1043
- }
1044
- this._updateRectMaskClipState();
1045
- this._render(context);
1046
- // union camera global macro and renderer macro.
1047
- ShaderMacroCollection.unionCollection(context.camera._globalShaderMacro, // @ts-ignore
1048
- this.shaderData._macroCollection, //@ts-ignore
1049
- this._globalShaderMacro);
1050
- };
1051
- // @ts-ignore
1052
- _proto._onEnableInScene = function _onEnableInScene() {
1053
- // @ts-ignore
1054
- this._overrideUpdate && this.scene._componentsManager.addOnUpdateRenderers(this);
1055
- this.entity._updateUIHierarchyVersion(UICanvas._hierarchyCounter);
1056
- Utils.setRootCanvasDirty(this);
1057
- Utils.setGroupDirty(this);
1058
- };
1059
- // @ts-ignore
1060
- _proto._onDisableInScene = function _onDisableInScene() {
1061
- // @ts-ignore
1062
- this._overrideUpdate && this.scene._componentsManager.removeOnUpdateRenderers(this);
1063
- this.entity._updateUIHierarchyVersion(UICanvas._hierarchyCounter);
1064
- Utils.cleanRootCanvas(this);
1065
- Utils.cleanGroup(this);
1066
- };
1067
- /**
1068
- * @internal
1069
- */ _proto._getGlobalAlpha = function _getGlobalAlpha() {
1070
- var _this__getGroup;
1071
- var _this__getGroup__getGlobalAlpha;
1072
- return (_this__getGroup__getGlobalAlpha = (_this__getGroup = this._getGroup()) == null ? void 0 : _this__getGroup._getGlobalAlpha()) != null ? _this__getGroup__getGlobalAlpha : 1;
1073
- };
1074
- /**
1075
- * @internal
1076
- */ _proto._getRootCanvas = function _getRootCanvas() {
1077
- this._isRootCanvasDirty && Utils.setRootCanvas(this, Utils.searchRootCanvasInParents(this));
1078
- return this._rootCanvas;
1079
- };
1080
- /**
1081
- * @internal
1082
- */ _proto._getGroup = function _getGroup() {
1083
- this._isGroupDirty && Utils.setGroup(this, Utils.searchGroupInParents(this));
1084
- return this._group;
1085
- };
1086
- /**
1087
- * @internal
1088
- */ _proto._groupListener = function _groupListener(flag) {
1089
- if (flag === EntityModifyFlags.Parent || flag === EntityUIModifyFlags.GroupEnableInScene) {
1090
- Utils.setGroupDirty(this);
1091
- }
1092
- };
1093
- /**
1094
- * @internal
1095
- */ _proto._rootCanvasListener = function _rootCanvasListener(flag, entity) {
1096
- switch(flag){
1097
- case EntityModifyFlags.Parent:
1098
- Utils.setRootCanvasDirty(this);
1099
- Utils.setGroupDirty(this);
1100
- case EntityModifyFlags.Child:
1101
- entity._updateUIHierarchyVersion(UICanvas._hierarchyCounter);
1102
- break;
1103
- }
1104
- };
1105
- /**
1106
- * @internal
1107
- */ _proto._onGroupModify = function _onGroupModify(flags) {
1108
- if (flags & GroupModifyFlags.GlobalAlpha) {
1109
- this._dirtyUpdateFlag |= 2;
1110
- }
1111
- };
1112
- _proto._onColorChanged = function _onColorChanged() {
1113
- this._dirtyUpdateFlag |= 2;
1114
- };
1115
- /**
1116
- * @internal
1117
- */ _proto._getChunkManager = function _getChunkManager() {
1118
- // @ts-ignore
1119
- return this.engine._batcherManager.primitiveChunkManagerUI;
1120
- };
1121
- /**
1122
- * @internal
1123
- */ _proto._setRectMasks = function _setRectMasks(rectMasks, count) {
1124
- var targetMasks = this._rectMasks;
1125
- targetMasks.length = count;
1126
- for(var i = 0; i < count; i++){
1127
- targetMasks[i] = rectMasks[i];
1128
- }
1129
- };
1130
- /**
1131
- * @internal
1132
- */ _proto._raycast = function _raycast(ray, out, distance) {
1133
- if (distance === void 0) distance = Number.MAX_SAFE_INTEGER;
1134
- var plane = UIRenderer._tempPlane;
1135
- var transform = this._transformEntity.transform;
1136
- var normal = plane.normal.copyFrom(transform.worldForward);
1137
- plane.distance = -Vector3.dot(normal, transform.worldPosition);
1138
- var curDistance = ray.intersectPlane(plane);
1139
- if (curDistance >= 0 && curDistance < distance) {
1140
- var hitPointWorld = ray.getPoint(curDistance, UIRenderer._tempVec30);
1141
- var worldMatrixInv = UIRenderer._tempMat;
1142
- Matrix.invert(transform.worldMatrix, worldMatrixInv);
1143
- var localPosition = UIRenderer._tempVec31;
1144
- Vector3.transformCoordinate(hitPointWorld, worldMatrixInv, localPosition);
1145
- if (this._hitTest(localPosition) && this._isRaycastVisibleByRectMask(hitPointWorld) && this._isRaycastVisibleByMask(hitPointWorld)) {
1146
- out.component = this;
1147
- out.distance = curDistance;
1148
- out.entity = this.entity;
1149
- out.normal.copyFrom(normal);
1150
- out.point.copyFrom(hitPointWorld);
1151
- return true;
1152
- }
1153
- }
1154
- return false;
1155
- };
1156
- _proto._hitTest = function _hitTest(localPosition) {
1157
- var x = localPosition.x, y = localPosition.y;
1158
- var uiTransform = this._transformEntity.transform;
1159
- var _uiTransform_size = uiTransform.size, width = _uiTransform_size.x, height = _uiTransform_size.y;
1160
- var _uiTransform_pivot = uiTransform.pivot, pivotX = _uiTransform_pivot.x, pivotY = _uiTransform_pivot.y;
1161
- var _this_raycastPadding = this.raycastPadding, paddingLeft = _this_raycastPadding.x, paddingBottom = _this_raycastPadding.y, paddingRight = _this_raycastPadding.z, paddingTop = _this_raycastPadding.w;
1162
- return x >= -width * pivotX + paddingLeft && x <= width * (1 - pivotX) - paddingRight && y >= -height * pivotY + paddingTop && y <= height * (1 - pivotY) - paddingBottom;
1163
- };
1164
- _proto._isRaycastVisibleByMask = function _isRaycastVisibleByMask(hitPointWorld) {
1165
- var maskInteraction = this._maskInteraction;
1166
- if (maskInteraction === SpriteMaskInteraction.None) {
1167
- return true;
1168
- }
1169
- // @ts-ignore
1170
- return this.scene._maskManager.isVisibleByMask(maskInteraction, this._maskLayer, hitPointWorld);
1171
- };
1172
- _proto._isRaycastVisibleByRectMask = function _isRaycastVisibleByRectMask(hitPointWorld) {
1173
- var rectMasks = this._rectMasks;
1174
- for(var i = 0, n = rectMasks.length; i < n; i++){
1175
- var rectMask = rectMasks[i];
1176
- if (!rectMask.enabled || !rectMask.entity.isActiveInHierarchy) {
1177
- continue;
1178
- }
1179
- if (!rectMask._containsWorldPoint(hitPointWorld)) {
1180
- return false;
1181
- }
1182
- }
1183
- return true;
1184
- };
1185
- _proto._updateRectMaskClipState = function _updateRectMaskClipState() {
1186
- var rectMasks = this._rectMasks;
1187
- var count = rectMasks.length;
1188
- if (count <= 0) {
1189
- this._resetRectMaskClipState();
1190
- return;
1191
- }
1192
- var minX = Number.NEGATIVE_INFINITY;
1193
- var minY = Number.NEGATIVE_INFINITY;
1194
- var maxX = Number.POSITIVE_INFINITY;
1195
- var maxY = Number.POSITIVE_INFINITY;
1196
- var clipSoftnessLeft = 0;
1197
- var clipSoftnessBottom = 0;
1198
- var clipSoftnessRight = 0;
1199
- var clipSoftnessTop = 0;
1200
- var clipHardClip = false;
1201
- var hasActiveMask = false;
1202
- var tempRect = UIRenderer._tempRect;
1203
- for(var i = 0; i < count; i++){
1204
- var rectMask = rectMasks[i];
1205
- if (!rectMask.enabled || !rectMask.entity.isActiveInHierarchy) {
1206
- continue;
1207
- }
1208
- hasActiveMask = true;
1209
- var softness = rectMask.softness;
1210
- if (!clipHardClip && rectMask.alphaClip) {
1211
- clipHardClip = true;
1212
- }
1213
- if (!rectMask._getWorldRect(tempRect)) {
1214
- minX = 1;
1215
- minY = 1;
1216
- maxX = 0;
1217
- maxY = 0;
1218
- break;
1219
- }
1220
- if (tempRect.x > minX) {
1221
- minX = tempRect.x;
1222
- clipSoftnessLeft = softness.x;
1223
- }
1224
- if (tempRect.y > minY) {
1225
- minY = tempRect.y;
1226
- clipSoftnessBottom = softness.y;
1227
- }
1228
- if (tempRect.z < maxX) {
1229
- maxX = tempRect.z;
1230
- clipSoftnessRight = softness.x;
1231
- }
1232
- if (tempRect.w < maxY) {
1233
- maxY = tempRect.w;
1234
- clipSoftnessTop = softness.y;
1235
- }
1236
- }
1237
- if (!hasActiveMask) {
1238
- this._resetRectMaskClipState();
1239
- return;
1240
- }
1241
- if (minX >= maxX || minY >= maxY) {
1242
- minX = 1;
1243
- minY = 1;
1244
- maxX = 0;
1245
- maxY = 0;
1246
- clipSoftnessLeft = 0;
1247
- clipSoftnessBottom = 0;
1248
- clipSoftnessRight = 0;
1249
- clipSoftnessTop = 0;
1250
- }
1251
- var rectMaskRect = this._rectMaskRect;
1252
- if (rectMaskRect.x !== minX || rectMaskRect.y !== minY || rectMaskRect.z !== maxX || rectMaskRect.w !== maxY) {
1253
- rectMaskRect.set(minX, minY, maxX, maxY);
1254
- this.shaderData.setVector4(UIRenderer._rectClipRectProperty, rectMaskRect);
1255
- }
1256
- var rectMaskSoftness = this._rectMaskSoftness;
1257
- if (rectMaskSoftness.x !== clipSoftnessLeft || rectMaskSoftness.y !== clipSoftnessBottom || rectMaskSoftness.z !== clipSoftnessRight || rectMaskSoftness.w !== clipSoftnessTop) {
1258
- rectMaskSoftness.set(clipSoftnessLeft, clipSoftnessBottom, clipSoftnessRight, clipSoftnessTop);
1259
- this.shaderData.setVector4(UIRenderer._rectClipSoftnessProperty, rectMaskSoftness);
1260
- }
1261
- if (this._rectMaskHardClip !== clipHardClip) {
1262
- this._rectMaskHardClip = clipHardClip;
1263
- this.shaderData.setFloat(UIRenderer._rectClipHardClipProperty, clipHardClip ? 1 : 0);
1264
- }
1265
- if (!this._rectMaskEnabled) {
1266
- this._rectMaskEnabled = true;
1267
- this.shaderData.setFloat(UIRenderer._rectClipEnabledProperty, 1);
1268
- }
1269
- };
1270
- _proto._resetRectMaskClipState = function _resetRectMaskClipState() {
1271
- if (this._rectMaskEnabled) {
1272
- this._rectMaskEnabled = false;
1273
- this.shaderData.setFloat(UIRenderer._rectClipEnabledProperty, 0);
1274
- }
1275
- var rectMaskSoftness = this._rectMaskSoftness;
1276
- if (rectMaskSoftness.x !== 0 || rectMaskSoftness.y !== 0 || rectMaskSoftness.z !== 0 || rectMaskSoftness.w !== 0) {
1277
- rectMaskSoftness.set(0, 0, 0, 0);
1278
- this.shaderData.setVector4(UIRenderer._rectClipSoftnessProperty, rectMaskSoftness);
1279
- }
1280
- if (this._rectMaskHardClip) {
1281
- this._rectMaskHardClip = false;
1282
- this.shaderData.setFloat(UIRenderer._rectClipHardClipProperty, 0);
1283
- }
1284
- };
1285
- _proto._onDestroy = function _onDestroy() {
1286
- if (this._subChunk) {
1287
- this._getChunkManager().freeSubChunk(this._subChunk);
1288
- this._subChunk = null;
1289
- }
1290
- Renderer.prototype._onDestroy.call(this);
1291
- //@ts-ignore
1292
- this._color._onValueChanged = null;
1293
- this._color = null;
1294
- this._rectMasks = null;
1295
- this._rectMaskSoftness = null;
1296
- };
1297
- _create_class(UIRenderer, [
1298
- {
1299
- key: "color",
1300
- get: /**
1301
- * Rendering color for the ui renderer.
1302
- */ function get() {
1303
- return this._color;
1304
- },
1305
- set: function set(value) {
1306
- if (this._color !== value) {
1307
- this._color.copyFrom(value);
1308
- }
1309
- }
1310
- },
1311
- {
1312
- key: "maskLayer",
1313
- get: /**
1314
- * The mask layer the ui renderer belongs to.
1315
- */ function get() {
1316
- return this._maskLayer;
1317
- },
1318
- set: function set(value) {
1319
- this._maskLayer = value;
1320
- }
1321
- },
1322
- {
1323
- key: "maskInteraction",
1324
- get: /**
1325
- * Interacts with the masks.
1326
- */ function get() {
1327
- return this._maskInteraction;
1328
- },
1329
- set: function set(value) {
1330
- if (this._maskInteraction !== value) {
1331
- this._maskInteraction = value;
1332
- }
1333
- }
1334
- },
1335
- {
1336
- key: "raycastEnabled",
1337
- get: /**
1338
- * Whether this renderer be picked up by raycast.
1339
- */ function get() {
1340
- return this._raycastEnabled;
1341
- },
1342
- set: function set(value) {
1343
- this._raycastEnabled = value;
1344
- }
1345
- }
1346
- ]);
1347
- return UIRenderer;
1348
- }(Renderer);
1349
- /** @internal */ UIRenderer._tempVec20 = new Vector2();
1350
- /** @internal */ UIRenderer._tempVec30 = new Vector3();
1351
- /** @internal */ UIRenderer._tempVec31 = new Vector3();
1352
- /** @internal */ UIRenderer._tempMat = new Matrix();
1353
- /** @internal */ UIRenderer._tempPlane = new Plane();
1354
- /** @internal */ UIRenderer._textureProperty = ShaderProperty.getByName("renderer_UITexture");
1355
- /** @internal */ UIRenderer._rectClipRectProperty = ShaderProperty.getByName("renderer_UIRectClipRect");
1356
- /** @internal */ UIRenderer._rectClipEnabledProperty = ShaderProperty.getByName("renderer_UIRectClipEnabled");
1357
- /** @internal */ UIRenderer._rectClipSoftnessProperty = ShaderProperty.getByName("renderer_UIRectClipSoftness");
1358
- /** @internal */ UIRenderer._rectClipHardClipProperty = ShaderProperty.getByName("renderer_UIRectClipHardClip");
1359
- /** @internal */ UIRenderer._tempRect = new Vector4();
1360
- __decorate([
1361
- ignoreClone
1362
- ], UIRenderer.prototype, "_indexInRootCanvas", void 0);
1363
- __decorate([
1364
- ignoreClone
1365
- ], UIRenderer.prototype, "_isRootCanvasDirty", void 0);
1366
- __decorate([
1367
- ignoreClone
1368
- ], UIRenderer.prototype, "_rootCanvasListeningEntities", void 0);
1369
- __decorate([
1370
- ignoreClone
1371
- ], UIRenderer.prototype, "_indexInGroup", void 0);
1372
- __decorate([
1373
- ignoreClone
1374
- ], UIRenderer.prototype, "_isGroupDirty", void 0);
1375
- __decorate([
1376
- ignoreClone
1377
- ], UIRenderer.prototype, "_groupListeningEntities", void 0);
1378
- __decorate([
1379
- ignoreClone
1380
- ], UIRenderer.prototype, "_subChunk", void 0);
1381
- __decorate([
1382
- ignoreClone
1383
- ], UIRenderer.prototype, "_rectMasks", void 0);
1384
- __decorate([
1385
- ignoreClone
1386
- ], UIRenderer.prototype, "_rectMaskRect", void 0);
1387
- __decorate([
1388
- ignoreClone
1389
- ], UIRenderer.prototype, "_rectMaskEnabled", void 0);
1390
- __decorate([
1391
- ignoreClone
1392
- ], UIRenderer.prototype, "_rectMaskSoftness", void 0);
1393
- __decorate([
1394
- ignoreClone
1395
- ], UIRenderer.prototype, "_rectMaskHardClip", void 0);
1396
- __decorate([
1397
- ignoreClone
1398
- ], UIRenderer.prototype, "_groupListener", null);
1399
- __decorate([
1400
- ignoreClone
1401
- ], UIRenderer.prototype, "_rootCanvasListener", null);
1402
- __decorate([
1403
- ignoreClone
1404
- ], UIRenderer.prototype, "_onColorChanged", null);
1405
- UIRenderer = __decorate([
1406
- dependentComponents(UITransform, DependentMode.AutoAdd)
1407
- ], UIRenderer);
1408
- /**
1409
- * @remarks Extends `RendererUpdateFlags`.
1410
- */ var UIRendererUpdateFlags = /*#__PURE__*/ function(UIRendererUpdateFlags) {
1411
- UIRendererUpdateFlags[UIRendererUpdateFlags["Color"] = 2] = "Color";
1412
- return UIRendererUpdateFlags;
1413
- }({});
1414
-
1415
- var UICanvas = /*#__PURE__*/ function(Component) {
1416
- _inherits(UICanvas, Component);
1417
- function UICanvas(entity) {
1418
- var _this;
1419
- _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._renderElements = [], /** @internal */ _this._batchedRenderElements = [], /** @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();
1420
- _this._onCanvasSizeListener = _this._onCanvasSizeListener.bind(_this);
1421
- _this._onCameraModifyListener = _this._onCameraModifyListener.bind(_this);
1422
- _this._onCameraTransformListener = _this._onCameraTransformListener.bind(_this);
1423
- _this._onReferenceResolutionChanged = _this._onReferenceResolutionChanged.bind(_this);
1424
- // @ts-ignore
1425
- _this._referenceResolution._onValueChanged = _this._onReferenceResolutionChanged;
1426
- _this._rootCanvasListener = _this._rootCanvasListener.bind(_this);
1427
- _this._centerDirtyFlag = entity.registerWorldChangeFlag();
1428
- return _this;
1429
- }
1430
- var _proto = UICanvas.prototype;
1431
- /**
1432
- * @internal
1433
- */ _proto._raycast = function _raycast(ray, out, distance) {
1434
- if (distance === void 0) distance = Number.MAX_SAFE_INTEGER;
1435
- var renderers = this._getRenderers();
1436
- for(var i = renderers.length - 1; i >= 0; i--){
1437
- var element = renderers[i];
1438
- if (element.raycastEnabled && element._raycast(ray, out, distance)) {
1439
- return true;
1440
- }
1441
- }
1442
- out.component = null;
1443
- out.entity = null;
1444
- out.distance = 0;
1445
- out.point.set(0, 0, 0);
1446
- out.normal.set(0, 0, 0);
1447
- return false;
1448
- };
1449
- /**
1450
- * @internal
1451
- */ _proto._getRootCanvas = function _getRootCanvas() {
1452
- return this._rootCanvas;
1453
- };
1454
- /**
1455
- * @internal
1456
- */ _proto._canRender = function _canRender(camera) {
1457
- return this._realRenderMode !== CanvasRenderMode.ScreenSpaceCamera || this._camera === camera;
1458
- };
1459
- /**
1460
- * @internal
1461
- */ _proto._canDispatchEvent = function _canDispatchEvent(camera) {
1462
- var realMode = this._realRenderMode;
1463
- if (realMode === CanvasRenderMode.ScreenSpaceOverlay) {
1464
- return true;
1465
- }
1466
- var assignedCamera = this._camera;
1467
- // @ts-ignore
1468
- return !assignedCamera || !assignedCamera._phasedActiveInScene || assignedCamera === camera;
1469
- };
1470
- /**
1471
- * @internal
1472
- */ _proto._prepareRender = function _prepareRender(context) {
1473
- var _this = this, engine = _this.engine, mode = _this._realRenderMode;
1474
- var _context_camera = context.camera, enableFrustumCulling = _context_camera.enableFrustumCulling, cullingMask = _context_camera.cullingMask, frustum = _context_camera._frustum;
1475
- var frameCount = engine.time.frameCount;
1476
- var renderElements = this._renderElements;
1477
- renderElements.length = 0;
1478
- var virtualCamera = context.virtualCamera;
1479
- this._updateSortDistance(virtualCamera.isOrthographic, virtualCamera.position, virtualCamera.forward);
1480
- var _engine_canvas = engine.canvas, width = _engine_canvas.width, height = _engine_canvas.height;
1481
- var renderers = this._getRenderers();
1482
- for(var i = 0, n = renderers.length; i < n; i++){
1483
- var renderer = renderers[i];
1484
- // Filter by camera culling mask
1485
- if (!(cullingMask & renderer.entity.layer)) {
1486
- continue;
428
+ * Reorders `elements` in place for optimal batching.
429
+ * @param elements - in hierarchy order (depth-first traversal); mutated in place
430
+ * @param canvasWorldMatrix - reduces world bounds to canvas-local for precise overlap
431
+ */ UIBatchSorter.sort = function sort(elements, canvasWorldMatrix) {
432
+ var count = elements.length;
433
+ if (count <= 1) return;
434
+ var gridDim = this._gridDim;
435
+ var entries = this._entries;
436
+ var grid = this._grid;
437
+ var dirtyCells = this._dirtyCells;
438
+ var localBoundsPool = this._localBoundsPool;
439
+ var worldToLocal = this._worldToLocal;
440
+ Matrix.invert(canvasWorldMatrix, worldToLocal);
441
+ while(entries.length < count)entries.push(new SortEntry());
442
+ // Allocate grid once, reuse forever (each cell must be a real [], not a sparse hole)
443
+ if (grid.length < gridDim) {
444
+ while(grid.length < gridDim)grid.push([]);
445
+ for(var i = 0; i < gridDim; i++){
446
+ var row = grid[i];
447
+ while(row.length < gridDim)row.push([]);
1487
448
  }
1488
- // Filter by camera frustum
1489
- if (enableFrustumCulling) {
1490
- switch(mode){
1491
- case CanvasRenderMode.ScreenSpaceOverlay:
1492
- var _renderer_bounds = renderer.bounds, min = _renderer_bounds.min, max = _renderer_bounds.max;
1493
- if (min.x > width || max.x < 0 || min.y > height || max.y < 0) {
1494
- continue;
1495
- }
1496
- break;
1497
- case CanvasRenderMode.ScreenSpaceCamera:
1498
- case CanvasRenderMode.WorldSpace:
1499
- if (!frustum.intersectsBox(renderer.bounds)) {
1500
- continue;
449
+ }
450
+ // Clear only previously-used cells (no full sweep)
451
+ for(var k = 0, n = dirtyCells.length; k < n; k += 2){
452
+ grid[dirtyCells[k]][dirtyCells[k + 1]].length = 0;
453
+ }
454
+ dirtyCells.length = 0;
455
+ // Pass 1: transform world bounds to canvas-local + accumulate the union AABB.
456
+ // Transform is already required to do precise overlap, so the union accumulation
457
+ // is essentially free — just a few minmax compares riding on the existing pass
458
+ var unionMinX = Infinity;
459
+ var unionMinY = Infinity;
460
+ var unionMaxX = -Infinity;
461
+ var unionMaxY = -Infinity;
462
+ for(var i1 = 0; i1 < count; i1++){
463
+ var _localBoundsPool, _i;
464
+ var localBounds = (_localBoundsPool = localBoundsPool)[_i = i1] || (_localBoundsPool[_i] = new BoundingBox());
465
+ BoundingBox.transform(elements[i1].component.bounds, worldToLocal, localBounds);
466
+ var min = localBounds.min, max = localBounds.max;
467
+ if (min.x < unionMinX) unionMinX = min.x;
468
+ if (min.y < unionMinY) unionMinY = min.y;
469
+ if (max.x > unionMaxX) unionMaxX = max.x;
470
+ if (max.y > unionMaxY) unionMaxY = max.y;
471
+ }
472
+ // Guard against a degenerate union (all elements collapsed onto a single point /
473
+ // axis); the grid then collapses to cell 0 which is semantically correct
474
+ var cellSizeX = Math.max(1e-6, unionMaxX - unionMinX) / gridDim;
475
+ var cellSizeY = Math.max(1e-6, unionMaxY - unionMinY) / gridDim;
476
+ var maxCell = gridDim - 1;
477
+ // Pass 2: register each element into grid cells and compute its depth
478
+ for(var i2 = 0; i2 < count; i2++){
479
+ var element = elements[i2];
480
+ var localBounds1 = localBoundsPool[i2];
481
+ var materialId = element.material.instanceId;
482
+ var textureId = element.texture ? element.texture.instanceId : 0;
483
+ // Floor + clamp guards floating-point edge cases (a `max` exactly on the union
484
+ // boundary would otherwise produce `gridDim`)
485
+ var minCellX = Math.min(maxCell, Math.max(0, Math.floor((localBounds1.min.x - unionMinX) / cellSizeX)));
486
+ var maxCellX = Math.min(maxCell, Math.max(0, Math.floor((localBounds1.max.x - unionMinX) / cellSizeX)));
487
+ var minCellY = Math.min(maxCell, Math.max(0, Math.floor((localBounds1.min.y - unionMinY) / cellSizeY)));
488
+ var maxCellY = Math.min(maxCell, Math.max(0, Math.floor((localBounds1.max.y - unionMinY) / cellSizeY)));
489
+ // Find the deepest overlapping prior, and whether that shelf has any incompatible occupant
490
+ var maxDepth = -1;
491
+ var maxDepthIncompatible = false;
492
+ for(var cellY = minCellY; cellY <= maxCellY; cellY++){
493
+ for(var cellX = minCellX; cellX <= maxCellX; cellX++){
494
+ var cell = grid[cellX][cellY];
495
+ for(var j = 0, m = cell.length; j < m; j++){
496
+ var other = cell[j];
497
+ if (!UIBatchSorter._rectOverlap(localBounds1, other.bounds)) continue;
498
+ var otherDepth = other.depth;
499
+ var otherIncompatible = other.materialId !== materialId || other.textureId !== textureId;
500
+ if (otherDepth > maxDepth) {
501
+ maxDepth = otherDepth;
502
+ maxDepthIncompatible = otherIncompatible;
503
+ } else if (otherDepth === maxDepth && otherIncompatible) {
504
+ maxDepthIncompatible = true;
1501
505
  }
1502
- break;
506
+ }
1503
507
  }
1504
508
  }
1505
- renderer._prepareRender(context);
1506
- renderer._renderFrameCount = frameCount;
1507
- }
1508
- var batchedRenderElements = this._batchedRenderElements;
1509
- batchedRenderElements.length = 0;
1510
- UIBatchSorter.sort(renderElements, this.entity.transform.worldMatrix);
1511
- engine._batcherManager.batch(renderElements, batchedRenderElements);
1512
- for(var i1 = 0, n1 = batchedRenderElements.length; i1 < n1; i1++){
1513
- batchedRenderElements[i1].subDistancePriority = i1;
1514
- }
1515
- };
1516
- /**
1517
- * @internal
1518
- */ _proto._updateSortDistance = function _updateSortDistance(isOrthographic, cameraPosition, cameraForward) {
1519
- switch(this._realRenderMode){
1520
- case CanvasRenderMode.ScreenSpaceOverlay:
1521
- this._sortDistance = 0;
1522
- break;
1523
- case CanvasRenderMode.ScreenSpaceCamera:
1524
- this._sortDistance = this._distance;
1525
- break;
1526
- case CanvasRenderMode.WorldSpace:
1527
- var boundsCenter = this._getCenter();
1528
- if (isOrthographic) {
1529
- var distance = UICanvas._tempVec3;
1530
- Vector3.subtract(boundsCenter, cameraPosition, distance);
1531
- this._sortDistance = Vector3.dot(distance, cameraForward);
1532
- } else {
1533
- this._sortDistance = Vector3.distanceSquared(boundsCenter, cameraPosition);
509
+ var entry = entries[i2];
510
+ entry.element = element;
511
+ entry.hierarchyIndex = i2;
512
+ // Share the deepest shelf if compatible; bump up one if blocked by an incompatible occupant
513
+ entry.depth = maxDepth < 0 ? 0 : maxDepth + (maxDepthIncompatible ? 1 : 0);
514
+ entry.materialId = materialId;
515
+ entry.textureId = textureId;
516
+ entry.bounds = localBounds1;
517
+ for(var cellY1 = minCellY; cellY1 <= maxCellY; cellY1++){
518
+ for(var cellX1 = minCellX; cellX1 <= maxCellX; cellX1++){
519
+ var cell1 = grid[cellX1][cellY1];
520
+ if (cell1.length === 0) dirtyCells.push(cellX1, cellY1);
521
+ cell1.push(entry);
1534
522
  }
1535
- break;
523
+ }
1536
524
  }
525
+ // @ts-ignore — Utils._quickSort is @internal
526
+ Utils$1._quickSort(entries, 0, count, UIBatchSorter._compareEntries);
527
+ for(var i3 = 0; i3 < count; i3++)elements[i3] = entries[i3].element;
1537
528
  };
1538
- // @ts-ignore
1539
- _proto._onEnableInScene = function _onEnableInScene() {
1540
- var entity = this.entity;
1541
- // @ts-ignore
1542
- entity._dispatchModify(4, this);
1543
- var rootCanvas = Utils.searchRootCanvasInParents(this);
1544
- this._setIsRootCanvas(!rootCanvas);
1545
- Utils.setRootCanvas(this, rootCanvas);
1546
- };
1547
- // @ts-ignore
1548
- _proto._onDisableInScene = function _onDisableInScene() {
1549
- this._setIsRootCanvas(false);
1550
- Utils.cleanRootCanvas(this);
529
+ UIBatchSorter._rectOverlap = function _rectOverlap(a, b) {
530
+ return a.min.x < b.max.x && a.max.x > b.min.x && a.min.y < b.max.y && a.max.y > b.min.y;
1551
531
  };
1552
- // @ts-ignore
1553
- _proto._onDisable = function _onDisable() {
1554
- this._renderElements.length = 0;
1555
- this._batchedRenderElements.length = 0;
532
+ UIBatchSorter._compareEntries = function _compareEntries(a, b) {
533
+ return a.depth - b.depth || a.materialId - b.materialId || a.textureId - b.textureId || a.hierarchyIndex - b.hierarchyIndex;
1556
534
  };
535
+ return UIBatchSorter;
536
+ }();
537
+ // Spatial-hash is fastest when cell size ≈ typical element size (one element per cell).
538
+ // UI elements typically span ~10% of the canvas → 10×10 grid.
539
+ UIBatchSorter._gridDim = 10;
540
+ UIBatchSorter._entries = new Array();
541
+ UIBatchSorter._grid = [];
542
+ // Interleaved (x, y) cell coords touched in the previous frame
543
+ UIBatchSorter._dirtyCells = new Array();
544
+ UIBatchSorter._localBoundsPool = new Array();
545
+ UIBatchSorter._worldToLocal = new Matrix();
546
+ // materialId/textureId/bounds are flattened from RenderElement to avoid
547
+ // multi-hop property access in the hot inner loop and the sort comparator.
548
+ var SortEntry = function SortEntry() {
549
+ this.hierarchyIndex = 0;
550
+ this.depth = 0;
551
+ this.materialId = 0;
552
+ this.textureId = 0;
553
+ };
554
+
555
+ /**
556
+ * Render mode for ui canvas.
557
+ */ var CanvasRenderMode = /*#__PURE__*/ function(CanvasRenderMode) {
1557
558
  /**
1558
- * @internal
1559
- */ _proto._rootCanvasListener = function _rootCanvasListener(flag, param) {
1560
- if (this._isRootCanvas) {
1561
- if (flag === EntityModifyFlags.Parent) {
1562
- var rootCanvas = Utils.searchRootCanvasInParents(this);
1563
- this._setIsRootCanvas(!rootCanvas);
1564
- Utils.setRootCanvas(this, rootCanvas);
1565
- } else if (flag === 4) {
1566
- this._setIsRootCanvas(false);
1567
- Utils.setRootCanvas(this, param);
1568
- }
1569
- } else {
1570
- if (flag === EntityModifyFlags.Parent) {
1571
- var rootCanvas1 = Utils.searchRootCanvasInParents(this);
1572
- this._setIsRootCanvas(!rootCanvas1);
1573
- Utils.setRootCanvas(this, rootCanvas1);
1574
- }
1575
- }
559
+ * The UI canvas will be rendered directly onto the screen and adapted to screen space,
560
+ * overlaying other rendering elements in the same scene.
561
+ * @remarks if the `engine.canvas` size change, the UI canvas will automatically adapt.
562
+ */ CanvasRenderMode[CanvasRenderMode["ScreenSpaceOverlay"] = 0] = "ScreenSpaceOverlay";
563
+ /**
564
+ * The UI canvas is placed at a specified distance in front of the camera and adapted to screen space,
565
+ * with all objects rendered by the camera.
566
+ * @remarks if the camera's properties or the `engine.canvas` size change, the UI canvas will automatically adapt.
567
+ * @remarks if set `ScreenSpaceCamera` but no corresponding camera is assigned, the actual rendering mode defaults to `ScreenSpaceOverlay`.
568
+ */ CanvasRenderMode[CanvasRenderMode["ScreenSpaceCamera"] = 1] = "ScreenSpaceCamera";
569
+ /**
570
+ * The UI canvas is placed in the 3D world space and rendered by every camera in the same scene.
571
+ */ CanvasRenderMode[CanvasRenderMode["WorldSpace"] = 2] = "WorldSpace";
572
+ return CanvasRenderMode;
573
+ }({});
574
+
575
+ /**
576
+ * Resolution adaptation mode.
577
+ * @remarks Only effective in screen space.
578
+ */ var ResolutionAdaptationMode = /*#__PURE__*/ function(ResolutionAdaptationMode) {
579
+ /** Adapt based on width.(`referenceResolution.x`) */ ResolutionAdaptationMode[ResolutionAdaptationMode["WidthAdaptation"] = 0] = "WidthAdaptation";
580
+ /** Adapt based on height.(`referenceResolution.y`) */ ResolutionAdaptationMode[ResolutionAdaptationMode["HeightAdaptation"] = 1] = "HeightAdaptation";
581
+ /** Adapt based on both width and height.(`referenceResolution`) */ ResolutionAdaptationMode[ResolutionAdaptationMode["BothAdaptation"] = 2] = "BothAdaptation";
582
+ /** Adapt to the side with a larger ratio. */ ResolutionAdaptationMode[ResolutionAdaptationMode["ExpandAdaptation"] = 3] = "ExpandAdaptation";
583
+ /** Adapt to the side with smaller ratio. */ ResolutionAdaptationMode[ResolutionAdaptationMode["ShrinkAdaptation"] = 4] = "ShrinkAdaptation";
584
+ return ResolutionAdaptationMode;
585
+ }({});
586
+
587
+ /** Horizontal alignment mode. */ var HorizontalAlignmentMode = /*#__PURE__*/ function(HorizontalAlignmentMode) {
588
+ /** No horizontal alignment. */ HorizontalAlignmentMode[HorizontalAlignmentMode["None"] = 0] = "None";
589
+ /** Left-aligned, `alignLeft` drives `position.x`. */ HorizontalAlignmentMode[HorizontalAlignmentMode["Left"] = 1] = "Left";
590
+ /** Right-aligned, `alignRight` drives `position.x`. */ HorizontalAlignmentMode[HorizontalAlignmentMode["Right"] = 2] = "Right";
591
+ /** Horizontal stretch, `alignLeft` and `alignRight` drive `position.x` and `size.x`. */ HorizontalAlignmentMode[HorizontalAlignmentMode["LeftAndRight"] = 3] = "LeftAndRight";
592
+ /** Center-aligned, `alignCenter` drives `position.x`. */ HorizontalAlignmentMode[HorizontalAlignmentMode["Center"] = 4] = "Center";
593
+ return HorizontalAlignmentMode;
594
+ }({});
595
+
596
+ /** Vertical alignment mode. */ var VerticalAlignmentMode = /*#__PURE__*/ function(VerticalAlignmentMode) {
597
+ /** No vertical alignment. */ VerticalAlignmentMode[VerticalAlignmentMode["None"] = 0] = "None";
598
+ /** Top-aligned, `alignTop` drives `position.y`. */ VerticalAlignmentMode[VerticalAlignmentMode["Top"] = 1] = "Top";
599
+ /** Bottom-aligned, `alignBottom` drives `position.y`. */ VerticalAlignmentMode[VerticalAlignmentMode["Bottom"] = 2] = "Bottom";
600
+ /** Vertical stretch, `alignTop` and `alignBottom` drive `position.y` and `size.y`. */ VerticalAlignmentMode[VerticalAlignmentMode["TopAndBottom"] = 3] = "TopAndBottom";
601
+ /** Middle-aligned, `alignMiddle` drives `position.y`. */ VerticalAlignmentMode[VerticalAlignmentMode["Middle"] = 4] = "Middle";
602
+ return VerticalAlignmentMode;
603
+ }({});
604
+
605
+ /**
606
+ * The Transform component exclusive to the UI element.
607
+ */ var UITransform = /*#__PURE__*/ function(Transform) {
608
+ _inherits(UITransform, Transform);
609
+ function UITransform(entity) {
610
+ var _this;
611
+ _this = Transform.call(this, entity) || this, _this._size = new Vector2(100, 100), _this._pivot = new Vector2(0.5, 0.5), _this._rect = new Rect(-50, -50, 100, 100), _this._alignLeft = 0, _this._alignRight = 0, _this._alignCenter = 0, _this._alignTop = 0, _this._alignBottom = 0, _this._alignMiddle = 0, _this._horizontalAlignment = HorizontalAlignmentMode.None, _this._verticalAlignment = VerticalAlignmentMode.None;
612
+ _this._onSizeChanged = _this._onSizeChanged.bind(_this);
613
+ _this._onPivotChanged = _this._onPivotChanged.bind(_this);
614
+ // @ts-ignore
615
+ _this._size._onValueChanged = _this._onSizeChanged;
616
+ // @ts-ignore
617
+ _this._pivot._onValueChanged = _this._onPivotChanged;
618
+ return _this;
619
+ }
620
+ var _proto = UITransform.prototype;
621
+ /**
622
+ * @internal
623
+ */ _proto._parentChange = function _parentChange() {
624
+ this._isParentDirty = true;
625
+ this._updateWorldFlagWithParentRectChange(TransformModifyFlags.WmWpWeWqWsWus);
1576
626
  };
1577
627
  /**
1578
628
  * @inheritdoc
1579
629
  */ _proto._onClone = function _onClone(target) {
1580
- target.renderMode = this._renderMode;
1581
- };
1582
- _proto._getRenderers = function _getRenderers() {
1583
- var _this = this, renderers = _this._orderedRenderers, entity = _this.entity;
1584
- var uiHierarchyVersion = entity._uiHierarchyVersion;
1585
- if (this._hierarchyVersion !== uiHierarchyVersion) {
1586
- UICanvas._tempRectMaskList.length = 0;
1587
- renderers.length = this._walk(this.entity, renderers, 0, null, 0);
1588
- UICanvas._tempGroupAbleList.length = 0;
1589
- this._hierarchyVersion = uiHierarchyVersion;
1590
- ++UICanvas._hierarchyCounter;
1591
- }
1592
- return renderers;
630
+ Transform.prototype._onClone.call(this, target);
631
+ var size = target._size, pivot = target._pivot;
632
+ // @ts-ignore
633
+ size._onValueChanged = pivot._onValueChanged = null;
634
+ size.copyFrom(this._size);
635
+ pivot.copyFrom(this._pivot);
636
+ // @ts-ignore
637
+ size._onValueChanged = target._onSizeChanged;
638
+ // @ts-ignore
639
+ pivot._onValueChanged = target._onPivotChanged;
1593
640
  };
1594
- _proto._adapterPoseInScreenSpace = function _adapterPoseInScreenSpace() {
1595
- var transform = this.entity.transform;
1596
- var realRenderMode = this._realRenderMode;
1597
- if (realRenderMode === CanvasRenderMode.ScreenSpaceCamera) {
1598
- var cameraEntity = this._camera.entity;
1599
- if (!this._isSameOrChildEntity(cameraEntity)) {
1600
- var cameraTransform = cameraEntity.transform;
1601
- var cameraWorldPosition = cameraTransform.worldPosition, cameraWorldForward = cameraTransform.worldForward;
1602
- var distance = this._distance;
1603
- transform.setWorldPosition(cameraWorldPosition.x + cameraWorldForward.x * distance, cameraWorldPosition.y + cameraWorldForward.y * distance, cameraWorldPosition.z + cameraWorldForward.z * distance);
1604
- transform.worldRotationQuaternion.copyFrom(cameraTransform.worldRotationQuaternion);
1605
- }
641
+ _proto._onLocalMatrixChanging = function _onLocalMatrixChanging() {
642
+ // `super._onLocalMatrixChanging()` will set `LocalMatrix` dirty flag `false`
643
+ // If there is an alignment, `position` and `localMatrix` will be reset again
644
+ if (this._horizontalAlignment || this._verticalAlignment) {
645
+ this._updatePositionByAlignment();
646
+ this._setDirtyFlagTrue(TransformModifyFlags.LocalMatrix);
1606
647
  } else {
1607
- var canvas = this.engine.canvas;
1608
- transform.setWorldPosition(canvas.width * 0.5, canvas.height * 0.5, 0);
1609
- transform.worldRotationQuaternion.set(0, 0, 0, 1);
648
+ Transform.prototype._onLocalMatrixChanging.call(this);
1610
649
  }
1611
650
  };
1612
- _proto._adapterSizeInScreenSpace = function _adapterSizeInScreenSpace() {
1613
- var transform = this.entity.transform;
1614
- var realRenderMode = this._realRenderMode;
1615
- var _this__referenceResolution = this._referenceResolution, width = _this__referenceResolution.x, height = _this__referenceResolution.y;
1616
- var curWidth;
1617
- var curHeight;
1618
- if (realRenderMode === CanvasRenderMode.ScreenSpaceCamera) {
1619
- var camera = this._camera;
1620
- curHeight = camera.isOrthographic ? camera.orthographicSize * 2 : 2 * (Math.tan(MathUtil.degreeToRadian(camera.fieldOfView * 0.5)) * this._distance);
1621
- curWidth = camera.aspectRatio * curHeight;
1622
- } else {
1623
- var canvas = this.engine.canvas;
1624
- curHeight = canvas.height;
1625
- curWidth = canvas.width;
1626
- }
1627
- var expectX, expectY, expectZ;
1628
- switch(this._resolutionAdaptationMode){
1629
- case ResolutionAdaptationMode.WidthAdaptation:
1630
- expectX = expectY = expectZ = curWidth / width;
1631
- break;
1632
- case ResolutionAdaptationMode.HeightAdaptation:
1633
- expectX = expectY = expectZ = curHeight / height;
1634
- break;
1635
- case ResolutionAdaptationMode.BothAdaptation:
1636
- expectX = curWidth / width;
1637
- expectY = curHeight / height;
1638
- expectZ = (expectX + expectY) * 0.5;
1639
- break;
1640
- case ResolutionAdaptationMode.ExpandAdaptation:
1641
- expectX = expectY = expectZ = Math.min(curWidth / width, curHeight / height);
1642
- break;
1643
- case ResolutionAdaptationMode.ShrinkAdaptation:
1644
- expectX = expectY = expectZ = Math.max(curWidth / width, curHeight / height);
1645
- break;
1646
- }
1647
- var worldMatrix = UICanvas._tempMat;
1648
- Matrix.affineTransformation(UICanvas._tempVec3.set(expectX, expectY, expectZ), transform.worldRotationQuaternion, transform.worldPosition, worldMatrix);
1649
- transform.worldMatrix = worldMatrix;
1650
- transform.size.set(curWidth / expectX, curHeight / expectY);
651
+ _proto._onWorldMatrixChanging = function _onWorldMatrixChanging() {
652
+ // `super._onWorldMatrixChanging()` will set `WorldMatrix` dirty flag `false`
653
+ // If there is an alignment, `position` and `worldMatrix` will be reset again(`worldMatrix` dirty flag is already `true`)
654
+ !this._horizontalAlignment && !this._verticalAlignment && Transform.prototype._onWorldMatrixChanging.call(this);
1651
655
  };
1652
- _proto._walk = function _walk(entity, renderers, depth, group, rectMaskCount) {
1653
- if (depth === void 0) depth = 0;
1654
- if (group === void 0) group = null;
1655
- if (rectMaskCount === void 0) rectMaskCount = 0;
1656
- // @ts-ignore
1657
- var components = entity._components;
1658
- var tempGroupAbleList = UICanvas._tempGroupAbleList;
1659
- var tempRectMaskList = UICanvas._tempRectMaskList;
1660
- var rectMask = null;
1661
- var groupAbleCount = 0;
1662
- for(var i = 0, n = components.length; i < n; i++){
1663
- var component = components[i];
1664
- if (!component.enabled) continue;
1665
- if (_instanceof(component, UIRenderer)) {
1666
- renderers[depth] = component;
1667
- ++depth;
1668
- component._isRootCanvasDirty && Utils.setRootCanvas(component, this);
1669
- if (component._isGroupDirty) {
1670
- tempGroupAbleList[groupAbleCount++] = component;
1671
- }
1672
- component._setRectMasks(tempRectMaskList, rectMaskCount);
1673
- } else if (_instanceof(component, UIInteractive)) {
1674
- component._isRootCanvasDirty && Utils.setRootCanvas(component, this);
1675
- if (component._isGroupDirty) {
1676
- tempGroupAbleList[groupAbleCount++] = component;
1677
- }
1678
- } else if (_instanceof(component, RectMask2D)) {
1679
- rectMask = component;
1680
- } else if (_instanceof(component, UIGroup)) {
1681
- component._isRootCanvasDirty && Utils.setRootCanvas(component, this);
1682
- component._isGroupDirty && Utils.setGroup(component, group);
1683
- group = component;
1684
- }
1685
- }
1686
- for(var i1 = 0; i1 < groupAbleCount; i1++){
1687
- Utils.setGroup(tempGroupAbleList[i1], group);
1688
- }
1689
- if (rectMask) {
1690
- tempRectMaskList[rectMaskCount++] = rectMask;
1691
- }
1692
- var children = entity.children;
1693
- for(var i2 = 0, n1 = children.length; i2 < n1; i2++){
1694
- var child = children[i2];
1695
- child.isActive && (depth = this._walk(child, renderers, depth, group, rectMaskCount));
1696
- }
1697
- return depth;
656
+ _proto._onPositionChanged = function _onPositionChanged() {
657
+ (this._horizontalAlignment || this._verticalAlignment) && this._updatePositionByAlignment();
658
+ Transform.prototype._onPositionChanged.call(this);
1698
659
  };
1699
- _proto._updateCameraObserver = function _updateCameraObserver() {
1700
- var camera = this._isRootCanvas && this._renderMode === CanvasRenderMode.ScreenSpaceCamera ? this._camera : null;
1701
- var preCamera = this._cameraObserver;
1702
- if (preCamera !== camera) {
1703
- this._cameraObserver = camera;
1704
- if (preCamera) {
1705
- // @ts-ignore
1706
- preCamera.entity._updateFlagManager.removeListener(this._onCameraTransformListener);
1707
- // @ts-ignore
1708
- preCamera._unRegisterModifyListener(this._onCameraModifyListener);
1709
- }
1710
- if (camera) {
1711
- // @ts-ignore
1712
- camera.entity._updateFlagManager.addListener(this._onCameraTransformListener);
1713
- // @ts-ignore
1714
- camera._registerModifyListener(this._onCameraModifyListener);
1715
- }
660
+ _proto._onWorldPositionChanged = function _onWorldPositionChanged() {
661
+ Transform.prototype._onWorldPositionChanged.call(this);
662
+ if (this._horizontalAlignment || this._verticalAlignment) {
663
+ this._setDirtyFlagTrue(TransformModifyFlags.WorldPosition);
1716
664
  }
1717
665
  };
1718
- _proto._onCameraModifyListener = function _onCameraModifyListener(flag) {
1719
- if (this._realRenderMode === CanvasRenderMode.ScreenSpaceCamera) {
1720
- switch(flag){
1721
- case CameraModifyFlags.ProjectionType:
1722
- case CameraModifyFlags.AspectRatio:
1723
- this._adapterSizeInScreenSpace();
666
+ _proto._updatePositionByAlignment = function _updatePositionByAlignment() {
667
+ var _this__getParentTransform;
668
+ var parentRect = (_this__getParentTransform = this._getParentTransform()) == null ? void 0 : _this__getParentTransform._rect;
669
+ if (parentRect) {
670
+ var position = this.position;
671
+ // @ts-ignore
672
+ position._onValueChanged = null;
673
+ var rect = this._rect;
674
+ switch(this._horizontalAlignment){
675
+ case HorizontalAlignmentMode.Left:
676
+ case HorizontalAlignmentMode.LeftAndRight:
677
+ position.x = parentRect.x - rect.x + this._alignLeft;
1724
678
  break;
1725
- case CameraModifyFlags.FieldOfView:
1726
- !this._camera.isOrthographic && this._adapterSizeInScreenSpace();
679
+ case HorizontalAlignmentMode.Center:
680
+ position.x = parentRect.x + parentRect.width * 0.5 - rect.x - rect.width * 0.5 + this._alignCenter;
1727
681
  break;
1728
- case CameraModifyFlags.OrthographicSize:
1729
- this._camera.isOrthographic && this._adapterSizeInScreenSpace();
682
+ case HorizontalAlignmentMode.Right:
683
+ position.x = parentRect.x + parentRect.width - rect.x - rect.width - this._alignRight;
1730
684
  break;
1731
- case CameraModifyFlags.DisableInScene:
1732
- this._setRealRenderMode(CanvasRenderMode.ScreenSpaceOverlay);
685
+ }
686
+ switch(this._verticalAlignment){
687
+ case VerticalAlignmentMode.Top:
688
+ position.y = parentRect.y + parentRect.height - rect.y - rect.height - this._alignTop;
689
+ break;
690
+ case VerticalAlignmentMode.Middle:
691
+ position.y = parentRect.y + parentRect.height * 0.5 - rect.y - rect.height * 0.5 + this._alignMiddle;
692
+ break;
693
+ case VerticalAlignmentMode.Bottom:
694
+ case VerticalAlignmentMode.TopAndBottom:
695
+ position.y = parentRect.y - rect.y + this._alignBottom;
1733
696
  break;
1734
697
  }
1735
- } else {
1736
- flag === CameraModifyFlags.EnableInScene && this._setRealRenderMode(CanvasRenderMode.ScreenSpaceCamera);
1737
- }
1738
- };
1739
- _proto._onCameraTransformListener = function _onCameraTransformListener() {
1740
- this._realRenderMode === CanvasRenderMode.ScreenSpaceCamera && this._adapterPoseInScreenSpace();
1741
- };
1742
- _proto._addCanvasListener = function _addCanvasListener() {
1743
- // @ts-ignore
1744
- this.engine.canvas._sizeUpdateFlagManager.addListener(this._onCanvasSizeListener);
1745
- };
1746
- _proto._removeCanvasListener = function _removeCanvasListener() {
1747
- // @ts-ignore
1748
- this.engine.canvas._sizeUpdateFlagManager.removeListener(this._onCanvasSizeListener);
1749
- };
1750
- _proto._onCanvasSizeListener = function _onCanvasSizeListener() {
1751
- var canvas = this.engine.canvas;
1752
- this.entity.transform.setWorldPosition(canvas.width * 0.5, canvas.height * 0.5, 0);
1753
- this._adapterSizeInScreenSpace();
1754
- };
1755
- _proto._onReferenceResolutionChanged = function _onReferenceResolutionChanged() {
1756
- var realRenderMode = this._realRenderMode;
1757
- if (realRenderMode === CanvasRenderMode.ScreenSpaceOverlay || realRenderMode === CanvasRenderMode.ScreenSpaceCamera) {
1758
- this._adapterSizeInScreenSpace();
698
+ // @ts-ignore
699
+ position._onValueChanged = this._onPositionChanged;
1759
700
  }
1760
701
  };
1761
- _proto._setIsRootCanvas = function _setIsRootCanvas(isRootCanvas) {
1762
- var _this = this;
1763
- if (this._isRootCanvas !== isRootCanvas) {
1764
- this._isRootCanvas = isRootCanvas;
1765
- this._updateCameraObserver();
1766
- this._setRealRenderMode(this._getRealRenderMode());
1767
- if (isRootCanvas) {
1768
- this.entity._updateUIHierarchyVersion(UICanvas._hierarchyCounter);
1769
- } else {
1770
- var _this1 = this, disorderedElements = _this1._disorderedElements;
1771
- disorderedElements.forEach(function(element) {
1772
- if (_instanceof(element, UICanvas)) {
1773
- var rootCanvas = Utils.searchRootCanvasInParents(element);
1774
- element._setIsRootCanvas(!rootCanvas);
1775
- Utils.setRootCanvas(element, rootCanvas);
1776
- } else {
1777
- Utils.setRootCanvasDirty(_this);
1778
- Utils.setGroupDirty(element);
1779
- }
1780
- });
1781
- disorderedElements.length = 0;
1782
- disorderedElements.garbageCollection();
1783
- this._orderedRenderers.length = 0;
702
+ _proto._updateSizeByAlignment = function _updateSizeByAlignment() {
703
+ var _this__getParentTransform;
704
+ var parentRect = (_this__getParentTransform = this._getParentTransform()) == null ? void 0 : _this__getParentTransform._rect;
705
+ if (parentRect) {
706
+ var size = this._size;
707
+ // @ts-ignore
708
+ size._onValueChanged = null;
709
+ // The values of size must be greater than 0
710
+ if (this._horizontalAlignment === HorizontalAlignmentMode.LeftAndRight) {
711
+ size.x = Math.max(parentRect.width - this._alignLeft - this._alignRight, 0);
1784
712
  }
713
+ if (this._verticalAlignment === VerticalAlignmentMode.TopAndBottom) {
714
+ size.y = Math.max(parentRect.height - this._alignTop - this._alignBottom, 0);
715
+ }
716
+ // @ts-ignore
717
+ size._onValueChanged = this._onSizeChanged;
1785
718
  }
1786
719
  };
1787
- _proto._getCenter = function _getCenter() {
1788
- if (this._centerDirtyFlag.flag) {
1789
- var center = this._center;
1790
- var uiTransform = this.entity.transform;
1791
- var pivot = uiTransform.pivot, size = uiTransform.size;
1792
- center.set((0.5 - pivot.x) * size.x, (0.5 - pivot.y) * size.y, 0);
1793
- Vector3.transformCoordinate(center, uiTransform.worldMatrix, center);
1794
- this._centerDirtyFlag.flag = false;
720
+ _proto._updateRectBySizeAndPivot = function _updateRectBySizeAndPivot() {
721
+ var _this = this, size = _this.size, pivot = _this._pivot;
722
+ var x = -pivot.x * size.x;
723
+ var y = -pivot.y * size.y;
724
+ this._rect.set(x, y, size.x, size.y);
725
+ };
726
+ _proto._onSizeChanged = function _onSizeChanged() {
727
+ if (this._horizontalAlignment === HorizontalAlignmentMode.LeftAndRight || this._verticalAlignment === VerticalAlignmentMode.TopAndBottom) {
728
+ this._updateSizeByAlignment();
1795
729
  }
1796
- return this._center;
730
+ this._updateRectBySizeAndPivot();
731
+ this._updateWorldFlagWithSelfRectChange();
732
+ // @ts-ignore
733
+ this._entity._updateFlagManager.dispatch(512);
1797
734
  };
1798
- _proto._getRealRenderMode = function _getRealRenderMode() {
1799
- if (this._isRootCanvas) {
1800
- var _this__camera;
1801
- var mode = this._renderMode;
1802
- // @ts-ignore
1803
- if (mode === CanvasRenderMode.ScreenSpaceCamera && !((_this__camera = this._camera) == null ? void 0 : _this__camera._phasedActiveInScene)) {
1804
- return CanvasRenderMode.ScreenSpaceOverlay;
1805
- } else {
1806
- return mode;
1807
- }
1808
- } else {
1809
- return 4;
735
+ _proto._onPivotChanged = function _onPivotChanged() {
736
+ this._updateRectBySizeAndPivot();
737
+ this._updateWorldFlagWithSelfRectChange();
738
+ // @ts-ignore
739
+ this._entity._updateFlagManager.dispatch(1024);
740
+ };
741
+ _proto._updateWorldFlagWithSelfRectChange = function _updateWorldFlagWithSelfRectChange() {
742
+ var worldFlags = 0;
743
+ if (this._horizontalAlignment || this._verticalAlignment) {
744
+ this._updatePositionByAlignment();
745
+ this._setDirtyFlagTrue(TransformModifyFlags.LocalMatrix);
746
+ worldFlags = TransformModifyFlags.WmWp;
747
+ !this._isContainDirtyFlags(worldFlags) && this._worldAssociatedChange(worldFlags);
748
+ }
749
+ var children = this.entity.children;
750
+ for(var i = 0, n = children.length; i < n; i++){
751
+ var _children_i_transform__updateWorldFlagWithParentRectChange, _children_i_transform;
752
+ (_children_i_transform = children[i].transform) == null ? void 0 : (_children_i_transform__updateWorldFlagWithParentRectChange = _children_i_transform._updateWorldFlagWithParentRectChange) == null ? void 0 : _children_i_transform__updateWorldFlagWithParentRectChange.call(_children_i_transform, worldFlags);
1810
753
  }
1811
754
  };
1812
- _proto._setRealRenderMode = function _setRealRenderMode(curRealMode) {
1813
- var preRealMode = this._realRenderMode;
1814
- if (preRealMode !== curRealMode) {
1815
- this._realRenderMode = curRealMode;
1816
- // @ts-ignore
1817
- var componentsManager = this.scene._componentsManager;
1818
- switch(preRealMode){
1819
- case CanvasRenderMode.ScreenSpaceOverlay:
1820
- this._removeCanvasListener();
1821
- case CanvasRenderMode.ScreenSpaceCamera:
1822
- case CanvasRenderMode.WorldSpace:
1823
- componentsManager.removeUICanvas(this, preRealMode === CanvasRenderMode.ScreenSpaceOverlay);
1824
- break;
1825
- }
1826
- switch(curRealMode){
1827
- case CanvasRenderMode.ScreenSpaceOverlay:
1828
- this._addCanvasListener();
1829
- case CanvasRenderMode.ScreenSpaceCamera:
1830
- this._adapterPoseInScreenSpace();
1831
- this._adapterSizeInScreenSpace();
1832
- case CanvasRenderMode.WorldSpace:
1833
- componentsManager.addUICanvas(this, curRealMode === CanvasRenderMode.ScreenSpaceOverlay);
1834
- break;
755
+ _proto._updateWorldFlagWithParentRectChange = function _updateWorldFlagWithParentRectChange(flags, parentChange) {
756
+ if (parentChange === void 0) parentChange = true;
757
+ var selfChange = false;
758
+ if (parentChange) {
759
+ var _this = this, horizontalAlignment = _this._horizontalAlignment, verticalAlignment = _this._verticalAlignment;
760
+ if (horizontalAlignment || verticalAlignment) {
761
+ if (horizontalAlignment === HorizontalAlignmentMode.LeftAndRight || verticalAlignment === VerticalAlignmentMode.TopAndBottom) {
762
+ this._updateSizeByAlignment();
763
+ this._updateRectBySizeAndPivot();
764
+ selfChange = true;
765
+ }
766
+ this._updatePositionByAlignment();
767
+ this._setDirtyFlagTrue(TransformModifyFlags.LocalMatrix);
768
+ flags |= TransformModifyFlags.WmWp;
1835
769
  }
1836
770
  }
1837
- };
1838
- _proto._isSameOrChildEntity = function _isSameOrChildEntity(cameraEntity) {
1839
- var canvasEntity = this.entity;
1840
- while(cameraEntity){
1841
- if (cameraEntity === canvasEntity) return true;
1842
- cameraEntity = cameraEntity.parent;
771
+ var containDirtyFlags = this._isContainDirtyFlags(flags);
772
+ !containDirtyFlags && this._worldAssociatedChange(flags);
773
+ if (selfChange || !containDirtyFlags) {
774
+ var children = this.entity.children;
775
+ for(var i = 0, n = children.length; i < n; i++){
776
+ var _children_i_transform__updateWorldFlagWithParentRectChange, _children_i_transform;
777
+ (_children_i_transform = children[i].transform) == null ? void 0 : (_children_i_transform__updateWorldFlagWithParentRectChange = _children_i_transform._updateWorldFlagWithParentRectChange) == null ? void 0 : _children_i_transform__updateWorldFlagWithParentRectChange.call(_children_i_transform, flags, selfChange);
778
+ }
1843
779
  }
1844
- return false;
780
+ // @ts-ignore
781
+ selfChange && this._entity._updateFlagManager.dispatch(512);
1845
782
  };
1846
- _create_class(UICanvas, [
783
+ _create_class(UITransform, [
1847
784
  {
1848
- key: "referenceResolutionPerUnit",
785
+ key: "size",
1849
786
  get: /**
1850
- * The conversion ratio between reference resolution and unit for UI elements in this canvas.
787
+ * Width and height of UI element.
1851
788
  */ function get() {
1852
- return this._referenceResolutionPerUnit;
789
+ return this._size;
1853
790
  },
1854
791
  set: function set(value) {
1855
- if (this._referenceResolutionPerUnit !== value) {
1856
- this._referenceResolutionPerUnit = value;
1857
- this._disorderedElements.forEach(function(element) {
1858
- element._onRootCanvasModify == null ? void 0 : element._onRootCanvasModify.call(element, 1);
1859
- });
792
+ var _this = this, size = _this._size;
793
+ if (size === value) return;
794
+ (size.x !== value.x || size.y !== value.y) && size.copyFrom(value);
795
+ }
796
+ },
797
+ {
798
+ key: "pivot",
799
+ get: /**
800
+ * Pivot of UI element.
801
+ */ function get() {
802
+ return this._pivot;
803
+ },
804
+ set: function set(value) {
805
+ var _this = this, pivot = _this._pivot;
806
+ if (pivot === value) return;
807
+ (pivot.x !== value.x || pivot.y !== value.y) && pivot.copyFrom(value);
808
+ }
809
+ },
810
+ {
811
+ key: "horizontalAlignment",
812
+ get: /**
813
+ * Horizontal alignment mode.
814
+ *
815
+ * @remarks
816
+ * Controls how the element aligns horizontally within its parent:
817
+ * - `Left` - Align to parent's left edge
818
+ * - `Center` - Align to parent's horizontal center
819
+ * - `Right` - Align to parent's right edge
820
+ * - `LeftAndRight` - Align to both left and right edges (stretch to fill width)
821
+ */ function get() {
822
+ return this._horizontalAlignment;
823
+ },
824
+ set: function set(value) {
825
+ if (this._horizontalAlignment === value) return;
826
+ this._horizontalAlignment = value;
827
+ switch(value){
828
+ case HorizontalAlignmentMode.Left:
829
+ case HorizontalAlignmentMode.Right:
830
+ case HorizontalAlignmentMode.Center:
831
+ this._onPositionChanged();
832
+ break;
833
+ case HorizontalAlignmentMode.LeftAndRight:
834
+ this._onPositionChanged();
835
+ this._onSizeChanged();
836
+ break;
1860
837
  }
1861
838
  }
1862
839
  },
1863
840
  {
1864
- key: "referenceResolution",
841
+ key: "alignLeft",
1865
842
  get: /**
1866
- * The reference resolution of the UI canvas in `ScreenSpaceCamera` and `ScreenSpaceOverlay` mode.
843
+ * Left margin when horizontalAlignment is Left or LeftAndRight.
844
+ *
845
+ * @remarks
846
+ * Only effective when horizontalAlignment includes Left mode.
847
+ * Distance from the parent's left edge to the element's left edge.
1867
848
  */ function get() {
1868
- return this._referenceResolution;
849
+ return this._alignLeft;
1869
850
  },
1870
851
  set: function set(value) {
1871
- var referenceResolution = this._referenceResolution;
1872
- if (referenceResolution === value) return;
1873
- (referenceResolution.x !== value.x || referenceResolution.y !== value.y) && referenceResolution.copyFrom(value);
852
+ if (!Number.isFinite(value)) return;
853
+ if (MathUtil.equals(value, this._alignLeft)) return;
854
+ this._alignLeft = value;
855
+ if (this._horizontalAlignment & HorizontalAlignmentMode.Left) {
856
+ this._onPositionChanged();
857
+ this._horizontalAlignment & HorizontalAlignmentMode.Right && this._onSizeChanged();
858
+ }
1874
859
  }
1875
860
  },
1876
861
  {
1877
- key: "renderMode",
862
+ key: "alignRight",
1878
863
  get: /**
1879
- * The rendering mode of the UI canvas.
864
+ * Right margin when horizontalAlignment is Right or LeftAndRight.
865
+ *
866
+ * @remarks
867
+ * Only effective when horizontalAlignment includes Right mode.
868
+ * Distance from the parent's right edge to the element's right edge.
1880
869
  */ function get() {
1881
- return this._renderMode;
870
+ return this._alignRight;
1882
871
  },
1883
- set: function set(mode) {
1884
- var preMode = this._renderMode;
1885
- if (preMode !== mode) {
1886
- this._renderMode = mode;
1887
- this._updateCameraObserver();
1888
- this._setRealRenderMode(this._getRealRenderMode());
872
+ set: function set(value) {
873
+ if (!Number.isFinite(value)) return;
874
+ if (MathUtil.equals(value, this._alignRight)) return;
875
+ this._alignRight = value;
876
+ if (this._horizontalAlignment & HorizontalAlignmentMode.Right) {
877
+ this._onPositionChanged();
878
+ this._horizontalAlignment & HorizontalAlignmentMode.Left && this._onSizeChanged();
879
+ }
880
+ }
881
+ },
882
+ {
883
+ key: "alignCenter",
884
+ get: /**
885
+ * Horizontal center offset when horizontalAlignment is Center.
886
+ *
887
+ * @remarks
888
+ * Only effective when horizontalAlignment is Center mode.
889
+ * Positive values move the element to the right, negative values to the left.
890
+ */ function get() {
891
+ return this._alignCenter;
892
+ },
893
+ set: function set(value) {
894
+ if (!Number.isFinite(value)) return;
895
+ if (MathUtil.equals(value, this._alignCenter)) return;
896
+ this._alignCenter = value;
897
+ this._horizontalAlignment & HorizontalAlignmentMode.Center && this._onPositionChanged();
898
+ }
899
+ },
900
+ {
901
+ key: "verticalAlignment",
902
+ get: /**
903
+ * Vertical alignment mode.
904
+ *
905
+ * @remarks
906
+ * Controls how the element aligns vertically within its parent:
907
+ * - `Top` - Align to parent's top edge
908
+ * - `Middle` - Align to parent's vertical center
909
+ * - `Bottom` - Align to parent's bottom edge
910
+ * - `TopAndBottom` - Align to both top and bottom edges (stretch to fill height)
911
+ */ function get() {
912
+ return this._verticalAlignment;
913
+ },
914
+ set: function set(value) {
915
+ if (this._verticalAlignment === value) return;
916
+ this._verticalAlignment = value;
917
+ switch(value){
918
+ case VerticalAlignmentMode.Top:
919
+ case VerticalAlignmentMode.Bottom:
920
+ case VerticalAlignmentMode.Middle:
921
+ this._onPositionChanged();
922
+ break;
923
+ case VerticalAlignmentMode.TopAndBottom:
924
+ this._onPositionChanged();
925
+ this._onSizeChanged();
926
+ break;
1889
927
  }
1890
928
  }
1891
929
  },
1892
930
  {
1893
- key: "camera",
931
+ key: "alignTop",
1894
932
  get: /**
1895
- * The camera associated with this canvas.
933
+ * Top margin when verticalAlignment is Top or TopAndBottom.
934
+ *
1896
935
  * @remarks
1897
- * - `ScreenSpaceCamera` mode: Used for rendering adaptation. Defaults to `ScreenSpaceOverlay` if not assigned.
1898
- * - `WorldSpace` mode: Used for event detection. If not assigned, events are handled by the highest-priority camera.
936
+ * Only effective when verticalAlignment includes Top mode.
937
+ * Used to offset the element from the parent's top edge.
1899
938
  */ function get() {
1900
- return this._camera;
939
+ return this._alignTop;
1901
940
  },
1902
941
  set: function set(value) {
1903
- var preCamera = this._camera;
1904
- if (preCamera !== value) {
1905
- if (value && this._isSameOrChildEntity(value.entity)) {
1906
- Logger.warn("Camera entity matching or nested within the canvas entity disables canvas auto-adaptation in ScreenSpaceCamera mode.");
1907
- }
1908
- this._camera = value;
1909
- this._updateCameraObserver();
1910
- var preRenderMode = this._realRenderMode;
1911
- var curRenderMode = this._getRealRenderMode();
1912
- if (preRenderMode === curRenderMode) {
1913
- if (curRenderMode === CanvasRenderMode.ScreenSpaceCamera) {
1914
- this._adapterPoseInScreenSpace();
1915
- this._adapterSizeInScreenSpace();
1916
- }
1917
- } else {
1918
- this._setRealRenderMode(curRenderMode);
1919
- }
942
+ if (!Number.isFinite(value)) return;
943
+ if (MathUtil.equals(value, this._alignTop)) return;
944
+ this._alignTop = value;
945
+ if (this._verticalAlignment & VerticalAlignmentMode.Top) {
946
+ this._onPositionChanged();
947
+ this._verticalAlignment & VerticalAlignmentMode.Bottom && this._onSizeChanged();
1920
948
  }
1921
949
  }
1922
950
  },
1923
951
  {
1924
- key: "renderCamera",
952
+ key: "alignBottom",
1925
953
  get: /**
1926
- * @deprecated Use {@link camera} instead.
954
+ * Bottom inset used in vertical alignment formulas.
1927
955
  */ function get() {
1928
- return this.camera;
956
+ return this._alignBottom;
1929
957
  },
1930
958
  set: function set(value) {
1931
- this.camera = value;
959
+ if (!Number.isFinite(value)) return;
960
+ if (MathUtil.equals(value, this._alignBottom)) return;
961
+ this._alignBottom = value;
962
+ if (this._verticalAlignment & VerticalAlignmentMode.Bottom) {
963
+ this._onPositionChanged();
964
+ this._verticalAlignment & VerticalAlignmentMode.Top && this._onSizeChanged();
965
+ }
1932
966
  }
1933
967
  },
1934
968
  {
1935
- key: "resolutionAdaptationMode",
969
+ key: "alignMiddle",
1936
970
  get: /**
1937
- * The screen resolution adaptation mode of the UI canvas in `ScreenSpaceCamera` and `ScreenSpaceOverlay` mode.
971
+ * Vertical middle offset relative to parent's middle.
1938
972
  */ function get() {
1939
- return this._resolutionAdaptationMode;
973
+ return this._alignMiddle;
1940
974
  },
1941
975
  set: function set(value) {
1942
- if (this._resolutionAdaptationMode !== value) {
1943
- this._resolutionAdaptationMode = value;
1944
- var realRenderMode = this._realRenderMode;
1945
- if (realRenderMode === CanvasRenderMode.ScreenSpaceCamera || realRenderMode === CanvasRenderMode.ScreenSpaceOverlay) {
1946
- this._adapterSizeInScreenSpace();
1947
- }
1948
- }
976
+ if (!Number.isFinite(value)) return;
977
+ if (MathUtil.equals(value, this._alignMiddle)) return;
978
+ this._alignMiddle = value;
979
+ this._verticalAlignment & VerticalAlignmentMode.Middle && this._onPositionChanged();
1949
980
  }
1950
- },
981
+ }
982
+ ]);
983
+ return UITransform;
984
+ }(Transform);
985
+ __decorate([
986
+ ignoreClone
987
+ ], UITransform.prototype, "_size", void 0);
988
+ __decorate([
989
+ ignoreClone
990
+ ], UITransform.prototype, "_pivot", void 0);
991
+ __decorate([
992
+ ignoreClone
993
+ ], UITransform.prototype, "_onPositionChanged", null);
994
+ __decorate([
995
+ ignoreClone
996
+ ], UITransform.prototype, "_onWorldPositionChanged", null);
997
+ __decorate([
998
+ ignoreClone
999
+ ], UITransform.prototype, "_onSizeChanged", null);
1000
+ __decorate([
1001
+ ignoreClone
1002
+ ], UITransform.prototype, "_onPivotChanged", null);
1003
+ /**
1004
+ * @internal
1005
+ * extends TransformModifyFlags
1006
+ */ var UITransformModifyFlags = /*#__PURE__*/ function(UITransformModifyFlags) {
1007
+ UITransformModifyFlags[UITransformModifyFlags["Size"] = 512] = "Size";
1008
+ UITransformModifyFlags[UITransformModifyFlags["Pivot"] = 1024] = "Pivot";
1009
+ return UITransformModifyFlags;
1010
+ }({});
1011
+
1012
+ var UIRenderer = /*#__PURE__*/ function(Renderer) {
1013
+ _inherits(UIRenderer, Renderer);
1014
+ function UIRenderer(entity) {
1015
+ var _this;
1016
+ _this = Renderer.call(this, entity) || this, /**
1017
+ * Custom boundary for raycast detection.
1018
+ * @remarks this is based on `this.entity.transform`.
1019
+ */ _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);
1020
+ _this._dirtyUpdateFlag = RendererUpdateFlags.WorldVolume | 2;
1021
+ _this._onColorChanged = _this._onColorChanged.bind(_this);
1022
+ //@ts-ignore
1023
+ _this._color._onValueChanged = _this._onColorChanged;
1024
+ _this._groupListener = _this._groupListener.bind(_this);
1025
+ _this._rootCanvasListener = _this._rootCanvasListener.bind(_this);
1026
+ return _this;
1027
+ }
1028
+ var _proto = UIRenderer.prototype;
1029
+ // @ts-ignore
1030
+ _proto._canBatch = function _canBatch(preElement, curElement) {
1031
+ return VertexMergeBatcher.canBatchSprite(preElement, curElement);
1032
+ };
1033
+ // @ts-ignore
1034
+ _proto._batch = function _batch(preElement, curElement) {
1035
+ VertexMergeBatcher.batch(preElement, curElement);
1036
+ };
1037
+ // @ts-ignore
1038
+ _proto._updateTransformShaderData = function _updateTransformShaderData(context, onlyMVP) {
1039
+ // @ts-ignore
1040
+ this._updateWorldSpaceTransformShaderData(context, onlyMVP);
1041
+ };
1042
+ // @ts-ignore
1043
+ _proto._prepareRender = function _prepareRender(context) {
1044
+ // Update once per frame per renderer, not influenced by batched
1045
+ if (this._renderFrameCount !== this.engine.time.frameCount) {
1046
+ this._update(context);
1047
+ }
1048
+ this._render(context);
1049
+ // union camera global macro and renderer macro.
1050
+ ShaderMacroCollection.unionCollection(context.camera._globalShaderMacro, // @ts-ignore
1051
+ this.shaderData._macroCollection, //@ts-ignore
1052
+ this._globalShaderMacro);
1053
+ };
1054
+ // @ts-ignore
1055
+ _proto._onEnableInScene = function _onEnableInScene() {
1056
+ // @ts-ignore
1057
+ this._overrideUpdate && this.scene._componentsManager.addOnUpdateRenderers(this);
1058
+ this.entity._updateUIHierarchyVersion(UICanvas._hierarchyCounter);
1059
+ Utils.setRootCanvasDirty(this);
1060
+ Utils.setGroupDirty(this);
1061
+ };
1062
+ // @ts-ignore
1063
+ _proto._onDisableInScene = function _onDisableInScene() {
1064
+ // @ts-ignore
1065
+ this._overrideUpdate && this.scene._componentsManager.removeOnUpdateRenderers(this);
1066
+ this.entity._updateUIHierarchyVersion(UICanvas._hierarchyCounter);
1067
+ Utils.cleanRootCanvas(this);
1068
+ Utils.cleanGroup(this);
1069
+ };
1070
+ /**
1071
+ * @internal
1072
+ */ _proto._getGlobalAlpha = function _getGlobalAlpha() {
1073
+ var _this__getGroup;
1074
+ var _this__getGroup__getGlobalAlpha;
1075
+ return (_this__getGroup__getGlobalAlpha = (_this__getGroup = this._getGroup()) == null ? void 0 : _this__getGroup._getGlobalAlpha()) != null ? _this__getGroup__getGlobalAlpha : 1;
1076
+ };
1077
+ /**
1078
+ * @internal
1079
+ */ _proto._getRootCanvas = function _getRootCanvas() {
1080
+ this._isRootCanvasDirty && Utils.setRootCanvas(this, Utils.searchRootCanvasInParents(this));
1081
+ return this._rootCanvas;
1082
+ };
1083
+ /**
1084
+ * @internal
1085
+ */ _proto._getGroup = function _getGroup() {
1086
+ this._isGroupDirty && Utils.setGroup(this, Utils.searchGroupInParents(this));
1087
+ return this._group;
1088
+ };
1089
+ /**
1090
+ * @internal
1091
+ */ _proto._groupListener = function _groupListener(flag) {
1092
+ if (flag === EntityModifyFlags.Parent || flag === EntityUIModifyFlags.GroupEnableInScene) {
1093
+ Utils.setGroupDirty(this);
1094
+ }
1095
+ };
1096
+ /**
1097
+ * @internal
1098
+ */ _proto._rootCanvasListener = function _rootCanvasListener(flag, entity) {
1099
+ switch(flag){
1100
+ case EntityModifyFlags.Parent:
1101
+ Utils.setRootCanvasDirty(this);
1102
+ Utils.setGroupDirty(this);
1103
+ case EntityModifyFlags.Child:
1104
+ entity._updateUIHierarchyVersion(UICanvas._hierarchyCounter);
1105
+ break;
1106
+ }
1107
+ };
1108
+ /**
1109
+ * @internal
1110
+ */ _proto._onGroupModify = function _onGroupModify(flags) {
1111
+ if (flags & GroupModifyFlags.GlobalAlpha) {
1112
+ this._dirtyUpdateFlag |= 2;
1113
+ }
1114
+ };
1115
+ _proto._onColorChanged = function _onColorChanged() {
1116
+ this._dirtyUpdateFlag |= 2;
1117
+ };
1118
+ /**
1119
+ * @internal
1120
+ */ _proto._getChunkManager = function _getChunkManager() {
1121
+ // @ts-ignore
1122
+ return this.engine._batcherManager.primitiveChunkManagerUI;
1123
+ };
1124
+ /**
1125
+ * @internal
1126
+ */ _proto._raycast = function _raycast(ray, out, distance) {
1127
+ if (distance === void 0) distance = Number.MAX_SAFE_INTEGER;
1128
+ var plane = UIRenderer._tempPlane;
1129
+ var transform = this._transformEntity.transform;
1130
+ var normal = plane.normal.copyFrom(transform.worldForward);
1131
+ plane.distance = -Vector3.dot(normal, transform.worldPosition);
1132
+ var curDistance = ray.intersectPlane(plane);
1133
+ if (curDistance >= 0 && curDistance < distance) {
1134
+ var hitPointWorld = ray.getPoint(curDistance, UIRenderer._tempVec30);
1135
+ var worldMatrixInv = UIRenderer._tempMat;
1136
+ Matrix.invert(transform.worldMatrix, worldMatrixInv);
1137
+ var localPosition = UIRenderer._tempVec31;
1138
+ Vector3.transformCoordinate(hitPointWorld, worldMatrixInv, localPosition);
1139
+ if (this._hitTest(localPosition)) {
1140
+ out.component = this;
1141
+ out.distance = curDistance;
1142
+ out.entity = this.entity;
1143
+ out.normal.copyFrom(normal);
1144
+ out.point.copyFrom(hitPointWorld);
1145
+ return true;
1146
+ }
1147
+ }
1148
+ return false;
1149
+ };
1150
+ _proto._hitTest = function _hitTest(localPosition) {
1151
+ var x = localPosition.x, y = localPosition.y;
1152
+ var uiTransform = this._transformEntity.transform;
1153
+ var _uiTransform_size = uiTransform.size, width = _uiTransform_size.x, height = _uiTransform_size.y;
1154
+ var _uiTransform_pivot = uiTransform.pivot, pivotX = _uiTransform_pivot.x, pivotY = _uiTransform_pivot.y;
1155
+ var _this_raycastPadding = this.raycastPadding, paddingLeft = _this_raycastPadding.x, paddingBottom = _this_raycastPadding.y, paddingRight = _this_raycastPadding.z, paddingTop = _this_raycastPadding.w;
1156
+ return x >= -width * pivotX + paddingLeft && x <= width * (1 - pivotX) - paddingRight && y >= -height * pivotY + paddingTop && y <= height * (1 - pivotY) - paddingBottom;
1157
+ };
1158
+ _proto._onDestroy = function _onDestroy() {
1159
+ if (this._subChunk) {
1160
+ this._getChunkManager().freeSubChunk(this._subChunk);
1161
+ this._subChunk = null;
1162
+ }
1163
+ Renderer.prototype._onDestroy.call(this);
1164
+ //@ts-ignore
1165
+ this._color._onValueChanged = null;
1166
+ this._color = null;
1167
+ };
1168
+ _create_class(UIRenderer, [
1951
1169
  {
1952
- key: "sortOrder",
1170
+ key: "color",
1953
1171
  get: /**
1954
- * The rendering order priority of the UI canvas in `ScreenSpaceOverlay` mode.
1172
+ * Rendering color for the ui renderer.
1955
1173
  */ function get() {
1956
- return this._sortOrder;
1174
+ return this._color;
1957
1175
  },
1958
1176
  set: function set(value) {
1959
- if (this._sortOrder !== value) {
1960
- this._sortOrder = value;
1961
- this._realRenderMode === CanvasRenderMode.ScreenSpaceOverlay && // @ts-ignore
1962
- (this.scene._componentsManager._overlayCanvasesSortingFlag = true);
1177
+ if (this._color !== value) {
1178
+ this._color.copyFrom(value);
1963
1179
  }
1964
1180
  }
1965
1181
  },
1966
1182
  {
1967
- key: "distance",
1183
+ key: "raycastEnabled",
1968
1184
  get: /**
1969
- * The distance between the UI canvas and the camera in `ScreenSpaceCamera` mode.
1185
+ * Whether this renderer be picked up by raycast.
1970
1186
  */ function get() {
1971
- return this._distance;
1187
+ return this._raycastEnabled;
1972
1188
  },
1973
1189
  set: function set(value) {
1974
- if (this._distance !== value) {
1975
- this._distance = value;
1976
- if (this._realRenderMode === CanvasRenderMode.ScreenSpaceCamera) {
1977
- this._adapterPoseInScreenSpace();
1978
- this._adapterSizeInScreenSpace();
1979
- }
1980
- }
1190
+ this._raycastEnabled = value;
1981
1191
  }
1982
1192
  }
1983
1193
  ]);
1984
- return UICanvas;
1985
- }(Component);
1986
- /** @internal */ UICanvas._hierarchyCounter = 1;
1987
- UICanvas._tempGroupAbleList = [];
1988
- UICanvas._tempRectMaskList = [];
1989
- UICanvas._tempVec3 = new Vector3();
1990
- UICanvas._tempMat = new Matrix();
1194
+ return UIRenderer;
1195
+ }(Renderer);
1196
+ /** @internal */ UIRenderer._tempVec30 = new Vector3();
1197
+ /** @internal */ UIRenderer._tempVec31 = new Vector3();
1198
+ /** @internal */ UIRenderer._tempMat = new Matrix();
1199
+ /** @internal */ UIRenderer._tempPlane = new Plane();
1200
+ /** @internal */ UIRenderer._textureProperty = ShaderProperty.getByName("renderer_UITexture");
1991
1201
  __decorate([
1992
1202
  ignoreClone
1993
- ], UICanvas.prototype, "_canvasIndex", void 0);
1203
+ ], UIRenderer.prototype, "_indexInRootCanvas", void 0);
1994
1204
  __decorate([
1995
1205
  ignoreClone
1996
- ], UICanvas.prototype, "_indexInRootCanvas", void 0);
1206
+ ], UIRenderer.prototype, "_isRootCanvasDirty", void 0);
1997
1207
  __decorate([
1998
1208
  ignoreClone
1999
- ], UICanvas.prototype, "_isRootCanvasDirty", void 0);
1209
+ ], UIRenderer.prototype, "_rootCanvasListeningEntities", void 0);
2000
1210
  __decorate([
2001
1211
  ignoreClone
2002
- ], UICanvas.prototype, "_rootCanvasListeningEntities", void 0);
1212
+ ], UIRenderer.prototype, "_indexInGroup", void 0);
1213
+ __decorate([
1214
+ ignoreClone
1215
+ ], UIRenderer.prototype, "_isGroupDirty", void 0);
1216
+ __decorate([
1217
+ ignoreClone
1218
+ ], UIRenderer.prototype, "_groupListeningEntities", void 0);
1219
+ __decorate([
1220
+ ignoreClone
1221
+ ], UIRenderer.prototype, "_subChunk", void 0);
1222
+ __decorate([
1223
+ ignoreClone
1224
+ ], UIRenderer.prototype, "_groupListener", null);
1225
+ __decorate([
1226
+ ignoreClone
1227
+ ], UIRenderer.prototype, "_rootCanvasListener", null);
1228
+ __decorate([
1229
+ ignoreClone
1230
+ ], UIRenderer.prototype, "_onColorChanged", null);
1231
+ UIRenderer = __decorate([
1232
+ dependentComponents(UITransform, DependentMode.AutoAdd)
1233
+ ], UIRenderer);
1234
+ /**
1235
+ * @remarks Extends `RendererUpdateFlags`.
1236
+ */ var UIRendererUpdateFlags = /*#__PURE__*/ function(UIRendererUpdateFlags) {
1237
+ UIRendererUpdateFlags[UIRendererUpdateFlags["Color"] = 2] = "Color";
1238
+ return UIRendererUpdateFlags;
1239
+ }({});
1240
+
1241
+ /**
1242
+ * Interactive component.
1243
+ */ var UIInteractive = /*#__PURE__*/ function(Script) {
1244
+ _inherits(UIInteractive, Script);
1245
+ function UIInteractive(entity) {
1246
+ var _this;
1247
+ _this = Script.call(this, entity) || this, /** @internal */ _this._indexInRootCanvas = -1, /** @internal */ _this._isRootCanvasDirty = false, /** @internal */ _this._rootCanvasListeningEntities = [], /** @internal */ _this._indexInGroup = -1, /** @internal */ _this._isGroupDirty = false, /** @internal */ _this._groupListeningEntities = [], /** @internal */ _this._globalInteractive = false, /** @internal */ _this._globalInteractiveDirty = false, _this._transitions = [], _this._interactive = true, _this._state = 0, /** @todo Multi-touch points are not considered yet. */ _this._isPointerInside = false, _this._isPointerDragging = false;
1248
+ _this._groupListener = _this._groupListener.bind(_this);
1249
+ _this._rootCanvasListener = _this._rootCanvasListener.bind(_this);
1250
+ return _this;
1251
+ }
1252
+ var _proto = UIInteractive.prototype;
1253
+ /**
1254
+ * Add transition on this interactive.
1255
+ * @param transition - The transition
1256
+ */ _proto.addTransition = function addTransition(transition) {
1257
+ var interactive = transition._interactive;
1258
+ if (interactive !== this) {
1259
+ interactive == null ? void 0 : interactive.removeTransition(transition);
1260
+ this._transitions.push(transition);
1261
+ transition._interactive = this;
1262
+ transition._setState(this._state, true);
1263
+ }
1264
+ };
1265
+ /**
1266
+ * Remove a transition.
1267
+ * @param shape - The transition.
1268
+ */ _proto.removeTransition = function removeTransition(transition) {
1269
+ var transitions = this._transitions;
1270
+ var lastOneIndex = transitions.length - 1;
1271
+ for(var i = lastOneIndex; i >= 0; i--){
1272
+ if (transitions[i] === transition) {
1273
+ i !== lastOneIndex && (transitions[i] = transitions[lastOneIndex]);
1274
+ transitions.length = lastOneIndex;
1275
+ transition._interactive = null;
1276
+ break;
1277
+ }
1278
+ }
1279
+ };
1280
+ /**
1281
+ * Remove all transitions.
1282
+ */ _proto.clearTransitions = function clearTransitions() {
1283
+ var transitions = this._transitions;
1284
+ for(var i = 0, n = transitions.length; i < n; i++){
1285
+ transitions[i]._interactive = null;
1286
+ }
1287
+ transitions.length = 0;
1288
+ };
1289
+ _proto.onUpdate = function onUpdate(deltaTime) {
1290
+ if (this._getGlobalInteractive()) {
1291
+ var transitions = this._transitions;
1292
+ for(var i = 0, n = transitions.length; i < n; i++){
1293
+ transitions[i]._onUpdate(deltaTime);
1294
+ }
1295
+ }
1296
+ };
1297
+ _proto.onPointerBeginDrag = function onPointerBeginDrag() {
1298
+ this._isPointerDragging = true;
1299
+ this._updateState(false);
1300
+ };
1301
+ _proto.onPointerEndDrag = function onPointerEndDrag() {
1302
+ this._isPointerDragging = false;
1303
+ this._updateState(false);
1304
+ };
1305
+ _proto.onPointerEnter = function onPointerEnter() {
1306
+ this._isPointerInside = true;
1307
+ this._updateState(false);
1308
+ };
1309
+ _proto.onPointerExit = function onPointerExit() {
1310
+ this._isPointerInside = false;
1311
+ this._updateState(false);
1312
+ };
1313
+ _proto.onDestroy = function onDestroy() {
1314
+ Script.prototype.onDestroy.call(this);
1315
+ var transitions = this._transitions;
1316
+ for(var i = transitions.length - 1; i >= 0; i--){
1317
+ transitions[i].destroy();
1318
+ }
1319
+ };
1320
+ /**
1321
+ * @internal
1322
+ */ _proto._getRootCanvas = function _getRootCanvas() {
1323
+ this._isRootCanvasDirty && Utils.setRootCanvas(this, Utils.searchRootCanvasInParents(this));
1324
+ return this._rootCanvas;
1325
+ };
1326
+ /**
1327
+ * @internal
1328
+ */ _proto._getGroup = function _getGroup() {
1329
+ this._isGroupDirty && Utils.setGroup(this, Utils.searchGroupInParents(this));
1330
+ return this._group;
1331
+ };
1332
+ // @ts-ignore
1333
+ _proto._onEnableInScene = function _onEnableInScene() {
1334
+ // @ts-ignore
1335
+ Script.prototype._onEnableInScene.call(this);
1336
+ Utils.setRootCanvasDirty(this);
1337
+ Utils.setGroupDirty(this);
1338
+ this._updateState(true);
1339
+ };
1340
+ // @ts-ignore
1341
+ _proto._onDisableInScene = function _onDisableInScene() {
1342
+ // @ts-ignore
1343
+ Script.prototype._onDisableInScene.call(this);
1344
+ Utils.cleanRootCanvas(this);
1345
+ Utils.cleanGroup(this);
1346
+ this._isPointerInside = this._isPointerDragging = false;
1347
+ };
1348
+ /**
1349
+ * @internal
1350
+ */ _proto._groupListener = function _groupListener(flag) {
1351
+ if (flag === EntityModifyFlags.Parent || flag === EntityUIModifyFlags.GroupEnableInScene) {
1352
+ Utils.setGroupDirty(this);
1353
+ }
1354
+ };
1355
+ /**
1356
+ * @internal
1357
+ */ _proto._rootCanvasListener = function _rootCanvasListener(flag) {
1358
+ if (flag === EntityModifyFlags.Parent || flag === EntityUIModifyFlags.CanvasEnableInScene) {
1359
+ Utils.setRootCanvasDirty(this);
1360
+ Utils.setGroupDirty(this);
1361
+ }
1362
+ };
1363
+ /**
1364
+ * @internal
1365
+ */ _proto._onGroupModify = function _onGroupModify(flags) {
1366
+ if (flags & GroupModifyFlags.GlobalInteractive) {
1367
+ this._globalInteractiveDirty = true;
1368
+ }
1369
+ };
1370
+ /**
1371
+ * @internal
1372
+ */ _proto._getGlobalInteractive = function _getGlobalInteractive() {
1373
+ if (this._globalInteractiveDirty) {
1374
+ var group = this._getGroup();
1375
+ var globalInteractive = this._interactive && (!group || group._getGlobalInteractive());
1376
+ if (this._globalInteractive !== globalInteractive) {
1377
+ this._globalInteractive = globalInteractive;
1378
+ this._updateState(true);
1379
+ }
1380
+ this._globalInteractiveDirty = false;
1381
+ }
1382
+ return this._globalInteractive;
1383
+ };
1384
+ _proto._updateState = function _updateState(instant) {
1385
+ var state = this._getInteractiveState();
1386
+ if (this._state !== state) {
1387
+ this._state = state;
1388
+ var transitions = this._transitions;
1389
+ for(var i = 0, n = transitions.length; i < n; i++){
1390
+ transitions[i]._setState(state, instant);
1391
+ }
1392
+ }
1393
+ };
1394
+ _proto._getInteractiveState = function _getInteractiveState() {
1395
+ if (!this._getGlobalInteractive()) {
1396
+ return 3;
1397
+ }
1398
+ if (this._isPointerDragging) {
1399
+ return 1;
1400
+ } else {
1401
+ return this._isPointerInside ? 2 : 0;
1402
+ }
1403
+ };
1404
+ _create_class(UIInteractive, [
1405
+ {
1406
+ key: "transitions",
1407
+ get: /**
1408
+ * The transitions of this interactive.
1409
+ */ function get() {
1410
+ return this._transitions;
1411
+ }
1412
+ },
1413
+ {
1414
+ key: "interactive",
1415
+ get: /**
1416
+ * Whether the interactive is enabled.
1417
+ */ function get() {
1418
+ return this._interactive;
1419
+ },
1420
+ set: function set(value) {
1421
+ if (this._interactive !== value) {
1422
+ this._interactive = value;
1423
+ this._globalInteractiveDirty = true;
1424
+ }
1425
+ }
1426
+ }
1427
+ ]);
1428
+ return UIInteractive;
1429
+ }(Script);
2003
1430
  __decorate([
2004
1431
  ignoreClone
2005
- ], UICanvas.prototype, "_isRootCanvas", void 0);
1432
+ ], UIInteractive.prototype, "_indexInRootCanvas", void 0);
2006
1433
  __decorate([
2007
1434
  ignoreClone
2008
- ], UICanvas.prototype, "_renderElements", void 0);
1435
+ ], UIInteractive.prototype, "_isRootCanvasDirty", void 0);
2009
1436
  __decorate([
2010
1437
  ignoreClone
2011
- ], UICanvas.prototype, "_batchedRenderElements", void 0);
1438
+ ], UIInteractive.prototype, "_rootCanvasListeningEntities", void 0);
2012
1439
  __decorate([
2013
1440
  ignoreClone
2014
- ], UICanvas.prototype, "_sortDistance", void 0);
1441
+ ], UIInteractive.prototype, "_indexInGroup", void 0);
2015
1442
  __decorate([
2016
1443
  ignoreClone
2017
- ], UICanvas.prototype, "_orderedRenderers", void 0);
1444
+ ], UIInteractive.prototype, "_isGroupDirty", void 0);
2018
1445
  __decorate([
2019
1446
  ignoreClone
2020
- ], UICanvas.prototype, "_realRenderMode", void 0);
1447
+ ], UIInteractive.prototype, "_groupListeningEntities", void 0);
2021
1448
  __decorate([
2022
1449
  ignoreClone
2023
- ], UICanvas.prototype, "_renderMode", void 0);
1450
+ ], UIInteractive.prototype, "_globalInteractive", void 0);
2024
1451
  __decorate([
2025
1452
  ignoreClone
2026
- ], UICanvas.prototype, "_hierarchyVersion", void 0);
1453
+ ], UIInteractive.prototype, "_globalInteractiveDirty", void 0);
2027
1454
  __decorate([
2028
1455
  ignoreClone
2029
- ], UICanvas.prototype, "_center", void 0);
1456
+ ], UIInteractive.prototype, "_state", void 0);
2030
1457
  __decorate([
2031
1458
  ignoreClone
2032
- ], UICanvas.prototype, "_rootCanvasListener", null);
1459
+ ], UIInteractive.prototype, "_isPointerInside", void 0);
2033
1460
  __decorate([
2034
1461
  ignoreClone
2035
- ], UICanvas.prototype, "_onCameraModifyListener", null);
1462
+ ], UIInteractive.prototype, "_isPointerDragging", void 0);
2036
1463
  __decorate([
2037
1464
  ignoreClone
2038
- ], UICanvas.prototype, "_onCameraTransformListener", null);
1465
+ ], UIInteractive.prototype, "_groupListener", null);
2039
1466
  __decorate([
2040
1467
  ignoreClone
2041
- ], UICanvas.prototype, "_onCanvasSizeListener", null);
1468
+ ], UIInteractive.prototype, "_rootCanvasListener", null);
2042
1469
  __decorate([
2043
1470
  ignoreClone
2044
- ], UICanvas.prototype, "_onReferenceResolutionChanged", null);
2045
- UICanvas = __decorate([
2046
- dependentComponents(UITransform, DependentMode.AutoAdd)
2047
- ], UICanvas);
2048
- /**
2049
- * @remarks Extends `EntityModifyFlags`.
2050
- */ var EntityUIModifyFlags = /*#__PURE__*/ function(EntityUIModifyFlags) {
2051
- EntityUIModifyFlags[EntityUIModifyFlags["CanvasEnableInScene"] = 4] = "CanvasEnableInScene";
2052
- EntityUIModifyFlags[EntityUIModifyFlags["GroupEnableInScene"] = 8] = "GroupEnableInScene";
2053
- return EntityUIModifyFlags;
2054
- }({});
2055
- var RootCanvasModifyFlags = /*#__PURE__*/ function(RootCanvasModifyFlags) {
2056
- RootCanvasModifyFlags[RootCanvasModifyFlags["None"] = 0] = "None";
2057
- RootCanvasModifyFlags[RootCanvasModifyFlags["ReferenceResolutionPerUnit"] = 1] = "ReferenceResolutionPerUnit";
2058
- RootCanvasModifyFlags[RootCanvasModifyFlags["All"] = 1] = "All";
2059
- return RootCanvasModifyFlags;
1471
+ ], UIInteractive.prototype, "_onGroupModify", null);
1472
+ var InteractiveState = /*#__PURE__*/ function(InteractiveState) {
1473
+ InteractiveState[InteractiveState["Normal"] = 0] = "Normal";
1474
+ InteractiveState[InteractiveState["Pressed"] = 1] = "Pressed";
1475
+ InteractiveState[InteractiveState["Hover"] = 2] = "Hover";
1476
+ InteractiveState[InteractiveState["Disable"] = 3] = "Disable";
1477
+ return InteractiveState;
2060
1478
  }({});
2061
1479
 
2062
- var Utils = /*#__PURE__*/ function() {
2063
- function Utils() {}
1480
+ var UICanvas = /*#__PURE__*/ function(Component) {
1481
+ _inherits(UICanvas, Component);
1482
+ function UICanvas(entity) {
1483
+ var _this;
1484
+ _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._renderElements = [], /** @internal */ _this._batchedRenderElements = [], /** @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();
1485
+ _this._onCanvasSizeListener = _this._onCanvasSizeListener.bind(_this);
1486
+ _this._onCameraModifyListener = _this._onCameraModifyListener.bind(_this);
1487
+ _this._onCameraTransformListener = _this._onCameraTransformListener.bind(_this);
1488
+ _this._onReferenceResolutionChanged = _this._onReferenceResolutionChanged.bind(_this);
1489
+ // @ts-ignore
1490
+ _this._referenceResolution._onValueChanged = _this._onReferenceResolutionChanged;
1491
+ _this._rootCanvasListener = _this._rootCanvasListener.bind(_this);
1492
+ _this._centerDirtyFlag = entity.registerWorldChangeFlag();
1493
+ return _this;
1494
+ }
1495
+ var _proto = UICanvas.prototype;
2064
1496
  /**
2065
- * Local position of a screen point in the component
2066
- */ Utils.screenToLocalPoint = function screenToLocalPoint(position, transform, out) {
2067
- var engine = transform.engine;
2068
- // Get root canvas
2069
- var entity = transform.entity;
2070
- var rootCanvas;
2071
- while(entity){
2072
- // @ts-ignore
2073
- var components = entity._components;
2074
- for(var i = 0, n = components.length; i < n; i++){
2075
- var component = components[i];
2076
- if (component.enabled && _instanceof(component, UICanvas) && component._isRootCanvas) {
2077
- rootCanvas = component;
2078
- }
1497
+ * @internal
1498
+ */ _proto._raycast = function _raycast(ray, out, distance) {
1499
+ if (distance === void 0) distance = Number.MAX_SAFE_INTEGER;
1500
+ var renderers = this._getRenderers();
1501
+ for(var i = renderers.length - 1; i >= 0; i--){
1502
+ var element = renderers[i];
1503
+ if (element.raycastEnabled && element._raycast(ray, out, distance)) {
1504
+ return true;
2079
1505
  }
2080
- entity = entity.parent;
2081
- }
2082
- if (!rootCanvas) return false;
2083
- // Calculate ray
2084
- var ray = this._tempRay;
2085
- switch(rootCanvas._realRenderMode){
2086
- case CanvasRenderMode.ScreenSpaceOverlay:
2087
- // Screen to world ( Assume that world units have a one-to-one relationship with pixel units )
2088
- ray.origin.set(position.x, engine.canvas.height - position.y, 1);
2089
- ray.direction.set(0, 0, -1);
2090
- break;
2091
- case CanvasRenderMode.ScreenSpaceCamera:
2092
- rootCanvas.renderCamera.screenPointToRay(position, ray);
2093
- break;
2094
- default:
2095
- // World space not yet supported, see issue #2793
2096
- return false;
2097
- }
2098
- // Intersect ray with UI plane to get local coordinates
2099
- var plane = this._tempPlane;
2100
- var normal = plane.normal.copyFrom(transform.worldForward);
2101
- plane.distance = -Vector3.dot(normal, transform.worldPosition);
2102
- var curDistance = ray.intersectPlane(plane);
2103
- if (curDistance >= 0 && curDistance < Number.MAX_SAFE_INTEGER) {
2104
- var hitPointWorld = ray.getPoint(curDistance, this._tempVec3);
2105
- var worldMatrixInv = this._tempMat;
2106
- Matrix.invert(transform.worldMatrix, worldMatrixInv);
2107
- Vector3.transformCoordinate(hitPointWorld, worldMatrixInv, out);
2108
- return true;
2109
1506
  }
1507
+ out.component = null;
1508
+ out.entity = null;
1509
+ out.distance = 0;
1510
+ out.point.set(0, 0, 0);
1511
+ out.normal.set(0, 0, 0);
2110
1512
  return false;
2111
1513
  };
2112
- Utils.setRootCanvasDirty = function setRootCanvasDirty(element) {
2113
- if (element._isRootCanvasDirty) return;
2114
- element._isRootCanvasDirty = true;
2115
- this._registerRootCanvas(element, null);
2116
- element._onRootCanvasModify == null ? void 0 : element._onRootCanvasModify.call(element, RootCanvasModifyFlags.All);
1514
+ /**
1515
+ * @internal
1516
+ */ _proto._getRootCanvas = function _getRootCanvas() {
1517
+ return this._rootCanvas;
2117
1518
  };
2118
- Utils.setRootCanvas = function setRootCanvas(element, rootCanvas) {
2119
- element._isRootCanvasDirty = false;
2120
- this._registerRootCanvas(element, rootCanvas);
2121
- var fromEntity = _instanceof(element, UICanvas) ? element.entity.parent : element.entity;
2122
- var _rootCanvas_entity_parent;
2123
- var toEntity = (_rootCanvas_entity_parent = rootCanvas == null ? void 0 : rootCanvas.entity.parent) != null ? _rootCanvas_entity_parent : null;
2124
- this._registerListener(fromEntity, toEntity, element._rootCanvasListener, element._rootCanvasListeningEntities);
1519
+ /**
1520
+ * @internal
1521
+ */ _proto._canRender = function _canRender(camera) {
1522
+ return this._realRenderMode !== CanvasRenderMode.ScreenSpaceCamera || this._camera === camera;
2125
1523
  };
2126
- Utils.cleanRootCanvas = function cleanRootCanvas(element) {
2127
- this._registerRootCanvas(element, null);
2128
- this._unRegisterListener(element._rootCanvasListener, element._rootCanvasListeningEntities);
1524
+ /**
1525
+ * @internal
1526
+ */ _proto._canDispatchEvent = function _canDispatchEvent(camera) {
1527
+ var realMode = this._realRenderMode;
1528
+ if (realMode === CanvasRenderMode.ScreenSpaceOverlay) {
1529
+ return true;
1530
+ }
1531
+ var assignedCamera = this._camera;
1532
+ // @ts-ignore
1533
+ return !assignedCamera || !assignedCamera._phasedActiveInScene || assignedCamera === camera;
2129
1534
  };
2130
- Utils.searchRootCanvasInParents = function searchRootCanvasInParents(element) {
2131
- var entity = _instanceof(element, UICanvas) ? element.entity.parent : element.entity;
2132
- while(entity){
2133
- // @ts-ignore
2134
- var components = entity._components;
2135
- for(var i = 0, n = components.length; i < n; i++){
2136
- var component = components[i];
2137
- if (component.enabled && _instanceof(component, UICanvas) && component._isRootCanvas) {
2138
- return component;
1535
+ /**
1536
+ * @internal
1537
+ */ _proto._prepareRender = function _prepareRender(context) {
1538
+ var _this = this, engine = _this.engine, mode = _this._realRenderMode;
1539
+ var _context_camera = context.camera, enableFrustumCulling = _context_camera.enableFrustumCulling, cullingMask = _context_camera.cullingMask, frustum = _context_camera._frustum;
1540
+ var frameCount = engine.time.frameCount;
1541
+ var renderElements = this._renderElements;
1542
+ renderElements.length = 0;
1543
+ var virtualCamera = context.virtualCamera;
1544
+ this._updateSortDistance(virtualCamera.isOrthographic, virtualCamera.position, virtualCamera.forward);
1545
+ var _engine_canvas = engine.canvas, width = _engine_canvas.width, height = _engine_canvas.height;
1546
+ var renderers = this._getRenderers();
1547
+ for(var i = 0, n = renderers.length; i < n; i++){
1548
+ var renderer = renderers[i];
1549
+ // Filter by camera culling mask
1550
+ if (!(cullingMask & renderer.entity.layer)) {
1551
+ continue;
1552
+ }
1553
+ // Filter by camera frustum
1554
+ if (enableFrustumCulling) {
1555
+ switch(mode){
1556
+ case CanvasRenderMode.ScreenSpaceOverlay:
1557
+ var _renderer_bounds = renderer.bounds, min = _renderer_bounds.min, max = _renderer_bounds.max;
1558
+ if (min.x > width || max.x < 0 || min.y > height || max.y < 0) {
1559
+ continue;
1560
+ }
1561
+ break;
1562
+ case CanvasRenderMode.ScreenSpaceCamera:
1563
+ case CanvasRenderMode.WorldSpace:
1564
+ if (!frustum.intersectsBox(renderer.bounds)) {
1565
+ continue;
1566
+ }
1567
+ break;
2139
1568
  }
2140
1569
  }
2141
- entity = entity.parent;
1570
+ renderer._prepareRender(context);
1571
+ renderer._renderFrameCount = frameCount;
1572
+ }
1573
+ var batchedRenderElements = this._batchedRenderElements;
1574
+ batchedRenderElements.length = 0;
1575
+ UIBatchSorter.sort(renderElements, this.entity.transform.worldMatrix);
1576
+ engine._batcherManager.batch(renderElements, batchedRenderElements);
1577
+ for(var i1 = 0, n1 = batchedRenderElements.length; i1 < n1; i1++){
1578
+ batchedRenderElements[i1].subDistancePriority = i1;
2142
1579
  }
2143
- return null;
2144
1580
  };
2145
- Utils.setGroupDirty = function setGroupDirty(element) {
2146
- if (element._isGroupDirty) return;
2147
- element._isGroupDirty = true;
2148
- this._registerGroup(element, null);
2149
- element._onGroupModify(GroupModifyFlags.All);
1581
+ /**
1582
+ * @internal
1583
+ */ _proto._updateSortDistance = function _updateSortDistance(isOrthographic, cameraPosition, cameraForward) {
1584
+ switch(this._realRenderMode){
1585
+ case CanvasRenderMode.ScreenSpaceOverlay:
1586
+ this._sortDistance = 0;
1587
+ break;
1588
+ case CanvasRenderMode.ScreenSpaceCamera:
1589
+ this._sortDistance = this._distance;
1590
+ break;
1591
+ case CanvasRenderMode.WorldSpace:
1592
+ var boundsCenter = this._getCenter();
1593
+ if (isOrthographic) {
1594
+ var distance = UICanvas._tempVec3;
1595
+ Vector3.subtract(boundsCenter, cameraPosition, distance);
1596
+ this._sortDistance = Vector3.dot(distance, cameraForward);
1597
+ } else {
1598
+ this._sortDistance = Vector3.distanceSquared(boundsCenter, cameraPosition);
1599
+ }
1600
+ break;
1601
+ }
2150
1602
  };
2151
- Utils.setGroup = function setGroup(element, group) {
2152
- element._isGroupDirty = false;
2153
- this._registerGroup(element, group);
2154
- var rootCanvas = element._getRootCanvas();
2155
- if (rootCanvas) {
2156
- var fromEntity = _instanceof(element, UIGroup) ? element.entity.parent : element.entity;
2157
- var _group_entity;
2158
- var toEntity = (_group_entity = group == null ? void 0 : group.entity) != null ? _group_entity : rootCanvas.entity.parent;
2159
- this._registerListener(fromEntity, toEntity, element._groupListener, element._groupListeningEntities);
1603
+ // @ts-ignore
1604
+ _proto._onEnableInScene = function _onEnableInScene() {
1605
+ var entity = this.entity;
1606
+ // @ts-ignore
1607
+ entity._dispatchModify(4, this);
1608
+ var rootCanvas = Utils.searchRootCanvasInParents(this);
1609
+ this._setIsRootCanvas(!rootCanvas);
1610
+ Utils.setRootCanvas(this, rootCanvas);
1611
+ };
1612
+ // @ts-ignore
1613
+ _proto._onDisableInScene = function _onDisableInScene() {
1614
+ this._setIsRootCanvas(false);
1615
+ Utils.cleanRootCanvas(this);
1616
+ };
1617
+ // @ts-ignore
1618
+ _proto._onDisable = function _onDisable() {
1619
+ this._renderElements.length = 0;
1620
+ this._batchedRenderElements.length = 0;
1621
+ };
1622
+ /**
1623
+ * @internal
1624
+ */ _proto._rootCanvasListener = function _rootCanvasListener(flag, param) {
1625
+ if (this._isRootCanvas) {
1626
+ if (flag === EntityModifyFlags.Parent) {
1627
+ var rootCanvas = Utils.searchRootCanvasInParents(this);
1628
+ this._setIsRootCanvas(!rootCanvas);
1629
+ Utils.setRootCanvas(this, rootCanvas);
1630
+ } else if (flag === 4) {
1631
+ this._setIsRootCanvas(false);
1632
+ Utils.setRootCanvas(this, param);
1633
+ }
2160
1634
  } else {
2161
- this._unRegisterListener(element._groupListener, element._groupListeningEntities);
1635
+ if (flag === EntityModifyFlags.Parent) {
1636
+ var rootCanvas1 = Utils.searchRootCanvasInParents(this);
1637
+ this._setIsRootCanvas(!rootCanvas1);
1638
+ Utils.setRootCanvas(this, rootCanvas1);
1639
+ }
2162
1640
  }
2163
1641
  };
2164
- Utils.cleanGroup = function cleanGroup(element) {
2165
- this._registerGroup(element, null);
2166
- this._unRegisterListener(element._groupListener, element._groupListeningEntities);
1642
+ /**
1643
+ * @inheritdoc
1644
+ */ _proto._onClone = function _onClone(target) {
1645
+ target.renderMode = this._renderMode;
2167
1646
  };
2168
- Utils.searchGroupInParents = function searchGroupInParents(element) {
2169
- var rootCanvas = element._getRootCanvas();
2170
- if (!rootCanvas) return null;
2171
- var entity = _instanceof(element, UIGroup) ? element.entity.parent : element.entity;
2172
- var rootCanvasParent = rootCanvas.entity.parent;
2173
- while(entity && entity !== rootCanvasParent){
2174
- // @ts-ignore
2175
- var components = entity._components;
2176
- for(var i = 0, n = components.length; i < n; i++){
2177
- var component = components[i];
2178
- if (component.enabled && _instanceof(component, UIGroup)) {
2179
- return component;
2180
- }
2181
- }
2182
- entity = entity.parent;
1647
+ _proto._getRenderers = function _getRenderers() {
1648
+ var _this = this, renderers = _this._orderedRenderers, entity = _this.entity;
1649
+ var uiHierarchyVersion = entity._uiHierarchyVersion;
1650
+ if (this._hierarchyVersion !== uiHierarchyVersion) {
1651
+ renderers.length = this._walk(this.entity, renderers);
1652
+ UICanvas._tempGroupAbleList.length = 0;
1653
+ this._hierarchyVersion = uiHierarchyVersion;
1654
+ ++UICanvas._hierarchyCounter;
2183
1655
  }
2184
- return null;
1656
+ return renderers;
2185
1657
  };
2186
- Utils._registerRootCanvas = function _registerRootCanvas(element, canvas) {
2187
- var preCanvas = element._rootCanvas;
2188
- if (preCanvas !== canvas) {
2189
- if (preCanvas) {
2190
- var replaced = preCanvas._disorderedElements.deleteByIndex(element._indexInRootCanvas);
2191
- replaced && (replaced._indexInRootCanvas = element._indexInRootCanvas);
2192
- element._indexInRootCanvas = -1;
2193
- }
2194
- if (canvas) {
2195
- var disorderedElements = canvas._disorderedElements;
2196
- element._indexInRootCanvas = disorderedElements.length;
2197
- disorderedElements.add(element);
1658
+ _proto._adapterPoseInScreenSpace = function _adapterPoseInScreenSpace() {
1659
+ var transform = this.entity.transform;
1660
+ var realRenderMode = this._realRenderMode;
1661
+ if (realRenderMode === CanvasRenderMode.ScreenSpaceCamera) {
1662
+ var cameraEntity = this._camera.entity;
1663
+ if (!this._isSameOrChildEntity(cameraEntity)) {
1664
+ var cameraTransform = cameraEntity.transform;
1665
+ var cameraWorldPosition = cameraTransform.worldPosition, cameraWorldForward = cameraTransform.worldForward;
1666
+ var distance = this._distance;
1667
+ transform.setWorldPosition(cameraWorldPosition.x + cameraWorldForward.x * distance, cameraWorldPosition.y + cameraWorldForward.y * distance, cameraWorldPosition.z + cameraWorldForward.z * distance);
1668
+ transform.worldRotationQuaternion.copyFrom(cameraTransform.worldRotationQuaternion);
2198
1669
  }
2199
- element._rootCanvas = canvas;
1670
+ } else {
1671
+ var canvas = this.engine.canvas;
1672
+ transform.setWorldPosition(canvas.width * 0.5, canvas.height * 0.5, 0);
1673
+ transform.worldRotationQuaternion.set(0, 0, 0, 1);
2200
1674
  }
2201
1675
  };
2202
- Utils._registerGroup = function _registerGroup(element, group) {
2203
- var preGroup = element._group;
2204
- if (preGroup !== group) {
2205
- if (preGroup) {
2206
- var replaced = preGroup._disorderedElements.deleteByIndex(element._indexInGroup);
2207
- replaced && (replaced._indexInGroup = element._indexInGroup);
2208
- element._indexInGroup = -1;
2209
- }
2210
- if (group) {
2211
- var disorderedElements = group._disorderedElements;
2212
- element._indexInGroup = disorderedElements.length;
2213
- disorderedElements.add(element);
2214
- }
2215
- element._group = group;
2216
- element._onGroupModify(GroupModifyFlags.All);
1676
+ _proto._adapterSizeInScreenSpace = function _adapterSizeInScreenSpace() {
1677
+ var transform = this.entity.transform;
1678
+ var realRenderMode = this._realRenderMode;
1679
+ var _this__referenceResolution = this._referenceResolution, width = _this__referenceResolution.x, height = _this__referenceResolution.y;
1680
+ var curWidth;
1681
+ var curHeight;
1682
+ if (realRenderMode === CanvasRenderMode.ScreenSpaceCamera) {
1683
+ var camera = this._camera;
1684
+ curHeight = camera.isOrthographic ? camera.orthographicSize * 2 : 2 * (Math.tan(MathUtil.degreeToRadian(camera.fieldOfView * 0.5)) * this._distance);
1685
+ curWidth = camera.aspectRatio * curHeight;
1686
+ } else {
1687
+ var canvas = this.engine.canvas;
1688
+ curHeight = canvas.height;
1689
+ curWidth = canvas.width;
1690
+ }
1691
+ var expectX, expectY, expectZ;
1692
+ switch(this._resolutionAdaptationMode){
1693
+ case ResolutionAdaptationMode.WidthAdaptation:
1694
+ expectX = expectY = expectZ = curWidth / width;
1695
+ break;
1696
+ case ResolutionAdaptationMode.HeightAdaptation:
1697
+ expectX = expectY = expectZ = curHeight / height;
1698
+ break;
1699
+ case ResolutionAdaptationMode.BothAdaptation:
1700
+ expectX = curWidth / width;
1701
+ expectY = curHeight / height;
1702
+ expectZ = (expectX + expectY) * 0.5;
1703
+ break;
1704
+ case ResolutionAdaptationMode.ExpandAdaptation:
1705
+ expectX = expectY = expectZ = Math.min(curWidth / width, curHeight / height);
1706
+ break;
1707
+ case ResolutionAdaptationMode.ShrinkAdaptation:
1708
+ expectX = expectY = expectZ = Math.max(curWidth / width, curHeight / height);
1709
+ break;
2217
1710
  }
1711
+ var worldMatrix = UICanvas._tempMat;
1712
+ Matrix.affineTransformation(UICanvas._tempVec3.set(expectX, expectY, expectZ), transform.worldRotationQuaternion, transform.worldPosition, worldMatrix);
1713
+ transform.worldMatrix = worldMatrix;
1714
+ transform.size.set(curWidth / expectX, curHeight / expectY);
2218
1715
  };
2219
- Utils._registerListener = function _registerListener(entity, root, listener, listeningEntities) {
2220
- var count = 0;
2221
- while(entity && entity !== root){
2222
- var preEntity = listeningEntities[count];
2223
- if (preEntity !== entity) {
2224
- // @ts-ignore
2225
- preEntity == null ? void 0 : preEntity._unRegisterModifyListener(listener);
2226
- listeningEntities[count] = entity;
2227
- // @ts-ignore
2228
- entity._registerModifyListener(listener);
1716
+ _proto._walk = function _walk(entity, renderers, depth, group) {
1717
+ if (depth === void 0) depth = 0;
1718
+ if (group === void 0) group = null;
1719
+ // @ts-ignore
1720
+ var components = entity._components;
1721
+ var tempGroupAbleList = UICanvas._tempGroupAbleList;
1722
+ var groupAbleCount = 0;
1723
+ for(var i = 0, n = components.length; i < n; i++){
1724
+ var component = components[i];
1725
+ if (!component.enabled) continue;
1726
+ if (_instanceof(component, UIRenderer)) {
1727
+ renderers[depth] = component;
1728
+ ++depth;
1729
+ component._isRootCanvasDirty && Utils.setRootCanvas(component, this);
1730
+ if (component._isGroupDirty) {
1731
+ tempGroupAbleList[groupAbleCount++] = component;
1732
+ }
1733
+ } else if (_instanceof(component, UIInteractive)) {
1734
+ component._isRootCanvasDirty && Utils.setRootCanvas(component, this);
1735
+ if (component._isGroupDirty) {
1736
+ tempGroupAbleList[groupAbleCount++] = component;
1737
+ }
1738
+ } else if (_instanceof(component, UIGroup)) {
1739
+ component._isRootCanvasDirty && Utils.setRootCanvas(component, this);
1740
+ component._isGroupDirty && Utils.setGroup(component, group);
1741
+ group = component;
2229
1742
  }
2230
- entity = entity.parent;
2231
- count++;
2232
1743
  }
2233
- listeningEntities.length = count;
2234
- };
2235
- Utils._unRegisterListener = function _unRegisterListener(listener, listeningEntities) {
2236
- for(var i = 0, n = listeningEntities.length; i < n; i++){
2237
- // @ts-ignore
2238
- listeningEntities[i]._unRegisterModifyListener(listener);
1744
+ for(var i1 = 0; i1 < groupAbleCount; i1++){
1745
+ Utils.setGroup(tempGroupAbleList[i1], group);
2239
1746
  }
2240
- listeningEntities.length = 0;
2241
- };
2242
- return Utils;
2243
- }();
2244
- Utils._tempRay = new Ray();
2245
- Utils._tempPlane = new Plane();
2246
- Utils._tempVec3 = new Vector3();
2247
- Utils._tempMat = new Matrix();
2248
-
2249
- /**
2250
- * Interactive component.
2251
- */ var UIInteractive = /*#__PURE__*/ function(Script) {
2252
- _inherits(UIInteractive, Script);
2253
- function UIInteractive(entity) {
2254
- var _this;
2255
- _this = Script.call(this, entity) || this, /** @internal */ _this._indexInRootCanvas = -1, /** @internal */ _this._isRootCanvasDirty = false, /** @internal */ _this._rootCanvasListeningEntities = [], /** @internal */ _this._indexInGroup = -1, /** @internal */ _this._isGroupDirty = false, /** @internal */ _this._groupListeningEntities = [], /** @internal */ _this._globalInteractive = false, /** @internal */ _this._globalInteractiveDirty = false, _this._transitions = [], _this._interactive = true, _this._state = 0, /** @todo Multi-touch points are not considered yet. */ _this._isPointerInside = false, _this._isPointerDragging = false;
2256
- _this._groupListener = _this._groupListener.bind(_this);
2257
- _this._rootCanvasListener = _this._rootCanvasListener.bind(_this);
2258
- return _this;
2259
- }
2260
- var _proto = UIInteractive.prototype;
2261
- /**
2262
- * Add transition on this interactive.
2263
- * @param transition - The transition
2264
- */ _proto.addTransition = function addTransition(transition) {
2265
- var interactive = transition._interactive;
2266
- if (interactive !== this) {
2267
- interactive == null ? void 0 : interactive.removeTransition(transition);
2268
- this._transitions.push(transition);
2269
- transition._interactive = this;
2270
- transition._setState(this._state, true);
1747
+ var children = entity.children;
1748
+ for(var i2 = 0, n1 = children.length; i2 < n1; i2++){
1749
+ var child = children[i2];
1750
+ child.isActive && (depth = this._walk(child, renderers, depth, group));
2271
1751
  }
1752
+ return depth;
2272
1753
  };
2273
- /**
2274
- * Remove a transition.
2275
- * @param shape - The transition.
2276
- */ _proto.removeTransition = function removeTransition(transition) {
2277
- var transitions = this._transitions;
2278
- var lastOneIndex = transitions.length - 1;
2279
- for(var i = lastOneIndex; i >= 0; i--){
2280
- if (transitions[i] === transition) {
2281
- i !== lastOneIndex && (transitions[i] = transitions[lastOneIndex]);
2282
- transitions.length = lastOneIndex;
2283
- transition._interactive = null;
2284
- break;
1754
+ _proto._updateCameraObserver = function _updateCameraObserver() {
1755
+ var camera = this._isRootCanvas && this._renderMode === CanvasRenderMode.ScreenSpaceCamera ? this._camera : null;
1756
+ var preCamera = this._cameraObserver;
1757
+ if (preCamera !== camera) {
1758
+ this._cameraObserver = camera;
1759
+ if (preCamera) {
1760
+ // @ts-ignore
1761
+ preCamera.entity._updateFlagManager.removeListener(this._onCameraTransformListener);
1762
+ // @ts-ignore
1763
+ preCamera._unRegisterModifyListener(this._onCameraModifyListener);
1764
+ }
1765
+ if (camera) {
1766
+ // @ts-ignore
1767
+ camera.entity._updateFlagManager.addListener(this._onCameraTransformListener);
1768
+ // @ts-ignore
1769
+ camera._registerModifyListener(this._onCameraModifyListener);
2285
1770
  }
2286
1771
  }
2287
1772
  };
2288
- /**
2289
- * Remove all transitions.
2290
- */ _proto.clearTransitions = function clearTransitions() {
2291
- var transitions = this._transitions;
2292
- for(var i = 0, n = transitions.length; i < n; i++){
2293
- transitions[i]._interactive = null;
2294
- }
2295
- transitions.length = 0;
2296
- };
2297
- _proto.onUpdate = function onUpdate(deltaTime) {
2298
- if (this._getGlobalInteractive()) {
2299
- var transitions = this._transitions;
2300
- for(var i = 0, n = transitions.length; i < n; i++){
2301
- transitions[i]._onUpdate(deltaTime);
1773
+ _proto._onCameraModifyListener = function _onCameraModifyListener(flag) {
1774
+ if (this._realRenderMode === CanvasRenderMode.ScreenSpaceCamera) {
1775
+ switch(flag){
1776
+ case CameraModifyFlags.ProjectionType:
1777
+ case CameraModifyFlags.AspectRatio:
1778
+ this._adapterSizeInScreenSpace();
1779
+ break;
1780
+ case CameraModifyFlags.FieldOfView:
1781
+ !this._camera.isOrthographic && this._adapterSizeInScreenSpace();
1782
+ break;
1783
+ case CameraModifyFlags.OrthographicSize:
1784
+ this._camera.isOrthographic && this._adapterSizeInScreenSpace();
1785
+ break;
1786
+ case CameraModifyFlags.DisableInScene:
1787
+ this._setRealRenderMode(CanvasRenderMode.ScreenSpaceOverlay);
1788
+ break;
2302
1789
  }
1790
+ } else {
1791
+ flag === CameraModifyFlags.EnableInScene && this._setRealRenderMode(CanvasRenderMode.ScreenSpaceCamera);
2303
1792
  }
2304
1793
  };
2305
- _proto.onPointerBeginDrag = function onPointerBeginDrag() {
2306
- this._isPointerDragging = true;
2307
- this._updateState(false);
1794
+ _proto._onCameraTransformListener = function _onCameraTransformListener() {
1795
+ this._realRenderMode === CanvasRenderMode.ScreenSpaceCamera && this._adapterPoseInScreenSpace();
2308
1796
  };
2309
- _proto.onPointerEndDrag = function onPointerEndDrag() {
2310
- this._isPointerDragging = false;
2311
- this._updateState(false);
1797
+ _proto._addCanvasListener = function _addCanvasListener() {
1798
+ // @ts-ignore
1799
+ this.engine.canvas._sizeUpdateFlagManager.addListener(this._onCanvasSizeListener);
2312
1800
  };
2313
- _proto.onPointerEnter = function onPointerEnter() {
2314
- this._isPointerInside = true;
2315
- this._updateState(false);
1801
+ _proto._removeCanvasListener = function _removeCanvasListener() {
1802
+ // @ts-ignore
1803
+ this.engine.canvas._sizeUpdateFlagManager.removeListener(this._onCanvasSizeListener);
2316
1804
  };
2317
- _proto.onPointerExit = function onPointerExit() {
2318
- this._isPointerInside = false;
2319
- this._updateState(false);
1805
+ _proto._onCanvasSizeListener = function _onCanvasSizeListener() {
1806
+ var canvas = this.engine.canvas;
1807
+ this.entity.transform.setWorldPosition(canvas.width * 0.5, canvas.height * 0.5, 0);
1808
+ this._adapterSizeInScreenSpace();
2320
1809
  };
2321
- _proto.onDestroy = function onDestroy() {
2322
- Script.prototype.onDestroy.call(this);
2323
- var transitions = this._transitions;
2324
- for(var i = transitions.length - 1; i >= 0; i--){
2325
- transitions[i].destroy();
1810
+ _proto._onReferenceResolutionChanged = function _onReferenceResolutionChanged() {
1811
+ var realRenderMode = this._realRenderMode;
1812
+ if (realRenderMode === CanvasRenderMode.ScreenSpaceOverlay || realRenderMode === CanvasRenderMode.ScreenSpaceCamera) {
1813
+ this._adapterSizeInScreenSpace();
2326
1814
  }
2327
1815
  };
2328
- /**
2329
- * @internal
2330
- */ _proto._getRootCanvas = function _getRootCanvas() {
2331
- this._isRootCanvasDirty && Utils.setRootCanvas(this, Utils.searchRootCanvasInParents(this));
2332
- return this._rootCanvas;
2333
- };
2334
- /**
2335
- * @internal
2336
- */ _proto._getGroup = function _getGroup() {
2337
- this._isGroupDirty && Utils.setGroup(this, Utils.searchGroupInParents(this));
2338
- return this._group;
2339
- };
2340
- // @ts-ignore
2341
- _proto._onEnableInScene = function _onEnableInScene() {
2342
- // @ts-ignore
2343
- Script.prototype._onEnableInScene.call(this);
2344
- Utils.setRootCanvasDirty(this);
2345
- Utils.setGroupDirty(this);
2346
- this._updateState(true);
2347
- };
2348
- // @ts-ignore
2349
- _proto._onDisableInScene = function _onDisableInScene() {
2350
- // @ts-ignore
2351
- Script.prototype._onDisableInScene.call(this);
2352
- Utils.cleanRootCanvas(this);
2353
- Utils.cleanGroup(this);
2354
- this._isPointerInside = this._isPointerDragging = false;
2355
- };
2356
- /**
2357
- * @internal
2358
- */ _proto._groupListener = function _groupListener(flag) {
2359
- if (flag === EntityModifyFlags.Parent || flag === EntityUIModifyFlags.GroupEnableInScene) {
2360
- Utils.setGroupDirty(this);
1816
+ _proto._setIsRootCanvas = function _setIsRootCanvas(isRootCanvas) {
1817
+ var _this = this;
1818
+ if (this._isRootCanvas !== isRootCanvas) {
1819
+ this._isRootCanvas = isRootCanvas;
1820
+ this._updateCameraObserver();
1821
+ this._setRealRenderMode(this._getRealRenderMode());
1822
+ if (isRootCanvas) {
1823
+ this.entity._updateUIHierarchyVersion(UICanvas._hierarchyCounter);
1824
+ } else {
1825
+ var _this1 = this, disorderedElements = _this1._disorderedElements;
1826
+ disorderedElements.forEach(function(element) {
1827
+ if (_instanceof(element, UICanvas)) {
1828
+ var rootCanvas = Utils.searchRootCanvasInParents(element);
1829
+ element._setIsRootCanvas(!rootCanvas);
1830
+ Utils.setRootCanvas(element, rootCanvas);
1831
+ } else {
1832
+ Utils.setRootCanvasDirty(_this);
1833
+ Utils.setGroupDirty(element);
1834
+ }
1835
+ });
1836
+ disorderedElements.length = 0;
1837
+ disorderedElements.garbageCollection();
1838
+ this._orderedRenderers.length = 0;
1839
+ }
2361
1840
  }
2362
1841
  };
2363
- /**
2364
- * @internal
2365
- */ _proto._rootCanvasListener = function _rootCanvasListener(flag) {
2366
- if (flag === EntityModifyFlags.Parent || flag === EntityUIModifyFlags.CanvasEnableInScene) {
2367
- Utils.setRootCanvasDirty(this);
2368
- Utils.setGroupDirty(this);
1842
+ _proto._getCenter = function _getCenter() {
1843
+ if (this._centerDirtyFlag.flag) {
1844
+ var center = this._center;
1845
+ var uiTransform = this.entity.transform;
1846
+ var pivot = uiTransform.pivot, size = uiTransform.size;
1847
+ center.set((0.5 - pivot.x) * size.x, (0.5 - pivot.y) * size.y, 0);
1848
+ Vector3.transformCoordinate(center, uiTransform.worldMatrix, center);
1849
+ this._centerDirtyFlag.flag = false;
2369
1850
  }
1851
+ return this._center;
2370
1852
  };
2371
- /**
2372
- * @internal
2373
- */ _proto._onGroupModify = function _onGroupModify(flags) {
2374
- if (flags & GroupModifyFlags.GlobalInteractive) {
2375
- this._globalInteractiveDirty = true;
1853
+ _proto._getRealRenderMode = function _getRealRenderMode() {
1854
+ if (this._isRootCanvas) {
1855
+ var _this__camera;
1856
+ var mode = this._renderMode;
1857
+ // @ts-ignore
1858
+ if (mode === CanvasRenderMode.ScreenSpaceCamera && !((_this__camera = this._camera) == null ? void 0 : _this__camera._phasedActiveInScene)) {
1859
+ return CanvasRenderMode.ScreenSpaceOverlay;
1860
+ } else {
1861
+ return mode;
1862
+ }
1863
+ } else {
1864
+ return 4;
2376
1865
  }
2377
1866
  };
2378
- /**
2379
- * @internal
2380
- */ _proto._getGlobalInteractive = function _getGlobalInteractive() {
2381
- if (this._globalInteractiveDirty) {
2382
- var group = this._getGroup();
2383
- var globalInteractive = this._interactive && (!group || group._getGlobalInteractive());
2384
- if (this._globalInteractive !== globalInteractive) {
2385
- this._globalInteractive = globalInteractive;
2386
- this._updateState(true);
1867
+ _proto._setRealRenderMode = function _setRealRenderMode(curRealMode) {
1868
+ var preRealMode = this._realRenderMode;
1869
+ if (preRealMode !== curRealMode) {
1870
+ this._realRenderMode = curRealMode;
1871
+ // @ts-ignore
1872
+ var componentsManager = this.scene._componentsManager;
1873
+ switch(preRealMode){
1874
+ case CanvasRenderMode.ScreenSpaceOverlay:
1875
+ this._removeCanvasListener();
1876
+ case CanvasRenderMode.ScreenSpaceCamera:
1877
+ case CanvasRenderMode.WorldSpace:
1878
+ componentsManager.removeUICanvas(this, preRealMode === CanvasRenderMode.ScreenSpaceOverlay);
1879
+ break;
1880
+ }
1881
+ switch(curRealMode){
1882
+ case CanvasRenderMode.ScreenSpaceOverlay:
1883
+ this._addCanvasListener();
1884
+ case CanvasRenderMode.ScreenSpaceCamera:
1885
+ this._adapterPoseInScreenSpace();
1886
+ this._adapterSizeInScreenSpace();
1887
+ case CanvasRenderMode.WorldSpace:
1888
+ componentsManager.addUICanvas(this, curRealMode === CanvasRenderMode.ScreenSpaceOverlay);
1889
+ break;
2387
1890
  }
2388
- this._globalInteractiveDirty = false;
2389
1891
  }
2390
- return this._globalInteractive;
2391
1892
  };
2392
- _proto._updateState = function _updateState(instant) {
2393
- var state = this._getInteractiveState();
2394
- if (this._state !== state) {
2395
- this._state = state;
2396
- var transitions = this._transitions;
2397
- for(var i = 0, n = transitions.length; i < n; i++){
2398
- transitions[i]._setState(state, instant);
1893
+ _proto._isSameOrChildEntity = function _isSameOrChildEntity(cameraEntity) {
1894
+ var canvasEntity = this.entity;
1895
+ while(cameraEntity){
1896
+ if (cameraEntity === canvasEntity) return true;
1897
+ cameraEntity = cameraEntity.parent;
1898
+ }
1899
+ return false;
1900
+ };
1901
+ _create_class(UICanvas, [
1902
+ {
1903
+ key: "referenceResolutionPerUnit",
1904
+ get: /**
1905
+ * The conversion ratio between reference resolution and unit for UI elements in this canvas.
1906
+ */ function get() {
1907
+ return this._referenceResolutionPerUnit;
1908
+ },
1909
+ set: function set(value) {
1910
+ if (this._referenceResolutionPerUnit !== value) {
1911
+ this._referenceResolutionPerUnit = value;
1912
+ this._disorderedElements.forEach(function(element) {
1913
+ element._onRootCanvasModify == null ? void 0 : element._onRootCanvasModify.call(element, 1);
1914
+ });
1915
+ }
1916
+ }
1917
+ },
1918
+ {
1919
+ key: "referenceResolution",
1920
+ get: /**
1921
+ * The reference resolution of the UI canvas in `ScreenSpaceCamera` and `ScreenSpaceOverlay` mode.
1922
+ */ function get() {
1923
+ return this._referenceResolution;
1924
+ },
1925
+ set: function set(value) {
1926
+ var referenceResolution = this._referenceResolution;
1927
+ if (referenceResolution === value) return;
1928
+ (referenceResolution.x !== value.x || referenceResolution.y !== value.y) && referenceResolution.copyFrom(value);
1929
+ }
1930
+ },
1931
+ {
1932
+ key: "renderMode",
1933
+ get: /**
1934
+ * The rendering mode of the UI canvas.
1935
+ */ function get() {
1936
+ return this._renderMode;
1937
+ },
1938
+ set: function set(mode) {
1939
+ var preMode = this._renderMode;
1940
+ if (preMode !== mode) {
1941
+ this._renderMode = mode;
1942
+ this._updateCameraObserver();
1943
+ this._setRealRenderMode(this._getRealRenderMode());
1944
+ }
1945
+ }
1946
+ },
1947
+ {
1948
+ key: "camera",
1949
+ get: /**
1950
+ * The camera associated with this canvas.
1951
+ * @remarks
1952
+ * - `ScreenSpaceCamera` mode: Used for rendering adaptation. Defaults to `ScreenSpaceOverlay` if not assigned.
1953
+ * - `WorldSpace` mode: Used for event detection. If not assigned, events are handled by the highest-priority camera.
1954
+ */ function get() {
1955
+ return this._camera;
1956
+ },
1957
+ set: function set(value) {
1958
+ var preCamera = this._camera;
1959
+ if (preCamera !== value) {
1960
+ if (value && this._isSameOrChildEntity(value.entity)) {
1961
+ Logger.warn("Camera entity matching or nested within the canvas entity disables canvas auto-adaptation in ScreenSpaceCamera mode.");
1962
+ }
1963
+ this._camera = value;
1964
+ this._updateCameraObserver();
1965
+ var preRenderMode = this._realRenderMode;
1966
+ var curRenderMode = this._getRealRenderMode();
1967
+ if (preRenderMode === curRenderMode) {
1968
+ if (curRenderMode === CanvasRenderMode.ScreenSpaceCamera) {
1969
+ this._adapterPoseInScreenSpace();
1970
+ this._adapterSizeInScreenSpace();
1971
+ }
1972
+ } else {
1973
+ this._setRealRenderMode(curRenderMode);
1974
+ }
1975
+ }
1976
+ }
1977
+ },
1978
+ {
1979
+ key: "renderCamera",
1980
+ get: /**
1981
+ * @deprecated Use {@link camera} instead.
1982
+ */ function get() {
1983
+ return this.camera;
1984
+ },
1985
+ set: function set(value) {
1986
+ this.camera = value;
2399
1987
  }
2400
- }
2401
- };
2402
- _proto._getInteractiveState = function _getInteractiveState() {
2403
- if (!this._getGlobalInteractive()) {
2404
- return 3;
2405
- }
2406
- if (this._isPointerDragging) {
2407
- return 1;
2408
- } else {
2409
- return this._isPointerInside ? 2 : 0;
2410
- }
2411
- };
2412
- _create_class(UIInteractive, [
1988
+ },
2413
1989
  {
2414
- key: "transitions",
1990
+ key: "resolutionAdaptationMode",
2415
1991
  get: /**
2416
- * The transitions of this interactive.
1992
+ * The screen resolution adaptation mode of the UI canvas in `ScreenSpaceCamera` and `ScreenSpaceOverlay` mode.
2417
1993
  */ function get() {
2418
- return this._transitions;
1994
+ return this._resolutionAdaptationMode;
1995
+ },
1996
+ set: function set(value) {
1997
+ if (this._resolutionAdaptationMode !== value) {
1998
+ this._resolutionAdaptationMode = value;
1999
+ var realRenderMode = this._realRenderMode;
2000
+ if (realRenderMode === CanvasRenderMode.ScreenSpaceCamera || realRenderMode === CanvasRenderMode.ScreenSpaceOverlay) {
2001
+ this._adapterSizeInScreenSpace();
2002
+ }
2003
+ }
2419
2004
  }
2420
2005
  },
2421
2006
  {
2422
- key: "interactive",
2007
+ key: "sortOrder",
2423
2008
  get: /**
2424
- * Whether the interactive is enabled.
2009
+ * The rendering order priority of the UI canvas in `ScreenSpaceOverlay` mode.
2425
2010
  */ function get() {
2426
- return this._interactive;
2011
+ return this._sortOrder;
2427
2012
  },
2428
2013
  set: function set(value) {
2429
- if (this._interactive !== value) {
2430
- this._interactive = value;
2431
- this._globalInteractiveDirty = true;
2014
+ if (this._sortOrder !== value) {
2015
+ this._sortOrder = value;
2016
+ this._realRenderMode === CanvasRenderMode.ScreenSpaceOverlay && // @ts-ignore
2017
+ (this.scene._componentsManager._overlayCanvasesSortingFlag = true);
2018
+ }
2019
+ }
2020
+ },
2021
+ {
2022
+ key: "distance",
2023
+ get: /**
2024
+ * The distance between the UI canvas and the camera in `ScreenSpaceCamera` mode.
2025
+ */ function get() {
2026
+ return this._distance;
2027
+ },
2028
+ set: function set(value) {
2029
+ if (this._distance !== value) {
2030
+ this._distance = value;
2031
+ if (this._realRenderMode === CanvasRenderMode.ScreenSpaceCamera) {
2032
+ this._adapterPoseInScreenSpace();
2033
+ this._adapterSizeInScreenSpace();
2034
+ }
2432
2035
  }
2433
2036
  }
2434
2037
  }
2435
2038
  ]);
2436
- return UIInteractive;
2437
- }(Script);
2039
+ return UICanvas;
2040
+ }(Component);
2041
+ /** @internal */ UICanvas._hierarchyCounter = 1;
2042
+ UICanvas._tempGroupAbleList = [];
2043
+ UICanvas._tempVec3 = new Vector3();
2044
+ UICanvas._tempMat = new Matrix();
2438
2045
  __decorate([
2439
2046
  ignoreClone
2440
- ], UIInteractive.prototype, "_indexInRootCanvas", void 0);
2047
+ ], UICanvas.prototype, "_canvasIndex", void 0);
2441
2048
  __decorate([
2442
2049
  ignoreClone
2443
- ], UIInteractive.prototype, "_isRootCanvasDirty", void 0);
2050
+ ], UICanvas.prototype, "_indexInRootCanvas", void 0);
2444
2051
  __decorate([
2445
2052
  ignoreClone
2446
- ], UIInteractive.prototype, "_rootCanvasListeningEntities", void 0);
2053
+ ], UICanvas.prototype, "_isRootCanvasDirty", void 0);
2447
2054
  __decorate([
2448
2055
  ignoreClone
2449
- ], UIInteractive.prototype, "_indexInGroup", void 0);
2056
+ ], UICanvas.prototype, "_rootCanvasListeningEntities", void 0);
2450
2057
  __decorate([
2451
2058
  ignoreClone
2452
- ], UIInteractive.prototype, "_isGroupDirty", void 0);
2059
+ ], UICanvas.prototype, "_isRootCanvas", void 0);
2453
2060
  __decorate([
2454
2061
  ignoreClone
2455
- ], UIInteractive.prototype, "_groupListeningEntities", void 0);
2062
+ ], UICanvas.prototype, "_renderElements", void 0);
2456
2063
  __decorate([
2457
2064
  ignoreClone
2458
- ], UIInteractive.prototype, "_globalInteractive", void 0);
2065
+ ], UICanvas.prototype, "_batchedRenderElements", void 0);
2459
2066
  __decorate([
2460
2067
  ignoreClone
2461
- ], UIInteractive.prototype, "_globalInteractiveDirty", void 0);
2068
+ ], UICanvas.prototype, "_sortDistance", void 0);
2462
2069
  __decorate([
2463
2070
  ignoreClone
2464
- ], UIInteractive.prototype, "_state", void 0);
2071
+ ], UICanvas.prototype, "_orderedRenderers", void 0);
2465
2072
  __decorate([
2466
2073
  ignoreClone
2467
- ], UIInteractive.prototype, "_isPointerInside", void 0);
2074
+ ], UICanvas.prototype, "_realRenderMode", void 0);
2468
2075
  __decorate([
2469
2076
  ignoreClone
2470
- ], UIInteractive.prototype, "_isPointerDragging", void 0);
2077
+ ], UICanvas.prototype, "_renderMode", void 0);
2471
2078
  __decorate([
2472
2079
  ignoreClone
2473
- ], UIInteractive.prototype, "_groupListener", null);
2080
+ ], UICanvas.prototype, "_hierarchyVersion", void 0);
2474
2081
  __decorate([
2475
2082
  ignoreClone
2476
- ], UIInteractive.prototype, "_rootCanvasListener", null);
2083
+ ], UICanvas.prototype, "_center", void 0);
2477
2084
  __decorate([
2478
2085
  ignoreClone
2479
- ], UIInteractive.prototype, "_onGroupModify", null);
2480
- var InteractiveState = /*#__PURE__*/ function(InteractiveState) {
2481
- InteractiveState[InteractiveState["Normal"] = 0] = "Normal";
2482
- InteractiveState[InteractiveState["Pressed"] = 1] = "Pressed";
2483
- InteractiveState[InteractiveState["Hover"] = 2] = "Hover";
2484
- InteractiveState[InteractiveState["Disable"] = 3] = "Disable";
2485
- return InteractiveState;
2086
+ ], UICanvas.prototype, "_rootCanvasListener", null);
2087
+ __decorate([
2088
+ ignoreClone
2089
+ ], UICanvas.prototype, "_onCameraModifyListener", null);
2090
+ __decorate([
2091
+ ignoreClone
2092
+ ], UICanvas.prototype, "_onCameraTransformListener", null);
2093
+ __decorate([
2094
+ ignoreClone
2095
+ ], UICanvas.prototype, "_onCanvasSizeListener", null);
2096
+ __decorate([
2097
+ ignoreClone
2098
+ ], UICanvas.prototype, "_onReferenceResolutionChanged", null);
2099
+ UICanvas = __decorate([
2100
+ dependentComponents(UITransform, DependentMode.AutoAdd)
2101
+ ], UICanvas);
2102
+ /**
2103
+ * @remarks Extends `EntityModifyFlags`.
2104
+ */ var EntityUIModifyFlags = /*#__PURE__*/ function(EntityUIModifyFlags) {
2105
+ EntityUIModifyFlags[EntityUIModifyFlags["CanvasEnableInScene"] = 4] = "CanvasEnableInScene";
2106
+ EntityUIModifyFlags[EntityUIModifyFlags["GroupEnableInScene"] = 8] = "GroupEnableInScene";
2107
+ return EntityUIModifyFlags;
2108
+ }({});
2109
+ var RootCanvasModifyFlags = /*#__PURE__*/ function(RootCanvasModifyFlags) {
2110
+ RootCanvasModifyFlags[RootCanvasModifyFlags["None"] = 0] = "None";
2111
+ RootCanvasModifyFlags[RootCanvasModifyFlags["ReferenceResolutionPerUnit"] = 1] = "ReferenceResolutionPerUnit";
2112
+ RootCanvasModifyFlags[RootCanvasModifyFlags["All"] = 1] = "All";
2113
+ return RootCanvasModifyFlags;
2486
2114
  }({});
2487
2115
 
2488
2116
  var Button = /*#__PURE__*/ function(UIInteractive) {
@@ -2522,7 +2150,7 @@ var Button = /*#__PURE__*/ function(UIInteractive) {
2522
2150
  _inherits(Image, UIRenderer1);
2523
2151
  function Image(entity) {
2524
2152
  var _this;
2525
- _this = UIRenderer1.call(this, entity) || this, _this._sprite = null, _this._tileMode = SpriteTileMode.Continuous, _this._tiledAdaptiveThreshold = 0.5, _this._filledMode = SpriteFilledMode.Radial360, _this._filledAmount = 1, _this._filledOrigin = SpriteFilledOrigin.Bottom, _this._filledClockWise = true;
2153
+ _this = UIRenderer1.call(this, entity) || this, _this._sprite = null, _this._tileMode = SpriteTileMode.Continuous, _this._tiledAdaptiveThreshold = 0.5;
2526
2154
  _this.drawMode = SpriteDrawMode.Simple;
2527
2155
  // @ts-ignore
2528
2156
  _this.setMaterial(_this._engine._getUIDefaultMaterial());
@@ -2610,7 +2238,7 @@ var Button = /*#__PURE__*/ function(UIInteractive) {
2610
2238
  canvas._renderElements.push(renderElement);
2611
2239
  };
2612
2240
  _proto._onTransformChanged = function _onTransformChanged(type) {
2613
- if (type & UITransformModifyFlags.Size && (this._drawMode === SpriteDrawMode.Tiled || this._drawMode === SpriteDrawMode.Filled)) {
2241
+ if (type & UITransformModifyFlags.Size && this._drawMode === SpriteDrawMode.Tiled) {
2614
2242
  this._dirtyUpdateFlag |= 15;
2615
2243
  }
2616
2244
  this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
@@ -2638,9 +2266,6 @@ var Button = /*#__PURE__*/ function(UIInteractive) {
2638
2266
  case SpriteDrawMode.Tiled:
2639
2267
  this._dirtyUpdateFlag |= 7;
2640
2268
  break;
2641
- case SpriteDrawMode.Filled:
2642
- this._dirtyUpdateFlag |= 7;
2643
- break;
2644
2269
  }
2645
2270
  break;
2646
2271
  case SpriteModifyFlags.border:
@@ -2658,25 +2283,13 @@ var Button = /*#__PURE__*/ function(UIInteractive) {
2658
2283
  this._dirtyUpdateFlag |= 5;
2659
2284
  break;
2660
2285
  case SpriteModifyFlags.atlasRegion:
2661
- this._dirtyUpdateFlag |= this._drawMode === SpriteDrawMode.Filled ? 5 : 4;
2286
+ this._dirtyUpdateFlag |= 4;
2662
2287
  break;
2663
2288
  case SpriteModifyFlags.destroy:
2664
2289
  this.sprite = null;
2665
2290
  break;
2666
2291
  }
2667
2292
  };
2668
- Image._correctOrigin = function _correctOrigin(mode, origin) {
2669
- switch(mode){
2670
- case SpriteFilledMode.Horizontal:
2671
- return origin === SpriteFilledOrigin.Left || origin === SpriteFilledOrigin.Right ? origin : SpriteFilledOrigin.Left;
2672
- case SpriteFilledMode.Vertical:
2673
- return origin === SpriteFilledOrigin.Top || origin === SpriteFilledOrigin.Bottom ? origin : SpriteFilledOrigin.Bottom;
2674
- case SpriteFilledMode.Radial90:
2675
- return origin === SpriteFilledOrigin.TopLeft || origin === SpriteFilledOrigin.TopRight || origin === SpriteFilledOrigin.BottomLeft || origin === SpriteFilledOrigin.BottomRight ? origin : SpriteFilledOrigin.BottomLeft;
2676
- default:
2677
- return origin === SpriteFilledOrigin.Top || origin === SpriteFilledOrigin.Bottom || origin === SpriteFilledOrigin.Left || origin === SpriteFilledOrigin.Right ? origin : SpriteFilledOrigin.Bottom;
2678
- }
2679
- };
2680
2293
  _create_class(Image, [
2681
2294
  {
2682
2295
  key: "drawMode",
@@ -2698,9 +2311,6 @@ var Button = /*#__PURE__*/ function(UIInteractive) {
2698
2311
  case SpriteDrawMode.Tiled:
2699
2312
  this._assembler = TiledSpriteAssembler;
2700
2313
  break;
2701
- case SpriteDrawMode.Filled:
2702
- this._assembler = FilledSpriteAssembler;
2703
- break;
2704
2314
  }
2705
2315
  this._assembler.resetData(this);
2706
2316
  this._dirtyUpdateFlag |= 7;
@@ -2740,73 +2350,6 @@ var Button = /*#__PURE__*/ function(UIInteractive) {
2740
2350
  }
2741
2351
  }
2742
2352
  },
2743
- {
2744
- key: "filledAmount",
2745
- get: /**
2746
- * The fill amount of the image, range from 0 to 1. (Only works in filled mode.)
2747
- */ function get() {
2748
- return this._filledAmount;
2749
- },
2750
- set: function set(value) {
2751
- value = MathUtil.clamp(value, 0, 1);
2752
- if (this._filledAmount !== value) {
2753
- this._filledAmount = value;
2754
- if (this._drawMode === SpriteDrawMode.Filled) {
2755
- this._dirtyUpdateFlag |= 5;
2756
- }
2757
- }
2758
- }
2759
- },
2760
- {
2761
- key: "filledMode",
2762
- get: /**
2763
- * The fill mode of the image. (Only works in filled mode.)
2764
- */ function get() {
2765
- return this._filledMode;
2766
- },
2767
- set: function set(value) {
2768
- if (this._filledMode !== value) {
2769
- this._filledMode = value;
2770
- this._filledOrigin = Image._correctOrigin(value, this._filledOrigin);
2771
- if (this._drawMode === SpriteDrawMode.Filled) {
2772
- this._dirtyUpdateFlag |= 5;
2773
- }
2774
- }
2775
- }
2776
- },
2777
- {
2778
- key: "filledOrigin",
2779
- get: /**
2780
- * The fill origin of the image. (Only works in filled mode.)
2781
- */ function get() {
2782
- return this._filledOrigin;
2783
- },
2784
- set: function set(value) {
2785
- value = Image._correctOrigin(this._filledMode, value);
2786
- if (this._filledOrigin !== value) {
2787
- this._filledOrigin = value;
2788
- if (this._drawMode === SpriteDrawMode.Filled) {
2789
- this._dirtyUpdateFlag |= 5;
2790
- }
2791
- }
2792
- }
2793
- },
2794
- {
2795
- key: "filledClockWise",
2796
- get: /**
2797
- * Whether the fill is clockwise. (Only works in filled radial mode.)
2798
- */ function get() {
2799
- return this._filledClockWise;
2800
- },
2801
- set: function set(value) {
2802
- if (this._filledClockWise !== value) {
2803
- this._filledClockWise = value;
2804
- if (this._drawMode === SpriteDrawMode.Filled) {
2805
- this._dirtyUpdateFlag |= 5;
2806
- }
2807
- }
2808
- }
2809
- },
2810
2353
  {
2811
2354
  key: "sprite",
2812
2355
  get: /**
@@ -2854,87 +2397,19 @@ __decorate([
2854
2397
  ignoreClone
2855
2398
  ], Image.prototype, "_onSpriteChange", null);
2856
2399
 
2857
- /**
2858
- * UI component that uses a sprite to mask child UI renderers via stencil.
2859
- */ var Mask = /*#__PURE__*/ function(_MaskRenderable) {
2860
- _inherits(Mask, _MaskRenderable);
2861
- function Mask(entity) {
2862
- var _this;
2863
- _this = _MaskRenderable.call(this, entity) || this;
2864
- _this._initMask();
2865
- _this.raycastEnabled = false;
2866
- return _this;
2867
- }
2868
- var _proto = Mask.prototype;
2869
- /**
2870
- * @internal
2871
- */ _proto._getChunkManager = function _getChunkManager() {
2872
- // @ts-ignore
2873
- return this.engine._batcherManager.primitiveChunkManagerMask;
2874
- };
2875
- /**
2876
- * @internal
2877
- */ // @ts-ignore
2878
- _proto._onClone = function _onClone(target) {
2879
- // @ts-ignore
2880
- _MaskRenderable.prototype._onClone.call(this, target);
2881
- this._cloneMaskData(target);
2882
- };
2883
- _proto._updateBounds = function _updateBounds(worldBounds) {
2884
- var rootCanvas = this._getRootCanvas();
2885
- if (this.sprite && rootCanvas) {
2886
- this._updateMaskBounds(worldBounds);
2887
- } else {
2888
- var worldPosition = this._transformEntity.transform.worldPosition;
2889
- worldBounds.min.copyFrom(worldPosition);
2890
- worldBounds.max.copyFrom(worldPosition);
2891
- }
2892
- };
2893
- /**
2894
- * @inheritdoc
2895
- */ _proto._render = function _render(context) {
2896
- this._renderMask(0);
2897
- };
2898
- /**
2899
- * @inheritdoc
2900
- */ _proto._onDestroy = function _onDestroy() {
2901
- this._destroyMaskResources();
2902
- _MaskRenderable.prototype._onDestroy.call(this);
2903
- if (this._subChunk) {
2904
- this._getChunkManager().freeSubChunk(this._subChunk);
2905
- this._subChunk = null;
2906
- }
2907
- };
2908
- _proto._getSpriteWidth = function _getSpriteWidth() {
2909
- return this._transformEntity.transform.size.x;
2910
- };
2911
- _proto._getSpriteHeight = function _getSpriteHeight() {
2912
- return this._transformEntity.transform.size.y;
2913
- };
2914
- _proto._getSpritePivot = function _getSpritePivot() {
2915
- return this._transformEntity.transform.pivot;
2916
- };
2917
- return Mask;
2918
- }(MaskRenderable(UIRenderer));
2919
-
2920
2400
  /**
2921
2401
  * UI component used to render text.
2922
2402
  */ var Text = /*#__PURE__*/ function(UIRenderer1) {
2923
2403
  _inherits(Text, UIRenderer1);
2924
2404
  function Text(entity) {
2925
2405
  var _this;
2926
- _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._characterSpacing = 0, _this._horizontalAlignment = TextHorizontalAlignment.Center, _this._verticalAlignment = TextVerticalAlignment.Center, _this._enableWrapping = false, _this._overflowMode = OverflowMode.Overflow, _this._outlineColor = new Color(0, 0, 0, 1), _this._outlineWidth = 0;
2406
+ _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._characterSpacing = 0, _this._horizontalAlignment = TextHorizontalAlignment.Center, _this._verticalAlignment = TextVerticalAlignment.Center, _this._enableWrapping = false, _this._overflowMode = OverflowMode.Overflow;
2927
2407
  var engine = _this.engine;
2928
2408
  // @ts-ignore
2929
2409
  _this.font = engine._textDefaultFont;
2930
2410
  _this.raycastEnabled = false;
2931
2411
  // @ts-ignore
2932
2412
  _this.setMaterial(engine._basicResources.textDefaultMaterial);
2933
- var shaderData = _this.shaderData;
2934
- shaderData.setFloat(Text._outlineWidthProperty, _this._outlineWidth);
2935
- shaderData.setColor(Text._outlineColorProperty, _this._outlineColor);
2936
- // @ts-ignore
2937
- _this._outlineColor._onValueChanged = _this._onOutlineColorChanged.bind(_this);
2938
2413
  return _this;
2939
2414
  }
2940
2415
  var _proto = Text.prototype;
@@ -2980,13 +2455,13 @@ __decorate([
2980
2455
  this._setDirtyFlagTrue(25);
2981
2456
  }
2982
2457
  };
2983
- /**
2984
- * @internal
2985
- */ _proto._canBatch = function _canBatch(preElement, curElement) {
2986
- return VertexMergeBatcher.canBatchText(preElement, curElement);
2987
- };
2988
2458
  _proto._updateBounds = function _updateBounds(worldBounds) {
2989
- BoundingBox.transform(this._localBounds, this._transformEntity.transform.worldMatrix, worldBounds);
2459
+ var transform = this._transformEntity.transform;
2460
+ var _transform_size = transform.size, width = _transform_size.x, height = _transform_size.y;
2461
+ var _transform_pivot = transform.pivot, pivotX = _transform_pivot.x, pivotY = _transform_pivot.y;
2462
+ worldBounds.min.set(-width * pivotX, -height * pivotY, 0);
2463
+ worldBounds.max.set(width * (1 - pivotX), height * (1 - pivotY), 0);
2464
+ BoundingBox.transform(worldBounds, this._transformEntity.transform.worldMatrix, worldBounds);
2990
2465
  };
2991
2466
  _proto._render = function _render(context) {
2992
2467
  if (this._isTextNoVisible()) {
@@ -3017,7 +2492,6 @@ __decorate([
3017
2492
  var distanceForSort = canvas._sortDistance;
3018
2493
  var textChunks = this._textChunks;
3019
2494
  var subShader = material.shader.subShaders[0];
3020
- var textTextureSize = Text._tempVec20;
3021
2495
  for(var i = 0, n = textChunks.length; i < n; ++i){
3022
2496
  var // @ts-ignore
3023
2497
  _renderElement;
@@ -3026,7 +2500,6 @@ __decorate([
3026
2500
  renderElement.set(this, material, subChunk.chunk.primitive, subChunk.subMesh, texture, subChunk);
3027
2501
  (_renderElement = renderElement).shaderData || (_renderElement.shaderData = new ShaderData(ShaderDataGroup.RenderElement));
3028
2502
  renderElement.shaderData.setTexture(Text._textTextureProperty, texture);
3029
- renderElement.shaderData.setVector2(Text._textTextureSizeProperty, textTextureSize.set(texture.width, texture.height));
3030
2503
  renderElement.subShader = subShader;
3031
2504
  renderElement.priority = priority;
3032
2505
  renderElement.distanceForSort = distanceForSort;
@@ -3039,15 +2512,6 @@ __decorate([
3039
2512
  this._subFont = font._getSubFont(this.fontSize, this.fontStyle);
3040
2513
  this._subFont.nativeFontString = TextUtils.getNativeFontString(font.name, this.fontSize, this.fontStyle);
3041
2514
  };
3042
- /**
3043
- * Switch the sub font to a specific font size, used by the SHRINK overflow measurement.
3044
- */ _proto._applyFontSizeForShrink = function _applyFontSizeForShrink(fontSize) {
3045
- var font = this._font;
3046
- // @ts-ignore
3047
- var subFont = font._getSubFont(fontSize, this._fontStyle);
3048
- subFont.nativeFontString = TextUtils.getNativeFontString(font.name, fontSize, this._fontStyle);
3049
- this._subFont = subFont;
3050
- };
3051
2515
  _proto._updatePosition = function _updatePosition() {
3052
2516
  var e = this._transformEntity.transform.worldMatrix.elements;
3053
2517
  // prettier-ignore
@@ -3100,30 +2564,18 @@ __decorate([
3100
2564
  }
3101
2565
  };
3102
2566
  _proto._updateLocalData = function _updateLocalData() {
3103
- var _this = this;
3104
2567
  // @ts-ignore
3105
2568
  var pixelsPerResolution = Engine._pixelsPerUnit / this._getRootCanvas().referenceResolutionPerUnit;
3106
2569
  var _this__localBounds = this._localBounds, min = _this__localBounds.min, max = _this__localBounds.max;
3107
2570
  var charRenderInfos = Text._charRenderInfos;
2571
+ var charFont = this._getSubFont();
3108
2572
  var _this__transformEntity_transform = this._transformEntity.transform, size = _this__transformEntity_transform.size, pivot = _this__transformEntity_transform.pivot;
3109
2573
  var rendererWidth = size.x;
3110
2574
  var rendererHeight = size.y;
3111
2575
  var offsetWidth = rendererWidth * (0.5 - pivot.x);
3112
2576
  var offsetHeight = rendererHeight * (0.5 - pivot.y);
3113
- var fontSize = this._fontSize;
3114
- var textMetrics;
3115
- if (this._overflowMode === OverflowMode.Shrink) {
3116
- var result = TextUtils.measureTextWithShrink(this, rendererWidth * pixelsPerResolution, rendererHeight * pixelsPerResolution, this._fontSize, this._lineSpacing, this._characterSpacing, this.enableWrapping, function(sizeValue) {
3117
- return _this._applyFontSizeForShrink(sizeValue);
3118
- });
3119
- fontSize = result.fontSize;
3120
- textMetrics = result.metrics;
3121
- } else {
3122
- var characterSpacing = this._characterSpacing * fontSize;
3123
- textMetrics = this.enableWrapping ? TextUtils.measureTextWithWrap(this, rendererWidth * pixelsPerResolution, rendererHeight * pixelsPerResolution, this._lineSpacing * fontSize, characterSpacing) : TextUtils.measureTextWithoutWrap(this, rendererHeight * pixelsPerResolution, this._lineSpacing * fontSize, characterSpacing);
3124
- }
3125
- var charFont = this._getSubFont();
3126
- var characterSpacing1 = this._characterSpacing * fontSize;
2577
+ var characterSpacing = this._characterSpacing * this._fontSize;
2578
+ var textMetrics = this.enableWrapping ? TextUtils.measureTextWithWrap(this, rendererWidth * pixelsPerResolution, rendererHeight * pixelsPerResolution, this._lineSpacing * this._fontSize, characterSpacing) : TextUtils.measureTextWithoutWrap(this, rendererHeight * pixelsPerResolution, this._lineSpacing * this._fontSize, characterSpacing);
3127
2579
  var height = textMetrics.height, lines = textMetrics.lines, lineWidths = textMetrics.lineWidths, lineHeight = textMetrics.lineHeight, lineMaxSizes = textMetrics.lineMaxSizes;
3128
2580
  // @ts-ignore
3129
2581
  var charRenderInfoPool = this.engine._charRenderInfoPool;
@@ -3144,10 +2596,7 @@ __decorate([
3144
2596
  startY = rendererHeight * 0.5 - halfLineHeight + topDiff;
3145
2597
  break;
3146
2598
  case TextVerticalAlignment.Center:
3147
- // Center the text block (lineHeight * lineCount) within the renderer, independent of
3148
- // `height` — which equals the renderer height for Truncate/Shrink and would otherwise
3149
- // push the text upward by (rendererHeight - blockHeight) / 2 when the box is taller.
3150
- startY = lineHeight * linesLen * 0.5 - halfLineHeight - (bottomDiff - topDiff) * 0.5;
2599
+ startY = height * 0.5 - halfLineHeight - (bottomDiff - topDiff) * 0.5;
3151
2600
  break;
3152
2601
  case TextVerticalAlignment.Bottom:
3153
2602
  startY = height - rendererHeight * 0.5 - halfLineHeight - bottomDiff;
@@ -3188,18 +2637,17 @@ __decorate([
3188
2637
  charRenderInfo.texture = charFont._getTextureByIndex(charInfo.index);
3189
2638
  charRenderInfo.uvs = charInfo.uvs;
3190
2639
  var w = charInfo.w, ascent = charInfo.ascent, descent = charInfo.descent;
3191
- var ow = this._outlineWidth * pixelsPerUnitReciprocal;
3192
- var left = (startX + offsetWidth) * pixelsPerUnitReciprocal - ow;
3193
- var right = (startX + w + offsetWidth) * pixelsPerUnitReciprocal + ow;
3194
- var top = (startY + ascent + offsetHeight) * pixelsPerUnitReciprocal + ow;
3195
- var bottom = (startY - descent + offsetHeight) * pixelsPerUnitReciprocal - ow;
2640
+ var left = (startX + offsetWidth) * pixelsPerUnitReciprocal;
2641
+ var right = (startX + w + offsetWidth) * pixelsPerUnitReciprocal;
2642
+ var top = (startY + ascent + offsetHeight) * pixelsPerUnitReciprocal;
2643
+ var bottom = (startY - descent + offsetHeight) * pixelsPerUnitReciprocal;
3196
2644
  localPositions.set(left, top, right, bottom);
3197
2645
  i === firstLine && (maxY = Math.max(maxY, top));
3198
2646
  minY = Math.min(minY, bottom);
3199
2647
  j === firstRow && (minX = Math.min(minX, left));
3200
2648
  maxX = Math.max(maxX, right);
3201
2649
  }
3202
- startX += charInfo.xAdvance + characterSpacing1;
2650
+ startX += charInfo.xAdvance + characterSpacing;
3203
2651
  }
3204
2652
  }
3205
2653
  startY -= lineHeight;
@@ -3259,7 +2707,7 @@ __decorate([
3259
2707
  };
3260
2708
  _proto._isTextNoVisible = function _isTextNoVisible() {
3261
2709
  var size = this._transformEntity.transform.size;
3262
- return !this._font || this._text === "" || this._fontSize === 0 || this.enableWrapping && size.x <= 0 || (this.overflowMode === OverflowMode.Truncate || this.overflowMode === OverflowMode.Shrink) && size.y <= 0 || !this._getRootCanvas();
2710
+ return !this._font || this._text === "" || this._fontSize === 0 || this.enableWrapping && size.x <= 0 || this.overflowMode === OverflowMode.Truncate && size.y <= 0 || !this._getRootCanvas();
3263
2711
  };
3264
2712
  _proto._buildChunk = function _buildChunk(textChunk, count) {
3265
2713
  var _this_color = this.color, r = _this_color.r, g = _this_color.g, b = _this_color.b, a = _this_color.a;
@@ -3270,10 +2718,6 @@ __decorate([
3270
2718
  var vertices = subChunk.chunk.vertices;
3271
2719
  var indices = subChunk.indices = [];
3272
2720
  var charRenderInfos = textChunk.charRenderInfos;
3273
- var ow = this._outlineWidth;
3274
- var texture = textChunk.texture;
3275
- var owU = ow > 0 ? ow / texture.width : 0;
3276
- var owV = ow > 0 ? ow / texture.height : 0;
3277
2721
  for(var i = 0, ii = 0, io = 0, vo = subChunk.vertexArea.start + 3; i < count; ++i, io += 4){
3278
2722
  var charRenderInfo = charRenderInfos[i];
3279
2723
  charRenderInfo.indexInChunk = i;
@@ -3281,13 +2725,10 @@ __decorate([
3281
2725
  for(var j = 0; j < tempIndicesLength; ++j){
3282
2726
  indices[ii++] = tempIndices[j] + io;
3283
2727
  }
3284
- // Set uv and color for vertices, expand uv outward by outline width
2728
+ // Set uv and color for vertices
3285
2729
  for(var j1 = 0; j1 < 4; ++j1, vo += 9){
3286
2730
  var uv = charRenderInfo.uvs[j1];
3287
- var su = j1 === 1 || j1 === 2 ? 1 : -1;
3288
- var sv = j1 >= 2 ? 1 : -1;
3289
- vertices[vo] = uv.x + owU * su;
3290
- vertices[vo + 1] = uv.y + owV * sv;
2731
+ uv.copyToArray(vertices, vo);
3291
2732
  vertices[vo + 2] = r;
3292
2733
  vertices[vo + 3] = g;
3293
2734
  vertices[vo + 4] = b;
@@ -3314,9 +2755,6 @@ __decorate([
3314
2755
  }
3315
2756
  textChunks.length = 0;
3316
2757
  };
3317
- _proto._onOutlineColorChanged = function _onOutlineColorChanged() {
3318
- this.shaderData.setColor(Text._outlineColorProperty, this._outlineColor);
3319
- };
3320
2758
  _create_class(Text, [
3321
2759
  {
3322
2760
  key: "text",
@@ -3463,32 +2901,14 @@ __decorate([
3463
2901
  }
3464
2902
  },
3465
2903
  {
3466
- key: "outlineWidth",
3467
- get: /**
3468
- * The outline width in pixels. 0 means outline is disabled. Clamped to [0, 8].
3469
- */ function get() {
3470
- return this._outlineWidth;
3471
- },
3472
- set: function set(value) {
3473
- value = Math.max(0, Math.min(value, 3));
3474
- if (this._outlineWidth !== value) {
3475
- this._outlineWidth = value;
3476
- this.shaderData.setFloat(Text._outlineWidthProperty, value);
3477
- this._setDirtyFlagTrue(25);
3478
- }
3479
- }
3480
- },
3481
- {
3482
- key: "outlineColor",
2904
+ key: "maskLayer",
3483
2905
  get: /**
3484
- * The outline color. Only effective when outlineWidth > 0.
2906
+ * The mask layer the sprite renderer belongs to.
3485
2907
  */ function get() {
3486
- return this._outlineColor;
2908
+ return this._maskLayer;
3487
2909
  },
3488
2910
  set: function set(value) {
3489
- if (this._outlineColor !== value) {
3490
- this._outlineColor.copyFrom(value);
3491
- }
2911
+ this._maskLayer = value;
3492
2912
  }
3493
2913
  },
3494
2914
  {
@@ -3499,14 +2919,8 @@ __decorate([
3499
2919
  if (this._isTextNoVisible()) {
3500
2920
  if (this._isContainDirtyFlag(RendererUpdateFlags.WorldVolume)) {
3501
2921
  var localBounds = this._localBounds;
3502
- if (this._getRootCanvas()) {
3503
- localBounds.min.set(0, 0, 0);
3504
- localBounds.max.set(0, 0, 0);
3505
- } else {
3506
- var _this_entity_transform = this.entity.transform, size = _this_entity_transform.size, pivot = _this_entity_transform.pivot;
3507
- localBounds.min.set(-size.x * pivot.x, -size.y * pivot.y, 0);
3508
- localBounds.max.set(size.x * (1 - pivot.x), size.y * (1 - pivot.y), 0);
3509
- }
2922
+ localBounds.min.set(0, 0, 0);
2923
+ localBounds.max.set(0, 0, 0);
3510
2924
  this._updateBounds(this._bounds);
3511
2925
  this._setDirtyFlagFalse(RendererUpdateFlags.WorldVolume);
3512
2926
  }
@@ -3524,9 +2938,6 @@ __decorate([
3524
2938
  return Text;
3525
2939
  }(UIRenderer);
3526
2940
  Text._textTextureProperty = ShaderProperty.getByName("renderElement_TextTexture");
3527
- Text._textTextureSizeProperty = ShaderProperty.getByName("renderElement_TextTextureSize");
3528
- Text._outlineColorProperty = ShaderProperty.getByName("renderer_OutlineColor");
3529
- Text._outlineWidthProperty = ShaderProperty.getByName("renderer_OutlineWidth");
3530
2941
  Text._worldPositions = [
3531
2942
  new Vector3(),
3532
2943
  new Vector3(),
@@ -3546,9 +2957,6 @@ __decorate([
3546
2957
  __decorate([
3547
2958
  ignoreClone
3548
2959
  ], Text.prototype, "_onTransformChanged", null);
3549
- __decorate([
3550
- ignoreClone
3551
- ], Text.prototype, "_onOutlineColorChanged", null);
3552
2960
  var TextChunk = function TextChunk() {
3553
2961
  this.charRenderInfos = new Array();
3554
2962
  };
@@ -3873,19 +3281,17 @@ __decorate([
3873
3281
 
3874
3282
  var GUIComponent = /*#__PURE__*/Object.freeze({
3875
3283
  __proto__: null,
3284
+ get UICanvas () { return UICanvas; },
3285
+ UIGroup: UIGroup,
3286
+ get UIRenderer () { return UIRenderer; },
3287
+ UITransform: UITransform,
3876
3288
  Button: Button,
3877
3289
  Image: Image,
3878
- Mask: Mask,
3879
- get RectMask2D () { return RectMask2D; },
3880
3290
  Text: Text,
3881
3291
  ColorTransition: ColorTransition,
3882
3292
  ScaleTransition: ScaleTransition,
3883
3293
  SpriteTransition: SpriteTransition,
3884
- Transition: Transition,
3885
- get UICanvas () { return UICanvas; },
3886
- UIGroup: UIGroup,
3887
- get UIRenderer () { return UIRenderer; },
3888
- UITransform: UITransform
3294
+ Transition: Transition
3889
3295
  });
3890
3296
 
3891
3297
  /**
@@ -3964,11 +3370,11 @@ var UIPointerEventEmitter = /*#__PURE__*/ function(PointerEventEmitter1) {
3964
3370
  }
3965
3371
  }
3966
3372
  if (camera.clearFlags & CameraClearFlags.Color) {
3967
- this._updateRaycast(null, pointer);
3373
+ this._updateRaycast(null);
3968
3374
  return;
3969
3375
  }
3970
3376
  }
3971
- this._updateRaycast(null, pointer);
3377
+ this._updateRaycast(null);
3972
3378
  }
3973
3379
  };
3974
3380
  _proto.processDrag = function processDrag(pointer) {
@@ -3998,7 +3404,10 @@ var UIPointerEventEmitter = /*#__PURE__*/ function(PointerEventEmitter1) {
3998
3404
  if (pressedPath.length > 0) {
3999
3405
  var common = UIPointerEventEmitter._tempArray0;
4000
3406
  if (this._findCommonInPath(enteredPath, pressedPath, common)) {
4001
- this._bubble(common, pointer, this._fireClick);
3407
+ var eventData = this._createEventData(pointer);
3408
+ for(var i = 0, n = common.length; i < n; i++){
3409
+ this._fireClick(common[i], eventData);
3410
+ }
4002
3411
  common.length = 0;
4003
3412
  }
4004
3413
  }
@@ -4030,16 +3439,18 @@ var UIPointerEventEmitter = /*#__PURE__*/ function(PointerEventEmitter1) {
4030
3439
  this._enteredPath.length = this._pressedPath.length = this._draggedPath.length = 0;
4031
3440
  };
4032
3441
  _proto._updateRaycast = function _updateRaycast(element, pointer) {
3442
+ if (pointer === void 0) pointer = null;
4033
3443
  var enteredPath = this._enteredPath;
4034
3444
  var curPath = this._composedPath(element, UIPointerEventEmitter._path);
4035
3445
  var add = UIPointerEventEmitter._tempArray0;
4036
3446
  var del = UIPointerEventEmitter._tempArray1;
4037
3447
  if (this._findDiffInPath(enteredPath, curPath, add, del)) {
3448
+ var eventData = this._createEventData(pointer);
4038
3449
  for(var i = 0, n = add.length; i < n; i++){
4039
- this._fireEnter(add[i], this._createEventData(pointer, add[i]));
3450
+ this._fireEnter(add[i], eventData);
4040
3451
  }
4041
3452
  for(var i1 = 0, n1 = del.length; i1 < n1; i1++){
4042
- this._fireExit(del[i1], this._createEventData(pointer, del[i1]));
3453
+ this._fireExit(del[i1], eventData);
4043
3454
  }
4044
3455
  var length = enteredPath.length = curPath.length;
4045
3456
  for(var i2 = 0; i2 < length; i2++){
@@ -4109,9 +3520,8 @@ var UIPointerEventEmitter = /*#__PURE__*/ function(PointerEventEmitter1) {
4109
3520
  _proto._bubble = function _bubble(path, pointer, fireEvent) {
4110
3521
  var length = path.length;
4111
3522
  if (length <= 0) return;
4112
- var eventData = this._createEventData(pointer, path[0]);
3523
+ var eventData = this._createEventData(pointer);
4113
3524
  for(var i = 0; i < length; i++){
4114
- eventData.currentTarget = path[i];
4115
3525
  fireEvent(path[i], eventData);
4116
3526
  }
4117
3527
  };
@@ -4181,5 +3591,5 @@ function _getOrCreateUIShader() {
4181
3591
  return Shader.find("2D/UIDefault");
4182
3592
  }
4183
3593
 
4184
- export { Button, CanvasRenderMode, ColorTransition, EngineExtension, EntityExtension, HorizontalAlignmentMode, Image, Mask, RectMask2D, ResolutionAdaptationMode, ScaleTransition, SpriteTransition, Text, Transition, UICanvas, UIGroup, UIPointerEventEmitter, UIRenderer, UITransform, VerticalAlignmentMode, registerGUI };
3594
+ export { Button, CanvasRenderMode, ColorTransition, EngineExtension, EntityExtension, HorizontalAlignmentMode, Image, ResolutionAdaptationMode, ScaleTransition, SpriteTransition, Text, Transition, UICanvas, UIGroup, UIPointerEventEmitter, UIRenderer, UITransform, VerticalAlignmentMode, registerGUI };
4185
3595
  //# sourceMappingURL=module.js.map