[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)-官 ...
随机推荐
- JavaSE复习日记 : 循环语句(for/while/do while)
/* * 循环语句(for循环,while和do while循环) */ /* * for循环语句 * * for循环语法: * for (表达式1;表达式2;表达式3 ){ * java语句 * } ...
- Lowest Common Ancestor of a Binary Tree, with Parent Pointer
Given a binary tree, find the lowest common ancestor of two given nodes in tree. Each node contains ...
- 织梦dedecms|文章页通用标签
当前位置: {dede:field name='position'/}上一页: {dede:prenext get='pre'/}下一页: {dede:prenext get='next'/}收 ...
- 0527 python 基础01
折行的处理 \>>> print "hi \... hello Lucy!"hi hello Lucy! 自然字符串,字符串加上r或R前缀指定>>&g ...
- 【C++学习笔记】继承与派生基础概念
面向对象的程序设计主要有四个特点:抽象.封装.继承和多态.其中继承是我认为最最重要的一个特性,可以说继承是面向对象的精华所在. 举一个继承的浅显易懂的例子:假如我们已经有了一个“马”的类,其中成员变量 ...
- Cow Acrobats(贪心)
Cow Acrobats Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3686 Accepted: 1428 Desc ...
- Android JNI入门第二篇——Java参数类型与本地参数类型对照
前面一篇通过简单的例子介绍了android中JNI的使用.这一篇从基础上了解一些Java参数类型与本地参数类型区别. 1) java中的返回值void和JNI中的void是完全对应的哦! ...
- JavaScript编程风格--基本的格式化
缩进层级 推荐4个空格字符作为一个缩进层级. 语句结尾 推荐不要省略分号. 行的长度 最好一行不超过80个字符. 换行 在运算符后换行,下一行增加两个层级的缩进. ...
- ADO.NET(一)
- PHP - 数组去重,(折中:符串去重)
[译]更快的方式实现PHP数组去重 Jan 11, 2016 • Hector 原文:Faster Alternative to PHP’s Array Unique Function 概述 使用PH ...