Unity HDRP Product Visualizer 1.0.0
Interactive 3D product showcase built with Unity 6 and HDRP
Loading...
Searching...
No Matches
VisualizerUI.cs
Go to the documentation of this file.
1using UnityEngine;
2using UnityEngine.UI;
3using TMPro;
4
9
29public class VisualizerUI : MonoBehaviour
30{
31 // ------------------------------------------------------------------
32 // Inspector fields — controllers
33 // ------------------------------------------------------------------
34
37
39 [Header("Scene Controllers")]
41
44
47
49
50 // ------------------------------------------------------------------
51 // Inspector fields — buttons
52 // ------------------------------------------------------------------
53
56
58 [Header("Buttons")]
59 public Button autoRotateButton;
60
62 public Button nextColorButton;
63
65 public Button prevColorButton;
66
68 public Button nextBgButton;
69
71 public Button resetCameraButton;
72
74
75 // ------------------------------------------------------------------
76 // Inspector fields — labels
77 // ------------------------------------------------------------------
78
81
83 [Header("Labels")]
84 public TextMeshProUGUI variantLabel;
85
87 public TextMeshProUGUI backgroundLabel;
88
90 public TextMeshProUGUI rotationLabel;
91
93
94 // ------------------------------------------------------------------
95 // Unity lifecycle
96 // ------------------------------------------------------------------
97
98 void Start()
99 {
100 autoRotateButton?.onClick.AddListener(OnToggleAutoRotate);
101 nextColorButton?.onClick.AddListener(() => canSwapper?.NextVariant());
102 prevColorButton?.onClick.AddListener(() => canSwapper?.PreviousVariant());
103 nextBgButton?.onClick.AddListener(() => backgroundController?.NextPreset());
104 resetCameraButton?.onClick.AddListener(() => orbitCamera?.ResetView());
105
106 if (canSwapper != null)
107 canSwapper.OnVariantChanged += (_, v) => SetLabel(variantLabel, $"Brand: {v.variantName}");
108
109 if (backgroundController != null)
110 backgroundController.OnPresetChanged += (_, p) => SetLabel(backgroundLabel, $"Scene: {p.presetName}");
111
112 RefreshAllLabels();
113 }
114
115 // ------------------------------------------------------------------
116 // Private helpers
117 // ------------------------------------------------------------------
118
120 void OnToggleAutoRotate()
121 {
123 RefreshRotationLabel();
124 }
125
127 void RefreshAllLabels()
128 {
129 SetLabel(variantLabel, $"Brand: {canSwapper?.CurrentVariantName}");
130 SetLabel(backgroundLabel, $"Scene: {backgroundController?.CurrentPresetName}");
131 RefreshRotationLabel();
132 }
133
135 void RefreshRotationLabel()
136 {
137 if (orbitCamera != null)
138 SetLabel(rotationLabel, orbitCamera.IsAutoRotating ? "Auto-Rotate: ON" : "Auto-Rotate: OFF");
139 }
140
144 static void SetLabel(TextMeshProUGUI label, string text)
145 {
146 if (label != null) label.text = text;
147 }
148}
Cycles through BackgroundPreset entries by writing to MaterialPropertyBlocks.
Cycles through brand variants by replacing the full material array on the can renderer.
Spherical-coordinate camera that orbits around a target Transform.
bool IsAutoRotating
Returns true when auto-rotation is active.
void ToggleAutoRotate()
Flips the auto-rotation state.
Connects Unity UI buttons and TextMeshPro labels to the three scene controllers.
TextMeshProUGUI rotationLabel
Displays the current auto-rotation state, e.g. "Auto-Rotate: ON".
Button nextColorButton
Advances to the next can brand variant.
OrbitCamera orbitCamera
Reference to the orbital camera. Drives rotation toggle and reset.
Button prevColorButton
Steps back to the previous can brand variant.
Button nextBgButton
Cycles to the next studio background preset.
TextMeshProUGUI backgroundLabel
Displays the current background preset name, e.g. "Scene: Dark Studio".
TextMeshProUGUI variantLabel
Displays the current brand name, e.g. "Brand: Coca-Cola".
BackgroundController backgroundController
Reference to the background controller. Drives scene preset cycling.
Button autoRotateButton
Toggles OrbitCamera auto-rotation on/off.
CanMaterialSwapper canSwapper
Reference to the can material swapper. Drives brand cycling.
Button resetCameraButton
Resets the camera to its default framing.