Unity3D豆知识:优化、资源、预编译

来源:互联网 发布:家具定制软件傻瓜 编辑:程序博客网 时间:2024/04/29 05:44
#优化
OnMouse类方法会导致额外监听消耗
drawcall < 20
profiler
使用Profiler.BeginSample额EndSample手工分区域分析代码
DeepProfiling更详细,但消耗内存
尽量避免使用静态变量,以便不使用时从内存中删除。
不要逐帧移动 一个静态碰撞器(有collider却没有rigdidbody),移动静态碰撞器将导致PhysX引擎的内部重置,非常耗费资源,而且会造成性能的极大下降。另外,基于一个静态碰撞器唤醒其他刚体的行为 是未定义的,而且移动静态碰撞器将不会对碰到它的刚体施加摩擦力。取而代之的是,要移动的碰撞器要保持是运动学刚体。
减少对transform之类的赋值




MonoBehaviour.CancelInvoke
取消当前mono的所有invoke


#define
/d is the short form of /define.
影响项目中所有文件


debug logs
#define DEBUG
// ...
#if DEBUG
    Console.WriteLine("Debug version");
#endif


#define 值为true
#undef 定义值为false


#if UNITY_EDITOR
    Debug.Log("Unity Editor");
#elif UNITY_IPHONE
    Debug.Log("Unity iPhone");
#else
    Debug.Log("Any other platform");
#endif