Example #1
0
 private void OnOpenAR(object sender, EventArgs e)
 {
     if (Calibrated)
     {
         if (UsingServerCalibration)
         {
             WorldAnchorLocal.GetComponent <RecalibrateUsingServer>().CreateSelectorItem();
         }
         else
         {
             WorldAnchorLocal.GetComponent <Recalibrate>().CreateSelectorItem();
         }
     }
     else
     {
         if (!UsingServerCalibration)
         {
             foreach (ARTrackedImage anchorCube in ARTrackedImageManager.trackables)
             {
                 CreateAnchor anchor = anchorCube.GetComponent <CreateAnchor>();
                 if (anchor != null)
                 {
                     anchor.CreateSelectorItem();
                 }
             }
         }
     }
 }
        public void ToggleAnchorPersistence(ARAnchor anchor)
        {
            if (m_anchorStore == null)
            {
                Debug.Log($"Anchor Store was not available.");
                return;
            }

            SampleAnchor sampleAnchor = anchor.GetComponent <SampleAnchor>();

            if (!sampleAnchor.Persisted)
            {
                // For the purposes of this sample, randomly generate a name for the saved anchor.
                string newName = $"anchor/{Guid.NewGuid().ToString().Substring(0, 4)}";

                bool succeeded = m_anchorStore.TryPersistAnchor(anchor.trackableId, newName);
                if (!succeeded)
                {
                    Debug.Log($"Anchor could not be persisted: {anchor.trackableId}");
                    return;
                }

                ChangeAnchorVisual(anchor, newName, true);
            }
            else
            {
                m_anchorStore.UnpersistAnchor(sampleAnchor.Name);
                ChangeAnchorVisual(anchor, "", false);
            }
        }
        private void ChangeAnchorVisual(ARAnchor anchor, string newName, bool isPersisted)
        {
            SampleAnchor sampleAnchor = anchor.GetComponent <SampleAnchor>();

            Debug.Log(isPersisted ? $"Anchor {anchor.trackableId} persisted with name {newName}" : $"Anchor {anchor.trackableId} with name {sampleAnchor.Name} unpersisted");
            sampleAnchor.Name      = newName;
            sampleAnchor.Persisted = isPersisted;
        }