Struct UnityMaterialTargetMapping
Represents a mapping from a MaterialId to a specific Renderer on the prefab. Stores relative path for prefab-safe serialization (like bone mappings).
In the Editor, users select a Renderer via ObjectField. The RendererPath and ColorPropertyName are auto-generated from the selection. At runtime, only the path-based fields are used for resolution.
Inherited Members
Namespace: Serenity.ProceduralExpression.Infrastructure.Settings
Assembly: Serenity.UnityProceduralExpression.Infrastructure.dll
Syntax
public struct UnityMaterialTargetMapping
Constructors
UnityMaterialTargetMapping(string, string, string, int)
Creates a new material target mapping.
Declaration
public UnityMaterialTargetMapping(string materialId, string rendererPath, string colorPropertyName, int materialIndex = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| string | materialId | Unique identifier for the target. |
| string | rendererPath | Relative path from root to renderer. |
| string | colorPropertyName | Shader property name. |
| int | materialIndex | Material slot index for multi-material renderers. |
Fields
ColorPropertyName
Shader property name for the color to animate. Common values: "_BaseColor" (URP/HDRP), "_Color" (Built-in). Auto-detected from the shader - do not edit manually.
Declaration
public string ColorPropertyName
Field Value
| Type | Description |
|---|---|
| string |
DefaultPropertyName
Default property name for URP/HDRP shaders.
Declaration
public const string DefaultPropertyName = "_BaseColor"
Field Value
| Type | Description |
|---|---|
| string |
EditorRenderer
Editor-only reference to the target Renderer for UX. Used to auto-generate RendererPath and ColorPropertyName. Stripped from builds automatically.
Declaration
public Renderer EditorRenderer
Field Value
| Type | Description |
|---|---|
| Renderer |
FallbackPropertyName
Fallback property name for Built-in shaders.
Declaration
public const string FallbackPropertyName = "_Color"
Field Value
| Type | Description |
|---|---|
| string |
MaterialId
Stable identifier for this material target. Used by MaterialColorSequenceLayerSO and other layers to reference this target.
Declaration
public string MaterialId
Field Value
| Type | Description |
|---|---|
| string |
MaterialIndex
Material slot index for multi-material renderers. Default: 0 (first material).
Declaration
public int MaterialIndex
Field Value
| Type | Description |
|---|---|
| int |
RendererPath
Relative path from the root transform to the Renderer's transform. Empty string means the root transform itself. Uses "/" as separator (e.g., "Body/Head/Eyes"). Auto-generated from EditorRenderer selection - do not edit manually.
Declaration
public string RendererPath
Field Value
| Type | Description |
|---|---|
| string |
TintPropertyName
Additional fallback for tint-based shaders.
Declaration
public const string TintPropertyName = "_TintColor"
Field Value
| Type | Description |
|---|---|
| string |
Properties
IsValid
Returns true if this mapping has valid data.
Declaration
public bool IsValid { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Methods
ComputeRelativePath(Transform, Transform)
Computes the relative path from a root transform to a target transform.
Declaration
public static string ComputeRelativePath(Transform root, Transform target)
Parameters
| Type | Name | Description |
|---|---|---|
| Transform | root | The root transform. |
| Transform | target | The target transform. |
Returns
| Type | Description |
|---|---|
| string | Relative path string, or empty if target is root. |
DetectColorPropertyName(Material)
Detects the best color property name for a material. Tries _BaseColor (URP/HDRP), _Color (Built-in), _TintColor in order.
Declaration
public static string DetectColorPropertyName(Material material)
Parameters
| Type | Name | Description |
|---|---|---|
| Material | material | The material to check. |
Returns
| Type | Description |
|---|---|
| string | The detected property name, or DefaultPropertyName if none found. |
ResolveRenderer(Transform)
Resolves the Renderer from the given root transform using the stored path.
Declaration
public Renderer ResolveRenderer(Transform root)
Parameters
| Type | Name | Description |
|---|---|---|
| Transform | root | The root transform to search from. |
Returns
| Type | Description |
|---|---|
| Renderer | The Renderer component, or null if not found. |
ToString()
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| string |
Overrides
UpdateFromEditorRenderer(Transform)
Updates RendererPath and ColorPropertyName from EditorRenderer. Call this after changing EditorRenderer to sync the runtime fields. Uses UnityShaderColorPropertyResolver for robust property detection.
Declaration
public void UpdateFromEditorRenderer(Transform prefabRoot)
Parameters
| Type | Name | Description |
|---|---|---|
| Transform | prefabRoot | The prefab root transform for path calculation. |