2025-01-04 23:00:19 +08:00

151 lines
3.7 KiB
Lua

---@class BP_Jigsaw_C:AActor
---@field Plane UStaticMeshComponent
---@field DefaultSceneRoot USceneComponent
---@field Row int32
---@field Col int32
---@field Frame int32
--Edit Below--
local BP_Jigsaw = {
TargetTexture = nil;
DynamicMaterial = nil;
-- 已放置在拼图框里
Placed = false;
Picked = false;
};
function BP_Jigsaw:ReceiveBeginPlay()
self.SuperClass.ReceiveBeginPlay(self);
self.StartPos = self:K2_GetActorLocation()
self.StartRot = self:K2_GetActorRotation()
if UGCGameSystem.IsServer() then
else
self:SetJigsawMaterial()
self:OnRep_Frame()
end
end
--[[
function BP_Jigsaw:ReceiveTick(DeltaTime)
self.SuperClass.ReceiveTick(self, DeltaTime);
end
--]]
function BP_Jigsaw:SetJigsawMaterial()
if self.DynamicMaterial == nil then
self.DynamicMaterial = KismetMaterialLibrary.CreateDynamicMaterialInstance(self, self.Plane:GetMaterial(0));
self.Plane:SetMaterial(0, self.DynamicMaterial);
end
end
--- Client Manager调用的更新图片
function BP_Jigsaw:UpdateTex(NewTex)
if self.TargetTexture ~= NewTex then
self.TargetTexture = NewTex
self.DynamicMaterial:SetTextureParameterValue("Texture", self.TargetTexture);
end
end
function BP_Jigsaw:UpdateRowCol(NewRow, NewCol)
self.Row = NewRow
self.Col = NewCol
if not UGCGameSystem.IsServer() and self.DynamicMaterial then
self.DynamicMaterial:SetScalarParameterValue("X", self.Col)
self.DynamicMaterial:SetScalarParameterValue("Y", self.Row)
end
end
---@param InFrame int Range: [1, Row * Col]
function BP_Jigsaw:SetFrameValue(InFrame)
self.Frame = InFrame
--UGCLogSystem.Log("[BP_Jigsaw_SetFrameValue] Frame:%s", tostring(self.Frame))
if not UGCGameSystem.IsServer() then
self:UpdateMaterFrameValue()
end
end
function BP_Jigsaw:UpdateMaterFrameValue()
if self and self.DynamicMaterial then
local FrameValue = (self:GetFrame() - 0.99) / (self.Row * self.Col)
--UGCLogSystem.Log("[BP_Jigsaw_UpdateMaterFrameValue]FrameValue:%s", tostring(FrameValue))
self.DynamicMaterial:SetScalarParameterValue("FrameNumber", FrameValue)
end
end
function BP_Jigsaw:OnRep_Frame()
--UGCLogSystem.Log("[BP_Jigsaw_OnRep_Frame] Frame:%s", tostring(self.Frame))
self:UpdateMaterFrameValue()
end
function BP_Jigsaw:GetFrame()
return self.Frame
end
function BP_Jigsaw:AttachPlayer(PlayerPawn)
if UE.IsValid(PlayerPawn) then
if UGCGameSystem.IsServer() then
self:SetPicked(true)
UGCSendRPCSystem.ActorRPCNotify(nil, self, "AttachPlayer", PlayerPawn)
end
self:K2_AttachToActor(PlayerPawn, "", EAttachmentRule.SnapToTarget, EAttachmentRule.KeepWorld, EAttachmentRule.KeepWorld)
self:K2_SetActorRelativeLocation({X=0, Y=0, Z=100})
end
end
function BP_Jigsaw:ResetJigsaw()
if UGCGameSystem.IsServer() then
self:SetPicked(false)
UGCSendRPCSystem.ActorRPCNotify(nil, self, "ResetJigsaw")
end
self:K2_DetachFromActor()
self:K2_SetActorLocation(self.StartPos)
self:K2_SetActorRotation(self.StartRot)
end
function BP_Jigsaw:DetachAndSetTargetPos(Pos)
if UGCGameSystem.IsServer() then
self:SetPicked(false)
UGCSendRPCSystem.ActorRPCNotify(nil, self, "DetachAndSetTargetPos", Pos)
end
self:K2_DetachFromActor()
Pos.Z = self.StartPos.Z
self:K2_SetActorLocation(Pos)
self:K2_SetActorRotation(self.StartRot)
end
function BP_Jigsaw:SetPlaced(NewPlaced)
self.Placed = NewPlaced
end
function BP_Jigsaw:GetPlaced()
return self.Placed
end
function BP_Jigsaw:SetPicked(NewPicked)
self.Picked = NewPicked
end
function BP_Jigsaw:GetPicked()
return self.Picked
end
--[[
function BP_Jigsaw:ReceiveEndPlay()
self.SuperClass.ReceiveEndPlay(self);
end
--]]
--[[
function BP_Jigsaw:GetReplicatedProperties()
return
end
--]]
--[[
function BP_Jigsaw:GetAvailableServerRPCs()
return
end
--]]
return BP_Jigsaw;