浏览代码

Fixed an issue with RelayUtpClient cleanup where its disconnect message wouldn't get through to the host.

/main/staging/ready_when_player_leaves
nathaniel.buck@unity3d.com 2 年前
当前提交
114ee0ac
共有 3 个文件被更改,包括 20 次插入6 次删除
  1. 4
      Assets/Scripts/Game/GameManager.cs
  2. 21
      Assets/Scripts/Relay/RelayUtpClient.cs
  3. 1
      Assets/Scripts/Relay/RelayUtpHost.cs

4
Assets/Scripts/Game/GameManager.cs


m_relaySetup = null;
}
if (m_relayClient != null)
{ Component.Destroy(m_relayClient);
{
m_relayClient.Dispose();
Component.Destroy(m_relayClient);
m_relayClient = null;
}
}

21
Assets/Scripts/Relay/RelayUtpClient.cs


using System.Collections.Generic;
using System;
using System.Collections.Generic;
using Unity.Networking.Transport;
using UnityEngine;

/// This observes the local player and updates remote players over Relay when there are local changes, demonstrating basic data transfer over the Unity Transport (UTP).
/// Created after the connection to Relay has been confirmed.
/// </summary>
public class RelayUtpClient : MonoBehaviour // This is a MonoBehaviour merely to have access to Update.
public class RelayUtpClient : MonoBehaviour, IDisposable // This is a MonoBehaviour merely to have access to Update.
{
protected LobbyUser m_localUser;
protected LocalLobby m_localLobby;

protected bool m_hasSentInitialMessage = false;
private const float k_heartbeatPeriod = 5;
private bool m_hasDisposed = false;
protected enum MsgType { Ping = 0, NewPlayer, PlayerApprovalState, ReadyState, PlayerName, Emote, StartCountdown, CancelCountdown, ConfirmInGame, EndInGame, PlayerDisconnect }

m_localUser.onChanged -= OnLocalChange;
Leave();
Locator.Get.UpdateSlow.Unsubscribe(UpdateSlow);
m_connections.Clear();
m_networkDriver.Dispose();
// Don't clean up the NetworkDriver here, or else our disconnect message won't get through to the host. The host will handle cleaning up the connection.
}
public void Dispose()
{
if (!m_hasDisposed)
{
Uninitialize();
m_hasDisposed = true;
}
Uninitialize();
Dispose();
}
private void OnLocalChange(LobbyUser localUser)

1
Assets/Scripts/Relay/RelayUtpHost.cs


{
base.Uninitialize();
Locator.Get.Messenger.Unsubscribe(this);
m_networkDriver.Dispose();
}
protected override void OnUpdate()

正在加载...
取消
保存