不修改Read/Write Enabled,Texture.GetPixels,Mesh.triangles

### 原理:将Texture拷贝一份出来然后读取
  /// <summary>
  /// 不通过设置Read/Write Enabled,直接克隆一份可读的Texture2D
  /// </summary>
  /// <param name="source"></param>
  /// <returns></returns>
  public static Texture2D CloneTextureToReadable(Texture2D source)
  {
      byte[] pix = source.GetRawTextureData();
      Texture2D readableText = new Texture2D(source.width, source.height, source.format, false);
      readableText.LoadRawTextureData(pix);
      readableText.Apply();
      return readableText;
  }

  //不要直接使用mesh.triangles
  private int GetTriangleCount(Mesh mesh)
  {
      List<int> tris = new List<int>();
      mesh.GetTriangles(tris, 0);
      return tris.Count / 3;
  }

posted @ 2023-10-19 10:37  jeoyao  阅读(51)  评论(0编辑  收藏  举报