Unity HDRP Product Visualizer 1.0.0
Interactive 3D product showcase built with Unity 6 and HDRP
Loading...
Searching...
No Matches
ProductVariantController Class Reference

Applies ProductVariant presets to a set of Renderers using MaterialPropertyBlock. More...

Inheritance diagram for ProductVariantController:
Collaboration diagram for ProductVariantController:

Public Member Functions

void NextVariant ()
 Advances to the next variant, wrapping around the list.
 
void PreviousVariant ()
 Steps back to the previous variant, wrapping around the list.
 
void SetVariantIndex (int index)
 Jumps directly to a variant by index.
 

Public Attributes

List< Renderer > bodyRenderers = new()
 Renderers whose material properties will be overridden.
 
List< ProductVariantvariants = new()
 Ordered list of PBR colour presets available in the visualizer.
 
System.Action< int, ProductVariantOnVariantChanged
 Fired after a variant change with (newIndex, newVariant).
 

Properties

ProductVariant CurrentVariant [get]
 The currently active ProductVariant, or null if the list is empty.
 
int CurrentIndex [get]
 Zero-based index of the active variant.
 
int VariantCount [get]
 Total number of registered variants.
 
string CurrentVariantName [get]
 Display name of the active variant (empty string if none).
 

Detailed Description

Applies ProductVariant presets to a set of Renderers using MaterialPropertyBlock.

This component is the colour-only counterpart to CanMaterialSwapper. Use it when the product mesh does not require texture swapping — for example, to quickly prototype colour options without authoring separate material assets.

MaterialPropertyBlock vs. material swap
MaterialPropertyBlock writes properties to the GPU without creating a new Material instance, so all renderers in bodyRenderers share the same draw-call state. This is the recommended approach for single-object colour variation in Unity.
See also
CanMaterialSwapper for texture-based brand swapping.

Definition at line 51 of file ProductVariantController.cs.

Member Function Documentation

◆ NextVariant()

void ProductVariantController.NextVariant ( )

Advances to the next variant, wrapping around the list.

Definition at line 96 of file ProductVariantController.cs.

References OnVariantChanged, and variants.

◆ PreviousVariant()

void ProductVariantController.PreviousVariant ( )

Steps back to the previous variant, wrapping around the list.

Definition at line 104 of file ProductVariantController.cs.

References OnVariantChanged, and variants.

◆ SetVariantIndex()

void ProductVariantController.SetVariantIndex ( int  index)

Jumps directly to a variant by index.

Parameters
indexZero-based index into variants. Out-of-range values are ignored.

Definition at line 113 of file ProductVariantController.cs.

References OnVariantChanged, and variants.

Member Data Documentation

◆ bodyRenderers

List<Renderer> ProductVariantController.bodyRenderers = new()

Renderers whose material properties will be overridden.

Typically the main body mesh(es) of the product.

Definition at line 60 of file ProductVariantController.cs.

◆ OnVariantChanged

System.Action<int, ProductVariant> ProductVariantController.OnVariantChanged

Fired after a variant change with (newIndex, newVariant).

Definition at line 71 of file ProductVariantController.cs.

Referenced by NextVariant(), PreviousVariant(), and SetVariantIndex().

◆ variants

List<ProductVariant> ProductVariantController.variants = new()

Ordered list of PBR colour presets available in the visualizer.

Definition at line 64 of file ProductVariantController.cs.

Referenced by NextVariant(), PreviousVariant(), and SetVariantIndex().

Property Documentation

◆ CurrentIndex

int ProductVariantController.CurrentIndex
get

Zero-based index of the active variant.

Definition at line 125 of file ProductVariantController.cs.

◆ CurrentVariant

ProductVariant ProductVariantController.CurrentVariant
get

The currently active ProductVariant, or null if the list is empty.

Definition at line 122 of file ProductVariantController.cs.

◆ CurrentVariantName

string ProductVariantController.CurrentVariantName
get

Display name of the active variant (empty string if none).

Definition at line 131 of file ProductVariantController.cs.

◆ VariantCount

int ProductVariantController.VariantCount
get

Total number of registered variants.

Definition at line 128 of file ProductVariantController.cs.


The documentation for this class was generated from the following file: