private void OnDestroy() => StopAndCleanupSession(); // When this sample is destroyed, ensure the session is cleaned up.

        /// <summary>
        /// Start the session and begin searching for anchors previously saved.
        /// </summary>
        private async Task StartSessionAsync()
        {
            // CreateSessionAsync cannot be called during Start(), since the SpatialAnchorManager may not have Start()ed yet itself.
            // Instead, we ensure the session is created before we start it.
            if (!m_cloudSpatialAnchorManagerSessionCreated)
            {
                await m_cloudSpatialAnchorManager.CreateSessionAsync();

                m_cloudSpatialAnchorManagerSessionCreated = true;
            }

            if (m_cloudSpatialAnchorManager.IsSessionStarted)
            {
                Debug.LogWarning("Cannot start session; session already started.");
                return;
            }

            // Start the session
            Debug.Log("Starting session...");
            await m_cloudSpatialAnchorManager.StartSessionAsync();

            Debug.Log($"Session started! Air tap to create a local anchor.");

            // And create the watcher to look for any created anchors
            if (m_cloudSpatialAnchorIDs.Count > 0)
            {
                Debug.Log($"Creating watcher to look for {m_cloudSpatialAnchorIDs.Count} spatial anchors");
                AnchorLocateCriteria anchorLocateCriteria = new AnchorLocateCriteria();
                anchorLocateCriteria.Identifiers = m_cloudSpatialAnchorIDs.ToArray();
                m_cloudSpatialAnchorWatcher      = m_cloudSpatialAnchorManager.Session.CreateWatcher(anchorLocateCriteria);
                Debug.Log($"Watcher created!");
            }
        }
コード例 #2
0
    public async void StartAzureSession()
    {
        trigger = false;

        Debug.Log("\nAnchorModuleScript.StartAzureSession()");

        SendTimeServer("ASA", Time.time.ToString() + "start Azure Session");

        // Notify AnchorFeedbackScript
        OnStartASASession?.Invoke();

        Debug.Log("Starting Azure session... please wait...");

        if (cloudManager.Session == null)
        {
            // Creates a new session if one does not exist
            await cloudManager.CreateSessionAsync();
        }

        // Starts the session if not already started
        await cloudManager.StartSessionAsync();

        Debug.Log("Azure session started successfully");

        SendTimeServer("ASA", Time.time.ToString() + "Azure session started successfully");

        trigger = true;
    }
コード例 #3
0
        /// <summary>
        ///     Azure Spatial Anchorsサービスとの接続を行い、セションを開始します。
        /// </summary>
        /// <returns></returns>
        public async Task StartAzureSession()
        {
            try
            {
                Debug.Log("\nAnchorModuleScript.StartAzureSession()");

                OutputLog("Starting Azure session... please wait...");

                if (cloudManager.Session == null)
                {
                    // Creates a new session if one does not exist
                    await cloudManager.CreateSessionAsync();
                }

                // Starts the session if not already started
                await cloudManager.StartSessionAsync();

                OutputLog("Azure session started successfully");
            }
            catch (Exception e)
            {
                Debug.Log(e);
                throw;
            }
        }
コード例 #4
0
    public async Task StartAzureSession(string accountID, string accountKey, string accountDomain)
    {
        Debug.Log("\nAnchorModuleScript.StartAzureSession()");

        //Setup cloudmanager
        //cloudManager.AuthenticationMode = AuthenticationMode.ApiKey;
        //cloudManager.SpatialAnchorsAccountId = accountID;
        //cloudManager.SpatialAnchorsAccountKey = accountKey;
        //cloudManager.SpatialAnchorsAccountDomain = accountDomain;
        // Notify AnchorFeedbackScript
        OnStartASASession?.Invoke();

        Debug.Log("Starting Azure session... please wait...");

        if (cloudManager.Session == null)
        {
            // Creates a new session if one does not exist
            await cloudManager.CreateSessionAsync();
        }

        // Starts the session if not already started
        await cloudManager.StartSessionAsync();

        Debug.Log("Azure session started successfully");
    }
コード例 #5
0
    // Start is called before the first frame update
    async void Start()
    {
        //have to Task Delay at the start in order to give ARSession time to set up properly
        await Task.Delay(3000);

        spatialAnchorManager = GetComponent <SpatialAnchorManager>();
        aRAnchorManager      = FindObjectOfType <ARAnchorManager>();

        //if the session doesn't exist, create session
        if (spatialAnchorManager.Session == null)
        {
            await spatialAnchorManager.CreateSessionAsync();
        }
        //add AnchorLocated event so when the session detects an anchor, it does what we want it to
        spatialAnchorManager.AnchorLocated += CloudAnchorManager_AnchorLocated;
        debugText.text = "\nSession Created";

        //begin the session
        await spatialAnchorManager.StartSessionAsync();

        //request the sesnsor permissions for wifi and geolocation -- then configure
        requestSensorPermissions();
        configureSensors();
        debugText.text += "\nSession Started";
        debugText.text += "\nID: " + spatialAnchorManager.SpatialAnchorsAccountId;
        debugText.text += "\nKey: " + spatialAnchorManager.SpatialAnchorsAccountKey;
    }
コード例 #6
0
    private async void StartAzureSession()
    {
        Debug.Log("\nAnchorModuleScript.StartAzureSession()");
        // Notify AnchorFeedbackScript
        OnStartASASession?.Invoke();

        Debug.Log("Starting Azure session... please wait...");

        if (cloudManager.Session == null)
        {
            // Creates a new session if one does not exist
            await cloudManager.CreateSessionAsync();
        }

        // Starts the session if not already started
        await cloudManager.StartSessionAsync();

        Debug.Log("Azure session started successfully");
    }
コード例 #7
0
 private async void Start()
 {
     try
     {
         await spatialAnchorManager.StartSessionAsync();
     }
     catch (Exception ex)
     {
         Debug.LogError($"Error: {ex.Message}");
     }
 }
コード例 #8
0
    private async void AttemptSetup()
    {
        if (anchorManagerIsSetup)
        {
            return;
        }

        //if the session doesn't exist, create session
        if (spatialAnchorManager.Session == null)
        {
            await spatialAnchorManager.CreateSessionAsync();
        }
        spatialAnchorManager.AnchorLocated += AnchorConverter_AnchorLocated;

        await spatialAnchorManager.StartSessionAsync();

        ConfigureSensors();
        anchorManagerIsSetup = true;
        FindAnchorsByLocation();
    }
コード例 #9
0
        private Task StartSession()
        {
            lock (sessionStartLock)
            {
                if (sessionStartTask == null)
                {
                    sessionStartTask = spatialAnchorManager.StartSessionAsync();
                }
            }

            return(sessionStartTask);
        }
コード例 #10
0
    private async Task InitializeSession()
    {
        Log($"{nameof(InitializeSession)}", true);

#if UNITY_EDITOR
        await Task.Delay(2000); //Mocking the session creation
#else
        Log($"{nameof(InitializeSession)} calling startSessionAsync", true);
        await CloudManager.StartSessionAsync();
#endif
        ReportSessionInitialized();
        IsInitialized = true;
        Log($"{nameof(InitializeSession)} end", true);
    }
コード例 #11
0
    async public Task ResetSession()
    {
        foreach (ARAnchor anchor in aRAnchorManager.trackables)
        {
            aRAnchorManager.RemoveAnchor(anchor);
            Debug.Log("trying to remove anchor: " + anchor.trackableId);
        }
        currentCloudAnchor  = null;
        previousCloudAnchor = null;
        foundAnchors.Clear();
        spatialAnchorManager.StopSession();
        await spatialAnchorManager.ResetSessionAsync();

        await spatialAnchorManager.StartSessionAsync();
    }
コード例 #12
0
    private async void SetupCloudSessionAsync()
    {
        spatialAnchorManager.AnchorLocated += CloudManagerAnchorLocated;

        anchorLocateCriteria = new AnchorLocateCriteria();

        if (spatialAnchorManager.Session == null)
        {
            await spatialAnchorManager.CreateSessionAsync();
        }

        currentAnchorId           = "";
        currentCloudSpatialAnchor = null;
        await spatialAnchorManager.StartSessionAsync();

        appStateManager.currentOutputMessage    = $"Startup OK.  Move camera around to find surfaces, onto which you can place scenery.  Otherwise press 'Restore' to look for previously saved anchor.";
        appStateManager.currentCloudAnchorState = CloudAnchorStateEnum.ReadyToCreateLocalAnchor;
    }
コード例 #13
0
        private async Task InitializeAsync()
        {
            CloudManager.AnchorLocated          += CloudManager_AnchorLocated;
            CloudManager.LocateAnchorsCompleted += (arg1, arg2) => Debug.Log("locate anchors completed");
            //CloudManager.LogDebug += (arg1, arg2) => Debug.Log(arg2.Message);
            CloudManager.Error += (arg1, arg2) => Debug.LogError(arg2.ErrorMessage);

            Debug.LogFormat("Creating session");

            if (CloudManager.Session == null)
            {
                await CloudManager.CreateSessionAsync();

                await Task.Delay(TimeSpan.FromSeconds(1));
            }

            Debug.LogFormat("Session created");

            currentAnchorId    = "";
            currentCloudAnchor = null;

            anchorLocateCriteria = new AnchorLocateCriteria();

            anchorLocateCriteria.Identifiers = new string[0];

            await CloudManager.StartSessionAsync();

            await Task.Delay(TimeSpan.FromSeconds(1));

            Debug.LogFormat("Started session");

            currentWatcher = CreateWatcher();

            Debug.LogFormat("Created watcher");
            Debug.LogFormat("watcher null: {0}", currentWatcher == null);
        }
        private async UniTask DemoRoutine()
        {
            _instructionUIPresenter.UpdateMessage("NearAnchor Demo");
            await _instructionUIPresenter.OnTriggerProceed().First();

            _instructionUIPresenter.UpdateMessage("1.最初に一つ目のアンカーを生成します");
            await _instructionUIPresenter.OnTriggerProceed().First();

            // セッション開始
            await _spatialAnchorManager.StartSessionAsync();

            // 最初のアンカーの生成
            var firstAnchor = await CreateAnchorTask();

            _instructionUIPresenter.UpdateMessage("2.続けて周辺に接続されたアンカーを生成します");
            await _instructionUIPresenter.OnTriggerProceed().First();

            _instructionUIPresenter.UpdateMessage("3.二つ目のアンカーを生成します");
            await _instructionUIPresenter.OnTriggerProceed().First();

            // 周辺のアンカーの生成
            var secondAnchor = await CreateAnchorTask();

            _instructionUIPresenter.UpdateMessage("4.三つ目のアンカーを生成します");
            await _instructionUIPresenter.OnTriggerProceed().First();

            var thirdAnchor = await CreateAnchorTask();

            _instructionUIPresenter.UpdateMessage("5.一度セッションを終了します");
            await _instructionUIPresenter.OnTriggerProceed().First();

            await _spatialAnchorManager.ResetSessionAsync();

            _instructionUIPresenter.UpdateMessage("6.アンカーが配置されていることを確認します");
            await _instructionUIPresenter.OnTriggerProceed().First();

            await GraphAnchorsTask(new[] { firstAnchor, secondAnchor, thirdAnchor }, Color.blue, new Vector3(0.08f, 0.2f, 0.08f));

            _instructionUIPresenter.UpdateMessage("7.もう一度セッションを終了します");
            await _instructionUIPresenter.OnTriggerProceed().First();

            await _spatialAnchorManager.ResetSessionAsync();

            _instructionUIPresenter.UpdateMessage("8.一つ目のアンカーを画像情報から検知します");
            await _instructionUIPresenter.OnTriggerProceed().First();

            var locatedFirstAnchor = (await LocateAnchorsTask(new[] { firstAnchor }, Color.green, new Vector3(0.2f, 0.08f, 0.08f))).ToList();

            Assert.IsTrue(locatedFirstAnchor.Count == 1);

            _instructionUIPresenter.UpdateMessage("9.残り二つのアンカーを接続情報から検知します");
            await _instructionUIPresenter.OnTriggerProceed().First();

            await LocateNearAnchorsTask(locatedFirstAnchor[0], 2);

            _instructionUIPresenter.UpdateMessage("10.セッションを終了します");
            await _instructionUIPresenter.OnTriggerProceed().First();

            _anchorObjectPresenter.CleanAllAnchors();
            _spatialAnchorManager.DestroySession();
        }
コード例 #15
0
 private async Task InitializeSession()
 {
     Log($"{nameof(InitializeSession)}", true);
     await CloudManager.StartSessionAsync();
 }
コード例 #16
0
        private async void CreateAsaAnchor(Transform indicatorTransform)
        {
            Debug.Log("\nAnchorManager.CreateAsaAnchor()");
            anchorCreationController.StartProgressIndicatorSession();

            if (cloudManager.Session == null)
            {
                // Creates a new session if one does not exist
                Debug.Log("await cloudManager.CreateSessionAsync()");
                await cloudManager.CreateSessionAsync();
            }

            // Starts the session if not already started
            Debug.Log("await cloudManager.StartSessionAsync()");
            await cloudManager.StartSessionAsync();

            var anchorPositionIndicator = Instantiate(anchorPositionPrefab, indicatorTransform.position, indicatorTransform.rotation);

            // Create native XR anchor at the location of the object
            anchorPositionIndicator.gameObject.CreateNativeAnchor();
            Debug.Log("anchorPosition.gameObject.CreateNativeAnchor()");

            // Create local cloud anchor
            var localCloudAnchor = new CloudSpatialAnchor();

            // Set the local cloud anchor's position to the native XR anchor's position
            localCloudAnchor.LocalAnchor = anchorPositionIndicator.gameObject.FindNativeAnchor().GetPointer();
            Debug.Log("anchorPosition.gameObject.FindNativeAnchor().GetPointer()");

            // Check to see if we got the local XR anchor pointer
            if (localCloudAnchor.LocalAnchor == IntPtr.Zero)
            {
                Debug.Log("Didn't get the local anchor...");
                return;
            }
            else
            {
                Debug.Log("Local anchor created");
            }

            // Set expiration (when anchor will be deleted from Azure)
            localCloudAnchor.Expiration = DateTimeOffset.Now.AddDays(7);

            // Save anchor to cloud
            while (!cloudManager.IsReadyForCreate)
            {
                await Task.Delay(330);

                var createProgress = cloudManager.SessionStatus.RecommendedForCreateProgress;
                UnityDispatcher.InvokeOnAppThread(() => Debug.Log($"Move your device to capture more environment data: {createProgress:0%}"));
            }
            Debug.Log("cloudManager is ready.");

            try
            {
                // Actually save
                Debug.Log("await cloudManager.CreateAnchorAsync(localCloudAnchor)");
                await cloudManager.CreateAnchorAsync(localCloudAnchor);

                Debug.Log("Anchor created!");

                // Store
                currentCloudAnchor = localCloudAnchor;

                // Success?
                var success = currentCloudAnchor != null;

                if (success)
                {
                    Debug.Log($"Azure anchor with ID '{currentCloudAnchor.Identifier}' created successfully");

                    // Update the current Azure anchor ID
                    Debug.Log($"Current Azure anchor ID updated to '{currentCloudAnchor.Identifier}'");

                    currentTrackedObject.SpatialAnchorId = currentCloudAnchor.Identifier;
                    activeAnchors.Add(currentTrackedObject.SpatialAnchorId, anchorPositionIndicator);
                    // Notify subscribers
                    Debug.Log("OnCreateAnchorSucceeded?.Invoke(this, currentCloudAnchor.Identifier)");
                    AppDispatcher.Instance().Enqueue(() =>
                    {
                        anchorPositionIndicator.Init(currentTrackedObject);
                        currentTrackedObject = null;
                        OnCreateAnchorSucceeded?.Invoke(this, currentCloudAnchor.Identifier);
                    });
                }
                else
                {
                    Debug.Log($"Failed to save cloud anchor with ID '{currentCloudAnchor.Identifier}' to Azure");

                    // Notify subscribers
                    AppDispatcher.Instance().Enqueue(() =>
                    {
                        currentTrackedObject = null;
                        Destroy(anchorPositionIndicator.gameObject);
                        OnCreateAnchorFailed?.Invoke(this, EventArgs.Empty);
                    });
                }
            }
            catch (Exception ex)
            {
                Debug.Log(ex.ToString());
            }

            StopAzureSession();
        }