Move buttons to HUD Manager
This commit is contained in:
69
Assets/Scripts/UI/HudMenuButton.cs
Normal file
69
Assets/Scripts/UI/HudMenuButton.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
using UI.Core;
|
||||
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;
|
||||
}
|
||||
|
||||
Debug.Log($"[HudMenuButton] {buttonName} opening page from prefab: {pagePrefab.name}");
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user