• Unity
  • Could you avoid implicit vector conversions?

Related Discussions
...

Hi. I found tiny improvement to performance in SpriteMesh.cs.

Line 683 Vector3 bmin = this.meshBoundsMin;
Line 684 Vector3 bmax = this.meshBoundsMax;

I think these variables are not Vector3 but Vector2.

And, this code create temporary Vector2 object.

Line 993 Vector2 halfSize = (meshBoundsMax - meshBoundsMin) * 0.5f;
Line 994 mesh.bounds = new Bounds {
Line 995     center = (Vector3)(meshBoundsMin + halfSize),
Line 996     extents = new Vector3(halfSize.x, halfSize.y, meshBoundsThickness * 0.5f)
Line 997 };

So, this may be better.

float halfWidth = (meshBoundsMax.x - meshBoundsMin.x) * 0.5f;
float halfHeight = (meshBoundsMax.y - meshBoundsMin.y) * 0.5f;
mesh.bounds = new Bounds {
    center = new Vector3(meshBoundsMin.x + halfWidth, meshBoundsMin.y + halfHeight, 0),
    extents = new Vector3(halfWidth, halfHeight, meshBoundsThickness * 0.5f)
};

I know it's a trade-off between performance and readability.