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);
    }
    public bool CheckOutAnchorSource(NetworkAnchorPlayer player)
    {
        if (player == null)
        {
            return(false);
        }

        bool checkedOut = false;

        lock (AnchorCheckoutLock)
        {
            if (AnchorSourceCheckedOutBy == null)
            {
                Debug.LogFormat("[NetworkAnchorManager] Server checked out anchor source. (player.netId: {0})", player.netId);
                checkedOut = true;
                SyncVar_AnchorSourceCheckedOut = true;
                AnchorSourceCheckedOutBy       = player;
            }
            else
            {
                Debug.LogFormat("[NetworkAnchorManager] Server could not checked out anchor source, already checked out. (player.netId: {0}) {1}", player.netId, DebugInfo());
            }
        }

        return(checkedOut);
    }
Beispiel #3
0
    /// <summary>
    /// Check if we can inititialize the local instance of an anchor player. If we can, only do the initialization work
    /// once. Note that the local player may not exist at "Start".
    /// </summary>
    private void WhenReadyInitializeAnchorPlayerOnce()
    {
        // Check if already initialized
        if (anchorPlayer != null)
        {
            return;
        }

        // Check if can initialize
        anchorPlayer = NetworkAnchorPlayer.LocalInstance;
        if (anchorPlayer == null)
        {
            return;
        }

        // If an anchor blob was received from another player, now's the time to handle this.
        if (networkAnchorManager != null)
        {
            OnReceivedRemoteAnchor(networkAnchorManager, networkAnchorManager.LastReceivedAnchor);
        }
        else
        {
            Debug.LogError("[NetworkAnchor] Network Anchor can't function correctly when there isn't a Network Anchor Manager.");
        }

        OnPersistenceEvent(anchorPersistence, pendingPersistenceEventArgs);
    }
Beispiel #4
0
    public override void OnStartAuthority()
    {
        base.OnStartAuthority();

        if (hasAuthority)
        {
            localInstance = this;
        }
    }
    /// <summary>
    /// When receiving a remote anchor, notify other components. Once of these compoents should apply the new anchor
    /// </summary>
    private void OnReceivedRemoteAnchor(NetworkAnchorPlayer sender, ImportedAnchorChangedArgs args)
    {
        if (args == null)
        {
            return;
        }

        Debug.LogFormat("[NetworkAnchor] Received a new anchor from a remote client. (anchorId: {0})", args.AnchorId);
        lastKnownAnchorId = args.AnchorId;
        if (ReceivedRemoteAnchorTransferBatch != null)
        {
            ReceivedRemoteAnchorTransferBatch(this, args.TransferBatch);
        }
    }
    /// <summary>
    /// Check if we can inititialize the local instance of an anchor player. If we can, only do the initialization work
    /// once. Note that the local player may not exist at "Start".
    /// </summary>
    private void WhenReadyInitializeAnchorPlayerOnce()
    {
        // Check if already initialized
        if (anchorPlayer != null)
        {
            return;
        }

        // Check if can initialize
        anchorPlayer = NetworkAnchorPlayer.LocalInstance;
        if (anchorPlayer == null)
        {
            return;
        }

        anchorPlayer.ImportedAnchorChanged += OnReceivedRemoteAnchor;
        anchorPlayer.ExportedAnchor        += OnSharedRemoteAnchor;
        OnReceivedRemoteAnchor(anchorPlayer, anchorPlayer.ImportedAnchor);
    }
    public bool MoveAnchorSource(NetworkAnchorPlayer player, string anchorId, Vector3 positionDelta, Vector3 eulerAnglesDelta)
    {
        bool moved = false;

        lock (AnchorCheckoutLock)
        {
            if (AnchorSourceCheckedOutBy != null && player.netId == AnchorSourceCheckedOutBy.netId)
            {
                Debug.LogFormat("[NetworkAnchorManager] Server moved anchor source. (player.netId: {0}) (anchorId: {1}) (positionDelta: {2}) (eulerAnglesDelta: {3}) {4}", player.netId, anchorId, positionDelta, eulerAnglesDelta, DebugInfo());
                MoveAllAnchors(positionDelta, eulerAnglesDelta);
                moved = true;
            }
            else
            {
                Debug.LogFormat("[NetworkAnchorManager] Server could not move anchor source. (player.netId: {0}) (anchorId: {1}) (positionDelta: {2}) (eulerAnglesDelta: {3}) {4}", player.netId, anchorId, positionDelta, eulerAnglesDelta, DebugInfo());
            }
        }
        return(moved);
    }
 /// <summary>
 /// Called when the local player has successfully exported and shared an anchor.
 /// </summary>
 private void OnSharedRemoteAnchor(NetworkAnchorPlayer sender, string anchorId)
 {
     Debug.LogFormat("[NetworkAnchor] Finished check-in and now sharing a new anchor. (anchorId: {0})", anchorId);
     lastKnownAnchorId = anchorId;
 }