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

60 lines
1.7 KiB
Lua

GlobalInit = {};
---@type PlayerKey 本地玩家 Key
LocalPlayerKey = LocalPlayerKey == nil and nil or LocalPlayerKey;
---@type UGCPlayerController_C 本地玩家控制器
LocalPlayerController = LocalPlayerController == nil and nil or LocalPlayerController;
---@type UGCGameState_C GameState
GameState = GameState == nil and nil or GameState;
---@type bool 是否在客户端
IsClient = IsClient == nil and nil or IsClient;
---@type bool 是否在服务器
IsServer = IsServer == nil and nil or IsServer;
--- 初始化
function GlobalInit.Init()
GlobalInit.InitGlobalVar();
end
--- 初始化全局变量
function GlobalInit.InitGlobalVar()
if GameState == nil then GameState = UGCGameSystem.GameState; end
if IsServer == nil then IsServer = UGCGameSystem.IsServer(); end
if IsClient == nil then IsClient = not IsServer end
--UGCLogSystem.Log("[GlobalInit.InitGlobalVar] IsClient = %s", tostring(IsClient))
if IsClient then
if LocalPlayerController == nil then LocalPlayerController = STExtraGameplayStatics.GetFirstPlayerController(GameState); end
if LocalPlayerKey == nil then
if LocalPlayerController then LocalPlayerKey = LocalPlayerController.PlayerKey; end
end
end
GlobalInit.RemoveUnused()
end
function GlobalInit.UnableVals()
IsClient = nil;
IsServer = nil;
GameState = nil;
LocalPlayerKey = nil;
LocalPlayerController = nil;
end
--- 移除不会被使用的东西
function GlobalInit.RemoveUnused()
if IsServer then
WidgetManager = nil;
WidgetConfig = {
EUIType = WidgetConfig.EUIType == nil and {} or WidgetConfig.EUIType,
}
--ItemTable = nil;
UITool = nil;
end
GlobalInit.RemoveWeaponTable()
end
function GlobalInit.RemoveWeaponTable()
--require("Script.Global.Table.ItemTable")
--WeaponTypeInfo = nil;
end