示例#1
0
    IEnumerator RoomStateCoroutine()
    {
        ulong lastTick = 0;

        while (true)
        {
            SnapshotData data;
            ServiceCallback <SnapshotData> callback = VrLifeCore.API.TickRate.GetSnapshot();
            yield return(callback.WaitCoroutine());

            if (callback.HasException)
            {
                yield break;
            }
            data = callback.Result;
            if (data.TickNum == lastTick)
            {
                continue;
            }
            List <SkeletonState>        skeletons    = data.Skeletons.Select(x => new SkeletonState(x)).ToList();
            Dictionary <ulong, IAvatar> _avatarsCopy = _api.GlobalAPI.Players.GetAvatars().ToDictionary(x => x.Key, x => x.Value);
            foreach (SkeletonState state in skeletons)
            {
                if (state.UserId == _playerAvatar.GetUserId())
                {
                    continue;
                }
                if (!_avatarsCopy.TryGetValue(state.UserId, out IAvatar avatar))
                {
                    IAvatar tmp = new DefaultAvatar(state.UserId, state.UserId.ToString(),
                                                    state.BodyLocation.ToUnity(), Quaternion.identity);
                    _api.GlobalAPI.Players.AddAvatar(state.UserId, tmp);
                    avatar = tmp;
                }
                _avatarsCopy.Remove(state.UserId);
                avatar.SetSkeleton(state);
            }
            foreach (IAvatar avatar in _avatarsCopy.Values)
            {
                _api.GlobalAPI.Players.DeleteAvatar(avatar.GetUserId());
            }
            lastTick = data.TickNum;
            yield return(null);
        }
    }