From af3aa34d664b9fda5347fa9f7e4b9edf3ff6ddf6 Mon Sep 17 00:00:00 2001 From: MelekTaus Moribundus Date: Wed, 24 Jun 2026 15:42:25 +0200 Subject: [PATCH] Dim toggle channel panels via CanvasGroup alpha Each channel panel (Albedo, Metallic+Smoothness, Occlusion, Emission) gets a CanvasGroup whose alpha follows its toggle: 1.0 when enabled, 0.5 when disabled. Ensured at runtime in WirePanel (no prefab re-bake), so both the prefab and code-gen paths behave identically. Panel_BrushSize has no toggle and is left untouched. Co-Authored-By: Claude Opus 4.8 --- Assets/Scripts/PaintHud.cs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Assets/Scripts/PaintHud.cs b/Assets/Scripts/PaintHud.cs index 44f73d5..6e13f81 100644 --- a/Assets/Scripts/PaintHud.cs +++ b/Assets/Scripts/PaintHud.cs @@ -161,6 +161,12 @@ public class PaintHud : MonoBehaviour WireToggle(panel, ToggleOcclusion, painter && painter.paintOcclusion, v => { if (painter) painter.paintOcclusion = v; }); WireToggle(panel, ToggleEmission, painter && painter.paintEmission, v => { if (painter) painter.paintEmission = v; }); + // Dim a channel panel to 0.5 alpha while its toggle is off, full alpha while on. + WirePanelFade(panel, PanelAlbedo, ToggleAlbedo); + WirePanelFade(panel, PanelMetallicSmoothness, ToggleMetallicSmoothness); + WirePanelFade(panel, PanelOcclusion, ToggleOcclusion); + WirePanelFade(panel, PanelEmission, ToggleEmission); + WirePicker(panel, PickerAlbedo, painter ? painter.brushColor : Color.red, c => { if (painter) painter.brushColor = new Color(c.r, c.g, c.b, painter.brushColor.a); }); @@ -206,6 +212,26 @@ public class PaintHud : MonoBehaviour toggle.onValueChanged.AddListener(v => onChanged(v)); } + /// + /// Ensures a on the channel panel and drives its alpha from the toggle: + /// 1 while the channel is enabled, 0.5 while disabled. Call after so the + /// initial alpha reflects the toggle's painter-synced state. The group stays interactive (default + /// interactable/blocksRaycasts), so a dimmed panel can still be clicked to re-enable its channel. + /// + private static void WirePanelFade(Transform root, string panelName, string toggleName) + { + var panel = FindDeep(root, panelName); + if (!panel) return; + var group = panel.GetComponent(); + if (!group) group = panel.gameObject.AddComponent(); + + var toggle = Find(panel, toggleName); + if (!toggle) { group.alpha = 1f; return; } + + group.alpha = toggle.isOn ? 1f : 0.5f; + toggle.onValueChanged.AddListener(v => group.alpha = v ? 1f : 0.5f); + } + private static void WireSlider(Transform panel, string name, float value, Action onChanged) { var cell = FindDeep(panel, name);