JetBrains / resharper-unity

Unity support for both ReSharper and Rider
Apache License 2.0
1.21k stars 131 forks source link

Repeated property access could be improved with awareness of SetPositionAndRotation #2413

Open vertxxyz opened 10 months ago

vertxxyz commented 10 months ago

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)

benblo commented 9 months ago

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...