The UpdateOrAddPlaneNode() method does exactly what the name implies: it takes an ARPlaneAnchor as an argument and either updates or adds a new PlaneNode instance to the scene. Let's set this up by going through the following steps:
- In the WhackABox.iOS project, open the Game.cs file.
- Add the UpdateOrAddPlaneNode() method, as shown in the following code block:
private void UpdateOrAddPlaneNode(ARPlaneAnchor anchor)
{
var node = FindNodeByPlaneId(anchor.Identifier.ToString());
if (node == null)
{
node = new PlaneNode()
{
PlaneId = anchor.Identifier.ToString(),
Name = $"plane{anchor.GetHashCode()}"
};
CreateSubPlane(node);
scene.AddChild(node);
}
SetPositionAndRotation(anchor, node);
}
A node is either already present in the scene or it needs to be added. The first line of code calls the FindNodeByPlaneId() method to query the scene for an object with the given...