---@class BP_MechanismWall_C:AActor ---@field BoxOverlapCmp UBoxComponent ---@field FloorMesh UStaticMeshComponent ---@field DefaultSceneRoot USceneComponent ---@field ToHideTime float ---@field ActiveSound UAkAudioEvent ---@field Walls TArray --Edit Below-- local BP_MechanismWall = { bIsShowing = true; BeginShowTime = 0; CheckShowTime = 3; }; --function BP_MechanismWall:GetWalls() -- return {self.Wall1, self.Wall2} --end function BP_MechanismWall:ReceiveBeginPlay() self.SuperClass.ReceiveBeginPlay(self); self:ShowWall(false) if UGCGameSystem.IsServer() then self.LoopCheckOverlapPlayerHandle = UGCEventSystem.SetTimerLoop(self, self.CheckOverlapPlayer, 0.5) self.LoopCheckIsShowHandle = UGCEventSystem.SetTimerLoop(self, self.CheckClientIsShow, self.CheckShowTime) UGCSystemLibrary.BindBeginOverlapFunc(self.BoxOverlapCmp, self.OverlapPlayer, self) end end function BP_MechanismWall:CheckOverlapPlayer() local AllPawn = UGCGameSystem.GetAllPlayerPawn() local IsOverlapping = false for i, v in pairs(AllPawn) do if self.BoxOverlapCmp:IsOverlappingActor(v) then IsOverlapping = true break end end if IsOverlapping then self:UpdateOverlapTime() elseif UGCSystemLibrary.GetGameTime() - self.BeginShowTime >= self.ToHideTime then self:ShowWall(false) end end function BP_MechanismWall:CheckClientIsShow() -- UGCLogSystem.Log("[BP_MechanismWall_CheckClientIsShow] self.bIsShowing:%s", tostring(self.bIsShowing)) UGCSendRPCSystem.ActorRPCNotify(nil, self, "ShowWall", self.bIsShowing) end function BP_MechanismWall:OverlapPlayer(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex, bFromSweep, SweepResult) self:UpdateOverlapTime() end function BP_MechanismWall:UpdateOverlapTime() self.BeginShowTime = UGCSystemLibrary.GetGameTime() self:ShowWall(true) end function BP_MechanismWall:OnRep_bIsShowing() if self then self:ShowWall(self.bIsShowing) end end function BP_MechanismWall:ShowWall(IsShow) for i, WallActor in pairs(self.Walls) do if UE.IsValid(WallActor) then if self.bIsShowing then WallActor.StaticMeshComponent:SetCollisionEnabled(ECollisionEnabled.QueryAndPhysics) else WallActor.StaticMeshComponent:SetCollisionEnabled(ECollisionEnabled.NoCollision) end end end if UGCGameSystem.IsServer() then if self.bIsShowing ~= IsShow then self.bIsShowing = IsShow UGCSendRPCSystem.ActorRPCNotify(nil, self, "ShowWall", self.bIsShowing) end else if self.bIsShowing ~= IsShow then self.bIsShowing = IsShow self:PlayEffect(self.bIsShowing) end for i, WallActor in pairs(self.Walls) do if UE.IsValid(WallActor) then WallActor.StaticMeshComponent:SetVisibility(self.bIsShowing) end end end --if self.bIsShowing ~= IsShow or not UGCGameSystem.IsServer() then -- self.bIsShowing = IsShow -- for i, WallActor in pairs(self.Walls) do -- if UE.IsValid(WallActor) then -- if self.bIsShowing then -- WallActor.StaticMeshComponent:SetCollisionEnabled(ECollisionEnabled.QueryAndPhysics) -- else -- WallActor.StaticMeshComponent:SetCollisionEnabled(ECollisionEnabled.NoCollision) -- end -- end -- end -- if UGCGameSystem.IsServer() then -- UGCSendRPCSystem.ActorRPCNotify(nil, self, "ShowWall", self.bIsShowing) -- else -- self:PlayEffect(self.bIsShowing) -- for i, WallActor in pairs(self.Walls) do -- if UE.IsValid(WallActor) then -- WallActor.StaticMeshComponent:SetVisibility(self.bIsShowing) -- end -- end -- end --end end function BP_MechanismWall:PlayEffect(IsShow) if IsShow then UGCSoundManagerSystem.PlaySoundAtLocation(self.ActiveSound, self:K2_GetActorLocation(), self:K2_GetActorRotation()) end end --[[ function BP_MechanismWall:ReceiveTick(DeltaTime) self.SuperClass.ReceiveTick(self, DeltaTime); end --]] function BP_MechanismWall:ReceiveEndPlay() if self.LoopCheckOverlapPlayerHandle then UGCEventSystem.StopTimer(self.LoopCheckOverlapPlayerHandle) self.LoopCheckOverlapPlayerHandle = nil end if self.LoopCheckIsShowHandle then UGCEventSystem.StopTimer(self.LoopCheckIsShowHandle) self.LoopCheckIsShowHandle = nil end self.SuperClass.ReceiveEndPlay(self); end function BP_MechanismWall:GetReplicatedProperties() return "bIsShowing" end --[[ function BP_MechanismWall:GetAvailableServerRPCs() return end --]] return BP_MechanismWall;