@galacean/engine-core 0.0.0-experimental-2.0-migrate.2 → 0.0.0-experimental-2.0-migrate.3
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/main.js +46 -16
- package/dist/main.js.map +1 -1
- package/dist/module.js +46 -16
- package/dist/module.js.map +1 -1
- package/package.json +3 -3
- package/types/Entity.d.ts +2 -1
package/dist/module.js
CHANGED
|
@@ -5313,10 +5313,12 @@ __decorate([
|
|
|
5313
5313
|
};
|
|
5314
5314
|
/**
|
|
5315
5315
|
* @internal
|
|
5316
|
-
*/ ComponentsDependencies._removeCheck = function _removeCheck(entity, type) {
|
|
5316
|
+
*/ ComponentsDependencies._removeCheck = function _removeCheck(entity, type, replace) {
|
|
5317
5317
|
var components = entity._components;
|
|
5318
5318
|
var n = components.length;
|
|
5319
5319
|
while(type !== Component){
|
|
5320
|
+
// The replacement still satisfies this type and all of its base types.
|
|
5321
|
+
if (replace && (replace === type || _instanceof(replace.prototype, type))) return;
|
|
5320
5322
|
var count = 0;
|
|
5321
5323
|
for(var i = 0; i < n; i++){
|
|
5322
5324
|
if (_instanceof(components[i], type) && ++count > 1) return;
|
|
@@ -6475,10 +6477,22 @@ var ComponentCloner = /*#__PURE__*/ function() {
|
|
|
6475
6477
|
_this = EngineObject.call(this, engine) || this, /** The layer the entity belongs to. */ _this.layer = Layer.Layer0, /** @internal */ _this._isActiveInHierarchy = false, /** @internal */ _this._isActiveInScene = false, /** @internal */ _this._components = [], /** @internal */ _this._scripts = new DisorderedArray(), /** @internal */ _this._scriptsVersion = 0, /** @internal */ _this._children = [], /** @internal */ _this._isRoot = false, /** @internal */ _this._isActive = true, /** @internal */ _this._siblingIndex = -1, /** @internal */ _this._isTemplate = false, /** @internal */ _this._updateFlagManager = new UpdateFlagManager(), _this._parent = null, //--------------------------------------------------------------deprecated----------------------------------------------------------------
|
|
6476
6478
|
_this._invModelMatrix = new Matrix();
|
|
6477
6479
|
_this.name = name != null ? name : "Entity";
|
|
6478
|
-
|
|
6479
|
-
|
|
6480
|
+
var transformType = Transform;
|
|
6481
|
+
var n = components.length;
|
|
6482
|
+
for(var i = n - 1; i >= 0; i--){
|
|
6483
|
+
var componentType = components[i];
|
|
6484
|
+
if (Entity._isTransformType(componentType)) {
|
|
6485
|
+
transformType = componentType;
|
|
6486
|
+
break;
|
|
6487
|
+
}
|
|
6488
|
+
}
|
|
6489
|
+
_this._transform = _this.addComponent(transformType);
|
|
6490
|
+
for(var i1 = 0; i1 < n; i1++){
|
|
6491
|
+
var componentType1 = components[i1];
|
|
6492
|
+
if (!Entity._isTransformType(componentType1)) {
|
|
6493
|
+
_this.addComponent(componentType1);
|
|
6494
|
+
}
|
|
6480
6495
|
}
|
|
6481
|
-
!_this._transform && _this.addComponent(Transform);
|
|
6482
6496
|
_this._inverseWorldMatFlag = _this.registerWorldChangeFlag();
|
|
6483
6497
|
return _this;
|
|
6484
6498
|
}
|
|
@@ -6492,13 +6506,19 @@ var ComponentCloner = /*#__PURE__*/ function() {
|
|
|
6492
6506
|
for(var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){
|
|
6493
6507
|
args[_key - 1] = arguments[_key];
|
|
6494
6508
|
}
|
|
6509
|
+
var needReplaceTransform = Entity._isTransformType(type) && this._transform;
|
|
6510
|
+
if (needReplaceTransform) {
|
|
6511
|
+
ComponentsDependencies._removeCheck(this, this._transform.constructor, type);
|
|
6512
|
+
}
|
|
6495
6513
|
ComponentsDependencies._addCheck(this, type);
|
|
6496
6514
|
var component = _construct(type, [].concat([
|
|
6497
6515
|
this
|
|
6498
6516
|
], args));
|
|
6499
|
-
|
|
6500
|
-
|
|
6501
|
-
|
|
6517
|
+
if (needReplaceTransform) {
|
|
6518
|
+
this._replaceTransform(component);
|
|
6519
|
+
} else {
|
|
6520
|
+
this._components.push(component);
|
|
6521
|
+
}
|
|
6502
6522
|
component._setActive(true, ActiveChangeFlag.All);
|
|
6503
6523
|
return component;
|
|
6504
6524
|
};
|
|
@@ -6706,9 +6726,13 @@ var ComponentCloner = /*#__PURE__*/ function() {
|
|
|
6706
6726
|
/**
|
|
6707
6727
|
* @internal
|
|
6708
6728
|
*/ _proto._removeComponent = function _removeComponent(component) {
|
|
6709
|
-
ComponentsDependencies._removeCheck(this, component.constructor);
|
|
6710
6729
|
var components = this._components;
|
|
6711
|
-
components.
|
|
6730
|
+
var index = components.indexOf(component);
|
|
6731
|
+
// A replaced Transform is detached from the component slot immediately but
|
|
6732
|
+
// can still reach here later because object destruction may be deferred.
|
|
6733
|
+
if (index < 0) return;
|
|
6734
|
+
ComponentsDependencies._removeCheck(this, component.constructor);
|
|
6735
|
+
components.splice(index, 1);
|
|
6712
6736
|
};
|
|
6713
6737
|
/**
|
|
6714
6738
|
* @internal
|
|
@@ -6910,15 +6934,18 @@ var ComponentCloner = /*#__PURE__*/ function() {
|
|
|
6910
6934
|
}
|
|
6911
6935
|
}
|
|
6912
6936
|
};
|
|
6913
|
-
_proto.
|
|
6937
|
+
_proto._replaceTransform = function _replaceTransform(value) {
|
|
6914
6938
|
var previous = this._transform;
|
|
6915
|
-
|
|
6916
|
-
|
|
6917
|
-
|
|
6918
|
-
|
|
6919
|
-
|
|
6920
|
-
|
|
6939
|
+
value.position.copyFrom(previous.position);
|
|
6940
|
+
value.rotationQuaternion.copyFrom(previous.rotationQuaternion);
|
|
6941
|
+
value.scale.copyFrom(previous.scale);
|
|
6942
|
+
// Keep the unique Transform in the same component slot. Detach the old
|
|
6943
|
+
// instance before destroy because destroy can be deferred during a frame.
|
|
6944
|
+
var components = this._components;
|
|
6945
|
+
var previousIndex = components.indexOf(previous);
|
|
6946
|
+
components[previousIndex] = value;
|
|
6921
6947
|
this._transform = value;
|
|
6948
|
+
previous.destroy();
|
|
6922
6949
|
var children = this._children;
|
|
6923
6950
|
for(var i = 0, n = children.length; i < n; i++){
|
|
6924
6951
|
var _children_i_transform;
|
|
@@ -6934,6 +6961,9 @@ var ComponentCloner = /*#__PURE__*/ function() {
|
|
|
6934
6961
|
}
|
|
6935
6962
|
return this._invModelMatrix;
|
|
6936
6963
|
};
|
|
6964
|
+
Entity._isTransformType = function _isTransformType(type) {
|
|
6965
|
+
return type === Transform || _instanceof(type.prototype, Transform);
|
|
6966
|
+
};
|
|
6937
6967
|
/**
|
|
6938
6968
|
* @internal
|
|
6939
6969
|
*/ Entity._findChildByName = function _findChildByName(entity, childIndex, paths, pathIndex) {
|