Files
jelito/Assets/jelycho/Code/Player/HUD/PlayerHUD.cs
2025-10-01 20:03:52 +02:00

53 lines
1.6 KiB
C#

using RebootKit.Engine.Extensions;
using UnityEngine;
using UnityEngine.UIElements;
using Logger = RebootKit.Engine.Foundation.Logger;
namespace RebootReality.jelycho.Player.HUD {
public class PlayerHUD : MonoBehaviour {
static readonly Logger s_Logger = new Logger(nameof(PlayerHUD));
[SerializeField] UIDocument m_MainDocument;
[field: SerializeField] public ObjectsLabelsVC ObjectsLabels { get; private set; }
[field: SerializeField] public PlayerInventoryUI InventoryUI { get; private set; }
PlayerActor m_PlayerActor;
void OnEnable() {
}
void OnDisable() {
InventoryUI.CleanUp();
}
public void SetPlayerActor(PlayerActor actor) {
UnsetPlayerActor();
if (actor.OrNull() == null) {
return;
}
m_PlayerActor = actor;
InventoryUI.Configure(m_MainDocument.rootVisualElement.Q("player-hud__inventory-slots"), actor.Inventory);
actor.OnSelectedInventorySlotChanged += OnInventorySelectedSlotChanged;
InventoryUI.SetSelectedSlot(actor.SelectedInventorySlot);
}
void UnsetPlayerActor() {
if (m_PlayerActor.OrNull() == null) {
return;
}
m_PlayerActor.OnSelectedInventorySlotChanged -= OnInventorySelectedSlotChanged;
m_PlayerActor = null;
InventoryUI.CleanUp();
}
void OnInventorySelectedSlotChanged(int newIndex) {
InventoryUI.SetSelectedSlot(newIndex);
}
}
}