Migrate Sample SpatialMap_Sparse_Localizing to 4000.0

Replace Plugin Package

  1. Close Unity.

  2. Delete Unity’s platform build directories generated by the editor (for example, the Android Gradle project directory and the iOS Xcode directory), or delete the entire Library folder.

  3. Reopen the Unity project and remove the old version of EasyAR Sense Unity Plugin from the project.

../../_images/image_u1_1.png
  1. Import EasyAR Sense Unity Plugin version 4000.0.

../../_images/image_u1_2.png

Rebuild Scene(Required): Prepare for New Features

Recreate AR Session (EasyAR) in the scene.

../../_images/image_u3_3.png ../../_images/image_u3_4.png

Recreate Sparse SpatialMap in the scene.

../../_images/image_u3_6.png ../../_images/image_u3_7.png

In the Inspector window of the Sparse SpatialMap Controller component, fill in the ID and Name of the sparse map, and specify the Tracker.

../../_images/image_u3_8.png

Reassign ARSession in the Sample script to the newly created AR Session (EasyAR).

../../_images/image_u3_5.png

Reassign MapController in the Sample script to the newly created Sparse SpatialMap Controller.

../../_images/image_u3_9.png

Modify Incompatible Code:

../../_images/image_u3_1.png ../../_images/image_u3_2.png

In Start, remove the code that prints Status, and update the localization callbacks for the local sparse map to MapController.TargetFound and MapController.TargetLost according to the new API.

private void Start()
{
    var launcher = "AllSamplesLauncher";
    if (Application.CanStreamedLevelBeLoaded(launcher))
    {
        var button = BackButton.GetComponent<Button>();
        button.onClick.AddListener(() => { UnityEngine.SceneManagement.SceneManager.LoadScene(launcher); });
    }
    else
    {
        BackButton.gameObject.SetActive(false);
    }

    sparse = Session.GetComponentInChildren<SparseSpatialMapWorkerFrameFilter>();

    MapController.TargetFound += () =>
    {
        Debug.Log($"Found target {{name = {MapController.Info.Name}}}");
    };

    MapController.TargetLost += () =>
    {
        if (!MapController) { return; }
        Debug.Log($"Lost target {{name = {MapController.Info.Name}}}");
    };
}

In Update, use the new API to check if the local sparse map exists and is being tracked directly.

private void Update()
{
    if (Input.touchCount == 1 && !EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId))
    {
        var touch = Input.touches[0];
        if (touch.phase == TouchPhase.Moved)
        {
            var viewPoint = new Vector2(touch.position.x / Screen.width, touch.position.y / Screen.height);
            if (MapController && MapController.IsDirectlyTracked)
            {
                var points = MapController.HitTest(viewPoint);
                foreach (var point in points)
                {
                    onSparse = true;
                    TouchControl.transform.position = MapController.transform.TransformPoint(point);
                    break;
                }
            }
        }
    }
}

The sample is now fully functional with the 4000.0 plugin.