Skip to content

Commit

Permalink
Avoid silent copy of vertices when obtaining vertices count
Browse files Browse the repository at this point in the history
> `mesh.vertices` returns a copy of _all_ vertices. If you have code like `mesh.vertices.Length`, this will be quite inefficient. It's much better to use `mesh.vertexCount`

Source:  microsoft/Microsoft.Unity.Analyzers#52
  • Loading branch information
originalfoo committed Jun 9, 2020
1 parent def7315 commit fd66d13
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Source/AdditiveShader/Manager/ManagedAsset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ internal ManagedAsset(BuildingInfo asset)
asset.m_lodHasDifferentShader = false;
asset.m_lodMissing = true;
asset.m_material.SetFloat("_InvFade", Info.Fade);
asset.m_mesh.colors = GetMeshColors(asset.m_mesh.vertices.Length);
asset.m_mesh.colors = GetMeshColors(asset.m_mesh.vertexCount);

CachedRenderDistance = GetRenderDistance(asset.m_generatedInfo.m_size);
ApplyCachedRenderDistance();
Expand Down Expand Up @@ -171,7 +171,7 @@ internal ManagedAsset(BuildingInfoSub asset)

asset.m_lodHasDifferentShader = false;
asset.m_material.SetFloat("_InvFade", Info.Fade);
asset.m_mesh.colors = GetMeshColors(asset.m_mesh.vertices.Length);
asset.m_mesh.colors = GetMeshColors(asset.m_mesh.vertexCount);

CachedRenderDistance = GetRenderDistance(asset.m_generatedInfo.m_size);
ApplyCachedRenderDistance();
Expand Down Expand Up @@ -200,7 +200,7 @@ internal ManagedAsset(VehicleInfoSub asset)
backup_maxRenderDistance = asset.m_maxRenderDistance;

asset.m_material.SetFloat("_InvFade", Info.Fade);
asset.m_mesh.colors = GetMeshColors(asset.m_mesh.vertices.Length);
asset.m_mesh.colors = GetMeshColors(asset.m_mesh.vertexCount);

CachedRenderDistance = GetRenderDistance(asset.m_generatedInfo.m_size);
ApplyCachedRenderDistance();
Expand Down

0 comments on commit fd66d13

Please sign in to comment.