153 lines
4.8 KiB
Lua
153 lines
4.8 KiB
Lua
---@class WB_InductionPlayer_C:UUserWidget
|
|
---@field CanvasPanel_Main UCanvasPanel
|
|
---@field CanvasPanel_Pointer UCanvasPanel
|
|
---@field TextBlock_9 UTextBlock
|
|
---@field TextBlock_Angle UTextBlock
|
|
---@field TextBlock_HorizontalDis UTextBlock
|
|
---@field TextBlock_UpDis UTextBlock
|
|
---@field WidgetSwitcher_HasEnemy UWidgetSwitcher
|
|
---@field WidgetSwitcher_UpOrDown UWidgetSwitcher
|
|
--Edit Below--
|
|
local WB_InductionPlayer = {
|
|
bInitDoOnce = false;
|
|
UpdateFPS = 90;
|
|
FindEnemyFPS = 1;
|
|
}
|
|
|
|
--[==[ Construct
|
|
function WB_InductionPlayer:Construct()
|
|
|
|
end
|
|
-- Construct ]==]
|
|
|
|
-- function WB_InductionPlayer:Tick(MyGeometry, InDeltaTime)
|
|
|
|
-- end
|
|
|
|
-- function WB_InductionPlayer:Destruct()
|
|
|
|
-- end
|
|
|
|
function WB_InductionPlayer:OnShowPanel(FindDis)
|
|
-- Test
|
|
if FindDis == nil then FindDis = 200000 end
|
|
-- Test End
|
|
|
|
UGCLogSystem.Log("[WB_InductionPlayer_OnShowPanel] FindDis:%s", tostring(FindDis))
|
|
|
|
self.FindDis = FindDis
|
|
if self.UpdateHandle == nil then
|
|
self.UpdateHandle = UGCEventSystem.SetTimerLoop(self, self.Update, 1./ self.UpdateFPS)
|
|
self.FindEnemyHandle = UGCEventSystem.SetTimerLoop(self, self.FindEnemy, 1./ self.FindEnemyFPS)
|
|
end
|
|
end
|
|
|
|
function WB_InductionPlayer:OnClosePanel()
|
|
if self.UpdateHandle then
|
|
UGCEventSystem.StopTimer(self.UpdateHandle)
|
|
end
|
|
if self.FindEnemyHandle then
|
|
UGCEventSystem.StopTimer(self.FindEnemyHandle)
|
|
end
|
|
end
|
|
|
|
function WB_InductionPlayer:Update()
|
|
local LocalPawn = UGCSystemLibrary.GetLocalPlayerPawn()
|
|
|
|
|
|
if UE.IsValid(self.TracePawn) and UE.IsValid(LocalPawn) then
|
|
self:IsFindPawn(true)
|
|
else
|
|
self:IsFindPawn(false)
|
|
return
|
|
end
|
|
|
|
local LocalPawnPos = LocalPawn:K2_GetActorLocation()
|
|
local TracePawnPos = self.TracePawn:K2_GetActorLocation()
|
|
|
|
local LocalPawnPos2D = {X = LocalPawnPos.X, Y = LocalPawnPos.Y, Z = 0}
|
|
local TracePawnPos2D = {X = TracePawnPos.X, Y = TracePawnPos.Y, Z = 0}
|
|
|
|
local LocalPawnForward = LocalPawn:GetActorForwardVector()
|
|
local LocalPawnRight = LocalPawn:GetActorRightVector()
|
|
|
|
local Dir = VectorHelper.Sub(TracePawnPos2D, LocalPawnPos2D)
|
|
local Dis = VectorHelper.GetDistance(LocalPawnPos2D, TracePawnPos2D)
|
|
local DisUp = TracePawnPos.Z - LocalPawnPos.Z
|
|
|
|
local CosForward = VectorHelper.CosineValue(LocalPawnForward, Dir)
|
|
local CosRight = VectorHelper.CosineValue(LocalPawnRight, Dir)
|
|
|
|
local FAngle = math.acos(CosForward)
|
|
|
|
local PI = 3.14159
|
|
|
|
if CosRight < 0 then
|
|
FAngle = 2 * PI - FAngle
|
|
end
|
|
|
|
local Angle = FAngle * 180 / PI;
|
|
|
|
if Angle > 180 then
|
|
Angle = Angle - 360
|
|
end
|
|
|
|
self.TextBlock_Angle:SetText(math.floor(Angle) .. "°")
|
|
self.TextBlock_HorizontalDis:SetText(math.floor((Dis // 100) + 0.5) .. "m")
|
|
self.TextBlock_UpDis:SetText(math.floor(DisUp // 100 + 1) .. "m")
|
|
|
|
self.CanvasPanel_Pointer:SetRenderAngle(Angle)
|
|
|
|
end
|
|
|
|
function WB_InductionPlayer:IsFindPawn(IsFind)
|
|
if IsFind ~= self.IsFind then
|
|
self.IsFind = IsFind
|
|
if self.IsFind then
|
|
self.CanvasPanel_Pointer:SetVisibility(ESlateVisibility.HitTestInvisible)
|
|
self.WidgetSwitcher_HasEnemy:SetActiveWidgetIndex(0)
|
|
else
|
|
self.CanvasPanel_Pointer:SetVisibility(ESlateVisibility.Collapsed)
|
|
self.WidgetSwitcher_HasEnemy:SetActiveWidgetIndex(1)
|
|
end
|
|
end
|
|
end
|
|
|
|
function WB_InductionPlayer:FindEnemy()
|
|
local LocalPawn = UGCSystemLibrary.GetLocalPlayerPawn()
|
|
if UE.IsValid(LocalPawn) and not UGCPawnSystem.HasPawnState(LocalPawn, EPawnState.Dead) then
|
|
self.CanvasPanel_Main:SetVisibility(ESlateVisibility.HitTestInvisible)
|
|
else
|
|
-- 本地玩家已死亡
|
|
self.CanvasPanel_Main:SetVisibility(ESlateVisibility.Collapsed)
|
|
self.TracePawn = nil
|
|
return
|
|
end
|
|
|
|
|
|
local LocalPlayerTeamID = UGCGameSystem.GameState:GetPlayerTeamIDByPlayerKey(UGCSystemLibrary.GetLocalPlayerKey())
|
|
local AllPawn = UGCGameSystem.GetAllPlayerPawn()
|
|
local TargetPawn = nil
|
|
local MinDis = 0
|
|
|
|
local LocalPawnPos = LocalPawn:K2_GetActorLocation()
|
|
|
|
for i, TempPawn in pairs(AllPawn) do
|
|
if TempPawn.PlayerKey then
|
|
local TempPawnTeamID = UGCGameSystem.GameState:GetPlayerTeamIDByPlayerKey(TempPawn.PlayerKey)
|
|
if TempPawnTeamID ~= LocalPlayerTeamID then
|
|
if not UGCPawnSystem.HasPawnState(LocalPawn, EPawnState.Dead) then
|
|
local Pos = TempPawn:K2_GetActorLocation()
|
|
local Dis = VectorHelper.GetDistance(LocalPawnPos, Pos)
|
|
if Dis <= self.FindDis * 100 and (TargetPawn == nil or MinDis > Dis) then
|
|
TargetPawn = TempPawn
|
|
MinDis = Dis
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
self.TracePawn = TargetPawn
|
|
end
|
|
|
|
return WB_InductionPlayer |