[Unity]直接引用GameObject Asset资源导致性能下降

2020/03 30 11:03
class Build : MonoBehaviour
{
  publuc GameObject buildObj;
  public GameObject buildAnimation;
  public GameObject buildUpgrade;
  public GameObject buildUpEnd;
  
  public void foo()
  {
    var obj = GameObject.Instantiate(buildObj);
    ...
  }
}

修改为

class Build : MonoBehaviour
{
  publuc string buildObj;
  public string buildAnimation;
  public string buildUpgrade;
  public string buildUpEnd;
  
  public void foo()
  {
    var obj = LoadPrefabByPath(buildObj);
    ...
  }
}

可大大提高加载速度
1、降低内存使用
2、降低加载时间

--转载请注明: http://blog.coolcoding.cn/?p=1528