查看: 1160|回复: 0
打印 上一主题 下一主题

iPhone optimization tips(1)

[复制链接]

5552

主题

2

听众

8万

积分

首席设计师

Rank: 8Rank: 8

纳金币
-1
精华
11

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

跳转到指定楼层
楼主
发表于 2012-6-28 15:29:57 |只看该作者 |倒序浏览
In general, some good practices: have a global script attached to an Empty game object where you will put all your 'static' variables you use repetitively elsewhere in the game, for example In a file GLOB.js Code: static timenow:float=0; static count=0; static globalrotate:float=0; function FixedUpdate(){ timenow = Time.realtimeSinceStartup; count+=1;if (count>10) count=0; globalrotate=Mathf.Sin(Time.deltaTime); }
Now if you need to check the absolute time spent between 2 calls to an Update, use GLO.timenow. If you want to***n a complex operation every 10 time an Update is called, check GLOB.count If you need to rotate a bunch of turrets then use globalrotate, you will save a lot of CPU cycles. Code: function Update(){ if (count==0) { var touch:Vector2=iPhone.GeTouch(0).position; } } is slow and should be Code: var touch:Vector2; function Update(){ if (count==0) { touch=iPhone.GeTouch(0).position;} } Some task do not need to be called every Update, for example : the enemy aim, the player IA every and the animations logic will be called every x updates. enemyanim.js in the Update function : Code: if (GLO.count%3){ //***cute the enemy aim at your player every 3 Update } if (GLO.count%5){ //***cute player IA every 5 Update } Another little one, I don't know if Unity's compiler is doing this kind of optimization but it is always better to use multiplications instead of divisions. Code: x=x/2 is much slower than x=x*0.5
分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

手机版|纳金网 ( 闽ICP备2021016425号-2/3

GMT+8, 2025-2-8 11:16 , Processed in 0.061044 second(s), 29 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部