[0]Component类自动移除侦听问题(显示对象从舞台移除再添加到舞台事件无效问题)
export class TestS extends Laya.Script extends Component一个显示对象上面挂个脚本
{
public onAwake ():void
{
super.onAwake();
this.owner.on(Laya.Event.CLICK, this, this.OnClick);
}
private OnClick ():void { console.log("点击了"); }
}
显示对象移除舞台后再次添加到舞台,发现点击无效了
后发现时Component类的_setActive方法中调用了this.owner.offAllCaller(this);
感觉这种清理没必要 我只是移除舞台又不是销毁
解决办法是把事件侦听放到onEnable方法中
没有找到相关结果
已邀请:
2 个回复
谷主
赞同来自:
谷主
赞同来自: