45 lines
1.3 KiB
C#
45 lines
1.3 KiB
C#
using System;
|
|
using R3;
|
|
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;
|
|
DisposableBag m_ActorBag;
|
|
|
|
void OnEnable() {
|
|
}
|
|
|
|
void OnDisable() {
|
|
InventoryUI.CleanUp();
|
|
m_ActorBag.Dispose();
|
|
}
|
|
|
|
public void SetPlayerActor(PlayerActor actor) {
|
|
m_ActorBag.Dispose();
|
|
|
|
if (actor == null) {
|
|
m_PlayerActor = null;
|
|
InventoryUI.CleanUp();
|
|
return;
|
|
}
|
|
|
|
m_ActorBag = new DisposableBag();
|
|
m_PlayerActor = actor;
|
|
InventoryUI.Configure(m_MainDocument.rootVisualElement.Q("player-hud__inventory-slots"), actor.Inventory);
|
|
|
|
actor.SelectedInventorySlot.Subscribe(x => {
|
|
InventoryUI.SetSelectedSlot(x);
|
|
}).AddTo(ref m_ActorBag);
|
|
}
|
|
}
|
|
} |