[Unity 3D] Unity 3D 性能优化(二)
IsAlive
public bool IsAlive()
{
bool withChildren = true;
return this.IsAlive(withChildren);
}
public bool IsAlive(bool withChildren)
{
if (withChildren)
{
ParticleSystem[] particleSystems = ParticleSystem.GetParticleSystems(this);
ParticleSystem[] array = particleSystems;
for (int i = 0; i < array.Length; i++)
{
ParticleSystem particleSystem = array[i];
if (particleSystem.Internal_IsAlive())
{
return true;
}
}
return false;
}
return this.Internal_IsAlive();
}
可以看到,如果传递的withChildren参数为true,那么函数会先尝试调用GetParticleSystems(this)来获取包括下级gameObject在内的所有能找得到的粒子系统组件,然后对这些粒子系统组件依次再调用IsAlive判断。而如果withChildren为false,就仅仅会判断自身。那么自然,开销大小与否,关键就在GetParticleSystems的实现上了。
internal static ParticleSystem[] GetParticleSystems(ParticleSystem root)
{
if (!root)
{
return null;
}
List<ParticleSystem> list = new List<ParticleSystem>();
list.Add(root);
ParticleSystem.GetDirectParticleSystemChildrenRecursive(root.transform, list);
return list.ToArray();
}
private static void GetDirectParticleSystemChildrenRecursive(Transform transform, List<ParticleSystem> particleSystems)
{
foreach (Transform transform2 in transform)
{
ParticleSystem component = transform2.gameObject.GetComponent<ParticleSystem>();
if (component != null)
{
particleSystems.Add(component);
ParticleSystem.GetDirectParticleSystemChildrenRecursive(transform2, particleSystems);
}
}
}
U3D对获取所有下级gameObject实例上的粒子系统组件使用了递归的方式,并在递归结束后返回结果列表时做了一次列表元素复制(List.ToArray()),并且在获取粒子系统组件的时候用的是transform2.gameObject.GetComponent<ParticleSystem>(),而不是transform2.GetComponent<ParticleSystem>(),从上一篇文章里我们已经用实验证实了,前一种方式开销更大。看到这里,我们心里大概已经有谱了,那就是——效率绝对不会高到哪里去,影响性能的地方太多了……还是设计一个小实验来看看这种情况下应该用什么样的方式更好吧:
[Unity 3D] Unity 3D 性能优化(二)的更多相关文章
- EMW 性能优化二之---并发配置
EMW 性能优化二之---并发配置 在前一个日志中写到交货的异步更新,对于RFUI RF的前台操作会提升效率,异步更新不用等待更新状态的返回,启用更新队列的方式执行(SM13). 下面再补全性能相关的 ...
- MySQL性能优化(二):优化数据库的设计
原文:MySQL性能优化(二):优化数据库的设计 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.n ...
- Unity技术支持团队性能优化经验分享
https://mp.weixin.qq.com/s?__biz=MzU5MjQ1NTEwOA==&mid=2247490321&idx=1&sn=f9f34407ee5c5d ...
- 【Unity游戏开发】性能优化之在真机上开启DeepProfile与踩坑
一.引子 最近马三入职了新公司,平时除了负责编辑器开发之外还要做一些游戏性能优化方面的工作.在这里首先给大家安利一下Unity官方的性能测试分析工具URP ,这个工具目前是免费,测试的过程中也不需要接 ...
- Spark性能优化(二)
资源调优 调优概述 在开发完Spark作业之后,就该为作业配置合适的资源了.Spark的资源参数,基本都可以在spark-submit命令中作为参数设置.很多Spark初学者,通常不知道该设置哪些必要 ...
- mysql性能优化(二)
###> mysql中有一个explain 命令可以用来分析select 语句的运行效果,例如explain可以获得select语句使用的索引情况.排序的情况等等.除此以外,explain 的e ...
- Tomcat性能优化(二) ExpiresFilter设置浏览器缓存
Tomcat性能调优 通过ExpiresFilter设置资源缓存 [官方文档] http://tomcat.apache.org/tomcat-7.0-doc/config/filter.html#E ...
- Tomcat性能优化(二) 启动参数设置
一.tomcat绿色版设置方法 进入tomcat/bin目录下,找到catalina.bat文件在文件首行中插入下面这段配置即可. set JAVA_OPTS=-server -Djava.awt.h ...
- Unity性能优化(4)-官方教程Optimizing graphics rendering in Unity games翻译
本文是Unity官方教程,性能优化系列的第四篇<Optimizing graphics rendering in Unity games>的翻译. 相关文章: Unity性能优化(1)-官 ...
- Unity性能优化(3)-官方教程Optimizing garbage collection in Unity games翻译
本文是Unity官方教程,性能优化系列的第三篇<Optimizing garbage collection in Unity games>的翻译. 相关文章: Unity性能优化(1)-官 ...
随机推荐
- LeetCode Coins in a Line
There are n coins in a line. Two players take turns to take one or two coins from right side until t ...
- error C2018: unknown character '0xa1'
调试程序时出现 error C2018: unknown character '0xa1',代码行中加入的有编译器不能识别的字符,才发现由空格引起的,删除掉就ok了.
- nodejs入门demo
demo的实例引用自:http://www.runoob.com/nodejs/nodejs-event.html, 官方文档:https://nodejs.org/dist/latest-v6.x/ ...
- C# 自定义控件的一些文章和博客
http://blog.csdn.net/songkexin/archive/2009/12/08/4961215.aspx http://www.cnblogs.com/yuanfan/archiv ...
- CSS3 模拟笑脸
参考 http://www.html5tricks.com/demo/html5-css3-smile-face/index.html 它还做了舌头... 一开始我都是用JS实现的动画 当然了 眼 ...
- 64位linux下安装oracle10 64位 遇到 :ins_ctx.mk ;ins_emdb.mk
http://blog.csdn.net/bamuta/article/details/10523835 http://www.cnblogs.com/kerrycode/p/3519446.html ...
- CPU卡
CPU卡芯片通俗地讲就是指芯片内含有一个微处理器,它的功能相当于一台微型计算机.人们经常使用的集成电路卡(IC卡)上的金属片就是CPU卡芯片.CPU卡可适用于金融.保险.交警.政府行业等多个领域,具有 ...
- Struts2 中action之间的跳转(分享)
例如从你的login.action到register.action 有两种实现方式 1. 设置type="redirect" <package name="st ...
- Microsoft Deployment Toolkit 2013 Preview Release Now Available
MDT 2013 provides a common console with comprehensive tools and guidance for every organizational ro ...
- epoll相关
1) 能不能给一个使用epoll相关API进行IO监控的示例?在<<epoll学习笔记>>中有一个简单的示例说明epoll相关API的使用, 但是这个示例是非常简单的, 它仅仅 ...