@galacean/engine 0.0.0-experimental-2.0-game.17 → 0.0.0-experimental-2.0-game.18

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/browser.js CHANGED
@@ -5872,10 +5872,10 @@
5872
5872
  */ _proto.onProgress = function onProgress(onTaskComplete, onTaskDetail) {
5873
5873
  var completeProgress = this._taskCompleteProgress;
5874
5874
  var detailProgress = this._taskDetailProgress;
5875
- if (completeProgress) {
5875
+ if (completeProgress && onTaskComplete) {
5876
5876
  onTaskComplete(completeProgress.loaded, completeProgress.total);
5877
5877
  }
5878
- if (detailProgress) {
5878
+ if (detailProgress && onTaskDetail) {
5879
5879
  for(var url in detailProgress){
5880
5880
  var _detailProgress_url = detailProgress[url], loaded = _detailProgress_url.loaded, total = _detailProgress_url.total;
5881
5881
  onTaskDetail(url, loaded, total);
@@ -7100,10 +7100,11 @@
7100
7100
  return FontStyle;
7101
7101
  }({});
7102
7102
  /**
7103
- * The way to handle the situation where wrapped text is too tall to fit in the height.
7103
+ * The way to handle the situation where the text is too large to fit in the bounds.
7104
7104
  */ var OverflowMode = /*#__PURE__*/ function(OverflowMode) {
7105
7105
  /** Overflow when the text is too tall */ OverflowMode[OverflowMode["Overflow"] = 0] = "Overflow";
7106
7106
  /** Truncate with height when the text is too tall */ OverflowMode[OverflowMode["Truncate"] = 1] = "Truncate";
7107
+ /** Shrink the font size until the text fits within the bounds (both width and height) */ OverflowMode[OverflowMode["Shrink"] = 2] = "Shrink";
7107
7108
  return OverflowMode;
7108
7109
  }({});
7109
7110
  /**
@@ -7167,7 +7168,8 @@
7167
7168
  TextUtils.measureChar = function measureChar(char, fontString) {
7168
7169
  return TextUtils._measureFontOrChar(fontString, char, true);
7169
7170
  };
7170
- TextUtils.measureTextWithWrap = function measureTextWithWrap(renderer, rendererWidth, rendererHeight, lineSpacing, characterSpacing) {
7171
+ TextUtils.measureTextWithWrap = function measureTextWithWrap(renderer, rendererWidth, rendererHeight, lineSpacing, characterSpacing, uploadCharTexture) {
7172
+ if (uploadCharTexture === void 0) uploadCharTexture = true;
7171
7173
  var subFont = renderer._getSubFont();
7172
7174
  var fontString = subFont.nativeFontString;
7173
7175
  var fontSizeInfo = TextUtils.measureFont(fontString);
@@ -7196,7 +7198,7 @@
7196
7198
  var notFirstLine = false;
7197
7199
  for(var j = 0, m = subText.length; j < m; ++j){
7198
7200
  var char = subText[j];
7199
- var charInfo = TextUtils._getCharInfo(char, fontString, subFont);
7201
+ var charInfo = TextUtils._getCharInfo(char, fontString, subFont, uploadCharTexture);
7200
7202
  var charCode = char.charCodeAt(0);
7201
7203
  var isSpace = charCode === 32;
7202
7204
  if (isSpace && notFirstLine && line.length === 0 && word.length === 0) {
@@ -7325,7 +7327,8 @@
7325
7327
  lineMaxSizes: lineMaxSizes
7326
7328
  };
7327
7329
  };
7328
- TextUtils.measureTextWithoutWrap = function measureTextWithoutWrap(renderer, rendererHeight, lineSpacing, characterSpacing) {
7330
+ TextUtils.measureTextWithoutWrap = function measureTextWithoutWrap(renderer, rendererHeight, lineSpacing, characterSpacing, uploadCharTexture) {
7331
+ if (uploadCharTexture === void 0) uploadCharTexture = true;
7329
7332
  var subFont = renderer._getSubFont();
7330
7333
  var fontString = subFont.nativeFontString;
7331
7334
  var fontSizeInfo = TextUtils.measureFont(fontString);
@@ -7344,7 +7347,7 @@
7344
7347
  var maxAscent = 0;
7345
7348
  var maxDescent = 0;
7346
7349
  for(var j = 0; j < lineLength; ++j){
7347
- var charInfo = TextUtils._getCharInfo(line[j], fontString, subFont);
7350
+ var charInfo = TextUtils._getCharInfo(line[j], fontString, subFont, uploadCharTexture);
7348
7351
  curWidth += charInfo.xAdvance;
7349
7352
  var offsetY = charInfo.offsetY;
7350
7353
  var halfH = charInfo.h * 0.5;
@@ -7372,6 +7375,64 @@
7372
7375
  };
7373
7376
  };
7374
7377
  /**
7378
+ * Measure text in SHRINK overflow mode: keep shrinking the font size until the text fits
7379
+ * within the bounds (both width and height). Mirrors Cocos Creator's `Overflow.SHRINK`.
7380
+ *
7381
+ * @param renderer - The text renderer
7382
+ * @param rendererWidth - The width of the bounds in pixels
7383
+ * @param rendererHeight - The height of the bounds in pixels
7384
+ * @param originalFontSize - The font size set on the renderer (the upper bound, never enlarged)
7385
+ * @param lineSpacing - The line spacing ratio (relative to font size)
7386
+ * @param characterSpacing - The character spacing ratio (relative to font size)
7387
+ * @param enableWrapping - Whether wrapping is enabled
7388
+ * @param applyFontSize - Callback that switches the renderer's sub font to the given font size
7389
+ * @returns The fitted text metrics and the actual font size used for layout
7390
+ */ TextUtils.measureTextWithShrink = function measureTextWithShrink(renderer, rendererWidth, rendererHeight, originalFontSize, lineSpacing, characterSpacing, enableWrapping, applyFontSize) {
7391
+ // During the binary search we only need the text dimensions, so pass `uploadCharTexture=false`
7392
+ // to avoid building GPU font atlases for the intermediate font sizes that won't be used.
7393
+ // The fitted size is then re-measured once with upload=true to populate its atlas. This trades
7394
+ // one extra full measure pass (CPU) for skipping ~log2(size) throwaway atlas textures (GPU);
7395
+ // we can't reuse the search's last measure because its char bitmaps were never cached.
7396
+ var measureAt = function measureAt(fontSize, uploadCharTexture) {
7397
+ applyFontSize(fontSize);
7398
+ return enableWrapping ? TextUtils.measureTextWithWrap(renderer, rendererWidth, rendererHeight, lineSpacing * fontSize, characterSpacing * fontSize, uploadCharTexture) : TextUtils.measureTextWithoutWrap(renderer, rendererHeight, lineSpacing * fontSize, characterSpacing * fontSize, uploadCharTexture);
7399
+ };
7400
+ // The content height is `lineHeight * lineCount`; `metrics.height` is clamped to the bounds
7401
+ // unless overflowMode is Overflow, so it can't be used to detect vertical overflow here.
7402
+ var isFit = function isFit(metrics) {
7403
+ return metrics.width <= rendererWidth && metrics.lineHeight * metrics.lines.length <= rendererHeight;
7404
+ };
7405
+ // If the text already fits at the original size, keep it (SHRINK only shrinks, never enlarges).
7406
+ var metrics = measureAt(originalFontSize, false);
7407
+ if (isFit(metrics)) {
7408
+ metrics = measureAt(originalFontSize, true);
7409
+ return {
7410
+ metrics: metrics,
7411
+ fontSize: originalFontSize
7412
+ };
7413
+ }
7414
+ // Binary search for the largest integer font size that fits (measure only, no atlas upload).
7415
+ var low = 1;
7416
+ var high = Math.floor(originalFontSize);
7417
+ var fitFontSize = low;
7418
+ while(low <= high){
7419
+ var mid = low + high >> 1;
7420
+ metrics = measureAt(mid, false);
7421
+ if (isFit(metrics)) {
7422
+ fitFontSize = mid;
7423
+ low = mid + 1;
7424
+ } else {
7425
+ high = mid - 1;
7426
+ }
7427
+ }
7428
+ // Re-measure the fitted size with upload=true so the sub font / atlas correspond to it.
7429
+ metrics = measureAt(fitFontSize, true);
7430
+ return {
7431
+ metrics: metrics,
7432
+ fontSize: fitFontSize
7433
+ };
7434
+ };
7435
+ /**
7375
7436
  * Get native font hash.
7376
7437
  * @param fontName - The font name
7377
7438
  * @param fontSize - The font size
@@ -7488,12 +7549,17 @@
7488
7549
  };
7489
7550
  /**
7490
7551
  * @internal
7491
- */ TextUtils._getCharInfo = function _getCharInfo(char, fontString, font) {
7552
+ */ TextUtils._getCharInfo = function _getCharInfo(char, fontString, font, uploadCharTexture) {
7553
+ if (uploadCharTexture === void 0) uploadCharTexture = true;
7492
7554
  var charInfo = font._getCharInfo(char);
7493
7555
  if (!charInfo) {
7494
7556
  charInfo = TextUtils.measureChar(char, fontString);
7495
- font._uploadCharTexture(charInfo);
7496
- font._addCharInfo(char, charInfo);
7557
+ // SHRINK 的二分阶段只需字符尺寸(measureChar 已给出),传 uploadCharTexture=false 跳过 GPU
7558
+ // 字形图集上传与缓存,避免给用不到的中间字号建字体 atlas 纹理。
7559
+ if (uploadCharTexture) {
7560
+ font._uploadCharTexture(charInfo);
7561
+ font._addCharInfo(char, charInfo);
7562
+ }
7497
7563
  }
7498
7564
  return charInfo;
7499
7565
  };
@@ -16372,6 +16438,14 @@
16372
16438
  this._subFont = font._getSubFont(this.fontSize, this.fontStyle);
16373
16439
  this._subFont.nativeFontString = TextUtils.getNativeFontString(font.name, this.fontSize, this.fontStyle);
16374
16440
  };
16441
+ /**
16442
+ * Switch the sub font to a specific font size, used by the SHRINK overflow measurement.
16443
+ */ _proto._applyFontSizeForShrink = function _applyFontSizeForShrink(fontSize) {
16444
+ var font = this._font;
16445
+ var subFont = font._getSubFont(fontSize, this._fontStyle);
16446
+ subFont.nativeFontString = TextUtils.getNativeFontString(font.name, fontSize, this._fontStyle);
16447
+ this._subFont = subFont;
16448
+ };
16375
16449
  _proto._updatePosition = function _updatePosition() {
16376
16450
  var transform = this.entity.transform;
16377
16451
  var e = transform.worldMatrix.elements;
@@ -16427,12 +16501,26 @@
16427
16501
  }
16428
16502
  };
16429
16503
  _proto._updateLocalData = function _updateLocalData() {
16504
+ var _this = this;
16430
16505
  var _pixelsPerUnit = Engine._pixelsPerUnit;
16431
16506
  var _this__localBounds = this._localBounds, min = _this__localBounds.min, max = _this__localBounds.max;
16432
16507
  var charRenderInfos = TextRenderer._charRenderInfos;
16508
+ var rendererWidth = this.width * _pixelsPerUnit;
16509
+ var rendererHeight = this.height * _pixelsPerUnit;
16510
+ var fontSize = this._fontSize;
16511
+ var textMetrics;
16512
+ if (this._overflowMode === OverflowMode.Shrink) {
16513
+ var result = TextUtils.measureTextWithShrink(this, rendererWidth, rendererHeight, this._fontSize, this._lineSpacing, this._characterSpacing, this.enableWrapping, function(size) {
16514
+ return _this._applyFontSizeForShrink(size);
16515
+ });
16516
+ fontSize = result.fontSize;
16517
+ textMetrics = result.metrics;
16518
+ } else {
16519
+ var characterSpacing = this._characterSpacing * fontSize;
16520
+ textMetrics = this.enableWrapping ? TextUtils.measureTextWithWrap(this, rendererWidth, rendererHeight, this._lineSpacing * fontSize, characterSpacing) : TextUtils.measureTextWithoutWrap(this, rendererHeight, this._lineSpacing * fontSize, characterSpacing);
16521
+ }
16433
16522
  var charFont = this._getSubFont();
16434
- var characterSpacing = this._characterSpacing * this._fontSize;
16435
- var textMetrics = this.enableWrapping ? TextUtils.measureTextWithWrap(this, this.width * _pixelsPerUnit, this.height * _pixelsPerUnit, this._lineSpacing * this._fontSize, characterSpacing) : TextUtils.measureTextWithoutWrap(this, this.height * _pixelsPerUnit, this._lineSpacing * this._fontSize, characterSpacing);
16523
+ var characterSpacing1 = this._characterSpacing * fontSize;
16436
16524
  var height = textMetrics.height, lines = textMetrics.lines, lineWidths = textMetrics.lineWidths, lineHeight = textMetrics.lineHeight, lineMaxSizes = textMetrics.lineMaxSizes;
16437
16525
  var charRenderInfoPool = this.engine._charRenderInfoPool;
16438
16526
  var linesLen = lines.length;
@@ -16440,9 +16528,7 @@
16440
16528
  if (linesLen > 0) {
16441
16529
  var horizontalAlignment = this.horizontalAlignment;
16442
16530
  var pixelsPerUnitReciprocal = 1.0 / _pixelsPerUnit;
16443
- var rendererWidth = this._width * _pixelsPerUnit;
16444
16531
  var halfRendererWidth = rendererWidth * 0.5;
16445
- var rendererHeight = this._height * _pixelsPerUnit;
16446
16532
  var halfLineHeight = lineHeight * 0.5;
16447
16533
  var startY = 0;
16448
16534
  var topDiff = lineHeight * 0.5 - lineMaxSizes[0].ascent;
@@ -16452,7 +16538,10 @@
16452
16538
  startY = rendererHeight * 0.5 - halfLineHeight + topDiff;
16453
16539
  break;
16454
16540
  case TextVerticalAlignment.Center:
16455
- startY = height * 0.5 - halfLineHeight - (bottomDiff - topDiff) * 0.5;
16541
+ // Center the text block (lineHeight * lineCount) within the renderer, independent of
16542
+ // `height` — which equals the renderer height for Truncate/Shrink and would otherwise
16543
+ // push the text upward by (rendererHeight - blockHeight) / 2 when the box is taller.
16544
+ startY = lineHeight * linesLen * 0.5 - halfLineHeight - (bottomDiff - topDiff) * 0.5;
16456
16545
  break;
16457
16546
  case TextVerticalAlignment.Bottom:
16458
16547
  startY = height - rendererHeight * 0.5 - halfLineHeight - bottomDiff;
@@ -16504,7 +16593,7 @@
16504
16593
  j === firstRow && (minX = Math.min(minX, left));
16505
16594
  maxX = Math.max(maxX, right);
16506
16595
  }
16507
- startX += charInfo.xAdvance + characterSpacing;
16596
+ startX += charInfo.xAdvance + characterSpacing1;
16508
16597
  }
16509
16598
  }
16510
16599
  startY -= lineHeight;
@@ -16560,7 +16649,7 @@
16560
16649
  this._setDirtyFlagTrue(4 | 8);
16561
16650
  };
16562
16651
  _proto._isTextNoVisible = function _isTextNoVisible() {
16563
- return !this._font || this._text === "" || this._fontSize === 0 || this.enableWrapping && this.width <= 0 || this.overflowMode === OverflowMode.Truncate && this.height <= 0;
16652
+ return !this._font || this._text === "" || this._fontSize === 0 || this.enableWrapping && this.width <= 0 || (this.overflowMode === OverflowMode.Truncate || this.overflowMode === OverflowMode.Shrink) && this.height <= 0;
16564
16653
  };
16565
16654
  _proto._buildChunk = function _buildChunk(textChunk, count) {
16566
16655
  var _this_color = this.color, r = _this_color.r, g = _this_color.g, b = _this_color.b, a = _this_color.a;
@@ -27040,6 +27129,249 @@
27040
27129
  /** The normal of the surface the ray hit. */ this.normal = new Vector3();
27041
27130
  /** The shape of the collider that was hit. */ this.shape = null;
27042
27131
  };
27132
+ function _array_like_to_array$2(arr, len) {
27133
+ if (len == null || len > arr.length) len = arr.length;
27134
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
27135
+ return arr2;
27136
+ }
27137
+ function _unsupported_iterable_to_array$2(o, minLen) {
27138
+ if (!o) return;
27139
+ if (typeof o === "string") return _array_like_to_array$2(o, minLen);
27140
+ var n = Object.prototype.toString.call(o).slice(8, -1);
27141
+ if (n === "Object" && o.constructor) n = o.constructor.name;
27142
+ if (n === "Map" || n === "Set") return Array.from(n);
27143
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$2(o, minLen);
27144
+ }
27145
+ function _create_for_of_iterator_helper_loose$2(o, allowArrayLike) {
27146
+ var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
27147
+ if (it) return (it = it.call(o)).next.bind(it);
27148
+ // Fallback for engines without symbol support
27149
+ if (Array.isArray(o) || (it = _unsupported_iterable_to_array$2(o)) || allowArrayLike && o && typeof o.length === "number") {
27150
+ if (it) o = it;
27151
+ var i = 0;
27152
+ return function() {
27153
+ if (i >= o.length) return {
27154
+ done: true
27155
+ };
27156
+ return {
27157
+ done: false,
27158
+ value: o[i++]
27159
+ };
27160
+ };
27161
+ }
27162
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
27163
+ }
27164
+ /**
27165
+ * Script class, used for logic writing.
27166
+ */ var Script = /*#__PURE__*/ function(Component) {
27167
+ _inherits$2(Script, Component);
27168
+ function Script() {
27169
+ var _this;
27170
+ _this = Component.apply(this, arguments) || this, /** @internal */ _this._started = false, /** @internal */ _this._onStartIndex = -1, /** @internal */ _this._onUpdateIndex = -1, /** @internal */ _this._onLateUpdateIndex = -1, /** @internal */ _this._onPhysicsUpdateIndex = -1, /** @internal */ _this._onPreRenderIndex = -1, /** @internal */ _this._onPostRenderIndex = -1, /** @internal */ _this._entityScriptsIndex = -1;
27171
+ return _this;
27172
+ }
27173
+ var _proto = Script.prototype;
27174
+ /**
27175
+ * Called when be enabled first time, only once.
27176
+ */ _proto.onAwake = function onAwake() {};
27177
+ /**
27178
+ * Called when be enabled.
27179
+ */ _proto.onEnable = function onEnable() {};
27180
+ /**
27181
+ * Called before the frame-level loop start for the first time, only once.
27182
+ */ _proto.onStart = function onStart() {};
27183
+ /**
27184
+ * The main loop, called frame by frame.
27185
+ * @param deltaTime - The delta time since last frame in seconds
27186
+ */ _proto.onUpdate = function onUpdate(deltaTime) {};
27187
+ /**
27188
+ * Called after the onUpdate finished, called frame by frame.
27189
+ * @param deltaTime - The delta time since last frame in seconds
27190
+ */ _proto.onLateUpdate = function onLateUpdate(deltaTime) {};
27191
+ /**
27192
+ * Called before camera rendering, called per camera.
27193
+ * @param camera - Current camera.
27194
+ */ _proto.onBeginRender = function onBeginRender(camera) {};
27195
+ /**
27196
+ * Called after camera rendering, called per camera.
27197
+ * @param camera - Current camera.
27198
+ */ _proto.onEndRender = function onEndRender(camera) {};
27199
+ /**
27200
+ * Called before physics calculations, the number of times is related to the physical update frequency.
27201
+ */ _proto.onPhysicsUpdate = function onPhysicsUpdate() {};
27202
+ /**
27203
+ * Called when the trigger enter.
27204
+ * @param other - ColliderShape
27205
+ */ _proto.onTriggerEnter = function onTriggerEnter(other) {};
27206
+ /**
27207
+ * Called when the trigger exit.
27208
+ * @param other - ColliderShape
27209
+ */ _proto.onTriggerExit = function onTriggerExit(other) {};
27210
+ /**
27211
+ * Called when the trigger stay.
27212
+ * @remarks onTriggerStay is called every frame while the trigger stay.
27213
+ * @param other - ColliderShape
27214
+ */ _proto.onTriggerStay = function onTriggerStay(other) {};
27215
+ /**
27216
+ * Called when the collision enter.
27217
+ * @param other - The Collision data associated with this collision event
27218
+ * @remarks The Collision data will be invalid after this call, you should copy the data if needed.
27219
+ */ _proto.onCollisionEnter = function onCollisionEnter(other) {};
27220
+ /**
27221
+ * Called when the collision exit.
27222
+ * @param other - The Collision data associated with this collision event
27223
+ * @remarks The Collision data will be invalid after this call, you should copy the data if needed.
27224
+ */ _proto.onCollisionExit = function onCollisionExit(other) {};
27225
+ /**
27226
+ * Called when the collision stay.
27227
+ * @param other - The Collision data associated with this collision event
27228
+ * @remarks The Collision data will be invalid after this call, you should copy the data if needed.
27229
+ */ _proto.onCollisionStay = function onCollisionStay(other) {};
27230
+ /**
27231
+ * Called when the pointer is down while over the ColliderShape.
27232
+ * @param eventData - The pointer event data that triggered this callback
27233
+ */ _proto.onPointerDown = function onPointerDown(eventData) {};
27234
+ /**
27235
+ * Called when the pointer is up while over the ColliderShape.
27236
+ * @param eventData - The pointer event data that triggered this callback
27237
+ */ _proto.onPointerUp = function onPointerUp(eventData) {};
27238
+ /**
27239
+ * Called when the pointer is down and up with the same collider.
27240
+ * @param eventData - The pointer event data that triggered this callback
27241
+ */ _proto.onPointerClick = function onPointerClick(eventData) {};
27242
+ /**
27243
+ * Called when the pointer enters the ColliderShape.
27244
+ * @param eventData - The pointer event data that triggered this callback
27245
+ */ _proto.onPointerEnter = function onPointerEnter(eventData) {};
27246
+ /**
27247
+ * Called when the pointer exits the ColliderShape.
27248
+ * @param eventData - The pointer event data that triggered this callback
27249
+ */ _proto.onPointerExit = function onPointerExit(eventData) {};
27250
+ /**
27251
+ * This function will be called when the pointer is pressed on the collider.
27252
+ * @param eventData - The pointer event data that triggered this callback
27253
+ */ _proto.onPointerBeginDrag = function onPointerBeginDrag(eventData) {};
27254
+ /**
27255
+ * When a drag collision occurs on the pointer, this function will be called every time it moves.
27256
+ * @param eventData - The pointer event data that triggered this callback
27257
+ */ _proto.onPointerDrag = function onPointerDrag(eventData) {};
27258
+ /**
27259
+ * When dragging ends, this function will be called (Dragged object).
27260
+ * @param eventData - The pointer event data that triggered this callback
27261
+ */ _proto.onPointerEndDrag = function onPointerEndDrag(eventData) {};
27262
+ /**
27263
+ * When dragging ends, this function will be called (Receiving object).
27264
+ * @param eventData - The pointer event data that triggered this callback
27265
+ */ _proto.onPointerDrop = function onPointerDrop(eventData) {};
27266
+ /**
27267
+ * Called when be disabled.
27268
+ */ _proto.onDisable = function onDisable() {};
27269
+ /**
27270
+ * Called at the end of the destroyed frame.
27271
+ */ _proto.onDestroy = function onDestroy() {};
27272
+ /**
27273
+ * @internal
27274
+ */ _proto._onAwake = function _onAwake() {
27275
+ this.onAwake();
27276
+ };
27277
+ /**
27278
+ * @internal
27279
+ */ _proto._onEnable = function _onEnable() {
27280
+ this.onEnable();
27281
+ };
27282
+ /**
27283
+ * @internal
27284
+ */ _proto._onDisable = function _onDisable() {
27285
+ this.onDisable();
27286
+ };
27287
+ /**
27288
+ * @internal
27289
+ */ _proto._onEnableInScene = function _onEnableInScene() {
27290
+ var _this_scene = this.scene, componentsManager = _this_scene._componentsManager;
27291
+ var prototype = Script.prototype;
27292
+ if (!this._started) {
27293
+ componentsManager.addOnStartScript(this);
27294
+ }
27295
+ if (this.onUpdate !== prototype.onUpdate) {
27296
+ componentsManager.addOnUpdateScript(this);
27297
+ }
27298
+ if (this.onLateUpdate !== prototype.onLateUpdate) {
27299
+ componentsManager.addOnLateUpdateScript(this);
27300
+ }
27301
+ if (this.onPhysicsUpdate !== prototype.onPhysicsUpdate) {
27302
+ componentsManager.addOnPhysicsUpdateScript(this);
27303
+ }
27304
+ for(var _iterator = _create_for_of_iterator_helper_loose$2(Object.values(PointerMethods)), _step; !(_step = _iterator()).done;){
27305
+ var pointerMethod = _step.value;
27306
+ if (this[pointerMethod] === prototype[pointerMethod]) {
27307
+ this[pointerMethod] = null;
27308
+ }
27309
+ }
27310
+ this._entity._addScript(this);
27311
+ };
27312
+ /**
27313
+ * @internal
27314
+ */ _proto._onDisableInScene = function _onDisableInScene() {
27315
+ var componentsManager = this.scene._componentsManager;
27316
+ var prototype = Script.prototype;
27317
+ if (!this._started) {
27318
+ componentsManager.removeOnStartScript(this);
27319
+ }
27320
+ if (this.onUpdate !== prototype.onUpdate) {
27321
+ componentsManager.removeOnUpdateScript(this);
27322
+ }
27323
+ if (this.onLateUpdate !== prototype.onLateUpdate) {
27324
+ componentsManager.removeOnLateUpdateScript(this);
27325
+ }
27326
+ if (this.onPhysicsUpdate !== prototype.onPhysicsUpdate) {
27327
+ componentsManager.removeOnPhysicsUpdateScript(this);
27328
+ }
27329
+ this._entity._removeScript(this);
27330
+ };
27331
+ /**
27332
+ * @internal
27333
+ */ _proto._onDestroy = function _onDestroy() {
27334
+ Component.prototype._onDestroy.call(this);
27335
+ this.onDestroy();
27336
+ };
27337
+ return Script;
27338
+ }(Component);
27339
+ __decorate$1([
27340
+ ignoreClone
27341
+ ], Script.prototype, "_started", void 0);
27342
+ __decorate$1([
27343
+ ignoreClone
27344
+ ], Script.prototype, "_onStartIndex", void 0);
27345
+ __decorate$1([
27346
+ ignoreClone
27347
+ ], Script.prototype, "_onUpdateIndex", void 0);
27348
+ __decorate$1([
27349
+ ignoreClone
27350
+ ], Script.prototype, "_onLateUpdateIndex", void 0);
27351
+ __decorate$1([
27352
+ ignoreClone
27353
+ ], Script.prototype, "_onPhysicsUpdateIndex", void 0);
27354
+ __decorate$1([
27355
+ ignoreClone
27356
+ ], Script.prototype, "_onPreRenderIndex", void 0);
27357
+ __decorate$1([
27358
+ ignoreClone
27359
+ ], Script.prototype, "_onPostRenderIndex", void 0);
27360
+ __decorate$1([
27361
+ ignoreClone
27362
+ ], Script.prototype, "_entityScriptsIndex", void 0);
27363
+ var PointerMethods = /*#__PURE__*/ function(PointerMethods) {
27364
+ PointerMethods["onPointerDown"] = "onPointerDown";
27365
+ PointerMethods["onPointerUp"] = "onPointerUp";
27366
+ PointerMethods["onPointerClick"] = "onPointerClick";
27367
+ PointerMethods["onPointerEnter"] = "onPointerEnter";
27368
+ PointerMethods["onPointerExit"] = "onPointerExit";
27369
+ PointerMethods["onPointerBeginDrag"] = "onPointerBeginDrag";
27370
+ PointerMethods["onPointerDrag"] = "onPointerDrag";
27371
+ PointerMethods["onPointerEndDrag"] = "onPointerEndDrag";
27372
+ PointerMethods["onPointerDrop"] = "onPointerDrop";
27373
+ return PointerMethods;
27374
+ }({});
27043
27375
  /**
27044
27376
  * Describes a contact point where the collision occurs.
27045
27377
  */ var ContactPoint = function ContactPoint() {
@@ -27311,6 +27643,7 @@
27311
27643
  for(var i = 0; i < step; i++){
27312
27644
  componentsManager.callScriptOnPhysicsUpdate();
27313
27645
  this._callColliderOnUpdate();
27646
+ nativePhysicsManager.setContactEventEnabled(this._hasCollisionEventConsumers());
27314
27647
  nativePhysicsManager.update(fixedTimeStep);
27315
27648
  this._callColliderOnLateUpdate();
27316
27649
  this._dispatchEvents(nativePhysicsManager.updateEvents());
@@ -27473,6 +27806,21 @@
27473
27806
  // Dispatch trigger events
27474
27807
  for(var i1 = 0, n1 = triggerEvents.length; i1 < n1; i1++)_loop1(i1);
27475
27808
  };
27809
+ _proto._hasCollisionEventConsumers = function _hasCollisionEventConsumers() {
27810
+ var _this__colliders = this._colliders, colliders = _this__colliders._elements;
27811
+ var _Script_prototype = Script.prototype, onCollisionEnter = _Script_prototype.onCollisionEnter, onCollisionExit = _Script_prototype.onCollisionExit, onCollisionStay = _Script_prototype.onCollisionStay;
27812
+ for(var i = this._colliders.length - 1; i >= 0; --i){
27813
+ var scripts = colliders[i].entity._scripts;
27814
+ var scriptElements = scripts._elements;
27815
+ for(var j = scripts.length - 1; j >= 0; --j){
27816
+ var script = scriptElements[j];
27817
+ if (script.onCollisionEnter !== onCollisionEnter || script.onCollisionExit !== onCollisionExit || script.onCollisionStay !== onCollisionStay) {
27818
+ return true;
27819
+ }
27820
+ }
27821
+ }
27822
+ return false;
27823
+ };
27476
27824
  _proto._setGravity = function _setGravity() {
27477
27825
  this._nativePhysicsScene.setGravity(this._gravity);
27478
27826
  };
@@ -35716,249 +36064,6 @@
35716
36064
  Scene._fogColorProperty = ShaderProperty.getByName("scene_FogColor");
35717
36065
  Scene._fogParamsProperty = ShaderProperty.getByName("scene_FogParams");
35718
36066
  Scene._prefilterdDFGProperty = ShaderProperty.getByName("scene_PrefilteredDFG");
35719
- function _array_like_to_array$2(arr, len) {
35720
- if (len == null || len > arr.length) len = arr.length;
35721
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
35722
- return arr2;
35723
- }
35724
- function _unsupported_iterable_to_array$2(o, minLen) {
35725
- if (!o) return;
35726
- if (typeof o === "string") return _array_like_to_array$2(o, minLen);
35727
- var n = Object.prototype.toString.call(o).slice(8, -1);
35728
- if (n === "Object" && o.constructor) n = o.constructor.name;
35729
- if (n === "Map" || n === "Set") return Array.from(n);
35730
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$2(o, minLen);
35731
- }
35732
- function _create_for_of_iterator_helper_loose$2(o, allowArrayLike) {
35733
- var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
35734
- if (it) return (it = it.call(o)).next.bind(it);
35735
- // Fallback for engines without symbol support
35736
- if (Array.isArray(o) || (it = _unsupported_iterable_to_array$2(o)) || allowArrayLike && o && typeof o.length === "number") {
35737
- if (it) o = it;
35738
- var i = 0;
35739
- return function() {
35740
- if (i >= o.length) return {
35741
- done: true
35742
- };
35743
- return {
35744
- done: false,
35745
- value: o[i++]
35746
- };
35747
- };
35748
- }
35749
- throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
35750
- }
35751
- /**
35752
- * Script class, used for logic writing.
35753
- */ var Script = /*#__PURE__*/ function(Component) {
35754
- _inherits$2(Script, Component);
35755
- function Script() {
35756
- var _this;
35757
- _this = Component.apply(this, arguments) || this, /** @internal */ _this._started = false, /** @internal */ _this._onStartIndex = -1, /** @internal */ _this._onUpdateIndex = -1, /** @internal */ _this._onLateUpdateIndex = -1, /** @internal */ _this._onPhysicsUpdateIndex = -1, /** @internal */ _this._onPreRenderIndex = -1, /** @internal */ _this._onPostRenderIndex = -1, /** @internal */ _this._entityScriptsIndex = -1;
35758
- return _this;
35759
- }
35760
- var _proto = Script.prototype;
35761
- /**
35762
- * Called when be enabled first time, only once.
35763
- */ _proto.onAwake = function onAwake() {};
35764
- /**
35765
- * Called when be enabled.
35766
- */ _proto.onEnable = function onEnable() {};
35767
- /**
35768
- * Called before the frame-level loop start for the first time, only once.
35769
- */ _proto.onStart = function onStart() {};
35770
- /**
35771
- * The main loop, called frame by frame.
35772
- * @param deltaTime - The delta time since last frame in seconds
35773
- */ _proto.onUpdate = function onUpdate(deltaTime) {};
35774
- /**
35775
- * Called after the onUpdate finished, called frame by frame.
35776
- * @param deltaTime - The delta time since last frame in seconds
35777
- */ _proto.onLateUpdate = function onLateUpdate(deltaTime) {};
35778
- /**
35779
- * Called before camera rendering, called per camera.
35780
- * @param camera - Current camera.
35781
- */ _proto.onBeginRender = function onBeginRender(camera) {};
35782
- /**
35783
- * Called after camera rendering, called per camera.
35784
- * @param camera - Current camera.
35785
- */ _proto.onEndRender = function onEndRender(camera) {};
35786
- /**
35787
- * Called before physics calculations, the number of times is related to the physical update frequency.
35788
- */ _proto.onPhysicsUpdate = function onPhysicsUpdate() {};
35789
- /**
35790
- * Called when the trigger enter.
35791
- * @param other - ColliderShape
35792
- */ _proto.onTriggerEnter = function onTriggerEnter(other) {};
35793
- /**
35794
- * Called when the trigger exit.
35795
- * @param other - ColliderShape
35796
- */ _proto.onTriggerExit = function onTriggerExit(other) {};
35797
- /**
35798
- * Called when the trigger stay.
35799
- * @remarks onTriggerStay is called every frame while the trigger stay.
35800
- * @param other - ColliderShape
35801
- */ _proto.onTriggerStay = function onTriggerStay(other) {};
35802
- /**
35803
- * Called when the collision enter.
35804
- * @param other - The Collision data associated with this collision event
35805
- * @remarks The Collision data will be invalid after this call, you should copy the data if needed.
35806
- */ _proto.onCollisionEnter = function onCollisionEnter(other) {};
35807
- /**
35808
- * Called when the collision exit.
35809
- * @param other - The Collision data associated with this collision event
35810
- * @remarks The Collision data will be invalid after this call, you should copy the data if needed.
35811
- */ _proto.onCollisionExit = function onCollisionExit(other) {};
35812
- /**
35813
- * Called when the collision stay.
35814
- * @param other - The Collision data associated with this collision event
35815
- * @remarks The Collision data will be invalid after this call, you should copy the data if needed.
35816
- */ _proto.onCollisionStay = function onCollisionStay(other) {};
35817
- /**
35818
- * Called when the pointer is down while over the ColliderShape.
35819
- * @param eventData - The pointer event data that triggered this callback
35820
- */ _proto.onPointerDown = function onPointerDown(eventData) {};
35821
- /**
35822
- * Called when the pointer is up while over the ColliderShape.
35823
- * @param eventData - The pointer event data that triggered this callback
35824
- */ _proto.onPointerUp = function onPointerUp(eventData) {};
35825
- /**
35826
- * Called when the pointer is down and up with the same collider.
35827
- * @param eventData - The pointer event data that triggered this callback
35828
- */ _proto.onPointerClick = function onPointerClick(eventData) {};
35829
- /**
35830
- * Called when the pointer enters the ColliderShape.
35831
- * @param eventData - The pointer event data that triggered this callback
35832
- */ _proto.onPointerEnter = function onPointerEnter(eventData) {};
35833
- /**
35834
- * Called when the pointer exits the ColliderShape.
35835
- * @param eventData - The pointer event data that triggered this callback
35836
- */ _proto.onPointerExit = function onPointerExit(eventData) {};
35837
- /**
35838
- * This function will be called when the pointer is pressed on the collider.
35839
- * @param eventData - The pointer event data that triggered this callback
35840
- */ _proto.onPointerBeginDrag = function onPointerBeginDrag(eventData) {};
35841
- /**
35842
- * When a drag collision occurs on the pointer, this function will be called every time it moves.
35843
- * @param eventData - The pointer event data that triggered this callback
35844
- */ _proto.onPointerDrag = function onPointerDrag(eventData) {};
35845
- /**
35846
- * When dragging ends, this function will be called (Dragged object).
35847
- * @param eventData - The pointer event data that triggered this callback
35848
- */ _proto.onPointerEndDrag = function onPointerEndDrag(eventData) {};
35849
- /**
35850
- * When dragging ends, this function will be called (Receiving object).
35851
- * @param eventData - The pointer event data that triggered this callback
35852
- */ _proto.onPointerDrop = function onPointerDrop(eventData) {};
35853
- /**
35854
- * Called when be disabled.
35855
- */ _proto.onDisable = function onDisable() {};
35856
- /**
35857
- * Called at the end of the destroyed frame.
35858
- */ _proto.onDestroy = function onDestroy() {};
35859
- /**
35860
- * @internal
35861
- */ _proto._onAwake = function _onAwake() {
35862
- this.onAwake();
35863
- };
35864
- /**
35865
- * @internal
35866
- */ _proto._onEnable = function _onEnable() {
35867
- this.onEnable();
35868
- };
35869
- /**
35870
- * @internal
35871
- */ _proto._onDisable = function _onDisable() {
35872
- this.onDisable();
35873
- };
35874
- /**
35875
- * @internal
35876
- */ _proto._onEnableInScene = function _onEnableInScene() {
35877
- var _this_scene = this.scene, componentsManager = _this_scene._componentsManager;
35878
- var prototype = Script.prototype;
35879
- if (!this._started) {
35880
- componentsManager.addOnStartScript(this);
35881
- }
35882
- if (this.onUpdate !== prototype.onUpdate) {
35883
- componentsManager.addOnUpdateScript(this);
35884
- }
35885
- if (this.onLateUpdate !== prototype.onLateUpdate) {
35886
- componentsManager.addOnLateUpdateScript(this);
35887
- }
35888
- if (this.onPhysicsUpdate !== prototype.onPhysicsUpdate) {
35889
- componentsManager.addOnPhysicsUpdateScript(this);
35890
- }
35891
- for(var _iterator = _create_for_of_iterator_helper_loose$2(Object.values(PointerMethods)), _step; !(_step = _iterator()).done;){
35892
- var pointerMethod = _step.value;
35893
- if (this[pointerMethod] === prototype[pointerMethod]) {
35894
- this[pointerMethod] = null;
35895
- }
35896
- }
35897
- this._entity._addScript(this);
35898
- };
35899
- /**
35900
- * @internal
35901
- */ _proto._onDisableInScene = function _onDisableInScene() {
35902
- var componentsManager = this.scene._componentsManager;
35903
- var prototype = Script.prototype;
35904
- if (!this._started) {
35905
- componentsManager.removeOnStartScript(this);
35906
- }
35907
- if (this.onUpdate !== prototype.onUpdate) {
35908
- componentsManager.removeOnUpdateScript(this);
35909
- }
35910
- if (this.onLateUpdate !== prototype.onLateUpdate) {
35911
- componentsManager.removeOnLateUpdateScript(this);
35912
- }
35913
- if (this.onPhysicsUpdate !== prototype.onPhysicsUpdate) {
35914
- componentsManager.removeOnPhysicsUpdateScript(this);
35915
- }
35916
- this._entity._removeScript(this);
35917
- };
35918
- /**
35919
- * @internal
35920
- */ _proto._onDestroy = function _onDestroy() {
35921
- Component.prototype._onDestroy.call(this);
35922
- this.onDestroy();
35923
- };
35924
- return Script;
35925
- }(Component);
35926
- __decorate$1([
35927
- ignoreClone
35928
- ], Script.prototype, "_started", void 0);
35929
- __decorate$1([
35930
- ignoreClone
35931
- ], Script.prototype, "_onStartIndex", void 0);
35932
- __decorate$1([
35933
- ignoreClone
35934
- ], Script.prototype, "_onUpdateIndex", void 0);
35935
- __decorate$1([
35936
- ignoreClone
35937
- ], Script.prototype, "_onLateUpdateIndex", void 0);
35938
- __decorate$1([
35939
- ignoreClone
35940
- ], Script.prototype, "_onPhysicsUpdateIndex", void 0);
35941
- __decorate$1([
35942
- ignoreClone
35943
- ], Script.prototype, "_onPreRenderIndex", void 0);
35944
- __decorate$1([
35945
- ignoreClone
35946
- ], Script.prototype, "_onPostRenderIndex", void 0);
35947
- __decorate$1([
35948
- ignoreClone
35949
- ], Script.prototype, "_entityScriptsIndex", void 0);
35950
- var PointerMethods = /*#__PURE__*/ function(PointerMethods) {
35951
- PointerMethods["onPointerDown"] = "onPointerDown";
35952
- PointerMethods["onPointerUp"] = "onPointerUp";
35953
- PointerMethods["onPointerClick"] = "onPointerClick";
35954
- PointerMethods["onPointerEnter"] = "onPointerEnter";
35955
- PointerMethods["onPointerExit"] = "onPointerExit";
35956
- PointerMethods["onPointerBeginDrag"] = "onPointerBeginDrag";
35957
- PointerMethods["onPointerDrag"] = "onPointerDrag";
35958
- PointerMethods["onPointerEndDrag"] = "onPointerEndDrag";
35959
- PointerMethods["onPointerDrop"] = "onPointerDrop";
35960
- return PointerMethods;
35961
- }({});
35962
36067
  /**
35963
36068
  * Signal is a typed event mechanism for Galacean Engine.
35964
36069
  * @typeParam T - Tuple type of the signal arguments
@@ -56637,7 +56742,7 @@
56637
56742
  ], EXT_texture_webp);
56638
56743
 
56639
56744
  //@ts-ignore
56640
- var version = "0.0.0-experimental-2.0-game.17";
56745
+ var version = "0.0.0-experimental-2.0-game.18";
56641
56746
  console.log("Galacean Engine Version: " + version);
56642
56747
  for(var key in CoreObjects){
56643
56748
  Loader.registerClass(key, CoreObjects[key]);