Modifying the base scene

The next thing we will do is just modify the base scene for our needs. Open up Unity and follow along:

  1. Select and drag the PointCloud object in the Hierarchy window and drop it into the Assets/ARCoreDesign/Prefabs folder in the Project window, as shown in the following excerpt:
Creating a prefab with the PointCloud object
  1. This will create a Prefab of the PointCloud object. Think of a Prefab as a template or almost like a class. Anytime we want to reuse the PointCloud object, we can drag it into a scene or instantiate it.
  2. Select the PointCloud object in the Hierarchy window and type the Delete key. Find it, and click on it. This will delete the object; we don't need it right now.
  3. Rename the ExampleController object in the Hierarchy window to SceneController.
  4. Select the Assets/ARCoreDesign/Scripts folder and from the menu, select Assets | Create | C# Script. Name the script SceneController. Then, double-click on it to open the script in your favorite code editor.
  5. Now, get back to Unity. Enter helloarcontroller in the Project search pane to filter the window to the script. Double-click on the script to open it in your code editor.
  6. Copy the entire HelloARController.cs script and paste it over the contents of the SceneController.cs file; yes, all of it. We are essentially making a copy. Rename your class and change the namespace, like this:
namespace Packt.ARCoreDesign
{
... //code omitted
public class SceneController : MonoBehaviour //rename me
... //code omitted
} // don't forget the closing brace at the end
  1. We wrap all our new code files with a namespace in order to avoid naming conflicts. Naming conflicts happen more frequently in Unity if you use a lot of assets. Generally, if you are new to Unity, you will use a lot of third-party assets.
  2. Make sure that all the following new using statements are identified, as follows:
 using System.Collections.Generic;
using GoogleARCore;
using UnityEngine;
using UnityEngine.Rendering;
using GoogleARCore.HelloAR;

#if UNITY_EDITOR
using Input = GoogleARCore.InstantPreviewInput;
#endif
  1. Save the file and return to Unity. Be sure to watch for any compiler errors.
  2. Select the SceneController object in the Hierarchy window and click on the Add Component button in the Inspector window.
  3. Enter scene in the search pane and then select the Scene Controller script, as shown in the following excerpt:
Adding the Scene Controller script as a component
  1. Click on the bullseye icon to set the properties for the Scene Controller. Ensure that they match Hello AR Controller (Script). When all the properties match, click on the Gear icon beside the Hello AR Controller (Script) and select Remove Component from the context menu. You should now be left with just the Scene Controller (Scene) component with the same properties set.
  2. Connect, build, and run the app on your device. If you encounter any issues, check for compiler errors and ensure that you set up the components correctly.

We can, of course, create duplicates for all the main scripts, but this will work for now. Obviously, we have a lot more work to do, but this is a good place to start. Ensure that you save the scene and your project. In the next section, we will look to change the content which we allow our user to place and choose where to place.

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

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