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

83 lines
2.7 KiB
Lua

GlobalInit = {};
---@type table<int32, PlayerKey> 己方队友
LocalTeamPlayers = LocalTeamPlayers == nil and nil or LocalTeamPlayers;
---@type table<int32, PlayerKey> 敌方队友
EnemyTeamPlayers = EnemyTeamPlayers == nil and nil or EnemyTeamPlayers;
---@type TeamId 本地队伍 ID
LocalTeamId = LocalTeamId == nil and nil or LocalTeamId;
---@type PlayerKey 本地玩家 Key
LocalPlayerKey = LocalPlayerKey == nil and nil or LocalPlayerKey;
---@type UGCPlayerController_C 本地玩家控制器
LocalPlayerController = LocalPlayerController or nil;
---@type UGCPlayerState_C 本地玩家状态
LocalPlayerState = LocalPlayerState or nil;
---@type string 玩家名称
LocalPlayerName = LocalPlayerName or nil;
---@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;
---@type MiniGameType
GlobalMiniType = GlobalMiniType == nil and 1 or GlobalMiniType;
--- 初始化
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
if LocalPlayerState == nil then
if LocalPlayerController then LocalPlayerState = LocalPlayerController.PlayerState; end
end
if LocalPlayerState then
LocalTeamId = LocalPlayerState.TeamID;
LocalPlayerName = LocalPlayerState.PlayerName;
end
end
GlobalInit.RemoveUnused();
end
function GlobalInit.UnableVals()
LocalTeamPlayers = nil;
IsClient = nil;
IsServer = nil;
GameState = nil;
LocalPlayerKey = nil;
LocalPlayerController = nil;
EnemyTeamPlayers = 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