88 lines
2.8 KiB
Lua
88 lines
2.8 KiB
Lua
|
---@class PortalDoor_C:AActor
|
||
|
---@field DisappearEffects UParticleSystemComponent
|
||
|
---@field Arrow UArrowComponent
|
||
|
---@field PortalLink UCapsuleComponent
|
||
|
---@field P_convey_01 UParticleSystemComponent
|
||
|
---@field Trigger UCapsuleComponent
|
||
|
---@field DefaultSceneRoot USceneComponent
|
||
|
---@field Group int32
|
||
|
---@field ChangeFaceDirection bool
|
||
|
---@field AudioEvent UAkAudioEvent
|
||
|
---@field CustomDistance int32
|
||
|
---@field PortalDoorClass UClass
|
||
|
--Edit Below--
|
||
|
local PortalDoor = { };
|
||
|
|
||
|
function PortalDoor:ReceiveBeginPlay()
|
||
|
sandbox.LogNormalDev(StringFormat_Dev("[PortalDoor:ReceiveBeginPlay] self=%s", GetObjectFullName_Dev(self)))
|
||
|
PortalDoor.SuperClass.ReceiveBeginPlay(self)
|
||
|
|
||
|
self.GroupsArray = {}
|
||
|
if self:HasAuthority() then
|
||
|
self:InitDoor()
|
||
|
|
||
|
local DoorsArray = GameplayStatics.GetAllActorsOfClass(self, self.PortalDoorClass, {})
|
||
|
for i, v in ipairs(DoorsArray) do
|
||
|
|
||
|
--根据代号放入对应的表里
|
||
|
if self.GroupsArray[v.Group] == nil then
|
||
|
self.GroupsArray[v.Group] = {}
|
||
|
table.insert(self.GroupsArray[v.Group], v)
|
||
|
else
|
||
|
table.insert(self.GroupsArray[v.Group], v)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function PortalDoor:InitDoor()
|
||
|
sandbox.LogNormalDev(StringFormat_Dev("[PortalDoor:InitDoor]"))
|
||
|
self.Trigger.OnComponentBeginOverlap:Add(self.OnBeginOverlap, self)
|
||
|
end
|
||
|
|
||
|
function PortalDoor:ReceiveEndPlay()
|
||
|
sandbox.LogNormalDev(StringFormat_Dev("[PortalDoor:ReceiveEndPlay]"))
|
||
|
self.Trigger.OnComponentBeginOverlap:Remove(self.OnBeginOverlap, self)
|
||
|
end
|
||
|
|
||
|
function PortalDoor:GetReplicatedProperties()
|
||
|
return
|
||
|
"IsPlay"
|
||
|
end
|
||
|
|
||
|
function PortalDoor:OnBeginOverlap(OverlappedComp, Actor, OtherComp, OtherBodyIndex, bFromSweep, SweepResult)
|
||
|
|
||
|
local CurrentGroup = self.GroupsArray[self.Group]
|
||
|
local LinkDoorId = math.random(#CurrentGroup)
|
||
|
local LinkDoor = nil
|
||
|
|
||
|
while (self == CurrentGroup[LinkDoorId]) do
|
||
|
LinkDoorId = math.random(#CurrentGroup)
|
||
|
end
|
||
|
LinkDoor = CurrentGroup[LinkDoorId]
|
||
|
--得到另一个门的位置
|
||
|
local LinkDoorLocation = LinkDoor.Trigger:K2_GetComponentLocation()
|
||
|
|
||
|
------------------------------
|
||
|
local TargetPortalLink = LinkDoor.PortalLink
|
||
|
------------------------------
|
||
|
local ActorTransferLocation = TargetPortalLink:K2_GetComponentLocation()
|
||
|
local NewRotation = TargetPortalLink:K2_GetComponentRotation()
|
||
|
|
||
|
Actor:K2_SetActorLocation(ActorTransferLocation)
|
||
|
local PlayerController = Actor:GetPlayerControllerSafety()
|
||
|
if self.ChangeFaceDirection then
|
||
|
PlayerController:ClientSetControlRotation(NewRotation)
|
||
|
end
|
||
|
|
||
|
--播放特效,音效
|
||
|
UnrealNetwork.CallUnrealRPC_Multicast(self, "PlayDisappear", Actor, LinkDoorLocation.X, LinkDoorLocation.Y)
|
||
|
end
|
||
|
|
||
|
function PortalDoor:PlayDisappear(Actor, LinkDoorLocation_X, LinkDoorLocation_Y)
|
||
|
self.DisappearEffects:SetActive(true, true)
|
||
|
UGCSoundManagerSystem.PlaySoundAtLocation(self.AudioEvent, Vector.New(LinkDoorLocation_X, LinkDoorLocation_Y, 0))
|
||
|
end
|
||
|
|
||
|
return PortalDoor;
|