Files
UnrealLuaDemo/Script/lua/game/bootstrap_player.lua
T

40 lines
1.5 KiB
Lua
Raw Normal View History

local ____exports = __module.env
local M__framework_context_game_context = __MODULE__.Import("framework.context.game_context", __module)
local GetGameInstanceContext = M__framework_context_game_context.GetGameInstanceContext
local M__game_demo_demo_router = __MODULE__.Import("game.demo.demo_router", __module)
local RouteCurrentLevel = M__game_demo_demo_router.RouteCurrentLevel
--- PIE / 启动地图玩家入口:绑定 LocalPlayer(0) 的 PlayerController 并按当前关卡路由对应 Demo 场景。
function ____exports.OnBeginPlay(pc)
local world = pc:GetWorld()
local gi = UE.UGameplayStatics.GetGameInstance(pc)
if gi == nil then
return
end
local ctx = GetGameInstanceContext(gi)
if ctx == nil then
return
end
if world ~= nil and ctx:GetWorldContext().world ~= world then
ctx:OnWorldCleanup(world)
end
ctx:GetOrCreateLocalPlayer(0, pc)
RouteCurrentLevel(ctx, pc)
end
function ____exports.OnEndPlay(pc, _endPlayReason)
local gi = UE.UGameplayStatics.GetGameInstance(pc)
if gi == nil then
return
end
local ctx = GetGameInstanceContext(gi)
if ctx == nil then
return
end
local lp = ctx:GetOrCreateLocalPlayer(0)
if lp.playerController == pc then
lp.playerController = nil
end
end
function __module.UpdateImports()
GetGameInstanceContext = M__framework_context_game_context.GetGameInstanceContext
RouteCurrentLevel = M__game_demo_demo_router.RouteCurrentLevel
end