---@class BP_MoveFromLineBase_C:AActor ---@field Arrow UArrowComponent ---@field Spline USplineComponent ---@field DefaultSceneRoot USceneComponent ---@field IsAutoActive bool ---@field AttachActorList TArray ---@field CycleTime float ---@field ActorMoveTimeInterval float ---@field RandomStart bool ---@field RandomCycleTime float ---@field MoveCurve UCurveFloat --Edit Below-- local BP_MoveFromLineBase = { IsActive = false; StartTime = 0; AddRandomTime = 0; }; -- ReplicatedProperties ------------------------------------------------------------------------------- function BP_MoveFromLineBase:GetReplicatedProperties() return "IsActive", "StartTime" end -- ReplicatedProperties End --------------------------------------------------------------------------- function BP_MoveFromLineBase:ReceiveBeginPlay() self.SuperClass.ReceiveBeginPlay(self); self:InitParam() if self.IsActive then self:Active() end end function BP_MoveFromLineBase:GetTime() return UGCGameSystem.GameState:GetServerGameTime() end function BP_MoveFromLineBase:InitParam() self.IsActive = (self.IsAutoActive or self.IsActive) self.SplineLength = self.Spline:GetSplineLength() -- 随机初始时间 if self.RandomStart then self.AddRandomTime = (math.random() * 2 - 1) * self.RandomCycleTime end end function BP_MoveFromLineBase:Active() if not UGCGameSystem.IsServer() then return end self.StartTime = self:GetTime() + self.AddRandomTime self.IsActive = true end function BP_MoveFromLineBase:Close() if not UGCGameSystem.IsServer() then return end self.IsActive = false end function BP_MoveFromLineBase:SetActorLocationFromTime(InActor, Time) local CyclePos = (Time % self.CycleTime) / self.CycleTime --UGCLogSystem.Log("[BP_MoveFromLineBase_SetActorLocationFromTime] CyclePos:%s", tostring(CyclePos)) local TargetSplineDis if UE.IsValid(self.MoveCurve) then TargetSplineDis = self.Spline:GetSplineLength() * self.MoveCurve:GetFloatValue(CyclePos) else TargetSplineDis = self.Spline:GetSplineLength() * CyclePos end local TargetPos = self.Spline:GetWorldLocationAtDistanceAlongSpline(TargetSplineDis) InActor:K2_SetActorLocation(TargetPos) end function BP_MoveFromLineBase:ReceiveTick(DeltaTime) self.SuperClass.ReceiveTick(self, DeltaTime); if self.IsActive then local NowTime = self:GetTime() for i, TargetActor in pairs(self.AttachActorList) do -- UGCLogSystem.Log("[BP_MoveFromLineBase_ReceiveTick] i: %s, Actor:%s", tostring(i), KismetSystemLibrary.GetObjectName(TargetActor)) self:SetActorLocationFromTime(TargetActor, NowTime - self.StartTime + self.ActorMoveTimeInterval * (i - 1)) end end end --[[ function BP_MoveFromLineBase:ReceiveEndPlay() self.SuperClass.ReceiveEndPlay(self); end --]] --[[ function BP_MoveFromLineBase:GetAvailableServerRPCs() return end --]] return BP_MoveFromLineBase;