コード例 #1
0
    private void ConfigureSensors()
    {
        PlatformLocationProvider sensorProvider = new PlatformLocationProvider();

        spatialAnchorManager.Session.LocationProvider = sensorProvider;
        sensorProvider.Sensors.GeoLocationEnabled     = CheckLocationPermissions();
    }
コード例 #2
0
        public static void EnableAllowedSensors(Context context, PlatformLocationProvider locationProvider)
        {
            // Retrieve permissions granted by the user
            bool hasFineLocationPermission         = HasPermission(context, Manifest.Permission.AccessFineLocation);
            bool hasAccessCoarseLocationPermission = HasPermission(context, Manifest.Permission.AccessCoarseLocation);
            bool hasAnyLocationPermission          = hasFineLocationPermission || hasAccessCoarseLocationPermission;
            bool hasAccessWifiStatePermission      = HasPermission(context, Manifest.Permission.AccessWifiState);
            bool hasChangeWifiStatePermission      = HasPermission(context, Manifest.Permission.ChangeWifiState);
            bool hasBluetoothPermission            = HasPermission(context, Manifest.Permission.Bluetooth);
            bool hasBluetoothAdminPermission       = HasPermission(context, Manifest.Permission.BluetoothAdmin);

            // Try to turn on Wi-Fi, if allowed
            bool isWifiAllowed = hasAnyLocationPermission &&
                                 hasAccessWifiStatePermission &&
                                 hasChangeWifiStatePermission;
            bool isWifiOn = isWifiAllowed && TryTurnOnWifi(context);

            // Try to turn on Bluetooth, if allowed
            bool isBluetoothAllowed = hasAnyLocationPermission &&
                                      hasBluetoothPermission &&
                                      hasBluetoothAdminPermission;
            bool isBluetoothOn = isBluetoothAllowed && TryTurnOnBluetooth();

            // Configure location provider to use the allowed sensors
            var sensors = locationProvider.Sensors;

            sensors.GeoLocationEnabled = hasAnyLocationPermission;
            sensors.WifiEnabled        = isWifiOn;
            sensors.BluetoothEnabled   = isBluetoothOn;
        }
コード例 #3
0
    private void SetSessionForCoarseRelocalization()
    {
        // Set Sensor info
        LocationProvider = new PlatformLocationProvider();

        cloudManager.Session.LocationProvider       = LocationProvider;
        LocationProvider.Sensors.GeoLocationEnabled =
            AppController.AppSettings.useGeoLocation &&
            SensorPermissionHelper.HasGeoLocationPermission();

        LocationProvider.Sensors.WifiEnabled =
            AppController.AppSettings.useWifi &&
            SensorPermissionHelper.HasWifiPermission();

        LocationProvider.Sensors.BluetoothEnabled =
            AppController.AppSettings.useBluetooth &&
            SensorPermissionHelper.HasBluetoothPermission();

        LocationProvider.Sensors.KnownBeaconProximityUuids = coarseRelocalizationSettings.KnownBeaconProximityUuids;

        //Debug.Log($"WifiEnabled={LocationProvider.Sensors.WifiEnabled}");
        //Debug.Log($"BluetoothEnabled={LocationProvider.Sensors.BluetoothEnabled}");

        foreach (var uuid in coarseRelocalizationSettings.KnownBeaconProximityUuids)
        {
            Debug.Log($"KnownBeaconProximityUuids={uuid}");
        }
    }
コード例 #4
0
        public async override Task SaveAnchorAsync()
        {
            CloudManager.StopSession();
            await CloudManager.ResetSessionAsync();

            locationProvider = null;
            currentAppState  = AppState.Menu;
        }
コード例 #5
0
    private void configureSensors()
    {
        PlatformLocationProvider sensorProvider = new PlatformLocationProvider();

        spatialAnchorManager.Session.LocationProvider = sensorProvider;
        //TODO: switch these values to equal the granted perissions instead of assuming true
        sensorProvider.Sensors.GeoLocationEnabled = true;
        sensorProvider.Sensors.WifiEnabled        = false;
        sensorProvider.Start();
    }
コード例 #6
0
        public async override Task StartWatcherAsync()
        {
            ConfigureSession();
            await CloudManager.StartSessionAsync();

            locationProvider = new PlatformLocationProvider();
            CloudManager.Session.LocationProvider = locationProvider;
            ConfigureSensors();

            currentWatcher = CreateWatcher();

            currentAppState = AppState.StartWatcher;
        }
コード例 #7
0
        protected override void OnPause()
        {
            sensorStatusView.Model = null;

            if (cloudAnchorManager != null)
            {
                cloudAnchorManager.StopSession();
                cloudAnchorManager = null;
            }
            locationProvider = null;

            base.OnPause();
        }
コード例 #8
0
        public async override Task CreateAnchorAsync()
        {
            currentCloudAnchor = null;

            ConfigureSession();
            await CloudManager.StartSessionAsync();

            locationProvider = new PlatformLocationProvider();
            CloudManager.Session.LocationProvider = locationProvider;

            ConfigureSensors();

            currentAppState = AppState.CreateAnchor;
        }
コード例 #9
0
        private void CreateLocationProvider()
        {
            locationProvider = new PlatformLocationProvider();

            // Register known Bluetooth beacons
            locationProvider.Sensors.KnownBeaconProximityUuids =
                CoarseRelocSettings.KnownBluetoothProximityUuids;

            // Display the sensor status
            var sensorStatus = new LocationProviderSensorStatus(locationProvider);

            sensorStatusView.Model = sensorStatus;

            EnableAllowedSensors();
        }
コード例 #10
0
        public async void ReturnToLauncher()
        {
            if (currentAppState == AppState.StartWatcher)
            {
                if (currentWatcher != null)
                {
                    currentWatcher.Stop();
                    currentWatcher = null;
                }
                currentWatcher = null;
            }
            CloudManager.StopSession();
            await CloudManager.ResetSessionAsync();

            locationProvider = null;
            currentAppState  = AppState.Menu;
        }
コード例 #11
0
    // Update is called once per frame
    void Update()
    {
        timer += Time.deltaTime;
        if (timer > Interval)
        {
            timer = 0f;
        }
        try
        {
            if (Icon == null)
            {
                return;
            }
            if (AnchorModule?.LocationProvider == null)
            {
                Icon.color = MissingProviderColor;
                return;
            }

            locationProvider = AnchorModule.LocationProvider;

            switch (SensorType)
            {
            case Sensor.GeoLocation:
                //Debug.Log($"GeoLocationStatus={GeoLocationStatus}");
                UpdateColor(GeoLocationStatus);
                break;

            case Sensor.Wifi:
                //Debug.Log($"WifiStatus={WifiStatus}");
                UpdateColor(WifiStatus);
                break;

            case Sensor.Bluetooth:
                //Debug.Log($"BluetoothStatus={BluetoothStatus}");
                UpdateColor(BluetoothStatus);
                break;
            }
        }
        catch (Exception e)
        {
            Debug.Log($"{e.GetType().Name}:{e.Message}");
            Debug.Log("ここにキタ━━━━(゚∀゚)━━━━!!");
        }
    }
コード例 #12
0
        protected override void OnResume()
        {
            base.OnResume();

            // ArFragment of Sceneform automatically requests the camera permission before creating the AR session,
            // so we don't need to request the camera permission explicitly.
            // This will cause onResume to be called again after the user responds to the permission request.
            if (!SceneformHelper.HasCameraPermission(this))
            {
                return;
            }

            if (sceneView?.Session is null && !SceneformHelper.TrySetupSessionForSceneView(this, sceneView))
            {
                // Exception will be logged and SceneForm will handle any ARCore specific issues.
                Finish();
                return;
            }

            if (string.IsNullOrWhiteSpace(AccountDetails.SpatialAnchorsAccountId) || AccountDetails.SpatialAnchorsAccountId == "Set me" ||
                string.IsNullOrWhiteSpace(AccountDetails.SpatialAnchorsAccountKey) || AccountDetails.SpatialAnchorsAccountKey == "Set me" ||
                string.IsNullOrWhiteSpace(AccountDetails.SpatialAnchorsAccountDomain) || AccountDetails.SpatialAnchorsAccountDomain == "Set me")
            {
                Toast.MakeText(this, $"\"Set {AccountDetails.SpatialAnchorsAccountId}, {AccountDetails.SpatialAnchorsAccountKey}, and {AccountDetails.SpatialAnchorsAccountDomain} in {nameof(AccountDetails)}.cs\"", ToastLength.Long)
                .Show();

                Finish();
                return;
            }

            SensorPermissionsHelper.RequestMissingPermissions(this);

            cloudAnchorManager = new AzureSpatialAnchorsManager(sceneView.Session);
            cloudAnchorManager.StartSession();

            locationProvider = new PlatformLocationProvider();
            locationProvider.Sensors.SetKnownBeaconProximityUuids(CoarseRelocSettings.KnownBluetoothProximityUuids);
            SensorPermissionsHelper.EnableAllowedSensors(this, locationProvider);
            cloudAnchorManager.LocationProvider = locationProvider;

            sensorStatusView.Model = new LocationProviderSensorStatus(locationProvider);
        }
コード例 #13
0
        public async override Task AdvanceDemoAsync()
        {
            switch (currentAppState)
            {
            case AppState.DemoStepCreateSession:
                if (CloudManager.Session == null)
                {
                    await CloudManager.CreateSessionAsync();
                }
                currentCloudAnchor = null;
                currentAppState    = AppState.DemoStepConfigSession;
                break;

            case AppState.DemoStepConfigSession:
                ConfigureSession();
                currentAppState = AppState.DemoStepStartSession;
                break;

            case AppState.DemoStepStartSession:
                await CloudManager.StartSessionAsync();

                currentAppState = AppState.DemoStepCreateLocationProvider;
                break;

            case AppState.DemoStepCreateLocationProvider:
                locationProvider = new PlatformLocationProvider();
                CloudManager.Session.LocationProvider = locationProvider;
                currentAppState = AppState.DemoStepConfigureSensors;
                break;

            case AppState.DemoStepConfigureSensors:
                SensorPermissionHelper.RequestSensorPermissions();
                ConfigureSensors();
                currentAppState = AppState.DemoStepCreateLocalAnchor;
                break;

            case AppState.DemoStepCreateLocalAnchor:
                if (spawnedObject != null)
                {
                    currentAppState = AppState.DemoStepSaveCloudAnchor;
                }
                break;

            case AppState.DemoStepSaveCloudAnchor:
                currentAppState = AppState.DemoStepSavingCloudAnchor;
                await SaveCurrentObjectAnchorToCloudAsync();

                break;

            case AppState.DemoStepStopSession:
                CloudManager.StopSession();
                CleanupSpawnedObjects();
                await CloudManager.ResetSessionAsync();

                locationProvider = null;
                currentAppState  = AppState.DemoStepCreateSessionForQuery;
                break;

            case AppState.DemoStepCreateSessionForQuery:
                ConfigureSession();
                locationProvider = new PlatformLocationProvider();
                CloudManager.Session.LocationProvider = locationProvider;
                ConfigureSensors();
                currentAppState = AppState.DemoStepStartSessionForQuery;
                break;

            case AppState.DemoStepStartSessionForQuery:
                await CloudManager.StartSessionAsync();

                currentAppState = AppState.DemoStepLookForAnchorsNearDevice;
                break;

            case AppState.DemoStepLookForAnchorsNearDevice:
                currentAppState = AppState.DemoStepLookingForAnchorsNearDevice;
                currentWatcher  = CreateWatcher();
                break;

            case AppState.DemoStepLookingForAnchorsNearDevice:
                break;

            case AppState.DemoStepStopWatcher:
                if (currentWatcher != null)
                {
                    currentWatcher.Stop();
                    currentWatcher = null;
                }
                currentAppState = AppState.DemoStepStopSessionForQuery;
                break;

            case AppState.DemoStepStopSessionForQuery:
                CloudManager.StopSession();
                currentWatcher   = null;
                locationProvider = null;
                currentAppState  = AppState.DemoStepComplete;
                break;

            case AppState.DemoStepComplete:
                currentCloudAnchor = null;
                currentAppState    = AppState.DemoStepCreateSession;
                CleanupSpawnedObjects();
                break;

            default:
                Debug.Log("Shouldn't get here for app state " + currentAppState.ToString());
                break;
            }
        }
        public async override Task AdvanceDemoAsync()
        {
            switch (currentAppState)
            {
            case AppState.DemoStepCreateSession:
                if (CloudManager.Session == null)
                {
                    await CloudManager.CreateSessionAsync();
                }
                currentCloudAnchor = null;
                currentAppState    = AppState.DemoStepConfigSession;
                break;

            case AppState.DemoStepConfigSession:
                ConfigureSession();
                currentAppState = AppState.DemoStepStartSession;
                break;

            case AppState.DemoStepStartSession:
                await CloudManager.StartSessionAsync();

                currentAppState = AppState.DemoStepCreateLocationProvider;
                break;

            case AppState.DemoStepCreateLocationProvider:
                locationProvider = new PlatformLocationProvider();
                CloudManager.Session.LocationProvider = locationProvider;
                currentAppState = AppState.DemoStepConfigureSensors;
                break;

            case AppState.DemoStepConfigureSensors:
                SensorPermissionHelper.RequestSensorPermissions();
                ConfigureSensors();
                currentAppState = AppState.DemoStepCreateLocalAnchor;
                // Enable advancing to next step on Air Tap, which is an easier interaction for placing the anchor.
                // (placing the anchor with Air tap automatically advances the demo).
                enableAdvancingOnSelect = true;
                break;

            case AppState.DemoStepCreateLocalAnchor:
                if (spawnedObject != null)
                {
                    currentAppState = AppState.DemoStepSaveCloudAnchor;
                }
                enableAdvancingOnSelect = false;
                break;

            case AppState.DemoStepSaveCloudAnchor:
                currentAppState = AppState.DemoStepSavingCloudAnchor;
                await SaveCurrentObjectAnchorToCloudAsync();

                break;

            case AppState.DemoStepStopSession:
                CloudManager.StopSession();
                CleanupSpawnedObjects();
                await CloudManager.ResetSessionAsync();

                locationProvider = null;
                currentAppState  = AppState.DemoStepCreateSessionForQuery;
                break;

            case AppState.DemoStepCreateSessionForQuery:
                ConfigureSession();
                locationProvider = new PlatformLocationProvider();
                CloudManager.Session.LocationProvider = locationProvider;
                ConfigureSensors();
                currentAppState = AppState.DemoStepStartSessionForQuery;
                break;

            case AppState.DemoStepStartSessionForQuery:
                await CloudManager.StartSessionAsync();

                currentAppState = AppState.DemoStepLookForAnchorsNearDevice;
                break;

            case AppState.DemoStepLookForAnchorsNearDevice:
                currentAppState = AppState.DemoStepLookingForAnchorsNearDevice;
                currentWatcher  = CreateWatcher();
                break;

            case AppState.DemoStepLookingForAnchorsNearDevice:
                break;

            case AppState.DemoStepStopWatcher:
                if (currentWatcher != null)
                {
                    currentWatcher.Stop();
                    currentWatcher = null;
                }
                currentAppState = AppState.DemoStepStopSessionForQuery;
                break;

            case AppState.DemoStepStopSessionForQuery:
                CloudManager.StopSession();
                currentWatcher   = null;
                locationProvider = null;
                currentAppState  = AppState.DemoStepComplete;
                break;

            case AppState.DemoStepComplete:
                currentCloudAnchor = null;
                currentAppState    = AppState.DemoStepCreateSession;
                CleanupSpawnedObjects();
                break;

            default:
                Debug.Log("Shouldn't get here for app state " + currentAppState.ToString());
                break;
            }
        }
 public LocationProviderSensorStatus(PlatformLocationProvider locationProvider)
 {
     this.locationProvider = locationProvider;
 }
コード例 #16
0
        public override void MainButtonTap()
        {
            if (ignoreMainButtonTaps)
            {
                return;
            }

            switch (step)
            {
            case DemoStep.Start:
            {
                UpdateMainStatusTitle("Tap to start Session");
                step = DemoStep.CreateAnchor;
                CreateLocationProvider();
                break;
            }

            case DemoStep.CreateAnchor:
            {
                ignoreMainButtonTaps   = true;
                currentlyPlacingAnchor = true;
                saveCount = 0;

                StartSession();
                AttachLocationProviderToSession();

                // When you tap on the screen, touchesBegan will call createLocalAnchor and create a local ARAnchor.
                // We will then put that anchor in the anchorVisuals dictionary with a special key and call CreateCloudAnchor when there is enough data for saving.
                // CreateCloudAnchor will call OnCloudAnchorCreated when its async method returns to move to the next step.
                UpdateMainStatusTitle("Tap on the screen to create an Anchor ☝️");
                break;
            }

            case DemoStep.LocateNearbyAnchors:
            {
                ignoreMainButtonTaps = true;
                StopSession();
                StartSession();
                AttachLocationProviderToSession();
                LookForAnchorsNearDevice();
                break;
            }

            case DemoStep.StopWatcher:
            {
                step = DemoStep.StopSession;
                nearDeviceWatcher?.Stop();
                nearDeviceWatcher = null;
                UpdateMainStatusTitle("Tap to stop Session and return to the main menu");
                break;
            }

            case DemoStep.StopSession:
            {
                StopSession();
                locationProvider       = null;
                sensorStatusView.Model = null;
                MoveToMainMenu();
                break;
            }

            default:
            {
                ShowLogMessage("Demo has somehow entered an invalid state", SubView.ErrorView);
                break;
            }
            }
        }
        private async Task LocateAnchorsDemoAsync()
        {
            switch (currentAppState)
            {
            case AppState.DemoStepCreateSessionForQuery:
                CleanupSpawnedObjects();
                currentCloudAnchor = null;
                if (CloudManager.Session == null)
                {
                    await CloudManager.CreateSessionAsync();

                    ConfigureSession();
                    await CloudManager.StartSessionAsync();
                }
                else
                {
                    CloudManager.StopSession();
                    await CloudManager.ResetSessionAsync();

                    ConfigureSession();
                }
                locationProvider = new PlatformLocationProvider();
                CloudManager.Session.LocationProvider = locationProvider;
                SensorPermissionHelper.RequestSensorPermissions();
                ConfigureSensors();
                currentAppState = AppState.DemoStepLookForAnchorsNearDevice;
                break;

            case AppState.DemoStepLookForAnchorsNearDevice:
                currentAppState = AppState.DemoStepLookingForAnchorsNearDevice;
                currentWatcher  = CreateWatcher();
                break;

            case AppState.DemoStepLookingForAnchorsNearDevice:
                break;

            case AppState.DemoStepStopWatcher:
                if (currentWatcher != null)
                {
                    currentWatcher.Stop();
                    currentWatcher = null;
                }
                break;

            case AppState.DemoStepStopSessionForQuery:
                CloudManager.StopSession();
                currentWatcher   = null;
                locationProvider = null;
                currentAppState  = AppState.DemoStepComplete;
                break;

            case AppState.DemoStepComplete:
                currentCloudAnchor = null;
                currentAppState    = AppState.DemoStepSettingMode;
                CleanupSpawnedObjects();
                break;

            default:
                Debug.Log("Shouldn't get here for app state " + currentAppState.ToString());
                break;
            }
        }
        private async Task CreateAnchorsDemoAsync()
        {
            switch (currentAppState)
            {
            case AppState.DemoStepCreateSession:
                CleanupSpawnedObjects();
                currentCloudAnchor = null;
                if (CloudManager.Session == null)
                {
                    await CloudManager.CreateSessionAsync();

                    ConfigureSession();
                    await CloudManager.StartSessionAsync();
                }
                else
                {
                    CloudManager.StopSession();
                    await CloudManager.ResetSessionAsync();

                    ConfigureSession();
                }
                locationProvider = new PlatformLocationProvider();
                CloudManager.Session.LocationProvider = locationProvider;

                SensorPermissionHelper.RequestSensorPermissions();
                ConfigureSensors();
                currentAppState = AppState.DemoStepCreateLocalAnchor;
                break;

            case AppState.DemoStepCreateLocalAnchor:
                if (spawnedObject != null)
                {
                    currentAppState = AppState.DemoStepSettingExplanationText;
                }

                break;

            case AppState.DemoStepSettingExplanationText:
                keyboardInputHelper = spawnedObject.GetComponentInChildren <SystemKeyboardInputHelper>();
                if (keyboardInputHelper != null && !string.IsNullOrEmpty(keyboardInputHelper.text))
                {
                    explanationText = new Dictionary <string, string>();
                    explanationText.Add("Explanation", keyboardInputHelper.text);
                    keyboardInputHelper = null;
                    currentAppState     = AppState.DemoStepSaveCloudAnchor;
                }
                break;

            case AppState.DemoStepSaveCloudAnchor:
                currentAppState = AppState.DemoStepSavingCloudAnchor;
                await SaveCurrentObjectAnchorToCloudAsync();

                currentAppState    = AppState.DemoStepReplay;
                spawnedObject      = null;
                currentCloudAnchor = null;
                break;

            case AppState.DemoStepReplay:
                break;

            case AppState.DemoStepStopSession:
                CloudManager.StopSession();
                CleanupSpawnedObjects();
                await CloudManager.ResetSessionAsync();

                locationProvider = null;
                currentAppState  = AppState.DemoStepComplete;
                break;

            case AppState.DemoStepComplete:
                currentCloudAnchor = null;
                currentAppState    = AppState.DemoStepSettingMode;
                CleanupSpawnedObjects();
                break;
            }
        }