[LayaAir 2.0]Uncaught 无法实例class PhysicsCollider extends PhysicsTriggerComponent

PhysicsCollider这个组件我只添加了一次,当我按住键盘在点击鼠标的时候,就会有这个错误。说我组件重复添加。我不知道,是你们有默认的键盘事件影响的,还是什么问题。
以下是报错信息,这个错误也不是每次都报,多试几次就会有。
Uncaught 无法实例class PhysicsCollider extends PhysicsTriggerComponent {
    constructor(collisionGroup = Physics3DUtils.COLLISIONFILTERGROUP_DEFAULTFILTER, canCollideWith = Physics3DUtils.COLLISIONFILTERGROUP_ALLFILTER) {
        super(collisionGroup, canCollideWith);
        this._enableProcessCollisions = false;
    }
    _addToSimulation() {
        this._simulation._addPhysicsCollider(this, this._collisionGroup, this._canCollideWith);
    }
    _removeFromSimulation() {
        this._simulation._removePhysicsCollider(this);
    }
    _parse(data) {
        (data.friction != null) && (this.friction = data.friction);
        (data.rollingFriction != null) && (this.rollingFriction = data.rollingFriction);
        (data.restitution != null) && (this.restitution = data.restitution);
        (data.isTrigger != null) && (this.isTrigger = data.isTrigger);
        super._parse(data);
        this._parseShape(data.shapes);
    }
    _onAdded() {
        var bt = Physics3D._bullet;
        var btColObj = bt.btCollisionObject_create();
        bt.btCollisionObject_setUserIndex(btColObj, this.id);
        bt.btCollisionObject_forceActivationState(btColObj, PhysicsComponent.ACTIVATIONSTATE_DISABLE_SIMULATION);
        var flags = bt.btCollisionObject_getCollisionFlags(btColObj);
        if (this.owner.isStatic) {
            if ((flags & PhysicsComponent.COLLISIONFLAGS_KINEMATIC_OBJECT) > 0)
                flags = flags ^ PhysicsComponent.COLLISIONFLAGS_KINEMATIC_OBJECT;
            flags = flags | PhysicsComponent.COLLISIONFLAGS_STATIC_OBJECT;
        }
        else {
            if ((flags & PhysicsComponent.COLLISIONFLAGS_STATIC_OBJECT) > 0)
                flags = flags ^ PhysicsComponent.COLLISIONFLAGS_STATIC_OBJECT;
            flags = flags | PhysicsComponent.COLLISIONFLAGS_KINEMATIC_OBJECT;
        }
        bt.btCollisionObject_setCollisionFlags(btColObj, flags);
        this._btColliderObject = btColObj;
        super._onAdded();
    }
}组件,class PhysicsCollider extends PhysicsTriggerComponent {
    constructor(collisionGroup = Physics3DUtils.COLLISIONFILTERGROUP_DEFAULTFILTER, canCollideWith = Physics3DUtils.COLLISIONFILTERGROUP_ALLFILTER) {
        super(collisionGroup, canCollideWith);
        this._enableProcessCollisions = false;
    }
    _addToSimulation() {
        this._simulation._addPhysicsCollider(this, this._collisionGroup, this._canCollideWith);
    }
    _removeFromSimulation() {
        this._simulation._removePhysicsCollider(this);
    }
    _parse(data) {
        (data.friction != null) && (this.friction = data.friction);
        (data.rollingFriction != null) && (this.rollingFriction = data.rollingFriction);
        (data.restitution != null) && (this.restitution = data.restitution);
        (data.isTrigger != null) && (this.isTrigger = data.isTrigger);
        super._parse(data);
        this._parseShape(data.shapes);
    }
    _onAdded() {
        var bt = Physics3D._bullet;
        var btColObj = bt.btCollisionObject_create();
        bt.btCollisionObject_setUserIndex(btColObj, this.id);
        bt.btCollisionObject_forceActivationState(btColObj, PhysicsComponent.ACTIVATIONSTATE_DISABLE_SIMULATION);
        var flags = bt.btCollisionObject_getCollisionFlags(btColObj);
        if (this.owner.isStatic) {
            if ((flags & PhysicsComponent.COLLISIONFLAGS_KINEMATIC_OBJECT) > 0)
                flags = flags ^ PhysicsComponent.COLLISIONFLAGS_KINEMATIC_OBJECT;
            flags = flags | PhysicsComponent.COLLISIONFLAGS_STATIC_OBJECT;
        }
        else {
            if ((flags & PhysicsComponent.COLLISIONFLAGS_STATIC_OBJECT) > 0)
                flags = flags ^ PhysicsComponent.COLLISIONFLAGS_STATIC_OBJECT;
            flags = flags | PhysicsComponent.COLLISIONFLAGS_KINEMATIC_OBJECT;
        }
        bt.btCollisionObject_setCollisionFlags(btColObj, flags);
        this._btColliderObject = btColObj;
        super._onAdded();
    }
}组件已存在!
1588670708(1).jpg
已邀请:

煮饭烫伤手

赞同来自:

找到原因了,是因为这里,没有关闭(this.close()),直接把3d场景new出来了。虽然页面被影藏了,但是当我点击到[开始]按钮的位置的时候,我的这个new LayaAir3D()又被执行了一次。导致场景中的地形被重复添加组件。
我想知道,为什么这里没有关闭Scene,而我的页面仍然被隐藏了呢。

要回复问题请先

商务合作
商务合作