Ejemplo n.º 1
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.M))
        {
            Canvas _canvas = canvas.GetComponent <Canvas>();
            _canvas.enabled = !_canvas.enabled;
        }

        if (BodyManager == null)
        {
            return;
        }

        _BodyManager = BodyManager.GetComponent <BodyManager>();
        if (_BodyManager == null)
        {
            return;
        }

        Avatar.Body[] data = _BodyManager.GetAvatarBodies();
        if (data == null)
        {
            return;
        }
        List <ulong> trackedIds = new List <ulong>();

        foreach (var body in data)
        {
            if (body == null)
            {
                continue;
            }

            if (body.IsTracked)
            {
                trackedIds.Add(body.TrackingId);
            }
        }

        Dictionary <int, ulong> knownAvatarIds = GetAvatarTrackingIds();

        foreach (KeyValuePair <int, ulong> avatarIdPair in knownAvatarIds)
        {
            if (!trackedIds.Contains(avatarIdPair.Value))
            {
                Avatars[avatarIdPair.Key].GetComponent <AvatarController>().RemoveFromTracking();
            }
        }

        foreach (var body in data)
        {
            if (body == null)
            {
                continue;
            }
            if (body.IsTracked)
            {
                int avaIdx = 0;
                if (!knownAvatarIds.ContainsValue(body.TrackingId))
                {
                    //mappimine
                    avaIdx = MapBodyToAvatar(body.TrackingId, knownAvatarIds);
                    SetupAvatarRendering(avaIdx);
                }
                if (avaIdx == 0)
                {
                    avaIdx = knownAvatarIds.FirstOrDefault(a => a.Value == body.TrackingId).Key;
                }
                Avatars[avaIdx].GetComponent <AvatarController>().RefreshAvatarBodyData(body);
            }
        }
        UpdateModelMenu();
    }