Esempio n. 1
0
    /// <summary>
    /// Begin import anchor data from source.
    /// </summary>
    private void ImportAnchorData(SharedAnchorData anchorSource)
    {
        if (HolographicSettings.IsDisplayOpaque)
        {
            Debug.LogFormat("[NetworkAnchorManager] Ignoring import anchor request, as this device doesn't support anchoring. {0} {1}", anchorSource.ToString(), DebugInfo());
            return;
        }

        if (!anchorSource.IsValid)
        {
            Debug.LogFormat("[NetworkAnchorManager] Ignoring anchor source since it's invalid. {0} {1}", anchorSource.ToString(), DebugInfo());
            return;
        }

        if (anchorSource.SourceIp == LocalAddress)
        {
            Debug.LogFormat("[NetworkAnchorManager] Ignoring anchor source since it originated from this player. {0} {1}", anchorSource.ToString(), DebugInfo());
            return;
        }

        Debug.LogFormat("[NetworkAnchorManager] Importing anchor. {0} {1}", anchorSource.ToString(), DebugInfo());

        LoadingAnchor = true;
        anchorTransmitter.RequestData(anchorSource.SourceIp);
    }
    /// <summary>
    /// Begin import anchor data from source.
    /// </summary>
    private bool ImportAnchorData(SharedAnchorData anchorSource)
    {
        lock (ImportingAndExportingLock)
        {
            if (HolographicSettings.IsDisplayOpaque)
            {
                Debug.LogFormat("[NetworkAnchorManager] Ignoring import anchor request, as this device doesn't support anchoring. {0} {1}", anchorSource.ToString(), DebugInfo());
                return(false);
            }

            if (!anchorSource.IsValid)
            {
                Debug.LogFormat("[NetworkAnchorManager] Ignoring import anchor request, since the anchor is invalid. {0} {1}", anchorSource.ToString(), DebugInfo());
                return(false);
            }

            if (anchorSource.SourceIp == LocalAddress)
            {
                Debug.LogFormat("[NetworkAnchorManager] Ignoring import anchor request, since it originated from this player. {0} {1}", anchorSource.ToString(), DebugInfo());
                return(false);
            }

            if (ImportedAnchor != null && anchorSource.AnchorId == ImportedAnchor.AnchorId)
            {
                Debug.LogFormat("[NetworkAnchorManager] IIgnoring import anchor request, since it's already imported. {0} {1}", anchorSource.ToString(), DebugInfo());
                return(false);
            }

            if (ImportingAnchorSource.IsValid && ImportingAnchorSource.AnchorId == anchorSource.AnchorId)
            {
                Debug.LogFormat("[NetworkAnchorManager] Ignoring import anchor request, since it's already being imported. {0} {1}", anchorSource.ToString(), DebugInfo());
                return(false);
            }

            Debug.LogFormat("[NetworkAnchorManager] Importing anchor. {0} {1}", anchorSource.ToString(), DebugInfo());

            // no longer exported an anchor
            ExportingAnchorSource = SharedAnchorData.Empty;

            // save anchor being imported
            ImportingAnchorSource = anchorSource;

            // begin requesting data
            anchorTransmitter.RequestData(ImportingAnchorSource.AnchorId, ImportingAnchorSource.SourceIp);

            return(true);
        }
    }
Esempio n. 3
0
 private void CmdShareAnchor(SharedAnchorData anchorSource)
 {
     if (NetworkAnchorManager.Instance != null)
     {
         Debug.LogFormat("[NetworkAnchorPlayer] Command is setting the anchor source {0} {1}", anchorSource.ToString(), DebugInfo());
         NetworkAnchorManager.Instance.SetAnchorSource(anchorSource);
     }
     else
     {
         Debug.LogErrorFormat("[NetworkAnchorPlayer] Can't set anchor source, network anchor server is missing. {0} {1}", anchorSource.ToString(), DebugInfo());
     }
 }
    public bool CheckInAnchorSource(NetworkAnchorPlayer player, SharedAnchorData anchorData)
    {
        bool checkedIn = false;

        lock (AnchorCheckoutLock)
        {
            if (AnchorSourceCheckedOutBy != null && player.netId == AnchorSourceCheckedOutBy.netId)
            {
                checkedIn = true;
                AnchorSourceCheckedOutBy = null;

                if (anchorData.IsValid)
                {
                    SyncVar_AnchorSource = anchorData;
                }

                SyncVar_AnchorSourceCheckedOut = false;
                Debug.LogFormat("[NetworkAnchorManager] Server checked in anchor source. (player.netId: {0}) {1} {2} {3}", player.netId, anchorData.ToString(), SyncVar_AnchorSource.ToString(), DebugInfo());
            }
            else
            {
                Debug.LogFormat("[NetworkAnchorManager] Server could not check in anchor source. (player.netId: {0}) {1} {2} {3}", player.netId, anchorData.ToString(), SyncVar_AnchorSource.ToString(), DebugInfo());
            }
        }
        return(checkedIn);
    }
Esempio n. 5
0
    public bool TrySharingAnchor(String anchorId, GameObject gameObject)
    {
        if (HolographicSettings.IsDisplayOpaque)
        {
            Debug.LogFormat("[NetworkAnchorManager] Ignoring share anchor request, as this device doesn't support anchoring. (anchor id: {0})", anchorId);
            return(false);
        }

        if (AnchorSource.AnchorId == anchorId)
        {
            Debug.LogFormat("[NetworkAnchorManager] Ignoring share anchor request, as anchor is already being shared. (anchor id: {0})", anchorId);
            return(false);
        }

        if (LastReceivedAnchor != null && LastReceivedAnchor.AnchorId == anchorId)
        {
            Debug.LogFormat("[NetworkAnchorManager] Ignoring share anchor request, as anchor was just received. (anchor id: {0})", anchorId);
            return(false);
        }

        WorldAnchor worldAnchor = gameObject.GetComponent <WorldAnchor>();

        if (worldAnchor == null)
        {
            Debug.LogErrorFormat("[NetworkAnchorManager] Unable to acquire anchor ownership. Game object is missing an anchor. (anchor id: {0})", anchorId);
            return(false);
        }

        Debug.LogFormat("[NetworkAnchorManager] Attempting to acquire anchor ownership and share anchor with other players. (new anchor id: {0}) {1} {2}", anchorId, AnchorSource.ToString(), DebugInfo());

        // The last received anchor will no longer be relevant since we're taking ownership
        LastReceivedAnchor = null;

        // Stop all pending work on the anchor transmitter
        anchorTransmitter.StopAll();

        // Export binary data
        List <byte> buffer             = new List <byte>();
        WorldAnchorTransferBatch batch = new WorldAnchorTransferBatch();

        batch.AddWorldAnchor(anchorId, worldAnchor);
        WorldAnchorTransferBatch.ExportAsync(
            batch,
            (byte[] data) => { buffer.AddRange(data); },
            (SerializationCompletionReason status) => { ExportAnchorDataComplete(status, buffer.ToArray(), anchorId, gameObject); });

        return(true);
    }
Esempio n. 6
0
 public void SetAnchorSource(SharedAnchorData anchorSource)
 {
     Debug.LogFormat("[NetworkAnchorManager] Server is setting the anchor source. {0} {1}", anchorSource.ToString(), DebugInfo());
     AnchorSource = anchorSource;
 }