I’m using Live Capture and I currently have to manually select the Client Device in the Face Device object every time I run my app (see attached screenshot). I would like to update this property programmatically in script.
I need to do 2 things:
Find a way to get a list of currently connected clients as seen in the Live Capture > Connections window (see attached screenshot).
Assign the active client device to the Client Device property of the ARKit Face Device object. I assume that I would use the ARKit Face Device method SetClient().
How do I get the currently active Live Capture device as a FaceClient object?
As I research this more, it looks like I would need to get access to: CompanionAppServer. However, CompanionAppServer is private and cannot be accessed.
You are correct that currently there is no public access to the client list.
For now, you can use reflection to access the clients, something like this:
using System;
using System.Collections.Generic;
using System.Reflection;
using Unity.LiveCapture;
using Unity.LiveCapture.CompanionApp;
public static class ClientUtility
{
public static IEnumerable<ICompanionAppClient> GetClients()
{
var serverType = Type.GetType("Unity.LiveCapture.CompanionApp.CompanionAppServer");
var server = UnityEngine.Object.FindObjectOfType(serverType);
var getClientsMethod = serverType.GetMethod("GetClients");
return getClientsMethod.Invoke(server, null) as IEnumerable<ICompanionAppClient>;
}
}
I’ve not tested it, but the general approach should work. Since this uses reflection, it is not guaranteed to work going forwards, but should work in the mean time until this functionality is exposed publicly. I hope this helps!
@DanRP
I’ve tested it and fixed the issue, here is a version that should work:
public static IEnumerable<ICompanionAppClient> GetClients()
{
var serverType = Type.GetType("Unity.LiveCapture.CompanionApp.CompanionAppServer, Unity.LiveCapture.CompanionApp");
var server = ServerManager.Instance.CreateServer(serverType);
var getClientsMethod = serverType.GetMethod("GetClients");
return getClientsMethod.Invoke(server, null) as IEnumerable<ICompanionAppClient>;
}