---@class BP_MoveActorManager_C:AActor ---@field DefaultSceneRoot USceneComponent --Edit Below-- ---@type BP_MoveActorManager_C local BP_MoveActorManager = {}; ---@type MovingActorsManager BP_MoveActorManager.MovingActorManager = nil; BP_MoveActorManager.IsOpen = false; BP_MoveActorManager.ActorPool = nil; BP_MoveActorManager.ActorPoolCount = 20; BP_MoveActorManager.MovingActorIndexList = {}; function BP_MoveActorManager:ReceiveBeginPlay() self.SuperClass.ReceiveBeginPlay(self); self.MovingActorManager = UGCGameSystem.GameState.MoveActorManager; self.ActorPool = require('Script.Blueprint.MiniLevelActor.JumpAndCrouch.ActorPool'); UGCLogSystem.Log("[BP_MoveActorManager:ReceiveBeginPlay] self.MovingActorManager = %s", tostring(self.MovingActorManager)); -- 注册不同的Actor UGCEventSystem.SetTimer(self, function() if UGCGameSystem.IsServer() then self:Init(); UGCEventSystem.SetTimer(self, function() self:StartMove(); end, 10) end end, 30); end BP_MoveActorManager.MoveDelta = { X = 75, Y = 0, Z = 0, }; ---@type table BP_MoveActorManager.MovingActorStarts = {}; BP_MoveActorManager.PinpongJump = 0.; BP_MoveActorManager.StartTime = 5.; BP_MoveActorManager.Symbol = 1; function BP_MoveActorManager:InitMoveActor1() UGCLogSystem.Log("[BP_MoveActorManager:InitMoveActor1] 执行") local MovingActor = {}; local RotatorActors = {}; GameplayStatics.GetAllActorsWithTag(self, "MovingActor", MovingActor); GameplayStatics.GetAllActorsWithTag(self, "RotatorActor", RotatorActors); UGCLogSystem.LogTree(string.format("[BP_MoveActorManager:InitMoveActor1] MovingActor = "), MovingActor) UGCLogSystem.LogTree(string.format("[BP_MoveActorManager:InitMoveActor1] RotatorActors = "), RotatorActors) for i, v in pairs(MovingActor) do self:LoadMovingActorManager():RegisterMovingActor(v, 5, function(InActor, InDeltaTime) if InDeltaTime == nil then return true, self.MoveDelta; end self.PinpongJump = self.PinpongJump + InDeltaTime; if self.PinpongJump > self.StartTime then self.PinpongJump = self.PinpongJump - self.StartTime; self.Symbol = self.Symbol * -1; end local Vec = VectorHelper.ToLuaTable(VectorHelper.Mul(self.MoveDelta, { X = self.Symbol, Y = 1, Z = 1, })); return true, Vec; end) end for i, v in pairs(RotatorActors) do self:LoadMovingActorManager():RegisterMovingActor(v, 5, function(Actor, InDeltaTime) local Rot = VectorHelper.MakeRotator({ 0, 0, 30 }) UGCLogSystem.LogTree(string.format("[BP_MoveActorManager:InitMoveActor1] Rot = "), Rot); return true, nil, Rot; end) end -- 设置玩家试试 local Pawns = UGCGameSystem.GetAllPlayerPawn() for i, v in pairs(Pawns) do self:LoadMovingActorManager():RegisterMovingActor(v, 5, function(Actor, InDeltaTime) local Vec = VectorHelper.MakeVector({ 30, 0, 0 }); return true, Vec, nil; end) end end ---@return MovingActorsManager function BP_MoveActorManager:LoadMovingActorManager() if self.MovingActorManager == nil then self.MovingActorManager = UGCGameSystem.GameState.MoveActorManager end return self.MovingActorManager; end -- 初始化 function BP_MoveActorManager:Init() -- 寻找场景中的东西 self.ActorPool:Init(self.ActorPoolCount, ObjectPathTable.BP_MovingActor_Class, self, VectorHelper.MakeVector(0, 0, 0), VectorHelper.MakeRotator({ 0, 0, 0 }), function(InActor, InIndex) UGCLogSystem.Log("[BP_MoveActorManager:Init] ActorName = %s, Index = %s", UE.GetName(InActor), tostring(InIndex)) end); if self:HasAuthority() then for i = 1, self.ActorPoolCount do self.MovingActorIndexList[#self.MovingActorIndexList + 1] = math.random(1, 2); end local Actors = {}; GameplayStatics.GetAllActorsOfClass(self, ObjectPathTable.BP_ActorStart_Class, Actors); for i, v in pairs(Actors) do local Index = v.StartIndex; self.MovingActorStarts[Index] = v; end end end BP_MoveActorManager.PopTimer = nil; BP_MoveActorManager.PopTimeFrequent = 1; -- pop的时间间隔 ---@type float 注意该值需要比池子里面总数要小 BP_MoveActorManager.ResetTime = 10; BP_MoveActorManager.PopIndex = 0; --- 开始移动 function BP_MoveActorManager:StartMove() UGCLogSystem.Log("[BP_MoveActorManager:StartMove] 执行") self.PopTimer = UGCEventSystem.SetTimerLoop(self, function() local Actor = self.ActorPool:Pop(function(InActor) UGCEventSystem.SetTimer(InActor, function() self.ActorPool:Push(InActor, function(A) self.MovingActorManager:ResetActor(A); A:SetActorHiddenInGame(true); self.MovingActorManager:UnregisterMovingActor(A, true); end) end, 10); end) self.PopIndex = self.PopIndex + 1 local Index = self.MovingActorIndexList[self.PopIndex] if Index == nil then self:EndMove(); return ; end local Start = self.MovingActorStarts[Index]; if UE.IsValid(Start) then self:RegisterMove(Actor, Start); end end, self.PopTimeFrequent); end --- 结束移动 function BP_MoveActorManager:EndMove() if self.PopTimer ~= nil then UGCEventSystem.StopTimer(self.PopTimer); self.PopTimer = nil; end self.PopIndex = 0; self.MovingActorIndexList = nil; self.ActorPoolCount = 0; self.MovingActorStarts = nil; end --- 注册移动 function BP_MoveActorManager:RegisterMove(InActor, InStart) InActor:K2_SetActorLocation(InStart:K2_GetActorLocation()); InActor:K2_SetActorRotation(InStart:K2_GetActorRotation()); self.MovingActorManager:RegisterMovingActor(InActor, 2, function(Actor, InDeltaTime) return true, VectorHelper.MakeVector(300, 0, 0), nil; end); if UGCGameSystem.IsServer() then UnrealNetwork.CallUnrealRPC_Multicast(self, "RegisterMove", InActor, InStart); end end function BP_MoveActorManager:ActorPoolSendRPC(FuncName, ...) if UGCGameSystem.IsServer() then UnrealNetwork.CallUnrealRPC_Multicast(self, "ActorPoolSendRPC", FuncName, ...); else end end return BP_MoveActorManager;