local Action_WaitPlayerJoin = { WaitTime = 0, } function Action_WaitPlayerJoin:Execute(...) local GameState = UGCGameSystem.GameState GameState.GameStage = EGameStage.WaitForPlayer self.EnterStateTime = GameplayStatics.GetRealTimeSeconds(self) self.LastUpdateRemainTime = self.WaitTime self.JoinedPlayerNum = 0 self.bOverBigWorld = false self.bEnableActionTick = true EventSystem:AddListener(EventType.UpdateInitialWidget, self.OnUpdateInitialWidget, self) print(string.format("[Action_WaitPlayerJoin:Execute] WaitTime = %d", self.WaitTime)) return true end function Action_WaitPlayerJoin:OnUpdateInitialWidget() print(string.format("[Action_WaitPlayerJoin:OnUpdateInitialWidget] 执行")) self.EnterStateTime = 0 self.bOverBigWorld = true end function Action_WaitPlayerJoin:Update(DeltaSeconds) local CurrentRealTime = GameplayStatics.GetRealTimeSeconds(self); -- 表示剩余时间 local RemainTime = self.WaitTime - (CurrentRealTime - self.EnterStateTime); RemainTime = RemainTime >= 0 and RemainTime or 0 local CurrentUpdateRemainTime = math.ceil(RemainTime) if self.LastUpdateRemainTime - CurrentUpdateRemainTime >= 1 then self.JoinedPlayerNum = #UGCGameSystem.GetAllPlayerState(false) self.LastUpdateRemainTime = CurrentUpdateRemainTime end if self.bOverBigWorld or CurrentUpdateRemainTime <= 0 or self.JoinedPlayerNum >= 4 then self.LastUpdateRemainTime = 0 self.bEnableActionTick = false UGCGameSystem.SendModeCustomEvent("EnterGameReadyStage") end --更新GameState.WaitPlayerJoinTime UGCGameSystem.GameState.WaitPlayerJoinTime = self.LastUpdateRemainTime end return Action_WaitPlayerJoin