惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

罗磊的独立博客
Apple Machine Learning Research
Apple Machine Learning Research
The Cloudflare Blog
WordPress大学
WordPress大学
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 叶小钗
博客园 - 聂微东
阮一峰的网络日志
阮一峰的网络日志
腾讯CDC
博客园 - 三生石上(FineUI控件)
V
V2EX
有赞技术团队
有赞技术团队
V
Visual Studio Blog
小众软件
小众软件
Jina AI
Jina AI
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - Franky
量子位
T
Tailwind CSS Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
P
Palo Alto Networks Blog
Cisco Talos Blog
Cisco Talos Blog
I
Intezer
Project Zero
Project Zero
A
Arctic Wolf
P
Privacy International News Feed
V
Vulnerabilities – Threatpost
L
Lohrmann on Cybersecurity
S
Securelist
C
Cybersecurity and Infrastructure Security Agency CISA
C
CXSECURITY Database RSS Feed - CXSecurity.com
T
Tor Project blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
S
Security @ Cisco Blogs
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Google DeepMind News
Google DeepMind News
N
News and Events Feed by Topic
TaoSecurity Blog
TaoSecurity Blog
L
LINUX DO - 热门话题
G
GRAHAM CLULEY
Help Net Security
Help Net Security
N
News | PayPal Newsroom
W
WeLiveSecurity
G
Google Developers Blog
Microsoft Security Blog
Microsoft Security Blog
Engineering at Meta
Engineering at Meta
MongoDB | Blog
MongoDB | Blog
C
Check Point Blog

博客园 - 阿土仔

Unity 2019中对象池的用法 Unity UGUI动态生成控件 Unity场景间数据传递方法 UGUI防止穿透和判断点击的是否是UI Unity中的Character Controller Unity插件研究-EasyTouch V5 Unity塔防游戏的创建 Unity性能优化-DrawCall Unity性能优化-音频设置 Unity性能优化-遮挡剔除 Unity异步加载场景 Unity 协程 HBuilder git使用-分工合作 HBuilder git合作-代码同步 微信小程序开发-窗体设置 HBuilder git合作-从Git Hub Clone项目 HBuilder git合作-上传项目到Git Hub 微信小程序开发-tabbar组件 HBuilder git使用-建立仓库,邀请用户
Unity性能优化-对象池
阿土仔 · 2019-07-20 · via 博客园 - 阿土仔

1.对象池Object Pool的原理:

   有些GameObject是在游戏中需要频繁生成并销毁的(比如射击游戏中的子弹),以前的常规做法是:Instantiate不断生成预设件Prefab,然后采用碰撞销毁,或者定时销毁,大量创建重复对象造成内存损耗,影响性能还容易产生内存碎片。

     所谓对象池,就是针对需要经常生成消失的对象。我们在对象需要消失的时候不Destroy而是SetActive(false),然后放入池子中,当需要再次显示一个新的对象的时候,先去池子中看有没有隐藏的对象,有就取出SetActive(true),若池子里没有可用的则再Instantiate。

2. 两篇相关的博客帮助理解

    (1)https://www.cnblogs.com/yugejuhao/p/7677497.html,它在这里面采用了一个单例模式,这个脚本不需要挂接在任何GameObject上;

    (2)https://blog.csdn.net/wangjiangrong/article/details/80196676,采用了一个队列实现对象池,

3. 效果:有的对象池一上来先生成10个对象,都设为setActive(false),然后按游戏逻辑使用其中为false的对象,转为true使用,达到条件不再销毁,再次设置为setActive(false)回到池中,这样对象的个数始终能保持下来,那内存和性能肯定就上去了!