when i browsed through the thread , the alternative solution to attach a gameobject to each of the instanciate avatar, and follow the exact position and rotation of that bone, is by set the gameobject the child of the hierachy of the avatar bone,(me use head),
now i want to access to each of that gameobject, activate only one and deactivate the rest use a hotkey or toggle button, how can i access to each of the instance of avatar in a foreach loop of the current detected bodies?
i try to subscribe to the OnBodyTracking event to access the body, or actually i dont need to do this?
Blockquote
private Dictionary<int,GameObject> currentDetectedCameras;
public Dictionary<int, GameObject> CurrentDetectedCameras { get => currentDetectedCameras;}
private GameObject[] Cameras;
private int currentCam;
public GameObject DefaultCamera;
void Start()
{
//Avatar.FindObjectOfType
currentDetectedCameras = new Dictionary<int,GameObject>(); //camera id, that exact npc's prefab
if(!spawned){
zedManager.OnBodyTracking += OnBodyTrackingFrame;
}
}
private void OnBodyTrackingFrame(BodyTrackingFrame bodyFrame)
{
List<int> remainingKeyList = new List<int>(currentDetectedCameras.Keys);
//List<DetectedBody> currentlyTrackedBodies;
var missingBodies = currentDetectedCameras.Where(existingBodies => !bodyFrame.detectedBodies.Select(detectedBodies => detectedBodies.id).ToList().Contains(existingBodies.Key)).ToList();
if(bodyFrame.bodyCount > 0)
{
DefaultCamera.SetActive(false);
bodyFrame.detectedBodies.ForEach(body =>
{
spawned = true;
int camera_id = body.rawBodyData.id;
if (!currentDetectedCameras.ContainsKey(camera_id))
{
Avatar.transform.GetChild
GameObject child = originalGameObject.transform.GetChild(i).gameObject;
//currentDetectedCameras.Add(camera_id, Prefab);
}
else
{
var Prefab = currentDetectedCameras.SingleOrDefault(x => x.Key == camera_id).Value;
}
});
missingBodies.ForEach(existingBody =>
{
Destroy(existingBody.Value);
currentDetectedCameras.Remove(existingBody.Key);
});
}
else
{
DefaultCamera.SetActive(true);
}
}