85 lines
2.8 KiB
Lua
85 lines
2.8 KiB
Lua
GlobalInit = {};
|
|
|
|
---@type table<int32, PlayerKey> 己方队友
|
|
LocalTeamPlayers = LocalTeamPlayers or nil;
|
|
---@type table<int32, PlayerKey> 敌方队友
|
|
EnemyTeamPlayers = EnemyTeamPlayers or nil;
|
|
---@type TeamId 本地队伍 ID
|
|
LocalTeamId = LocalTeamId or nil;
|
|
---@type PlayerKey 本地玩家 Key
|
|
LocalPlayerKey = LocalPlayerKey or nil;
|
|
---@type UGCPlayerController_C 本地玩家控制器
|
|
LocalPlayerController = LocalPlayerController or nil;
|
|
---@type UGCPlayerState_C 本地玩家状态
|
|
LocalPlayerState = LocalPlayerState or nil;
|
|
---@type string 玩家名称
|
|
LocalPlayerName = LocalPlayerName or "";
|
|
---@type UGCGameState_C GameState
|
|
GameState = GameState or nil;
|
|
---@type bool 是否在客户端
|
|
IsClient = IsClient or nil;
|
|
---@type bool 是否在服务器
|
|
IsServer = IsServer or nil;
|
|
---@type MiniGameType
|
|
GlobalMiniType = GlobalMiniType or 1;
|
|
---@type bool 是否是全局观战
|
|
LocalIsGlobalSpectator = LocalIsGlobalSpectator or nil;
|
|
---@type bool 是否是好友观战
|
|
LocalIsFriendSpectator = LocalIsFriendSpectator or nil;
|
|
|
|
--- 初始化
|
|
function GlobalInit.Init()
|
|
GlobalInit.InitGlobalVar();
|
|
end
|
|
|
|
--- 初始化全局变量
|
|
function GlobalInit.InitGlobalVar()
|
|
GameState = UGCGameSystem.GameState;
|
|
IsServer = UGCGameSystem.IsServer();
|
|
IsClient = not IsServer;
|
|
if IsClient then
|
|
if LocalPlayerController == nil then
|
|
LocalPlayerController = STExtraGameplayStatics.GetFirstPlayerController(GameState);
|
|
if LocalIsGlobalSpectator == nil then
|
|
LocalIsGlobalSpectator = LocalPlayerController:IsPureSpectator();
|
|
end
|
|
if LocalIsFriendSpectator == nil then
|
|
LocalIsFriendSpectator = LocalPlayerController:IsFriendObserver();
|
|
end
|
|
end
|
|
if LocalPlayerController then LocalPlayerKey = LocalPlayerController.PlayerKey; end
|
|
if not LocalIsGlobalSpectator then
|
|
if LocalPlayerState == nil then
|
|
if LocalPlayerController then LocalPlayerState = LocalPlayerController.PlayerState; end
|
|
end
|
|
if LocalPlayerState then
|
|
LocalTeamId = LocalPlayerState.TeamID;
|
|
LocalPlayerName = LocalPlayerState.PlayerName;
|
|
end
|
|
end
|
|
UGCLogSystem.Log("[GlobalInit.InitGlobalVar] LocalPlayerKey = %s, PlayerName = %s, TeamId = %s", tostring(LocalPlayerKey), tostring(LocalPlayerName), tostring(LocalTeamId));
|
|
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,
|
|
}
|
|
UITool = nil;
|
|
end
|
|
end
|