Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

不能针对GameObject设置active #186

Open
fanmingfei opened this issue Feb 25, 2022 · 4 comments · May be fixed by #192
Open

不能针对GameObject设置active #186

fanmingfei opened this issue Feb 25, 2022 · 4 comments · May be fixed by #192
Labels
enhancement New feature or request

Comments

@fanmingfei
Copy link
Member

fanmingfei commented Feb 25, 2022

所有对能力都在Component上,GameObject没有属性,如果设置active是false的话,虽然可以防止GameObject被遍历,Component的生命周期不会被执行。但是目前渲染和运行时是两套,需要想办法把对应的渲染也取消掉。

@fanmingfei fanmingfei added the enhancement New feature or request label Feb 25, 2022
@fanmingfei
Copy link
Member Author

fanmingfei commented Mar 1, 2022

设置GameObject的active状态 GameObject.prototype.setActive(flag: boolean)

当GameObject的父对象active是false的时候,其active不能设置true

当前对象的子对象单独被设置成false的时候,当前原对象active变化不会影响子对象的active

GameObject 为 false 时,游戏循环中,不对当前GameObject的Component进行循环Update

为Component增加enable属性,当GameObject设置成false的时候,GameObject所有的 Component 的 enable 属性变为false

需要针对active为true,或者变为true的话,需要单独去执行某些功能。
例如,监听 Transform 组件的 enable 变化,系统需要做如下行为:
active 为 true 将创建好的PIXI.Container设置成visible。如果active被设置成false,对应的 PIXI.Container 会变成false

例如监听 A11y 组件的系统需要做如下行为:
active 为 true 将 DOM 展示出来,active 为 false 的话将 DOM 隐藏。

每个System根据自己负责的Component的enable属性变化去做固定的行为,在生命周期中的onEnable/OnDisable实现

每个 Component 上面有 onDisable/onEnable 的生命周期回调方法来监听enable的变化,以便实现脚本组件的能力。

@fanmingfei fanmingfei linked a pull request Mar 7, 2022 that will close this issue
3 tasks
@fanmingfei
Copy link
Member Author

已经完成 GameObject.active 变化的时候, 不遍历GameObject的Component,并且active为false的时候不现实对应渲染内容。

后需要针对每个组件进行设置

@terrykingcha
Copy link
Member

为啥不是只在transform component上提供active属性来完成组件的显示隐藏?

@fanmingfei
Copy link
Member Author

为啥不是只在transform component上提供active属性来完成组件的显示隐藏?

GameObject.active 变化的时候 会触发GameObject所有components的enable的变化,component的enable,其实就是Transform的enable变成了false,然后组件隐藏。单独去吧component的enable设置成false,也会有相同的效果

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants