Sharing Anchors with Photon
Was this helpful?
Was this helpful?
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 void 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<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");
}
}
}
public void ShareUUID()
{
if (m_NRWorldAnchor != null)
{
UUIDManager.instance.ShareAnchorUUID(m_NRWorldAnchor.UUID);
Debug.Log("Shared anchor: " + m_NRWorldAnchor.UUID);
}
}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");
}
}