Exemplo n.º 1
0
        /// <summary>
        /// Exports and uploads the anchor to the sharing service.
        /// </summary>
        /// <param name="anchor">The anchor to export.</param>
        /// <returns>Success</returns>
        protected override void ExportAnchor(UnityEngine.XR.WSA.WorldAnchor anchor)
        {
            if (SharingStage.Instance == null ||
                SharingStage.Instance.Manager == null ||
                SharingStage.Instance.CurrentRoom == null)
            {
                Debug.LogErrorFormat("[SharingWorldAnchorManager] Failed to export anchor \"{0}\"!  The sharing service was not ready.", anchor.name);
                if (AnchorDebugText != null)
                {
                    AnchorDebugText.text += string.Format("\nFailed to export anchor \"{0}\"!  The sharing service was not ready.", anchor.name);
                }

                return;
            }

            if (!shouldExportAnchors)
            {
                if (ShowDetailedLogs)
                {
                    Debug.LogWarningFormat("[SharingWorldAnchorManager] Attempting to export anchor \"{0}\".", anchor.name);
                }

                if (AnchorDebugText != null)
                {
                    AnchorDebugText.text += string.Format("\nAttempting to export anchor \"{0}\".", anchor.name);
                }

                if (currentAnchorTransferBatch == null)
                {
                    currentAnchorTransferBatch = new UnityEngine.XR.WSA.Sharing.WorldAnchorTransferBatch();
                    if (AnchorDebugText != null)
                    {
                        AnchorDebugText.text += "\nCreating a new World Anchor Transfer Batch...";
                    }
                }
                else
                {
                    Debug.LogWarning("[SharingWorldAnchorManager] We didn't properly cleanup our WorldAnchorTransferBatch!");
                    if (AnchorDebugText != null)
                    {
                        AnchorDebugText.text += "\nWe didn't properly cleanup our WorldAnchorTransferBatch!";
                    }
                }

                currentAnchorTransferBatch.AddWorldAnchor(anchor.name, anchor);
                shouldExportAnchors = true;
            }
        }
        /// <summary>
        /// Exports the currently created anchor.
        /// </summary>
        private void Export()
        {
            var anchor = GetComponent <UnityEngine.XR.WSA.WorldAnchor>();

            string guidString = Guid.NewGuid().ToString();

            exportingAnchorName = guidString;

            // Save the anchor to our local anchor store.
            if (anchor != null && anchorStore.Save(exportingAnchorName, anchor))
            {
                sharedAnchorInterface = new UnityEngine.XR.WSA.Sharing.WorldAnchorTransferBatch();
                sharedAnchorInterface.AddWorldAnchor(guidString, anchor);
                UnityEngine.XR.WSA.Sharing.WorldAnchorTransferBatch.ExportAsync(sharedAnchorInterface, WriteBuffer, ExportComplete);
            }
            else
            {
                Debug.LogWarning("Failed to export anchor, trying again...");
                currentState = ImportExportState.InitialAnchorRequired;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// If we are supposed to create the anchor for export, this is the function to call.
        /// </summary>
        public void CreateAnchor()
        {
#if UNITY_EDITOR
            Debug.LogError("Anchors cannot be created from the Unity editor.");
#endif

            exportingAnchorBytes.Clear();
            GenericNetworkTransmitter.Instance.SetData(null);
            objectToAnchor = UNetAnchorManager.Instance.gameObject;

            UnityEngine.XR.WSA.WorldAnchor worldAnchor = objectToAnchor.GetComponent <UnityEngine.XR.WSA.WorldAnchor>();
            if (worldAnchor == null)
            {
                worldAnchor = objectToAnchor.AddComponent <UnityEngine.XR.WSA.WorldAnchor>();
            }

            Debug.Log("Checking for saved anchor: " + AnchorName);
            if (PlayerPrefs.HasKey(SavedAnchorKey) && AttachToCachedAnchor(PlayerPrefs.GetString(SavedAnchorKey)))
            {
                exportingAnchorName = PlayerPrefs.GetString(SavedAnchorKey);
                Debug.Log("found " + AnchorName + " again");
            }
            else if (PlayerPrefs.HasKey(AnchorName) && AttachToCachedAnchor(AnchorName))
            {
                exportingAnchorName = AnchorName;
                Debug.Log("_found " + AnchorName + " again");
            }
            else
            {
                exportingAnchorName = Guid.NewGuid().ToString();
            }

            UnityEngine.XR.WSA.Sharing.WorldAnchorTransferBatch watb = new UnityEngine.XR.WSA.Sharing.WorldAnchorTransferBatch();

            Debug.Log("exporting " + exportingAnchorName);
            watb.AddWorldAnchor(exportingAnchorName, worldAnchor);
            UnityEngine.XR.WSA.Sharing.WorldAnchorTransferBatch.ExportAsync(watb, WriteBuffer, ExportComplete);

            SaveAnchor(exportingAnchorName);
        }