zoukankan      html  css  js  c++  java
  • 代码层面优化

    优化:
    unity只维护localPos, localeRot, local Scale,所以尽量避免直接只用position, rotation, scale. 如果必须要使用,则可以使用caching防止同一帧里多次修改transform
    1 UpdateLateUpdateFixedUpdateStart
    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 (数量巨大才会有效果)

    优化内存使用

    通过Unity Profiler里的GC Alloc一列,可以看到具体的内存申请。在用户操作应用的时候,尽可能让其接近0。(当然了,如果是载入资源就没事)

    • 尽可能重用集合(例如Lists, HashSets)

    • 避免字符串拼接,可以考虑重用StringBuilder来完成

    • 避免匿名函数和闭包

    Foreach

    当循环开始时会申请一个Enumerator,这也是广为人知的Mono的锅了…别这么写就行。

    装箱问题(Boxing)

    当将值类型当做引用类型传入时,会在堆顶临时分配一个值来用

  • 相关阅读:
    Android发送信息模拟系统
    Android SharedPreferences
    Android中SQLiteDatabase操作【附源码】
    poj 2453
    pku 1020
    poj 2594 Treasure Exploration
    pku 2092 Grandpa is Famous
    zoj Weekend Party
    poj 3259 Wormholes
    poj 2455 Secret Milking Machine
  • 原文地址:https://www.cnblogs.com/mttnor/p/6247725.html
Copyright © 2011-2022 走看看