resharper-unity
resharper-unity copied to clipboard
Improve quick fix for introducing a cached property ID
The Material.SetFloat method can take a string name, that is immediately converted to a property ID via Shader.PropertyToID. We already have an inspection and quick fix to recognise this and introduce a field with a converted property ID. We can make some improvements:
- When replacing one instance, check to see if there are any other instances in the same file and prompt to replace all.
- Check to see if a field already exists and change text to say something like "Use existing property field 'Whatever'"
- Provide name suggestions to choose from, based on the initial string literal value, but with additional suffixes, such as
PropIdandShaderPropertyId
Maybe generate something like the following?
public class MyComponent : MonoBehaviour
{
private static class ShaderProperties
{
public static readonly int Tint = Shader.PropertyToID("_Tint");
}
}
I think that would be cleaner if you have a couple of shader properties but might be a bit bulky for a single one.
Yeah, I think moving to a separate class should be a separate refactoring step.
Am I tripping or has this feature been removed?