Compare commits
5 Commits
be50401453
...
4de0778dc8
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4de0778dc8 | ||
|
|
eb27008e4d | ||
|
|
0b3a12f64d | ||
|
|
f44815c600 | ||
|
|
ca1f7c0637 |
@@ -167,7 +167,7 @@ public static class PlayerManagerGUI
|
||||
|
||||
private static string GetRoomPublicText()
|
||||
{
|
||||
return MatchmakingHandler.LobbyType == ELobbyType.k_ELobbyTypePublic ? "公开" : "好友可见";
|
||||
return PlayerManager.IsPublic ? "公开" : "好友可见";
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -180,17 +180,7 @@ public static class PlayerManagerGUI
|
||||
|
||||
private static void OnRoomPublicToggleButtonClick()
|
||||
{
|
||||
if (MultiplayerManager.IsServer)
|
||||
{
|
||||
if (MatchmakingHandler.LobbyType == ELobbyType.k_ELobbyTypePublic)
|
||||
{
|
||||
MatchmakingHandler.SetNewLobbyType(ELobbyType.k_ELobbyTypeFriendsOnly);
|
||||
}
|
||||
else
|
||||
{
|
||||
MatchmakingHandler.SetNewLobbyType(ELobbyType.k_ELobbyTypePublic);
|
||||
}
|
||||
}
|
||||
PlayerManager.ToggleLobbyPublicity();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -243,6 +233,7 @@ public static class PlayerManagerGUI
|
||||
private static void OnCycleLobbyDistanceFilterClick()
|
||||
{
|
||||
CycleLobbyDistanceFilter();
|
||||
PlayerManager.RequestLobbyList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -276,14 +267,14 @@ public static class PlayerManagerGUI
|
||||
{
|
||||
// 绘制房间公开性
|
||||
GUI.Label(
|
||||
new Rect(OffsetX, GetNewYPosition(), 500f, 40f),
|
||||
new Rect(OffsetX, GetNewYPosition(), 200f, 40f),
|
||||
$"房间类型: {GetRoomPublicText()}",
|
||||
TitleStyle
|
||||
);
|
||||
|
||||
// 绘制房间公开切换按钮
|
||||
if (GUI.Button(
|
||||
new Rect(OffsetX + 520f, GetCurrentYPosition(), 100f, 40f),
|
||||
new Rect(OffsetX + 220f, GetCurrentYPosition(), 150f, 40f),
|
||||
"切换公开性",
|
||||
CommonButtonStyle
|
||||
))
|
||||
@@ -471,9 +462,8 @@ public static class PlayerManagerGUI
|
||||
"当前不在大厅中",
|
||||
TitleStyle
|
||||
);
|
||||
DrawLobbySearchInfo();
|
||||
}
|
||||
|
||||
DrawLobbySearchInfo();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
85
Plugin.cs
85
Plugin.cs
@@ -82,6 +82,24 @@ public class PlayerManager : BaseUnityPlugin
|
||||
/// </summary>
|
||||
public static MatchmakingHandler MatchmakingHandler => MatchmakingHandler.Instance;
|
||||
|
||||
/// <summary>
|
||||
/// 原始的设置lobby类型方法
|
||||
/// </summary>
|
||||
public static MethodInfo RawChangeLobbyTypeMI => AccessTools.Method(
|
||||
typeof(MatchmakingHandler),
|
||||
"ChangeLobbyType"
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// leverhandler实例
|
||||
/// </summary>
|
||||
public static HostLeverHandler HostLeverHandler => UnityEngine.Object.FindObjectOfType<HostLeverHandler>();
|
||||
|
||||
/// <summary>
|
||||
/// 房间公开性
|
||||
/// </summary>
|
||||
public static bool IsPublic => HostLeverHandler?.isOn ?? MatchmakingHandler.LobbyType == ELobbyType.k_ELobbyTypePublic;
|
||||
|
||||
/// <summary>
|
||||
/// 当前大厅ID
|
||||
/// </summary>
|
||||
@@ -186,6 +204,25 @@ public class PlayerManager : BaseUnityPlugin
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改lever朝向
|
||||
/// </summary>
|
||||
/// <param name="angle">朝向角度</param>
|
||||
/// <returns>修改成功返回true</returns>
|
||||
private static bool SetHostLeverDirection(float angle)
|
||||
{
|
||||
if (HostLeverHandler is not null)
|
||||
{
|
||||
var rig = HostLeverHandler.lever.GetComponent<Rigidbody>();
|
||||
if (rig is not null)
|
||||
{
|
||||
rig.MoveRotation(Quaternion.Euler(0, angle, 0));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 公共方法
|
||||
@@ -210,21 +247,51 @@ public class PlayerManager : BaseUnityPlugin
|
||||
return player.Equals(LocalPlayer);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改大厅公开性
|
||||
/// </summary>
|
||||
public static void ToggleLobbyPublicity()
|
||||
{
|
||||
if (MultiplayerManager.IsServer)
|
||||
{
|
||||
if (IsPublic)
|
||||
{
|
||||
MatchmakingHandler.SetNewLobbyType(ELobbyType.k_ELobbyTypeFriendsOnly);
|
||||
if (!SetHostLeverDirection(30f))
|
||||
{
|
||||
// 如果lever不存在则直接调用原始方法
|
||||
RawChangeLobbyTypeMI.Invoke(MatchmakingHandler, [ELobbyType.k_ELobbyTypeFriendsOnly]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
MatchmakingHandler.SetNewLobbyType(ELobbyType.k_ELobbyTypePublic);
|
||||
if (!SetHostLeverDirection(-30f))
|
||||
{
|
||||
// 如果lever不存在则直接调用原始方法
|
||||
RawChangeLobbyTypeMI.Invoke(MatchmakingHandler, [ELobbyType.k_ELobbyTypePublic]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 请求大厅列表
|
||||
/// </summary>
|
||||
public static void RequestLobbyList()
|
||||
{
|
||||
Debug.Log("正在请求大厅列表...");
|
||||
SteamMatchmaking.AddRequestLobbyListDistanceFilter(lobbyDistanceFilter);
|
||||
SteamAPICall_t apiCall = SteamMatchmaking.RequestLobbyList();
|
||||
LobbyMatchListCallResult.Set(apiCall, OnLobbyMatchListReceived);
|
||||
LobbyMatchListCallResult.Set(apiCall, new CallResult<LobbyMatchList_t>.APIDispatchDelegate(OnRequestLobbyList));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 处理大厅列表查询结果
|
||||
/// </summary>
|
||||
private static void OnLobbyMatchListReceived(LobbyMatchList_t result, bool ioFailure)
|
||||
private static void OnRequestLobbyList(LobbyMatchList_t result, bool ioFailure)
|
||||
{
|
||||
Debug.Log("大厅列表请求完成: " + result.m_nLobbiesMatching + " 个大厅");
|
||||
lobbyDataList = [];
|
||||
uint lobbyCount = result.m_nLobbiesMatching;
|
||||
|
||||
@@ -235,6 +302,11 @@ public class PlayerManager : BaseUnityPlugin
|
||||
{
|
||||
lobbyDataList.Add(lobbyId);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("过滤掉不兼容版本的大厅: " + lobbyId);
|
||||
Debug.Log("大厅 " + lobbyId + " 版本: " + SteamMatchmaking.GetLobbyData(lobbyId, StickFightConstants.VERSION_KEY));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -297,12 +369,3 @@ public class PlayerManager : BaseUnityPlugin
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stick Fight游戏常量
|
||||
/// </summary>
|
||||
internal static class StickFightConstants
|
||||
{
|
||||
public const string VERSION_KEY = "version";
|
||||
public const string VERSION_VALUE = "1.0.0";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user