Home > Software engineering >  Passing IMars interface as parameter to method using Unity MARS plugin
Passing IMars interface as parameter to method using Unity MARS plugin

Time:10-17

I'm trying to Impliment body tracking uning Unity's MARS plugin using API given by mars plugin called IProvidesMarsBodyTracking. Below is script that inherits interface and Monobehaviour.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.MARS.Providers;
using System;
using Unity.MARS.Data;

public class BodyTrackManager : MonoBehaviour, IProvidesMarsBodyTracking
{
    public event Action<IMarsBody> BodyAdded;
    public event Action<IMarsBody> BodyUpdated;
    public event Action<IMarsBody> BodyRemoved;

    [SerializeField] GameObject marsBody;

    public void ConnectSubscriber(object obj)
    {
        throw new NotImplementedException();
    }

    public void GetBodies(List<IMarsBody> bodies)
    {
        BodyAdded  = BodyTrackManager_BodyAdded;
        Debug.Log("Test");
    }

    private void BodyTrackManager_BodyAdded(IMarsBody obj)
    {
        marsBody.transform.position = obj.BodyPose.bodyPosition;
        marsBody.SetActive(true);
    }

    public void LoadProvider()
    {
        throw new NotImplementedException();
    }

    public void UnloadProvider()
    {
        throw new NotImplementedException();
    }
}

This script is attached MARS camera and I have taken a sphere object as reference tracker just observe weather the body is tracked and untracked. BodyTrackManager_BodyAdded is custom method which is registered on BodyAdded event. Here I'm not able to understand which object shuld be passed as parameter to BodyTrackManager_BodyAdded, as it accepts IMars as interface.

CodePudding user response:

You need to create a class that implements IMarsBody so that it can supply the data to subscribers. Rather than subscribing to the BodyAdded event, you are meant to invoke that event when a body is tracked.

Are you sure you want IProvidesMarsBodyTracking and not IUsesMarsBodyTracking? The provider side is meant to be implemented by AR data providers like ARKit or ARCore. For example, a body tracking provider might be hooked up to a machine learning model that tracks human bodies in a video feed, and then implements this interface to provide data about these tracked bodies to the system. IUsesMarsBodyTracking, on the other end, is intended to be implemented by game code to get access to that data.

  • Related