Bind PaintHud to the scene-authored canvas
Drop the code-gen canvas/EventSystem bootstrap and the layoutPrefab instantiation; the canvas and its panel now live in the scene, so PaintHud binds to its first child at startup instead of building the UI at runtime. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
8f9b6cf1bc
commit
cadc8f8b17
1 file changed
+1
-44
@@ -25,9 +25,6 @@ public partial class PaintHud : MonoBehaviour
|
||||
[Tooltip("Painter the HUD edits. Empty = the manager's painter, else found automatically.")]
|
||||
public MeshPainter painter;
|
||||
|
||||
[Tooltip("Authored panel layout. Instantiated and bound at startup.")]
|
||||
public GameObject layoutPrefab;
|
||||
|
||||
// Stable widget names shared by the baked prefab and the binder.
|
||||
private const string PanelGeneral = "Panel_General";
|
||||
private const string PanelSpray = "Panel_Spray";
|
||||
@@ -111,16 +108,7 @@ public partial class PaintHud : MonoBehaviour
|
||||
private void Start()
|
||||
{
|
||||
_font = LoadFont();
|
||||
|
||||
EnsureEventSystem();
|
||||
EnsureCanvas();
|
||||
|
||||
if (layoutPrefab)
|
||||
{
|
||||
var go = Instantiate(layoutPrefab, transform);
|
||||
go.name = layoutPrefab.name; // strip the "(Clone)" suffix
|
||||
_panel = go;
|
||||
}
|
||||
_panel = transform.GetChild(0).gameObject;
|
||||
|
||||
// Snapshot the authored panel positions now, while the layout is untouched - before RestoreHudState
|
||||
// (in BindPainter) overwrites them. The reset button restores exactly these.
|
||||
@@ -209,37 +197,6 @@ public partial class PaintHud : MonoBehaviour
|
||||
return f;
|
||||
}
|
||||
|
||||
// --- Canvas ---
|
||||
|
||||
private void EnsureCanvas()
|
||||
{
|
||||
var canvas = GetComponent<Canvas>();
|
||||
if (!canvas) canvas = gameObject.AddComponent<Canvas>();
|
||||
canvas.renderMode = RenderMode.ScreenSpaceOverlay;
|
||||
canvas.sortingOrder = 100;
|
||||
|
||||
var scaler = GetComponent<CanvasScaler>();
|
||||
if (!scaler) scaler = gameObject.AddComponent<CanvasScaler>();
|
||||
scaler.uiScaleMode = CanvasScaler.ScaleMode.ScaleWithScreenSize;
|
||||
scaler.referenceResolution = new Vector2(1920f, 1080f);
|
||||
scaler.screenMatchMode = CanvasScaler.ScreenMatchMode.Expand;
|
||||
|
||||
if (!GetComponent<GraphicRaycaster>()) gameObject.AddComponent<GraphicRaycaster>();
|
||||
}
|
||||
|
||||
private void EnsureEventSystem()
|
||||
{
|
||||
if (FindFirstObjectByType<EventSystem>()) return;
|
||||
|
||||
var es = new GameObject("EventSystem", typeof(EventSystem));
|
||||
#if ENABLE_INPUT_SYSTEM
|
||||
var module = es.AddComponent<InputSystemUIInputModule>();
|
||||
if (!module.actionsAsset) module.AssignDefaultActions();
|
||||
#else
|
||||
es.AddComponent<StandaloneInputModule>();
|
||||
#endif
|
||||
}
|
||||
|
||||
// --- Wiring (behaviour; shared by the code-gen and prefab paths) ---
|
||||
|
||||
private void WirePanel(Transform panel)
|
||||
|
||||
Reference in new issue
Block a user