Skip to content

Commit 1927396

Browse files
committed
feat(网络): 添加失去焦点时发送心跳包的功能
在NetworkManager和NetworkChannelBase中添加SetFocusHeartbeat方法,允许配置失去焦点时是否继续发送心跳包 移除NetworkComponent中不再使用的_isGaming变量
1 parent 09c5853 commit 1927396

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

Runtime/Network/Network/NetworkManager.NetworkChannelBase.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,10 @@ public void SetIgnoreLogNetworkIds(List<int> sendIds, List<int> receiveIds)
972972
IgnoreReceiveIds = receiveIds;
973973
}
974974

975+
/// <summary>
976+
/// 设置是否开启心跳包失去焦点时也发送心跳包
977+
/// </summary>
978+
/// <param name="hasFocus">是否开启心跳包失去焦点时也发送心跳包</param>
975979
public void SetFocusHeartbeat(bool hasFocus)
976980
{
977981
PFocusHeartbeat = hasFocus;

Runtime/Network/Network/NetworkManager.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,10 @@ public bool DestroyNetworkChannel(string channelName)
246246
return false;
247247
}
248248

249+
/// <summary>
250+
/// 设置是否开启心跳包失去焦点时也发送心跳包
251+
/// </summary>
252+
/// <param name="hasFocus">是否开启心跳包失去焦点时也发送心跳包</param>
249253
public void SetFocusHeartbeat(bool hasFocus)
250254
{
251255
foreach (var networkChannel in m_NetworkChannels.Values)

Runtime/Network/NetworkComponent.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,13 @@ public int NetworkChannelCount
7575
get { return m_NetworkManager.NetworkChannelCount; }
7676
}
7777

78-
/// <summary>
79-
/// 是否正在游戏中。
80-
/// </summary>
81-
private bool _isGaming = true;
8278

8379
/// <summary>
8480
/// 应用程序获得或失去焦点时调用。
8581
/// </summary>
8682
/// <param name="hasFocus">应用程序是否获得焦点。</param>
8783
private void OnApplicationFocus(bool hasFocus)
8884
{
89-
_isGaming = hasFocus;
9085
if (!m_FocusHeartbeat)
9186
{
9287
return;

0 commit comments

Comments
 (0)