代码优化

优化:
unity只维护localPos, localeRot, local Scale,所以尽量避免直接只用position, rotation, scale. 如果必须要使用,则可以使用caching防止同一帧里多次修改transform
1 Update\LateUpdate\FixedUpdate\Start
2 GameObject.Find
3 Component cache, GetComponent("")
4 DistToHost Change to SqrMagnitude, magnitude所有地方 Update中(替换)
5 caching transform changes
6 gameObject != null --> !System.Object.ReferenceEquals(gameObject, null) 减少native-managerment bridge (数量巨大才会有效果)

7.频繁实例化,销毁的类缓存

7.On** 空函数移除

8.Dictionary的foreach遍历优化改成获取迭代器去while去执行

9,减少GC,减少new,代码不需要了回收,下次继续使用

OnRenderObject
OnTriggerExit
OnTriggerEnter
OnPreRender
OnPreCull
OnPostRender
OnMouseOver
OnMouseUp
OnMouseExit
OnMouseEnter
OnMouseDrag
OnMouseDown
OnLevelWasLoaded
OnEnable
OnDisable
OnDestroy
OnCollisionEnter
OnAnimatorIK
OnApplicationFocus
OnApplicationPause
OnApplicationQuit
OnAudioFilterRead
OnBecameInvisible
OnBecameVisible

posted on 2017-05-16 10:16  魔天天  阅读(151)  评论(0编辑  收藏  举报