using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UIElements; using UnityEngine.InputSystem; using BITKit; using BITKit.UX; using BITKit.Entities; using Net.Share; using Net.Client; namespace BITFALL.UX { public class HUD : UXPanel, ISelectableCallback { [Header(Constant.Header.Input)] public InputActionReference inventoryAction; public InputActionReference returnAction; public InputActionGroup inputActionGroup = new(); public UXLabel nameLabel; public override void OnStart() { base.OnStart(); inputActionGroup.RegisterCallback(returnAction, OnReturn); inputActionGroup.RegisterCallback(inventoryAction, OnInventry); BITNet.OnConnected += OnConnected; } public override void Set(bool active) { base.Set(active); inputActionGroup.RegisterCallback(inventoryAction, OnInventry); inputActionGroup.allowInput.SetElements(this, active); } public void OnActive(ISelectable selectable) { } public void OnHover(ISelectable selectable) { if (!selectable.GetTransform().TryGetComponent(out var description)) return; nameLabel.SetActive(true); nameLabel.Set(description.Name); } public void OnInactive(ISelectable selectable) { nameLabel.SetActive(false); } void OnEnable() { IEntity.OnSpawnLocalPlayer += OnSpawnLocalPlayer; } void OnDisable() { IEntity.OnSpawnLocalPlayer -= OnSpawnLocalPlayer; } void OnConnected() { UXFramework.Enter(); } void Start() { nameLabel.SetActive(false); } void OnSpawnLocalPlayer(IEntity entity) { entity.RegisterCallback(this); } void OnInventry(InputAction.CallbackContext context) { if (context.performed) UXFramework.Enter(); } void OnReturn(InputAction.CallbackContext context) { UXFramework.Enter(); } } }