35 lines
1.5 KiB
Lua
Raw Normal View History

2025-01-04 23:00:19 +08:00
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 == 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.InitGlobalVar()
if GameState == nil then GameState = UGCGameSystem.GameState; end
if IsServer == nil then IsServer = UGCGameSystem.IsServer(); end
if IsClient == nil then IsClient = not UGCGameSystem.IsServer(); end
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
UGCLogSystem.Log("[GlobalInit.InitGlobalVar] IsClient = %s, IsServer = %s", tostring(IsClient), tostring(IsServer));
end