resharper-unity icon indicating copy to clipboard operation
resharper-unity copied to clipboard

Repeated property access could be improved with awareness of SetPositionAndRotation

Open vertxxyz opened this issue 1 year ago • 1 comments

The detection of:

transform.localPosition = Vector3.zero;
transform.localRotation = Quaternion.identity;
// Or
transform.position = Vector3.zero;
transform.rotation = Quaternion.identity;

And turning it into:

transform.SetLocalPositionAndRotation(Vector3.zero, Quaternion.identity);
// Or
transform.SetPositionAndRotation(Vector3.zero, Quaternion.identity);

Would be a great way to help notify users that these combined APIs exist, instead of making their code grow by introducing a local variable when it may not be necessary.

(Do note that SetLocalPositionAndRotation was introduced in 2021.3.11f1)

vertxxyz avatar Aug 24 '23 22:08 vertxxyz

This (and many more) is already implemented by Microsoft's (UnityVS) Roslyn Analyzers: https://github.com/microsoft/Microsoft.Unity.Analyzers/blob/main/doc/UNT0022.md It's be great is those analyzers where shared between VS and Rider...

benblo avatar Sep 21 '23 14:09 benblo