53 lines
1.5 KiB
Lua
53 lines
1.5 KiB
Lua
|
---@class WB_HP_C:UUserWidget
|
||
|
---@field TextBlock_HP UTextBlock
|
||
|
---@field TextBlock_MaxHP UTextBlock
|
||
|
--Edit Below--
|
||
|
local WB_HP = {
|
||
|
bInitDoOnce = false;
|
||
|
HealthColor = {R = 0, G = 1, B = 0, A = 1};
|
||
|
UnHealthColor = {R = 1, G = 0, B = 0, A = 1};
|
||
|
HealthProportion = 0.4
|
||
|
};
|
||
|
|
||
|
|
||
|
function WB_HP:Construct()
|
||
|
UGCEventSystem.SetTimerLoop(self, self.UpdateHealth, 0.1)
|
||
|
end
|
||
|
|
||
|
function WB_HP:UpdateHealth()
|
||
|
local Pawn = UGCSystemLibrary.GetLocalPlayerPawn()
|
||
|
if UE.IsValid(Pawn) and not UGCPawnSystem.HasPawnState(Pawn, EPawnState.Dead) then
|
||
|
local HP = KismetMathLibrary.Round(UGCPawnAttrSystem.GetHealth(Pawn))
|
||
|
local MaxHP = KismetMathLibrary.Round(UGCPawnAttrSystem.GetHealthMax(Pawn))
|
||
|
self.TextBlock_HP:SetText(HP)
|
||
|
self.TextBlock_MaxHP:SetText(MaxHP)
|
||
|
if HP / MaxHP > self.HealthProportion then
|
||
|
self.TextBlock_HP:SetColorAndOpacity({SpecifiedColor = self.HealthColor, ColorUseRule = 0})
|
||
|
else
|
||
|
self.TextBlock_HP:SetColorAndOpacity({SpecifiedColor = self.UnHealthColor, ColorUseRule = 0})
|
||
|
end
|
||
|
self:SetVis(true)
|
||
|
else
|
||
|
self:SetVis(false)
|
||
|
end
|
||
|
end
|
||
|
function WB_HP:SetVis(IsVis)
|
||
|
if self.IsVis ~= IsVis then
|
||
|
self.IsVis = IsVis
|
||
|
if self.IsVis then
|
||
|
self:SetVisibility(ESlateVisibility.SelfHitTestInvisible)
|
||
|
else
|
||
|
self:SetVisibility(ESlateVisibility.Collapsed)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
-- function WB_HP:Tick(MyGeometry, InDeltaTime)
|
||
|
|
||
|
-- end
|
||
|
|
||
|
-- function WB_HP:Destruct()
|
||
|
|
||
|
-- end
|
||
|
|
||
|
return WB_HP;
|