コード例 #1
0
        async void CreateSecondaryTile()
        {
            rootPage.NotifyUser("", NotifyType.StatusMessage);

            if (glbUri == null)
            {
                rootPage.NotifyUser("Please pick content to be shown.", NotifyType.ErrorMessage);
                return;
            }

            // Create a guid to use as a unique tile id
            string tileId = GenerateTileId();

            var logoUri = new Uri("ms-appx:///Assets/squareTile-sdk.png");
            var tile    = new SecondaryTile(
                tileId,                  // TileId
                glbName,                 // Display Name
                tileId,                  // Arguments
                logoUri,                 // Square150x150Logo
                TileSize.Square150x150); // DesiredSize

            // Set the mixed reality model properties.
            TileMixedRealityModel model = tile.VisualElements.MixedRealityModel;

            model.Uri = glbUri;

            if (BoundingBoxCheckBox.IsChecked.Value)
            {
                var boundingBox = new SpatialBoundingBox();
                boundingBox.Center = new Vector3(
                    ParseFloatOrDefault(BoundingBoxCenterXTextBox.Text),
                    ParseFloatOrDefault(BoundingBoxCenterYTextBox.Text),
                    ParseFloatOrDefault(BoundingBoxCenterZTextBox.Text));
                boundingBox.Extents = new Vector3(
                    ParseFloatOrDefault(BoundingBoxExtentsXTextBox.Text),
                    ParseFloatOrDefault(BoundingBoxExtentsYTextBox.Text),
                    ParseFloatOrDefault(BoundingBoxExtentsZTextBox.Text));
                model.BoundingBox = boundingBox;
            }

            // Create the tile
            bool created = await tile.RequestCreateAsync();

            if (created)
            {
                // Warn the user that they need to be in the headset for anything interesting to happen.
                if (!HolographicApplicationPreview.IsCurrentViewPresentedOnHolographicDisplay())
                {
                    rootPage.NotifyUser("3D content can be created only while the view is being displayed in a Mixed Reality headset.", NotifyType.StatusMessage);
                }
            }
            else
            {
                rootPage.NotifyUser("Could not create secondary tile.", NotifyType.ErrorMessage);
            }
        }
コード例 #2
0
        async void CreateSecondaryTile()
        {
            // Warn the user that they need to be in the headset for anything interesting to happen.
            if (!HolographicApplicationPreview.IsCurrentViewPresentedOnHolographicDisplay())
            {
                ContentDialog dialog = new ContentDialog()
                {
                    Title           = "Secondary Tile",
                    Content         = "3D content can be created only while the view is being displayed in a Mixed Reality headset.",
                    CloseButtonText = "Ok",
                };
                await dialog.ShowAsync();

                return;
            }

            try
            {
                if (glbPath == null && !await SelectGlb())
                {
                    return;
                }

                // Create a guid to use as a unique tile id
                string tileId = GenerateTileId();

                var logoUri = new Uri("ms-appx:///assets/Square150x150Logo.png");

                var tile = new SecondaryTile(
                    tileId,                  // TileId
                    glbPath.Name,            // DisplayName
                    tileId,                  // Arguments
                    logoUri,                 // Square150x150Logo
                    TileSize.Square150x150); // DesiredSize

                TileMixedRealityModel model = tile.VisualElements.MixedRealityModel;

                var tcs = new TaskCompletionSource <string>();

                var copiedPath = await CopyAssetToLocalAppData();

                if (String.IsNullOrEmpty(copiedPath))
                {
                    return;
                }

                model.Uri = new Uri(copiedPath);

                if (CreateWithBoundingBox)
                {
                    var boundingBoxCenterFloats  = BoundingBoxCenter.Split(',').Select(s => ParseWithDefault(s, 0f)).ToArray();
                    var boundingBoxExtentsFloats = BoundingBoxExtents.Split(',').Select(s => ParseWithDefault(s, 1f)).ToArray();

                    var boundingBox = new SpatialBoundingBox();
                    if (boundingBoxCenterFloats.Length == 3)
                    {
                        boundingBox.Center = new Vector3(boundingBoxCenterFloats[0], boundingBoxCenterFloats[1], boundingBoxCenterFloats[2]);
                    }
                    if (boundingBoxExtentsFloats.Length == 3)
                    {
                        boundingBox.Extents = new Vector3(boundingBoxExtentsFloats[0], boundingBoxExtentsFloats[1], boundingBoxExtentsFloats[2]);
                    }

                    model.BoundingBox = boundingBox;
                }

                if (DoNotActivate)
                {
                    model.ActivationBehavior = TileMixedRealityModelActivationBehavior.None;
                }

                // Commit the tile
                bool created = await tile.RequestCreateAsync();

                if (!created)
                {
                    ContentDialog dialog = new ContentDialog()
                    {
                        Title           = "Secondary Tile",
                        Content         = "Creation denied",
                        CloseButtonText = "Ok",
                    };
                    await dialog.ShowAsync();
                }
            }
            catch
            {
                ContentDialog dialog = new ContentDialog()
                {
                    Title           = "Secondary Tile",
                    Content         = "Failed to create",
                    CloseButtonText = "Ok",
                };
                await dialog.ShowAsync();
            }
        }