2025-01-04 23:00:19 +08:00

96 lines
3.0 KiB
Lua

---@class BP_TrophyAttach_C:AActor
---@field ParticleSystem UParticleSystemComponent
---@field Widget UWidgetComponent
---@field DefaultSceneRoot USceneComponent
---@field DirRand float
---@field DirMin float
---@field ScaleMax float
---@field ScaleMin float
--Edit Below--
---@type BP_TrophyAttach_C
local BP_KeyAttach = {
TargetPlayerKey = -1;
LocalPlayerKey = -1
};
function BP_KeyAttach:ReceiveBeginPlay()
self.SuperClass.ReceiveBeginPlay(self);
UGCEventSystem.AddListener(EventEnum.KeyOwnerChange, self.KeyOwnerChange, self)
self:SetOwner(UGCGameSystem.GameState)
if UGCGameSystem.IsServer() then
else
self.LoopGetLocalControllerKey = UGCEventSystem.SetTimerLoop(self,
function ()
local LocalController = STExtraGameplayStatics.GetFirstPlayerController(self)
if LocalController then
self.LocalPlayerKey = LocalController.PlayerKey
UGCEventSystem.StopTimer(self.LoopGetLocalControllerKey)
self.LoopGetLocalControllerKey = nil
end
end,
0.2
)
end
end
function BP_KeyAttach:KeyOwnerChange(NewOwnerPlayerKey)
self.TargetPlayerKey = NewOwnerPlayerKey
if UGCGameSystem.IsServer() then
else
if self.TargetPlayerKey > 0 and self.LocalPlayerKey ~= self.TargetPlayerKey then
self.DefaultSceneRoot:SetVisibility(true, true)
else
self.DefaultSceneRoot:SetVisibility(false, true)
end
end
end
function BP_KeyAttach:ReceiveTick(DeltaTime)
self.SuperClass.ReceiveTick(self, DeltaTime);
if UGCGameSystem.IsServer() then
else
if self.TargetPlayerKey > 0 then
if self.TargetPlayerKey ~= self.LocalPlayerKey then
local TargetPawn = UGCGameSystem.GetPlayerPawnByPlayerKey(self.TargetPlayerKey)
if UE.IsValid(TargetPawn) then
local TargetLocation = TargetPawn.Mesh:K2_GetComponentLocation()
self:K2_SetActorLocation(TargetLocation)
local LocalPawn = UGCGameSystem.GetPlayerPawnByPlayerKey(self.LocalPlayerKey)
if LocalPawn then
local Dir = VectorHelper.Length(VectorHelper.Sub(TargetLocation, LocalPawn:K2_GetActorLocation()))
local TargetScale = KismetMathLibrary.Lerp(self.ScaleMax, self.ScaleMin, math.clamp((Dir - self.DirMin) / self.DirRand, 0, 1))
-- UE.Log("[BP_TrophyAttach_ReceiveTick] TargetScale:%f, Dir:%f", TargetScale, Dir)
self.Widget:GetUserWidgetObject():SetRenderScale({X = TargetScale, Y = TargetScale})
end
end
end
end
end
end
--[[
function BP_KeyAttach:ReceiveEndPlay()
self.SuperClass.ReceiveEndPlay(self);
end
--]]
--[[
function BP_KeyAttach:GetReplicatedProperties()
return
end
--]]
--[[
function BP_KeyAttach:GetAvailableServerRPCs()
return
end
--]]
return BP_KeyAttach;