Files
megakoop/UI/Scripts/PanelSettingsSetup.cs
2025-10-05 18:18:12 +02:00

40 lines
1.3 KiB
C#

using UnityEngine;
using UnityEngine.UIElements;
namespace MegaKoop.UI
{
/// <summary>
/// Ensures Panel Settings are configured for proper scaling across all resolutions
/// </summary>
[RequireComponent(typeof(UIDocument))]
public class PanelSettingsSetup : MonoBehaviour
{
private void Awake()
{
var uiDocument = GetComponent<UIDocument>();
if (uiDocument != null && uiDocument.panelSettings != null)
{
var settings = uiDocument.panelSettings;
// Set Scale Mode to Scale With Screen Size for responsive design
settings.scaleMode = PanelScaleMode.ScaleWithScreenSize;
// Reference resolution (base design resolution)
settings.referenceResolution = new Vector2Int(1920, 1080);
// Match width or height (0.5 = balanced)
settings.match = 0.5f;
// Sort order
settings.sortingOrder = 0;
Debug.Log($"Panel Settings configured for responsive design: {settings.scaleMode}");
}
else
{
Debug.LogWarning("UIDocument or PanelSettings not found! UI may not scale properly.");
}
}
}
}