1
1
mirror of https://github.com/Rundll86/Dog-Lynx-And-HCN.git synced 2026-05-28 06:51:54 +08:00
Files
Dog-Lynx-And-HCN/scripts/Tools/Managers/MultiplayerState.gd
T
fallingshrimp c28d725d3e feat(多人游戏): 添加连接状态检查和断开连接功能
- 在MultiplayerState中添加isConnected方法检查连接状态
- 修改launchServer和connectClient方法以更新连接状态
- 在Starter面板中添加断开连接按钮并实现状态同步
- 更新UI显示连接状态和颜色
2025-11-09 15:24:24 +08:00

40 lines
1.2 KiB
GDScript

@tool
class_name MultiplayerState
enum ConnectionState {
DISCONNECTED,
CONNECTING,
CONNECTED_HOST,
CONNECTED_CLIENT,
}
static var stateTextMap = {
ConnectionState.DISCONNECTED: "未连接到服务器。",
ConnectionState.CONNECTING: "连接中...",
ConnectionState.CONNECTED_HOST: "服务器启动成功!",
ConnectionState.CONNECTED_CLIENT: "已连接到服务器!",
}
static var stateColorMap = {
ConnectionState.DISCONNECTED: Color.RED,
ConnectionState.CONNECTING: Color.YELLOW,
ConnectionState.CONNECTED_HOST: Color.GREEN,
ConnectionState.CONNECTED_CLIENT: Color.GREEN,
}
static var state: ConnectionState = ConnectionState.DISCONNECTED
static var isMultiplayer: bool = false
static var maxPlayer: int = 10
static func isConnected():
return [ConnectionState.CONNECTED_HOST, ConnectionState.CONNECTED_CLIENT].has(state)
static func launchServer(port: int):
var peer = ENetMultiplayerPeer.new()
peer.create_server(port, maxPlayer)
state = ConnectionState.CONNECTED_HOST
return peer
static func connectClient(host: String, port: int):
var peer = ENetMultiplayerPeer.new()
peer.create_client(host, port)
state = ConnectionState.CONNECTED_CLIENT
return peer