UGCProjects/ExtremeParkour/Script/Blueprint/PlaceItems/BP_ClientPreviewItemBase.lua

172 lines
5.8 KiB
Lua
Raw Normal View History

2025-01-04 23:00:19 +08:00
---@class BP_ClientPreviewItemBase_C:AActor
---@field Sphere7 USphereComponent
---@field Sphere6 USphereComponent
---@field Sphere4 USphereComponent
---@field Sphere5 USphereComponent
---@field Sphere3 USphereComponent
---@field Sphere USphereComponent
---@field Sphere2 USphereComponent
---@field Sphere1 USphereComponent
---@field PointRoot USceneComponent
---@field ItemRoot USceneComponent
---@field DefaultSceneRoot USceneComponent
---@field bIsPlacing bool
---@field bRotateAlignment bool
--Edit Below--
local BP_ClientPreviewItemBase = {
bCanPlace = true;
CmpList = {};
bSetMatSucceed = false;
};
--[[
function BP_ClientPreviewItemBase:ReceiveBeginPlay()
self.SuperClass.ReceiveBeginPlay(self);
end
--]]
--[[
function BP_ClientPreviewItemBase:ReceiveTick(DeltaTime)
self.SuperClass.ReceiveTick(self, DeltaTime);
end
--]]
--[[
function BP_ClientPreviewItemBase:ReceiveEndPlay()
self.SuperClass.ReceiveEndPlay(self);
end
--]]
--[[
function BP_ClientPreviewItemBase:GetReplicatedProperties()
return
end
--]]
--[[
function BP_ClientPreviewItemBase:GetAvailableServerRPCs()
return
end
--]]
function BP_ClientPreviewItemBase:GetAllVertexPos()
local TempAllVertexCmp = self:GetAllVertexCmp()
local Res = {}
for i, v in pairs(TempAllVertexCmp) do
Res[#Res + 1] = v:K2_GetComponentLocation()
end
return Res
end
function BP_ClientPreviewItemBase:GetAllVertexRelativePos()
if self.AllVertexCmpRelativePos == nil then
local TempAllVertexCmp = self:GetAllVertexCmp()
self.AllVertexCmpRelativePos = {}
for i, v in pairs(TempAllVertexCmp) do
self.AllVertexCmpRelativePos[#self.AllVertexCmpRelativePos + 1] = VectorHelper.ToLuaTable(v:GetRelativeTransform().Translation)
end
UGCLogSystem.LogTree("[BP_ClientPreviewItemBase_GetAllVertexRelativePos] AllVertexCmpRelativePos", self.AllVertexCmpRelativePos)
end
return self.AllVertexCmpRelativePos
end
-- 这里获取一下顶点的预览位置
function BP_ClientPreviewItemBase:GetAllVertexPreviewPos(PreviewPos, PreviewRot)
local AllVertexRelativePos = self:GetAllVertexRelativePos()
local Res = {}
for i, v in pairs(AllVertexRelativePos) do
Res[#Res + 1] = VectorHelper.ToLuaTable(VectorHelper.Add(KismetMathLibrary.GreaterGreater_VectorRotator(v, PreviewRot), PreviewPos))
end
return Res
end
-- 这里获取一下顶点的预览位置
function BP_ClientPreviewItemBase:GetAllVertexPreviewRelativePos(PreviewRot)
local AllVertexRelativePos = self:GetAllVertexRelativePos()
local Res = {}
PreviewRot = {Roll = PreviewRot.Roll % 360, Pitch = PreviewRot.Pitch % 360, Yaw = PreviewRot.Yaw % 360}
UGCLogSystem.Log("[BP_ClientPreviewItemBase_GetAllVertexPreviewRelativePos] PreviewRot:%s", VectorHelper.RotToString(PreviewRot))
for i, v in pairs(AllVertexRelativePos) do
Res[#Res + 1] = VectorHelper.ToLuaTable(KismetMathLibrary.GreaterGreater_VectorRotator(v, PreviewRot))
end
return Res
end
function BP_ClientPreviewItemBase:SetAllVertexCmp(InAllCmp)
self.AllVertexCmp = InAllCmp
end
function BP_ClientPreviewItemBase:GetAllVertexCmp()
if self.AllVertexCmp == nil then
self.AllVertexCmp = {self.Sphere, self.Sphere1, self.Sphere2, self.Sphere3, self.Sphere4, self.Sphere5, self.Sphere6, self.Sphere7, }
end
return self.AllVertexCmp
end
function BP_ClientPreviewItemBase:GetIsRotateAlignment()
return self.bRotateAlignment
end
function BP_ClientPreviewItemBase:PlaceItem(UnitPos, UnitRot)
--UGCLogSystem.Log("[BP_ClientPreviewItemBase_PlaceItem] Pos:%s, Rot:%s", VectorHelper.ToString(Pos), VectorHelper.RotToString(Rot))
local TargetPos = PlacementModeConfig.UnitVectorToVector(UnitPos)
local TargetRot = PlacementModeConfig.UnitRotatorToRotator(UnitRot)
self:K2_SetActorLocation(TargetPos)
self:K2_SetActorRotation(TargetRot)
end
function BP_ClientPreviewItemBase:AddSMCmp(InCmp)
if type(InCmp) == "table" then
for i, v in pairs(InCmp) do
self.CmpList[#self.CmpList + 1] = v
v:SetMaterial(0, PlacementModeConfig.GetPreviewDynamicMat())
end
else
self.CmpList[#self.CmpList + 1] = InCmp
InCmp:SetMaterial(0, PlacementModeConfig.GetPreviewDynamicMat())
end
end
function BP_ClientPreviewItemBase:IsOverlappingPlayer()
local AllPawn = UGCGameSystem.GetAllPlayerPawn()
-- 正常来说只有一个玩家需要判断
for i, PlayerPawn in pairs(AllPawn) do
-- 正常来说只有一个Mesh需要判断
for _, SM in pairs(self.CmpList) do
if SM:IsOverlappingActor(PlayerPawn) then
return true
end
end
end
return false
end
function BP_ClientPreviewItemBase:SetMat()
if self.CmpList[1] then
-- self.DynamicMaterial = KismetMaterialLibrary.CreateDynamicMaterialInstance(self, self.CmpList[1]:GetMaterial(0));
for i, v in pairs(self.CmpList) do
v:SetMaterial(0, PlacementModeConfig.GetPreviewDynamicMat())
end
self.bSetMatSucceed = true
end
end
function BP_ClientPreviewItemBase:SetCanPlace(InCanPlace)
if InCanPlace ~= self.bCanPlace then
UGCLogSystem.Log("[BP_ClientPreviewItemBase_SetCanPlace] InCanPlace:%s", tostring(InCanPlace))
if not self.bSetMatSucceed then
self:SetMat()
end
self.bCanPlace = InCanPlace
if self.bCanPlace then
PlacementModeConfig.GetPreviewDynamicMat():SetVectorParameterValue("DiffLight", PlacementModeConfig.PlacingAttr.CanPlaceColor)
else
PlacementModeConfig.GetPreviewDynamicMat():SetVectorParameterValue("DiffLight", PlacementModeConfig.PlacingAttr.CanNotPlaceColor)
end
UGCLogSystem.Log("[BP_ClientPreviewItemBase_SetCanPlace] Finish")
end
end
return BP_ClientPreviewItemBase;