以下是部分内容
Hash the value instead
// Assigning values to properties as a string
animator.SetTrigger("Jump");
material.SetTexture("_MainMap", selectedTexture) ;
shader.SetGlobalColor("_MainColor", selectedColor);
// Getting the hashed value and caching it, using the overr ide accepting an it as identifier
int parameterId = Animator.StringToHash("Jump");
animator.SetTrigger(parameterId);
// For materials, use the Shader class
int propertyId = Shader.PropertyToID("_MainMap");;
material.SetTexture(propertyId, selectedTexture);
// As well as for shaders
int propertyId = Shader.PropertyToID("_MainColor");
shader.SetGlobalColor(propertyId, selectedColor);
Reduce Hierarchy complexity
过深的层级在移动、旋转、缩放 root
时,其他节点即使没有渲染,也会产生 OnTransformChanged
事件,会传递给下面的每一个子节点,且会增加 GC
花更多的事件在层级结构间进行遍历
只有在真正需要坐标转换的对象才使用上述的方式,尽量减少非必要的层级结构
如果 GameObjectB
不需要依赖 GameObjectA
的 Transform
信息,可以将其调整为下图所示
Accelerometer Frequency
在一些不需要 Accelerometer
的游戏中建议关闭此选项
Transforming Object
在移动有刚体碰撞的物体时建议使用 rigidBody.MovePosition()
代替 transform.Translate(...);
,且要在 FixedUpdate()
中使用
通过坐标转换移动带有刚体的组件对象时,会造成物理引擎整体重新计算