We've now come to the last part of the iOS-specific code, which is where we initialize ARKit. This method is called InitializeAR() and takes no parameters. It's defined as an abstract method in the Game base class and must be implemented by the Game class defined in the iOS project.
The code to initialize ARKit is straightforward, and the ARKitComponent class does a lot of work for us. Let's set it up by going through the following steps:
- In the WhackABox.iOS project, open the Game.cs file.
- Add the InitializeAR() method anywhere in the class, as shown in the following code block:
protected override void InitializeAR()
{
arkitComponent = scene.CreateComponent<ARKitComponent>();
arkitComponent.Orientation =
UIKit.UIInterfaceOrientation.Portrait;
arkitComponent.ARConfiguration = new
ARWorldTrackingConfiguration
{
PlaneDetection = ARPlaneDetection.Horizontal
};
arkitComponent.DidAddAnchors += OnAddAnchor;
...