QoS(서비스 품질)

참고: Relay를 WebSockets/WebGL과 함께 사용하는 경우에는 현재 QoS가 작동하지 않습니다.

Relay QoS(서비스 품질) 기능을 사용하면 타겟 지역을 선택하지 않아도 호스트 플레이어로 NetworkDriver를 시작하여 서비스 품질 데이터에 따라 자동으로 지역을 선택할 수 있습니다.

참고: 모든 Unity 에디터 버전이 QoS를 지원하지는 않습니다. QoS SDK를 사용하려는 경우, 다음 버전 중 하나를 사용해야 합니다.

  • 2022.2.0a10+
  • 2022.1.0f1+
  • 2021.3.2f1+
  • 2020.3.34f1+

지역을 지정하지 않고 할당 요청을 생성하면 Allocations 서비스가 트리거되어 서비스 품질 데이터를 통해 각 지역과 호스트 간의 연결 품질에 따라 사용할 수 있는 가장 좋은 지역을 선택합니다. Relay는 지연과 패킷 손실을 모두 고려합니다. 아래 샘플 코드를 확인하십시오.

// Launch this method as a coroutine
private IEnumerator StartRelayServer()
{

  // Request an allocation to the Relay service without a target region
  var relayMaxPlayers = 5;
  var allocationTask = RelayService.Instance.CreateAllocationAsync(relayMaxPlayers);

  while(!allocationTask.IsCompleted)
  {
      yield return null;
  }

  if (allocationTask.IsFaulted)
  {
      Debug.LogError("Create allocation request failed");
      yield break;
  }

  var allocation = allocationTask.Result;

  // Request the join code to the Relay service
  var joinCodeTask = RelayService.Instance.GetJoinCodeAsync(allocation.AllocationId);

  while(!joinCodeTask.IsCompleted)
  {
      yield return null;
  }

  if (joinCodeTask.IsFaulted)
  {
      Debug.LogError("Create join code request failed");
      yield break;
  }

  // Get the Join Code, you can then share it with the clients so they can join
  JoinCode = joinCodeTask.Result;

  // Format the server data, based on desired connectionType
  var relayServerData = HostRelayData(allocation, "dtls");

  // Create the network parameters using the Relay server data
  var relayNetworkParameter = new RelayNetworkParameter{ ServerData = relayServerData };

  // Bind and listen to the Relay server
  yield return ServerBindAndListen(relayNetworkParameter);
}

아래 다이어그램은 Relay가 호스트 플레이어 클라이언트와 사용할 수 있는 지역 간의 QoS 데이터에 따라 지역을 어떻게 선택하는지 보여 줍니다. Relay가 QoS 서버를 찾을 수 없거나 측정값을 수집할 수 없는 경우, 클라이언트의 위치를 사용하여 가장 가까운 지역을 선택합니다. 클라이언트의 위치를 확인할 수 없는 경우, 기본 지역인 미국 중부를 선택합니다.