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

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - 阿土仔

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)回到池中,这样对象的个数始终能保持下来,那内存和性能肯定就上去了!