3:尽量不用像素光(pixels Lights) 4:不用 软阴影(soft shadow), 或者不用阴影(No Shadows) 灯光能不用就不用, 阴影可以用面来代替. 5:少用实时灯光, 尽量使用lightmap http://blog.sina.com.cn/s/blog_409cc4b00100no8y.html 动态实时灯光相比静态灯光,非常耗费资源。所以除了能动的角色和物体(比如可以被打的到处乱飞的油桶)静态的地形和建筑,通通使用Lightmap。 强大的Unity内置了一个强大的光照图烘焙工具Beast,这个东东是Autodesk公司的产品 6:transform和OnGUI (运算上的优化远比不上 绘制效率上的优化,少个dc可能就比得上这些了) http://fredxxx123.wordpress.com/2013/05/22/unity%E6%80%A7%E8%83%BD%E5%84%AA%E5%8C%96%E4%B9%8B%E5%B0%8F%E6%B8%AC%E8%A9%A6/ // transfrom 少用transform, 多用 myCachedTransform 頻繁使用該物件的地方,就是先把該物件cache起來,理論上就會避免這種不必的開銷。 ※這也可延伸至其他是property的變數。例如:transform.position。 ***直接使用的版本: public class TestUnit : MonoBehaviour { void Update() { var t = this.transform; t = this.transform; t = this.transform; t = this.transform; t = this.transform; } } ***cache 使用的版本: public class TestUnit : MonoBehaviour { Transform myTransform; void Start() { myTransform = transform; }
void Update () { var t = this.myTransform; t = this.myTransform; t = this.myTransform; t = this.myTransform; t = this.myTransform; } } // OnGUI 空物件版本: public class TestUnit : MonoBehaviour { } 外加一個空白OnGUI的版本: public class TestUnit : MonoBehaviour { void OnGUI() { } } 實際上是被GUI.Begin()和GUI.End()所佔據,function本身是無辜的~~ 非必要避免使用OnGUI(),即使它裡面甚麼事情都沒做! 如需使用,請盡可能集中到同一個OnGUI()底下執行繪製,好避免Begin End的開銷。