Hide
ShaderParam

Select a shader parameter from a shader, material or renderer. (Requires Unity 2021.2+)

For string, it will save the name. For int, it will save the hash.

Parameters:

  • [Optional] string name: the target. Be a property or a callback that returns a shader, material or renderer. When omitted, it will try to get the Renderer component from the current component.
  • [Optional] ShaderPropertyType propertyType: filter the shader parameters by type. Omitted to show all types.
  • [Optional] int index=0: which material index to use when the target is a Renderer.
[ShaderParam] public string shaderParamString; [ShaderParam(0)] public int shaderParamInt; [ShaderParam(ShaderPropertyType.Texture)] public int shaderParamFilter; [Separator("By Target")] [GetComponent] public Renderer targetRenderer; [ShaderParam(nameof(targetRenderer))] public int shaderParamRenderer; private Material GetMat() => targetRenderer.sharedMaterial; [ShaderParam(nameof(GetMat))] public int shaderParamMat; private Shader GetShader() => targetRenderer.sharedMaterial.shader; [ShaderParam(nameof(GetShader))] public int shaderParamShader;

image

It works with ShowInInspector

[ShowInInspector, ShaderParam] public int ShowShaderParamInt { get => shaderParamInt; set => shaderParamInt = value; }

It works with ShowInInspector/Button parameters and return value

[ShowInInspector] private string ShowShaderParam([ShaderParam] string shaderS) => shaderS; [Button] private string ShowShaderParam([ShaderParam] string shaderS) => shaderS;