using System;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
#if ENABLE_INPUT_SYSTEM
using UnityEngine.InputSystem.UI;
#endif
///
/// In-game paint UI. Builds its own Screen Space - Overlay canvas (and an EventSystem
/// if the scene has none) entirely in code and binds the widgets directly to the live
/// fields, so changes apply immediately. The panel is shown
/// only while the active is (it follows
/// the manager's ModeChanged event).
///
/// First, simple pass: channel toggles, an HSV colour picker for albedo, metallic /
/// smoothness / occlusion sliders, an HSV picker + intensity for emission, and brush
/// size. Attach to an empty GameObject; everything else is generated at runtime.
///
[DisallowMultipleComponent]
public class PaintHud : MonoBehaviour
{
[Tooltip("Mode manager driving visibility. Empty = found automatically.")]
public GameModeManager modeManager;
[Tooltip("Painter the HUD edits. Empty = the manager's painter, else found automatically.")]
public MeshPainter painter;
private static readonly Color PanelColor = new Color(0.09f, 0.09f, 0.11f, 0.9f);
private static readonly Color Accent = new Color(0.40f, 0.75f, 1f, 1f);
private static readonly Color BoxColor = new Color(0.20f, 0.20f, 0.24f, 1f);
private GameObject _panel;
private Font _font;
private void Awake()
{
if (!modeManager) modeManager = FindFirstObjectByType();
}
private void OnEnable()
{
if (modeManager) modeManager.ModeChanged += OnModeChanged;
}
private void OnDisable()
{
if (modeManager) modeManager.ModeChanged -= OnModeChanged;
}
private void Start()
{
if (!painter) painter = modeManager ? modeManager.Painter : null;
if (!painter) painter = FindFirstObjectByType();
_font = Resources.GetBuiltinResource("LegacyRuntime.ttf");
if (!_font) _font = Resources.GetBuiltinResource("Arial.ttf");
EnsureEventSystem();
BuildUi();
// Set initial visibility (the manager's first SwitchTo may have fired before this Start).
OnModeChanged(modeManager ? modeManager.ActiveMode : null);
}
private void OnModeChanged(GameMode mode)
{
if (_panel) _panel.SetActive(mode is PaintMode);
}
// --- UI construction ---
private void BuildUi()
{
var canvas = GetComponent