using UnityEngine;
using System;
using System.Collections.Generic;
using System.Linq;
///
/// iFacialMocap/Rokoko 페이셜 모션캡처 관리
///
[Serializable]
public class FacialMotionManager
{
[Tooltip("true면 씬의 모든 페이셜 모션 클라이언트를 자동으로 찾습니다")]
public bool autoFindFacialMotionClients = true;
[Tooltip("수동으로 지정할 페이셜 모션 클라이언트 목록 (autoFindFacialMotionClients가 false일 때 사용)")]
public List facialMotionClients = new List();
private Action log;
private Action logError;
public void Initialize(Action log, Action logError)
{
this.log = log;
this.logError = logError;
if (autoFindFacialMotionClients)
{
RefreshFacialMotionClients();
}
}
public void RefreshFacialMotionClients()
{
var allClients = UnityEngine.Object.FindObjectsOfType();
facialMotionClients = allClients.ToList();
log?.Invoke($"Facial Motion 클라이언트 {facialMotionClients.Count}개 발견");
}
public void ReconnectFacialMotion()
{
if (autoFindFacialMotionClients)
{
RefreshFacialMotionClients();
}
if (facialMotionClients == null || facialMotionClients.Count == 0)
{
logError?.Invoke("Facial Motion 클라이언트가 없습니다!");
return;
}
log?.Invoke($"Facial Motion 클라이언트 재접속 시도... ({facialMotionClients.Count}개)");
int reconnectedCount = 0;
foreach (var client in facialMotionClients)
{
if (client != null)
{
try
{
client.Reconnect();
reconnectedCount++;
log?.Invoke($"클라이언트 재접속 성공: {client.gameObject.name}");
}
catch (Exception e)
{
logError?.Invoke($"클라이언트 재접속 실패 ({client.gameObject.name}): {e.Message}");
}
}
}
if (reconnectedCount > 0)
{
log?.Invoke($"=== Facial Motion 재접속 완료 ({reconnectedCount}/{facialMotionClients.Count}개) ===");
}
else
{
logError?.Invoke("재접속에 성공한 클라이언트가 없습니다!");
}
}
}