The intent is that you use them as extension methods. Our system will hook up scene objects to their functionality provider, and you can call this.Foo()
In your case, you would just add a MonoBehaviour to your scene that looks something like this:
using System;
using TMPro;
using Unity.MARS.Providers;
using Unity.MARS.Settings;
using Unity.XRTools.ModuleLoader;
using UnityEngine;
using UnityEngine.Events;
namespace Unity.MARS
{
public class SessionUI : MonoBehaviour, IUsesFunctionalityInjection
{
class Subscriber : IUsesSessionControl, IUsesPointCloud, IUsesPlaneFinding, IUsesMarkerTracking
{
IProvidesSessionControl IFunctionalitySubscriber<IProvidesSessionControl>.provider { get; set; }
IProvidesPointCloud IFunctionalitySubscriber<IProvidesPointCloud>.provider { get; set; }
IProvidesPlaneFinding IFunctionalitySubscriber<IProvidesPlaneFinding>.provider { get; set; }
IProvidesMarkerTracking IFunctionalitySubscriber<IProvidesMarkerTracking>.provider { get; set; }
}
[Serializable]
class PauseEvent : UnityEvent<bool> { }
const string k_PauseText = "Pause";
const string k_ResumeText = "Resume";
#pragma warning disable 649
[SerializeField]
TextMeshProUGUI m_Text;
#pragma warning restore 649
readonly Subscriber m_Subscriber = new Subscriber();
IProvidesFunctionalityInjection IFunctionalitySubscriber<IProvidesFunctionalityInjection>.provider { get; set; }
void Start()
{
m_Text.text = MARSCore.instance.paused ? k_ResumeText : k_PauseText;
this.InjectFunctionalitySingle(m_Subscriber);
}
public void TogglePaused()
{
var paused = MARSCore.instance.paused;
if (paused)
{
m_Text.text = k_PauseText;
paused = false;
}
else
{
m_Text.text = k_ResumeText;
paused = true;
}
MARSCore.instance.paused = paused;
if (paused)
{
if (m_Subscriber.HasProvider<IProvidesPointCloud>())
m_Subscriber.StopDetectingPoints();
if (m_Subscriber.HasProvider<IProvidesPlaneFinding>())
m_Subscriber.StopDetectingPlanes();
if (m_Subscriber.HasProvider<IProvidesMarkerTracking>())
m_Subscriber.StopTrackingMarkers();
}
else
{
if (m_Subscriber.HasProvider<IProvidesPointCloud>())
m_Subscriber.StartDetectingPoints();
if (m_Subscriber.HasProvider<IProvidesPlaneFinding>())
m_Subscriber.StartDetectingPlanes();
if (m_Subscriber.HasProvider<IProvidesMarkerTracking>())
m_Subscriber.StartTrackingMarkers();
}
}
public void TriggerSessionReset()
{
if (m_Subscriber.HasProvider<IProvidesSessionControl>())
m_Subscriber.ResetSession();
}
}
}
This is from an app that we use to test MARS, and is hooked up to a UI canvas with buttons and a text object to indicate status. You may notice that the Subscriber
sub-class is actually what implements IUsesSessionControl
, etc. This allows us to include this script in our scene without adding a requirement for planes, point clouds, and image markers, but still to control those systems if they are active.
Feel free to keep the questions coming. If this example doesn’t make sense, I can provide a simpler one that just covers the basics.
Cheers!