- 试试把gameobject 一个一个禁用,确定下什么最影响性能
- stats 里面有多少个 Draw calls & 三角形
- 合并网格物体
- 合并材质张数
- 不要用网格碰撞.
- Unity对带动作的模型渲染消耗比较大,如果是静态的不带动作文件的模型渲染不会出现效率问题,但是要确保只绘制屏幕内的东西
1. 尽量避免每帧处理
比如:
function Update() { DoSomeThing(); }
可改为每5帧处理一次:
function Update() { if(Time.frameCount % 5 == 0) { DoSomeThing(); } }
2. 定时重复处理用 InvokeRepeating 函数实现
比如,启动0.5秒后每隔1秒执行一次 DoSomeThing 函数:
function Start() { InvokeRepeating("DoSomeThing", 0.5, 1.0); }
3. 优化 Update, FixedUpdate, LateUpdate 等每帧处理的函数
函数里面的变量尽量在头部声明。
比如:
function Update() { var pos: Vector3 = transform.position; }
可改为
private var pos: Vector3; function Update(){ pos = transform.position; }
4. 主动回收垃圾
给某个 GameObject 绑上以下的代码:
function Update() { if(Time.frameCount % 50 == 0) { System.GC.Collect(); } }
5. 运行时尽量减少 Tris 和 Draw Calls
预览的时候,可点开 Stats,查看图形渲染的开销情况。特别注意 Tris 和 Draw Calls 这两个参数。
一般来说,要做到:
Tris 保持在 7.5k 以下
Draw Calls 保持在 20 以下
6. 压缩 Mesh
导入 3D 模型之后,在不影响显示效果的前提下,最好打开 Mesh Compression。
Off, Low, Medium, High 这几个选项,可酌情选取。
7. 避免大量使用 Unity 自带的 Sphere 等内建 Mesh
Unity 内建的 Mesh,多边形的数量比较大,如果物体不要求特别圆滑,可导入其他的简单3D模型代替。
8. 优化数学计算
比如,如果可以避免使用浮点型(float),尽量使用整形(int),尽量少用复杂的数学函数比如 Sin 和 Cos 等等。
1、 ArrayList的对象在使用时应该注意以下事项
使用
arraylen = myarray. length;
for (i=0; i< arraylen; i++)
{
}
避免
for (i=0; i<myarray.length; i++) {
}
2、 少用临时变量
使用
var touch:Vector2;
function Update(){
if (count==0) { touch=iPhone.GeTouch(0).position;}
}
避免
function Update(){
if (count==0) {
var touch:Vector2=iPhone.GeTouch(0).position;
}
}
3、 少用算数符号/,改为乘以相应小数
使用
x * 0.5f
避免
x/2
4、 动作和AI不需要每帧都执行
if (GLO.count%3){
// execute the enemy aim at your player every 3 Update
}
if (GLO.count%5){
// execute player IA every 5 Update
}
5、 Mesh部分
原文:
- do not use several materials for one mesh. I got the problem with a little model that had 2 materials. It was taking 2 time more polys! When i removed one material, it was showing at half his the size. I don't know why. Usually each material = 1 draw call, so use texture atlas!
个人译文:
-对于一个mesh不要使用多张materials。我遇到过这样的问题是一个小模型拥有2张materials导致了2倍甚至更多的时间!而当我减少一个material的时候,时间减少了一半。
原文
- Use polygon cruncher to lower your mesh polys but even if your mesh look a little square, you can compensate this by tweaking "smoothing angle" in the importer inspector. For a highly optimized mesh, change the smoothing angle to 80 or even 120 and you mesh will look more smooth even with just a few polygons.
个人译文:
使用多边形粉碎机降低你mesh的面熟,但是虽然你的mesh看起来像一个正方形。你可以通过调整在导入区的” smoothing angle”选项来进行补偿。对于一个高优化的mesh,调整平滑角度到80甚至120度,你的mesh将看起来很配合虽然只是一点点的数量(???)
原文
- try not to use any expensive arithmetic like sin() or cos(). instead fill an array with precalculated values with x=0 to 360) sin(x) and cos(x) and use the values of this table. Of course it is in the case of you don't need precision.
个人译文
不要尝试使用任何昂贵消耗的数学公式,例如sin() 或 cos(),用预定义好的0到360度的sin(x)和cos(x)的值组成链表来替代。当然了前提是你不需要太精确。
原文
- force integer when possible. If you have a counter or check the position on the screen, declare the variable as INT, they are faster.
个人译文
尽可能的使用整形。如果你有一个检测屏幕位置的变量或者一个计数器,定义成整形会更快。
Unity3d的一些小窍门
1、防止黑屏
In script change iPhoneSettings.screenCanDarken to false. This basically does the same as:
//Objective-C call [UIApplication sharedApplication].idleTimerDisabled = YES;
It prevents the auto lock on iPhone to kick-in.
分享到:
相关推荐
unity3d iphone游戏开发时的场景优化
Unity3D游戏开发教程 Unity3D 入门教程
一些unity3d开发ipad,iphone的英文资料
Complete Unity3D iPhone tutorial
iphone 3D游戏开发,unity 3D基础教程
雨松MOMO Unity3D 游戏开发系列博文之Unity3D 游戏引擎之详解游戏开发音频的播放,欢迎大家下载阅读,哇咔咔~~
Unity3D是由Unity Technologies开发的一个让玩家轻松创建诸如三维视频游戏、建筑可视化、实时三维动画等类型互动内容的多平台的综合型游戏开发工具,是一个全面整合的专业游戏引擎。 Unity3D的PC插件安装量达到2 亿...
雨松MOMO Unity3D 游戏开发系列博文之Unity3D 游戏引擎之Unity3D回馈IOS高级界面消息,欢迎大家下载阅读,哇咔咔~~ 转与缩放,欢迎大家下载阅读,哇咔咔~~
雨松MOMO Unity3D 游戏开发系列博文之Unity3D 游戏引擎之IOS触摸屏手势控制镜头旋转与缩放,欢迎大家下载阅读,哇咔咔~~
Unity3D 作为一款跨平台的游戏开发引擎,可以开发出运行在网页、客户端、安卓手机、 Iphone 手机,Ipad、Xbox360、PS3、Wii 客户端的游戏。其内置的 Mono 和 ShaderLab 程序 语言体系良好的解决了多系统跨平台直接...
iPhone游戏开发iPhone游戏开发iPhone游戏开发iPhone游戏开发iPhone游戏开发iPhone游戏开发iPhone游戏开发iPhone游戏开发iPhone游戏开发iPhone游戏开发
雨松MOMO Unity3D 游戏开发系列博文之Unity3D 游戏引擎之IOS高级界面发送消息与Unity3D消息的接收,欢迎大家下载阅读,哇咔咔~~ 转与缩放,欢迎大家下载阅读,哇咔咔~~
IPhone 3D游戏艺术_Unity3D篇 从美工到程序,完整的一个游戏教程 As a 3D artist, you’ll find yourself presented with numerous opportunities and avenues to explore within different industries. The ...
这是不错的,unity3d 用于开发iPhone
雨松MOMO Unity3D 游戏开发系列博文之Unity3D 游戏引擎之平面小球重力感应详解,欢迎大家下载阅读,哇咔咔~~
雨松MOMO Unity3D 游戏开发系列博文之Unity3D 游戏引擎之游戏场景的切换与持久化简单数据的储存,欢迎大家下载阅读,哇咔咔~~
iPhone模拟器对于unity不是非常有用,因为它没有模拟iPhone所有的交互方式,而且它模拟的性能和运行在iPhone上是不一样的。您可以直接在Unity
雨松MOMO Unity3D 游戏开发系列博文之Unity3D 游戏引擎之iOS自定义游戏摇杆与飞机平滑的移动,欢迎大家下载阅读,哇咔咔~~
雨松MOMO Unity3D 游戏开发系列博文之Unity3D Unity3D 游戏引擎之FBX模型的载入与人物行走动画的播放,欢迎大家下载阅读,哇咔咔~~
iphone游戏开发实践指南每一节的源代码,以及游戏Sir Lamorak's Quest的完整的带有注释的源代码