> For the complete documentation index, see [llms.txt](https://xreal.gitbook.io/nrsdk/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://xreal.gitbook.io/nrsdk/v2.1.0/development/spatial-anchor/tutorial-sharing-anchors/sharing-anchors-with-photon.md).

# Sharing Anchors with Photon

### **1. Setting up the UUIDManager**

Create a script named `UUIDManager.cs`. Within the `UUIDManager` class, utilize a `PhotonView` to synchronize the UUID. In the `AnchorItem` class, when there's a need to share the UUID, call the relevant method from `UUIDManager`. The `UUIDManager` will then use Photon's RPC mechanism to send the UUID to other clients. Ensure that the `UUIDManager` class is attached to a GameObject in your scene and that this GameObject has a `PhotonView` component added to it.

<figure><img src="/files/uMmPhmjK0Ki5yELcpXuQ" alt=""><figcaption></figcaption></figure>

<pre class="language-csharp"><code class="lang-csharp">using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
using Photon.Realtime;
using NRKernal.NRExamples;

public class UUIDManager : MonoBehaviourPun
{
    public static UUIDManager instance; // 单例实例

    private <a data-footnote-ref href="#user-content-fn-1">void</a> Awake()
    {
        if (instance == null)
        {
            instance = this;
        }
        else if (instance != this)
        {
            Destroy(gameObject);
        }
    }

    [PunRPC]
    public void ShareAnchorUUID(string uuid)
    {
        photonView.RPC("ReceiveAnchorUUID", RpcTarget.Others, uuid);
    }

    [PunRPC]
    public void ReceiveAnchorUUID(string uuid)
    {
        Debug.Log("Received UUID: " + uuid);

        GameObject localMapDemo = GameObject.Find("LocalMapDemo");
        if (localMapDemo != null)
        {
            LocalMapExample localMapExample = localMapDemo.GetComponent&#x3C;LocalMapExample>();
            if (localMapExample != null)
            {
                localMapExample.CloudLoad(uuid);
                Debug.Log("CloudLoad:"+uuid);
            }
            else
            {
                Debug.LogError("LocalMapExample component not found");
            }
        }
        else
        {
            Debug.LogError("LocalMapDemo GameObject not found");
        }
    }

}

</code></pre>

### 2. Add a ShareUUID method to AnchorItem to receive the UUID of the anchor.

```csharp
 public void ShareUUID()
        {
            if (m_NRWorldAnchor != null)
            {
                UUIDManager.instance.ShareAnchorUUID(m_NRWorldAnchor.UUID);
                Debug.Log("Shared anchor: " + m_NRWorldAnchor.UUID);
            }
        }
```

### 3. Add ShareUUID in the CloudSave method.

When a player in the room performs cloud storage, it will be automatically shared with other players in the room.

```csharp
public async void CloudSave()
        {
            if (m_NRWorldAnchor != null)
            {
                bool result=await NRWorldAnchorStore.Instance.CloudSaveAnchor(m_NRWorldAnchor);
                if (result)
                {
                    NRDebugger.Info("Ready to share anchor: " + m_NRWorldAnchor.UUID);
                    Debug.Log("Ready to share anchor: " + m_NRWorldAnchor.UUID);
                    ShareUUID();
                }
                else
                {
                    Debug.LogError("Failed to save anchor");
                }
            }
            else
            {
                Debug.LogError("m_NRWorldAnchor is null, failed to save this anchor to CloudStorage");
            }
        }  
```

### **Conclusion**

Congratulations on completing this comprehensive guide on sharing anchors using Photon and Cloud Storage! You've taken significant steps in enhancing the multi-user AR experience. Thank you for dedicating your time and effort to this tutorial. Best of luck with your future AR projects!

[^1]:


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://xreal.gitbook.io/nrsdk/v2.1.0/development/spatial-anchor/tutorial-sharing-anchors/sharing-anchors-with-photon.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
