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 <noreply@anthropic.com>
This commit is contained in:
1 parent
8f45aa1537
commit
af3aa34d66
1 file changed
+26
@@ -161,6 +161,12 @@ public class PaintHud : MonoBehaviour
|
|||||||
WireToggle(panel, ToggleOcclusion, painter && painter.paintOcclusion, v => { if (painter) painter.paintOcclusion = v; });
|
WireToggle(panel, ToggleOcclusion, painter && painter.paintOcclusion, v => { if (painter) painter.paintOcclusion = v; });
|
||||||
WireToggle(panel, ToggleEmission, painter && painter.paintEmission, v => { if (painter) painter.paintEmission = 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,
|
WirePicker(panel, PickerAlbedo, painter ? painter.brushColor : Color.red,
|
||||||
c => { if (painter) painter.brushColor = new Color(c.r, c.g, c.b, painter.brushColor.a); });
|
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));
|
toggle.onValueChanged.AddListener(v => onChanged(v));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ensures a <see cref="CanvasGroup"/> on the channel panel and drives its alpha from the toggle:
|
||||||
|
/// 1 while the channel is enabled, 0.5 while disabled. Call after <see cref="WireToggle"/> 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.
|
||||||
|
/// </summary>
|
||||||
|
private static void WirePanelFade(Transform root, string panelName, string toggleName)
|
||||||
|
{
|
||||||
|
var panel = FindDeep(root, panelName);
|
||||||
|
if (!panel) return;
|
||||||
|
var group = panel.GetComponent<CanvasGroup>();
|
||||||
|
if (!group) group = panel.gameObject.AddComponent<CanvasGroup>();
|
||||||
|
|
||||||
|
var toggle = Find<Toggle>(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<float> onChanged)
|
private static void WireSlider(Transform panel, string name, float value, Action<float> onChanged)
|
||||||
{
|
{
|
||||||
var cell = FindDeep(panel, name);
|
var cell = FindDeep(panel, name);
|
||||||
|
|||||||
Reference in new issue
Block a user