앵커 공유는 월드 앵커를 다양한 기기에 로드할 수 있는 방법으로 하나의 기기에 저장하는 시스템입니다.
예를 들어, 두 사용자가 테이블 위에 놓은 가상 게임 보드를 사용하여 게임을 플레이합니다. 두 사용자의 게임 보드가 정렬되려면 두 디바이스에 모두 실제 월드를 기준으로 한 가상 게임 보드의 상대적인 위치에 대한 공간적 이해가 있어야 합니다. 앵커 공유를 사용하면 앵커 정보를 한 사용자의 디바이스로부터 저장하고 다른 사용자의 디바이스에서 재현할 수 있습니다.
앵커 공유 기능에는 디바이스 간에 데이터를 전송하는 데 필요한 전송 레이어가 포함되어 있지 않습니다. 이 기능은 네트워크 전송 시스템을 통해 제공됩니다. 이에 대한 자세한 내용은 네트워킹의 Unity 문서고를 참조하십시오.
기존 월드 앵커를 익스포트려면 해당 앵커의 공유 이름과 WorldAnchorTransferBatch
가 필요합니다.
아래 예제에는 이 API의 기본 사용법이 나와 있습니다. 다음 사항에 유의하십시오.
OnExportDataAvailable
이 여러 번 호출될 것이라 예상해야 합니다.private void ExportWorldAnchor()
{
WorldAnchorTransferBatch transferBatch = new WorldAnchorTransferBatch();
transferBatch.AddWorldAnchor("GameRootAnchor", this.MyWorldAnchor);
WorldAnchorTransferBatch.ExportAsync(transferBatch, OnExportDataAvailable, OnExportComplete);
}
private void OnExportComplete(SerializationCompletionReason completionReason)
{
if (completionReason != SerializationCompletionReason.Succeeded)
{
// If we have been transferring data and it failed,
// tell the client to discard the data
SendExportFailedToClient();
}
else
{
// Tell the client that serialization has succeeded.
// The client can start importing once all the data is received.
SendExportSucceededToClient();
}
}
private void OnExportDataAvailable(byte[] data)
{
// Send the bytes to the client. Data may also be buffered.
TransferDataToClient(data);
}
데이터가 수신되면 WorldAnchorTransferBatch
를 통해 데이터를 임포트하여 월드 앵커를 다른 클라이언트에서 재현합니다.
다음은 기본 사용법의 예입니다. 때때로 임포트에 실패할 수 있습니다. 이 경우 프로세스를 다시 시도합니다.
private int retryCount = 10;
private void ImportWorldAnchor(byte[] importedData)
{
WorldAnchorTransferBatch.ImportAsync(importedData, OnImportComplete);
}
private void OnImportComplete(SerializationCompletionReason completionReason, WorldAnchorTransferBatch deserializedTransferBatch)
{
if (completionReason != SerializationCompletionReason.Succeeded)
{
Debug.Log("Failed to import: " + completionReason.ToString());
if (retryCount > 0)
{
retryCount--;
WorldAnchorTransferBatch.ImportAsync(fileData, OnImportComplete);
}
return;
}
string[] ids = deserializedTransferBatch.GetAllIds();
foreach (string id in ids)
{
GameObject gameObject = GetGameObjectFromAnchorId(id);
if (gameObject != null)
{
transferBatch.LockObject(id, gameObject);
}
else
{
Debug.Log("Failed to find object for anchor id: " + id);
}
}
}
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.