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

144 lines
3.9 KiB
Lua

---@class BP_MachineBase_C:AActor
---@field DefaultSceneRoot USceneComponent
---@field Script FString
--Edit Below--
require('Script.Global.Tool.TableTool')
---@type BP_MachineBase_C
local BP_MachineBase = {};
---@type bool 是否是第一次初始化
BP_MachineBase.bInitDoOnce = false;
---@type MachineItemScriptBase
BP_MachineBase.ScriptItem = nil;
BP_MachineBase.ScriptParams = nil;
BP_MachineBase.PreScript = "Script.Blueprint.SceneObj.Machine.Script.";
EMachineType = EMachineType ~= nil and EMachineType or {
None = 1, -- 不执行任何操作
Continue = 2, -- 持续执行
Duration = 3, -- 持续一段时间
}
--function BP_MachineBase:ReceiveBeginPlay()
-- self.SuperClass.ReceiveBeginPlay(self);
-- self:ToLuaInit();
--end
function BP_MachineBase:new()
return setmetatable({
bInitDoOnce = false;
ContinueTime = 0;
}, {
__metatable = self,
__index = self;
})
end
function BP_MachineBase:LuaInit(InBox, ...)
if self.bInitDoOnce then return; end
local Params = {...};
if not table.isEmpty(Params) then
self.ScriptParams = Params;
end
self:PreInit();
self:InitItem(InBox);
self:PostInit();
self.bInitDoOnce = true;
end
function BP_MachineBase:PreInit() end
---@param InComponent UShapeComponent
function BP_MachineBase:InitItem(InComponent)
if InComponent then
UGCLogSystem.Log("[BP_MachineBase:InitItem] 执行")
InComponent.OnComponentBeginOverlap:Add(self.OnBoxBeginOverlap, self);
InComponent.OnComponentEndOverlap:Add(self.OnBoxEndOverlap, self);
end
UGCLogSystem.Log("[BP_MachineBase:InitItem] ".. self.Script);
if string.len(self.Script) ~= 0 then
local Item = require(self.PreScript .. self.Script);
self.ScriptItem = setmetatable({
bEnableTick = true;
bEnableMachine = true,
}, {
__index = Item,
__metatable = Item,
__tostring = function(t)
return table.func(t, t["ToString"]);
end,
});
table.func(self.ScriptItem, self.ScriptItem['Init'], table.unpackTable(self.ScriptParams))
-- 注册一下 Tick
UGCLogSystem.Log("[BP_MachineBase:InitItem] 执行");
if self.ScriptItem["Tick"] then
GlobalTickTool:AddTick(self.ScriptItem, self.ScriptItem['Tick']);
end
end
end
function BP_MachineBase:PostInit() end
---@param OtherActor UGCPlayerPawn_C
function BP_MachineBase:OnBoxBeginOverlap(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex, bFromSweep, SweepResult)
UGCLogSystem.Log("[BP_MachineBase:OnBoxBeginOverlap] ObjectPath.UGCPlayerPawn = %s", UE.GetName(ObjectPath.UGCPlayerPawn));
if UE.IsPlayerPawn(OtherActor) then
UGCLogSystem.Log("[BP_MachineBase:OnBoxBeginOverlap] 执行")
self:OnPlayerIn(OtherActor);
end
end
---@param OtherActor UGCPlayerPawn_C
function BP_MachineBase:OnBoxEndOverlap(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex)
if UE.IsPlayerPawn(OtherActor) then
self:OnPlayerOut(OtherActor);
end
end
--- 玩家进入
---@param InPawn UGCPlayerPawn_C
function BP_MachineBase:OnPlayerIn(InPawn)
if self.ScriptItem then
if table.func(self.ScriptItem, self.ScriptItem['GetEnable']) or self.ScriptItem["GetEnable"] == nil then
table.func(self.ScriptItem, self.ScriptItem['Execute'], InPawn);
end
end
end
--- 玩家退出
---@param InPawn UGCPlayerPawn_C
function BP_MachineBase:OnPlayerOut(InPawn)
if table.func(self.ScriptItem, self.ScriptItem['GetEnable']) or self.ScriptItem["GetEnable"] == nil then
table.func(self.ScriptItem, self.ScriptItem['Exit'], InPawn)
end
end
function BP_MachineBase:EnableMachine(IsEnable)
table.func(self.ScriptItem, self.ScriptItem["SetEnable"], IsEnable);
end
--[[
function BP_MachineBase:ReceiveTick(DeltaTime)
self.SuperClass.ReceiveTick(self, DeltaTime);
end
--]]
--[[
function BP_MachineBase:ReceiveEndPlay()
self.SuperClass.ReceiveEndPlay(self);
end
--]]
--[[
function BP_MachineBase:GetReplicatedProperties()
return
end
--]]
--[[
function BP_MachineBase:GetAvailableServerRPCs()
return
end
--]]
return BP_MachineBase;