Migrate Sample SpatialMap_Sparse_Building to 4000.0¶
Replace Plugin Package¶
Close Unity.
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.
Reopen the Unity project and remove the old version of EasyAR Sense Unity Plugin from the project.
Import EasyAR Sense Unity Plugin version 4000.0.
Modify Incompatible Code: Minimum to get running¶
Replace SparseSpatialMapWorkerFrameFilter with SparseSpatialMapBuilderFrameFilter in the original MapBuilding_SparseSample script.
private SparseSpatialMapBuilderFrameFilter sparse;
In Awake, update the code to get SparseSpatialMapBuilderFrameFilter .
Session.StateChanged += (state) =>
{
if (state == ARSession.SessionState.Ready)
{
sparse = Session.Assembly.FrameFilters.Where(f => f is SparseSpatialMapBuilderFrameFilter).FirstOrDefault() as SparseSpatialMapBuilderFrameFilter;
TouchControl.TurnOn(TouchControl.gameObject.transform, Session.Assembly.Camera, false, false, true, false);
}
};
In Update, remove the code that prints Status, and update the reference to the local sparse map to sparse.Target according to the new API.
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 (sparse && sparse.Target)
{
var points = sparse.Target.HitTest(viewPoint);
foreach (var point in points)
{
TouchControl.transform.position = sparse.Target.transform.TransformPoint(point);
break;
}
}
}
}
}
The sample is now functional.
Rebuild Scene: Prepare for New Features¶
Delete the Sparse SpatialMap node in the scene.
Recreate AR Session (EasyAR) in the scene.
Reassign ARSession in the Sample script to the newly created AR Session (EasyAR).
The sample is now fully functional with the 4000.0 plugin.