Example #1
0
    /// <summary>
    /// Handle load and save persistence events. During these events attempt to share an anchor if the current
    /// conditions make sense for the given event.
    /// </summary>
    private void OnPersistenceEvent(AnchorPersistence source, PersistenceEventArgs args)
    {
        if (args == null)
        {
            return;
        }

        if (args.AnchorOwner != gameObject)
        {
            Debug.LogErrorFormat("[NetworkAnchor] Unexpected persistence event, anchor owner is not the expected game object (anchor id: {0})", args.AnchorId);
            return;
        }

        pendingPersistenceEventArgs = args;
        if (anchorPlayer == null)
        {
            Debug.LogErrorFormat("[NetworkAnchor] Unable to process persistence event without a local instance of the Network Anchor Player (anchor id: {0})", args.AnchorId);
            return;
        }

        if (pendingPersistenceEventArgs.Type == PersistenceEventType.Loaded)
        {
            anchorPlayer.DefaultNetworkAnchor(pendingPersistenceEventArgs.AnchorId, gameObject);
        }
        else if (pendingPersistenceEventArgs.Type == PersistenceEventType.Saved)
        {
            anchorPlayer.ShareNetworkAnchor(pendingPersistenceEventArgs.AnchorId, gameObject);
        }

        pendingPersistenceEventArgs = null;
    }
Example #2
0
 /// <summary>
 /// Initialization the Network Anchor. Note, this will search of an Anchor Persistence behavior. If not present,
 /// then this behavior will not function correctly.
 /// </summary>
 private void Start()
 {
     anchorPersistence = gameObject.GetComponent <AnchorPersistence>();
     if (anchorPersistence != null)
     {
         anchorPersistence.PersistenceEvent += OnPersistenceEvent;
     }
     else
     {
         Debug.LogError("[NetworkAnchor] Network Anchor can't function correctly when there isn't an Anchor Persistence behaviour applied.");
     }
 }