Game.Rendering.MaterialPropertyAttribute
Assembly:
Game (assembly containing game code)
Namespace: Game.Rendering
Type:
class (Attribute)
Base:
System.Attribute
Summary:
MaterialPropertyAttribute is a custom attribute that can be applied to fields to declare how they map to shader properties. It stores the shader property name, the managed data type expected for that property, and a flag indicating whether the property is a built-in shader property. This attribute is intended for use by material/renderer tooling or reflection-based systems that build or bind material properties from game data.
Fields
- (none)
This type does not declare private instance fields; it exposes its data via properties.
Properties
-
public string ShaderPropertyName { get; protected set; }
The name of the shader property (e.g., the name used in the shader or material). This string is used by reflection/tooling to look up and bind the field to the corresponding shader property. -
public Type DataType { get; protected set; }
The managed System.Type that represents the expected data type for the shader property (for example, typeof(UnityEngine.Vector4) or typeof(float)). Tooling can use this to validate or convert field values when binding to the shader. -
public bool IsBuiltin { get; protected set; }
If true, indicates the shader property is considered a built-in property (provided by the engine or shared across shaders). This can be used to treat builtin properties differently from custom per-material properties.
Constructors
public MaterialPropertyAttribute(string shaderPropertyName, Type dataType, bool isBuiltin = false)
Creates a new MaterialPropertyAttribute.
Parameters: - shaderPropertyName: The shader-side property name to map to. - dataType: The System.Type describing the data type to be used for this shader property. - isBuiltin: Optional boolean flag (default false) marking the property as builtin when true.
Methods
- (none declared)
There are no additional methods declared on this attribute type beyond those inherited from System.Attribute.
Usage Example
using System;
using Game.Rendering;
using UnityEngine;
public class ExampleMaterialData
{
// Map this field to a shader property named "_Color" with a Vector4 value
[MaterialProperty("_Color", typeof(Vector4))]
public Vector4 color;
// Map this field to a shader float property and mark it as builtin
[MaterialProperty("_Glossiness", typeof(float), isBuiltin: true)]
public float glossiness;
}
Additional notes: - The attribute is restricted to fields via [AttributeUsage(AttributeTargets.Field)]. - Reflection-based systems can read these attributes to generate material bindings or editors that expose the correct shader property names and types.