1
This commit is contained in:
@@ -8,25 +8,31 @@ using BITKit;
|
||||
using BITKit.UX;
|
||||
using BITKit.Entities;
|
||||
using BITKit.Entities.Player;
|
||||
using BITKit.Steamwork;
|
||||
|
||||
namespace BITFALL.UX
|
||||
{
|
||||
public class UXHud : UIToolKitPanel, ISelectableCallback
|
||||
{
|
||||
[Header(Constant.Header.Providers)]
|
||||
[SerializeReference, SubclassSelector]
|
||||
private INetClient netClient;
|
||||
[SerializeReference, SubclassSelector]
|
||||
private INetProvider netProvider;
|
||||
[SerializeField, SerializeReference, SubclassSelector]
|
||||
private IPlayerService playerService;
|
||||
[SerializeReference, SubclassSelector] private INetClient netClient;
|
||||
[SerializeReference, SubclassSelector] private INetProvider netProvider;
|
||||
[SerializeReference, SubclassSelector] private IPlayerService playerService;
|
||||
[SerializeReference, SubclassSelector] private ISteamService steamService;
|
||||
|
||||
[Header(Constant.Header.Components)]
|
||||
[SerializeField] private UXImage crosshairImage;
|
||||
[SerializeField] private UXLabel playerNameLabel;
|
||||
[SerializeField] private UXImage playerAvatarImage;
|
||||
[SerializeField] private UXBar healthBar;
|
||||
|
||||
[Header(Constant.Header.Input)]
|
||||
public InputActionReference inventoryAction;
|
||||
public InputActionReference returnAction;
|
||||
public InputActionGroup inputActionGroup = new();
|
||||
public UXLabel nameLabel;
|
||||
private IHealth _health;
|
||||
|
||||
protected IEntityMovement _entityMovement;
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
@@ -36,6 +42,8 @@ namespace BITFALL.UX
|
||||
|
||||
netClient.OnConnected += OnConnected;
|
||||
playerService.OnPlayerInitialized += OnPlayerInitializedLocalPlayer;
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
@@ -65,11 +73,18 @@ namespace BITFALL.UX
|
||||
{
|
||||
UXService.Entry<UXHud>();
|
||||
}
|
||||
private void OnPlayerInitializedLocalPlayer(IEntity entity)
|
||||
private async void OnPlayerInitializedLocalPlayer(IEntity entity)
|
||||
{
|
||||
entity.RegisterCallback<ISelectableCallback>(this);
|
||||
_health = entity.Get<IHealth>();
|
||||
_entityMovement = entity.Get<IEntityMovement>();
|
||||
_health.OnSetAlive += OnSetAlive;
|
||||
_health.OnSetHealthPoint += OnSetHP;
|
||||
|
||||
if (!steamService.IsInitialized) return;
|
||||
playerNameLabel.Set(steamService.Name);
|
||||
var avatar = await steamService.GetAvatarAsync(cancellationToken);
|
||||
playerAvatarImage.SetTexture(avatar);
|
||||
}
|
||||
private void OnInventory(InputAction.CallbackContext context)
|
||||
{
|
||||
@@ -78,6 +93,13 @@ namespace BITFALL.UX
|
||||
if(context.JustPressed())
|
||||
UXService.Entry<UXInventory>();
|
||||
}
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
if (playerService.LocalPlayer is null) return;
|
||||
crosshairImage.SetPosition(_entityMovement.ViewCenter + _entityMovement.ViewRotation * Vector3.forward);
|
||||
}
|
||||
|
||||
private static void OnReturn(InputAction.CallbackContext context)
|
||||
{
|
||||
if (context.JustPressed())
|
||||
@@ -91,5 +113,10 @@ namespace BITFALL.UX
|
||||
Entry();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnSetHP(int hp)
|
||||
{
|
||||
healthBar.Set(hp);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user