Files
AppleHillsProduction/Assets/Scripts/UI/HudMenuButton.cs

71 lines
2.1 KiB
C#
Raw Normal View History

2025-11-10 13:03:36 +01:00
using Core;
using UI.Core;
2025-11-09 13:23:03 +01:00
using UnityEngine;
using UnityEngine.UI;
namespace UI
{
/// <summary>
/// HUD button that opens a UI page from a prefab when clicked.
/// Implements ITouchInputConsumer as a dummy (no touch handling).
/// </summary>
[RequireComponent(typeof(Button))]
public class HudMenuButton : MonoBehaviour, ITouchInputConsumer
{
[Header("Page Configuration")]
[SerializeField] private GameObject pagePrefab;
[Tooltip("Optional: Custom name for debug logging")]
[SerializeField] private string buttonName = "HudButton";
private Button _button;
private void Awake()
{
_button = GetComponent<Button>();
if (_button != null)
{
_button.onClick.AddListener(OnButtonClicked);
}
else
{
Debug.LogError($"[HudMenuButton] {buttonName} missing Button component!");
}
}
private void OnDestroy()
{
if (_button != null)
{
_button.onClick.RemoveListener(OnButtonClicked);
}
}
private void OnButtonClicked()
{
if (pagePrefab == null)
{
Debug.LogError($"[HudMenuButton] {buttonName} has no page prefab assigned!");
return;
}
if (PlayerHudManager.Instance == null)
{
Debug.LogError($"[HudMenuButton] {buttonName} cannot find PlayerHudManager instance!");
return;
}
2025-11-10 13:03:36 +01:00
Logging.Debug($"[HudMenuButton] {buttonName} opening page from prefab: {pagePrefab.name}");
2025-11-09 13:23:03 +01:00
UIPageController.Instance.PushPageFromPrefab(pagePrefab);
}
#region ITouchInputConsumer - Dummy Implementation
// Required by interface but not used
public void OnTap(Vector2 position) { }
public void OnHoldStart(Vector2 position) { }
public void OnHoldMove(Vector2 position) { }
public void OnHoldEnd(Vector2 position) { }
#endregion
}
}