Switching between AR Mode

The first thing we'll do is provide an easy way for users to toggle views of the app between conventional 2D views to a 3D AR view by adding an AR Mode button on the bottom of the screen. We have decided a 50 pixel height, to be consistent with the nav bar at top.

Make room for it on the bottom by shortening the Content Scroll View:

  1. In Hierarchy, select the Content Scroll View (under Main Canvas).
  2. On its Rect Transform, set Bottom to 50.
  3. Now to add a new button to the Main Canvas; select it, go to UI | Button, and rename it AR Button.
  4. Set Height to 50.

 

  1. For Anchor Presets, set Bottom/Stretch and then also Alt+click the same to move it into position.
  2. Set Source Image to none and Color the same as the Nav Panel: 74, 182, 208, 255 (#4AB6D0FF).

The following screenshot shows us setting the Anchor Presets for the AR Button:

Next, edit its child text with the following values:

  1. Text: AR Mode.
  2. Font Size: 25.
  3. Color: White (#FFFFFFFF).

The new button should look something like this on the bottom of the screen:

As we did a few moments ago to verify the AR Camera video feed, when one presses the AR View button we want to hide the 2D content. Edit the InstructionsController.cs script to provide a ToggleAr() function.

First, we declare we're using Vuforia:

using vuforia; 

And then define a public variable for the Content panel; we named it StandardContent. Add a private variable to track the current mode:

    public GameObject standardContent; 
    private bool arMode; 

The we add the code to toggle the AR mode; at this point we're just hiding or showing the 2D panel:

    public void ToggleAr() { 
        arMode = !arMode; 
        if (arMode) { 
            TurnOnArMode(); 
        } else { 
            TurnOffArMode(); 
        } 
    } 
 
    void TurnOnArMode() { 
        standardContent.SetActive(false); 
    } 
 
    void TurnOffArMode() { 
        standardContent.SetActive(true); 
    } 

Save your changes. Then continue in Unity as follows:

  1. Select Game Controller and drag the Content Scroll View object onto the Standard Content slot.
  2. Select the AR Button and add the OnClick event.
  3. Press the + in the OnClick list.
  4. Drag the Game Controller to the Object slot, and then choose the function InstructionsController.ToggleAr().

When you press Play you can toggle between the 2D content and the video feed on the screen.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset