IEnumerator InitializeAvatarController()
        {
            if (!defaultAvatarInstance.IsLoaded)
            {
#if DEBUG
                Plugin.log.Info("Waiting for avatar to load");
#endif
                yield return(new WaitWhile(delegate() { return !defaultAvatarInstance.IsLoaded; }));
            }
            else
            {
                yield return(null);
            }

#if DEBUG
            Plugin.log.Info("Spawning avatar");
#endif
            centerAdjust = FindObjectOfType <VRCenterAdjust>();

            avatar          = AvatarSpawner.SpawnAvatar(defaultAvatarInstance, this);
            exclusionScript = avatar.GameObject.GetComponentsInChildren <AvatarScriptPack.FirstPersonExclusion>().FirstOrDefault();
            if (exclusionScript != null)
            {
                exclusionScript.SetVisible();
            }

            playerNameText = CustomExtensions.CreateWorldText(transform, "INVALID");
            playerNameText.rectTransform.anchoredPosition3D = new Vector3(0f, 0.25f, 0f);
            playerNameText.alignment = TextAlignmentOptions.Center;
            playerNameText.fontSize  = 2.5f;

            playerSpeakerIcon = new GameObject("Player Speaker Icon", typeof(Canvas), typeof(CanvasRenderer)).AddComponent <Image>();
            playerSpeakerIcon.GetComponent <Canvas>().renderMode = RenderMode.WorldSpace;
            playerSpeakerIcon.rectTransform.SetParent(transform);
            playerSpeakerIcon.rectTransform.localScale         = new Vector3(0.004f, 0.004f, 1f);
            playerSpeakerIcon.rectTransform.pivot              = new Vector2(0.5f, 0.5f);
            playerSpeakerIcon.rectTransform.anchoredPosition3D = new Vector3(0f, 0.65f, 0f);
            playerSpeakerIcon.sprite = Sprites.speakerIcon;

            avatar.GameObject.transform.SetParent(centerAdjust.transform, false);
            transform.SetParent(centerAdjust.transform, false);

            if (ModelSaberAPI.cachedAvatars.Any(x => x.Value == avatar.CustomAvatar))
            {
                currentAvatarHash = ModelSaberAPI.cachedAvatars.First(x => x.Value == avatar.CustomAvatar).Key;
            }
            else
            {
                currentAvatarHash = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF";
            }
        }
Ejemplo n.º 2
0
        private void AvatarDownloaded(string hash)
        {
            if (this != null && ModelSaberAPI.cachedAvatars.First(x => x.Value == avatar.CustomAvatar).Key != playerInfo.avatarHash && playerInfo.avatarHash == hash)
            {
                ModelSaberAPI.avatarDownloaded -= AvatarDownloaded;

                if (avatar != null)
                {
                    Destroy(avatar.GameObject);
                }

                avatar          = AvatarSpawner.SpawnAvatar(ModelSaberAPI.cachedAvatars[hash], this);
                exclusionScript = avatar.GameObject.GetComponentsInChildren <AvatarScriptPack.FirstPersonExclusion>().FirstOrDefault();
                if (exclusionScript != null)
                {
                    exclusionScript.SetVisible();
                }
                currentAvatarHash = hash;
            }
        }
        private void AvatarDownloaded(string hash)
        {
            if (this != null && (!ModelSaberAPI.cachedAvatars.ContainsValue(avatar.CustomAvatar) || ModelSaberAPI.cachedAvatars.First(x => x.Value == avatar.CustomAvatar).Key != playerAvatarHash) && playerAvatarHash == hash)
            {
                Plugin.log.Debug($"Avatar with hash \"{hash}\" loaded! (2)");
                ModelSaberAPI.avatarDownloaded -= AvatarDownloaded;

                if (avatar != null)
                {
                    Destroy(avatar.GameObject);
                }

                avatar          = AvatarSpawner.SpawnAvatar(ModelSaberAPI.cachedAvatars[hash], this);
                exclusionScript = avatar.GameObject.GetComponentsInChildren <AvatarScriptPack.FirstPersonExclusion>().FirstOrDefault();
                if (exclusionScript != null)
                {
                    exclusionScript.SetVisible();
                }
                currentAvatarHash = hash;
            }
        }
        IEnumerator InitializeAvatarController()
        {
            if (!defaultAvatarInstance.IsLoaded)
            {
#if DEBUG
                Misc.Logger.Info("Waiting for avatar to load");
#endif
                yield return(new WaitWhile(delegate() { return !defaultAvatarInstance.IsLoaded; }));
            }
            else
            {
                yield return(null);
            }

#if DEBUG
            Misc.Logger.Info("Spawning avatar");
#endif
            _centerAdjust = FindObjectOfType <VRCenterAdjust>();

            avatar          = AvatarSpawner.SpawnAvatar(defaultAvatarInstance, this);
            exclusionScript = avatar.GameObject.GetComponentsInChildren <AvatarScriptPack.FirstPersonExclusion>().FirstOrDefault();
            if (exclusionScript != null)
            {
                exclusionScript.SetVisible();
            }

            playerNameText = CustomExtensions.CreateWorldText(transform, "INVALID");
            playerNameText.rectTransform.anchoredPosition3D = new Vector3(0f, 0.25f, 0f);
            playerNameText.alignment = TextAlignmentOptions.Center;
            playerNameText.fontSize  = 2.5f;

            avatar.GameObject.transform.SetParent(_centerAdjust.transform, false);
            transform.SetParent(_centerAdjust.transform, false);

            currentAvatarHash = ModelSaberAPI.cachedAvatars.First(x => x.Value == avatar.CustomAvatar).Key;
        }
        public void SetPlayerInfo(PlayerInfo _playerInfo, float offset, bool isLocal)
        {
            if (_playerInfo == default)
            {
                if (playerNameText != null)
                {
                    playerNameText.gameObject.SetActive(false);
                }
                if (playerSpeakerIcon != null)
                {
                    playerSpeakerIcon.gameObject.SetActive(false);
                }
                if (avatar != null && avatar.GameObject != null)
                {
                    Destroy(avatar.GameObject);
                }
                return;
            }

            try
            {
                playerInfo       = _playerInfo.updateInfo;
                playerId         = _playerInfo.playerId;
                playerAvatarHash = _playerInfo.avatarHash;
                playerName       = _playerInfo.playerName;

                if (playerNameText != null && playerSpeakerIcon != null)
                {
                    if (isLocal)
                    {
                        playerNameText.gameObject.SetActive(false);
                        playerSpeakerIcon.gameObject.SetActive(false);
#if !DEBUG
                        if (avatar != null)
                        {
                            Destroy(avatar.GameObject);
                        }
#endif
                    }
                    else
                    {
                        playerNameText.gameObject.SetActive(true);
                        playerNameText.alignment = TextAlignmentOptions.Center;
                        playerSpeakerIcon.gameObject.SetActive(InGameOnlineController.Instance.VoiceChatIsTalking(playerId));
                    }
                }
                else
                {
                    return;
                }
#if !DEBUG
                if ((avatar == null || currentAvatarHash != playerAvatarHash) && !isLocal)
#else
                if ((avatar == null || currentAvatarHash != playerAvatarHash))
#endif
                {
                    if (ModelSaberAPI.cachedAvatars.ContainsKey(playerAvatarHash))
                    {
                        CustomAvatar.CustomAvatar cachedAvatar = ModelSaberAPI.cachedAvatars[playerAvatarHash];

                        if (cachedAvatar != null)
                        {
                            if (pendingAvatars.Contains(cachedAvatar))
                            {
                                AvatarLoaded -= AvatarController_AvatarLoaded;
                                AvatarLoaded += AvatarController_AvatarLoaded;
                            }
                            else if (!pendingAvatars.Contains(cachedAvatar) && !cachedAvatar.IsLoaded)
                            {
                                if (avatar != null)
                                {
                                    Destroy(avatar.GameObject);
                                }

                                avatar          = AvatarSpawner.SpawnAvatar(defaultAvatarInstance, this);
                                exclusionScript = avatar.GameObject.GetComponentsInChildren <AvatarScriptPack.FirstPersonExclusion>().FirstOrDefault();
                                if (exclusionScript != null)
                                {
                                    exclusionScript.SetVisible();
                                }

                                pendingAvatars.Add(cachedAvatar);
                                AvatarLoaded -= AvatarController_AvatarLoaded;
                                AvatarLoaded += AvatarController_AvatarLoaded;
                                cachedAvatar.Load((CustomAvatar.CustomAvatar loadedAvatar, AvatarLoadResult result) =>
                                {
                                    if (result == AvatarLoadResult.Completed)
                                    {
                                        pendingAvatars.Remove(ModelSaberAPI.cachedAvatars[playerAvatarHash]);
                                        AvatarLoaded?.Invoke(ModelSaberAPI.cachedAvatars.First(x => x.Value == loadedAvatar).Key);
                                    }
                                });
                            }
                            else
                            {
                                if (avatar != null)
                                {
                                    Destroy(avatar.GameObject);
                                }

                                avatar          = AvatarSpawner.SpawnAvatar(cachedAvatar, this);
                                exclusionScript = avatar.GameObject.GetComponentsInChildren <AvatarScriptPack.FirstPersonExclusion>().FirstOrDefault();
                                if (exclusionScript != null)
                                {
                                    exclusionScript.SetVisible();
                                }

                                currentAvatarHash = playerAvatarHash;
                            }
                        }
                    }
                    else
                    {
                        if (Config.Instance.DownloadAvatars)
                        {
                            if (ModelSaberAPI.queuedAvatars.Contains(playerAvatarHash))
                            {
                                ModelSaberAPI.avatarDownloaded -= AvatarDownloaded;
                                ModelSaberAPI.avatarDownloaded += AvatarDownloaded;
                            }
                            else
                            {
                                ModelSaberAPI.avatarDownloaded -= AvatarDownloaded;
                                ModelSaberAPI.avatarDownloaded += AvatarDownloaded;
                                SharedCoroutineStarter.instance.StartCoroutine(ModelSaberAPI.DownloadAvatarCoroutine(playerAvatarHash));

                                if (avatar != null)
                                {
                                    Destroy(avatar.GameObject);
                                }

                                avatar          = AvatarSpawner.SpawnAvatar(defaultAvatarInstance, this);
                                exclusionScript = avatar.GameObject.GetComponentsInChildren <AvatarScriptPack.FirstPersonExclusion>().FirstOrDefault();
                                if (exclusionScript != null)
                                {
                                    exclusionScript.SetVisible();
                                }
                            }
                        }
                    }
                }

                Vector3 offsetVector = new Vector3(offset, 0f, 0f);

                HeadPos      = playerInfo.headPos + offsetVector;
                RightHandPos = playerInfo.rightHandPos + offsetVector;
                LeftHandPos  = playerInfo.leftHandPos + offsetVector;

                HeadRot      = playerInfo.headRot;
                RightHandRot = playerInfo.rightHandRot;
                LeftHandRot  = playerInfo.leftHandRot;

                if (playerInfo.fullBodyTracking)
                {
                    RightLegPos = playerInfo.rightLegPos + offsetVector;
                    LeftLegPos  = playerInfo.leftLegPos + offsetVector;
                    PelvisPos   = playerInfo.pelvisPos + offsetVector;
                    RightLegRot = playerInfo.rightLegRot;
                    LeftLegRot  = playerInfo.leftLegRot;
                    PelvisRot   = playerInfo.pelvisRot;
                }
                else
                {
                    RightLegPos = new Vector3();
                    LeftLegPos  = new Vector3();
                    PelvisPos   = new Vector3();
                    RightLegRot = new Quaternion();
                    LeftLegRot  = new Quaternion();
                    PelvisRot   = new Quaternion();
                }

                transform.position = HeadPos;

                playerNameText.text = playerName;

                if (playerInfo.playerFlags.rainbowName && !rainbowName)
                {
                    playerNameText.color = playerInfo.playerNameColor;
                    nameColor            = HSBColor.FromColor(playerInfo.playerNameColor);
                }
                else if (!playerInfo.playerFlags.rainbowName && playerNameText.color != playerInfo.playerNameColor)
                {
                    playerNameText.color = playerInfo.playerNameColor;
                }

                rainbowName = playerInfo.playerFlags.rainbowName;
            }
            catch (Exception e)
            {
                Plugin.log.Critical(e);
            }
        }
Ejemplo n.º 6
0
        public void SetPlayerInfo(PlayerInfo _playerInfo, float offset, bool isLocal)
        {
            if (_playerInfo == null)
            {
                if (playerNameText != null)
                {
                    playerNameText.gameObject.SetActive(false);
                }
                if (playerSpeakerIcon != null)
                {
                    playerSpeakerIcon.gameObject.SetActive(false);
                }
                if (avatar != null)
                {
                    Destroy(avatar.GameObject);
                }
                return;
            }

            try
            {
                playerInfo = _playerInfo;

                if (playerNameText != null && playerSpeakerIcon != null)
                {
                    if (isLocal)
                    {
                        playerNameText.gameObject.SetActive(false);
                        playerSpeakerIcon.gameObject.SetActive(false);
#if !DEBUG
                        if (avatar != null)
                        {
                            Destroy(avatar.GameObject);
                        }
#endif
                    }
                    else
                    {
                        playerNameText.gameObject.SetActive(true);
                        playerNameText.alignment = TextAlignmentOptions.Center;
                        playerSpeakerIcon.gameObject.SetActive(InGameOnlineController.Instance.VoiceChatIsTalking(playerInfo.playerId));
                    }
                }

                if (playerNameText == null || playerSpeakerIcon == null)
                {
                    return;
                }

                if ((avatar == null || currentAvatarHash != playerInfo.avatarHash) && !isLocal)
                {
                    if (ModelSaberAPI.cachedAvatars.ContainsKey(playerInfo.avatarHash))
                    {
                        CustomAvatar.CustomAvatar cachedAvatar = ModelSaberAPI.cachedAvatars[playerInfo.avatarHash];

                        if (cachedAvatar != null)
                        {
                            if (pendingAvatars.Contains(cachedAvatar))
                            {
                                AvatarLoaded -= AvatarController_AvatarLoaded;
                                AvatarLoaded += AvatarController_AvatarLoaded;
                            }
                            else if (!pendingAvatars.Contains(cachedAvatar) && !cachedAvatar.IsLoaded)
                            {
                                if (avatar != null)
                                {
                                    Destroy(avatar.GameObject);
                                }

                                avatar          = AvatarSpawner.SpawnAvatar(defaultAvatarInstance, this);
                                exclusionScript = avatar.GameObject.GetComponentsInChildren <AvatarScriptPack.FirstPersonExclusion>().FirstOrDefault();
                                if (exclusionScript != null)
                                {
                                    exclusionScript.SetVisible();
                                }

                                pendingAvatars.Add(cachedAvatar);
                                cachedAvatar.Load((CustomAvatar.CustomAvatar loadedAvatar, AvatarLoadResult result) =>
                                {
                                    if (result == AvatarLoadResult.Completed)
                                    {
                                        pendingAvatars.Remove(ModelSaberAPI.cachedAvatars[playerInfo.avatarHash]);
                                        AvatarLoaded?.Invoke(ModelSaberAPI.cachedAvatars.First(x => x.Value == loadedAvatar).Key);
                                    }
                                });
                                AvatarLoaded += AvatarController_AvatarLoaded;
                            }
                            else
                            {
                                if (avatar != null)
                                {
                                    Destroy(avatar.GameObject);
                                }

                                avatar          = AvatarSpawner.SpawnAvatar(cachedAvatar, this);
                                exclusionScript = avatar.GameObject.GetComponentsInChildren <AvatarScriptPack.FirstPersonExclusion>().FirstOrDefault();
                                if (exclusionScript != null)
                                {
                                    exclusionScript.SetVisible();
                                }

                                currentAvatarHash = playerInfo.avatarHash;
                            }
                        }
                    }
                    else
                    {
                        if (Config.Instance.DownloadAvatars)
                        {
                            if (ModelSaberAPI.queuedAvatars.Contains(playerInfo.avatarHash))
                            {
                                ModelSaberAPI.avatarDownloaded += AvatarDownloaded;
                            }
                            else
                            {
                                SharedCoroutineStarter.instance.StartCoroutine(ModelSaberAPI.DownloadAvatarCoroutine(playerInfo.avatarHash, (string hash) => { AvatarDownloaded(hash); }));

                                if (avatar != null)
                                {
                                    Destroy(avatar.GameObject);
                                }

                                avatar          = AvatarSpawner.SpawnAvatar(defaultAvatarInstance, this);
                                exclusionScript = avatar.GameObject.GetComponentsInChildren <AvatarScriptPack.FirstPersonExclusion>().FirstOrDefault();
                                if (exclusionScript != null)
                                {
                                    exclusionScript.SetVisible();
                                }
                            }
                        }
                    }
                }

                Vector3 offsetVector = new Vector3(offset, 0f, 0f);

                HeadPos      = playerInfo.headPos + offsetVector;
                RightHandPos = playerInfo.rightHandPos + offsetVector;
                LeftHandPos  = playerInfo.leftHandPos + offsetVector;

                HeadRot      = playerInfo.headRot;
                RightHandRot = playerInfo.rightHandRot;
                LeftHandRot  = playerInfo.leftHandRot;

                transform.position = HeadPos;

                playerNameText.text  = playerInfo.playerName;
                playerNameText.color = playerInfo.playerNameColor;
            }
            catch (Exception e)
            {
                Misc.Logger.Exception($"Avatar controller exception: {playerInfo.playerName}: {e}");
            }
        }
        public void SetPlayerInfo(PlayerInfo _playerInfo, float offset, bool isLocal)
        {
            if (_playerInfo == null)
            {
                playerNameText.gameObject.SetActive(false);
                if (rendererEnabled)
                {
                    SetRendererInChilds(avatar.GameObject.transform, false);
                    rendererEnabled = false;
                }
                return;
            }

            try
            {
                playerInfo = _playerInfo;

                if (playerNameText == null)
                {
                    return;
                }

                if (avatar == null || currentAvatarHash != playerInfo.avatarHash)
                {
                    if (ModelSaberAPI.cachedAvatars.ContainsKey(playerInfo.avatarHash))
                    {
                        CustomAvatar.CustomAvatar cachedAvatar = ModelSaberAPI.cachedAvatars[playerInfo.avatarHash];
                        if (cachedAvatar != null)
                        {
                            if (cachedAvatar.IsLoaded)
                            {
                                if (avatar != null)
                                {
                                    Destroy(avatar.GameObject);
                                }

                                avatar          = AvatarSpawner.SpawnAvatar(cachedAvatar, this);
                                exclusionScript = avatar.GameObject.GetComponentsInChildren <AvatarScriptPack.FirstPersonExclusion>().FirstOrDefault();
                                if (exclusionScript != null)
                                {
                                    exclusionScript.SetVisible();
                                }

                                currentAvatarHash = playerInfo.avatarHash;
                            }
                            else if (!pendingAvatars.Contains(cachedAvatar))
                            {
                                if (avatar != null)
                                {
                                    Destroy(avatar.GameObject);
                                }

                                avatar          = AvatarSpawner.SpawnAvatar(defaultAvatarInstance, this);
                                exclusionScript = avatar.GameObject.GetComponentsInChildren <AvatarScriptPack.FirstPersonExclusion>().FirstOrDefault();
                                if (exclusionScript != null)
                                {
                                    exclusionScript.SetVisible();
                                }

                                pendingAvatars.Add(cachedAvatar);
                                cachedAvatar.Load((CustomAvatar.CustomAvatar loadedAvatar, AvatarLoadResult result) =>
                                {
                                    if (result == AvatarLoadResult.Completed)
                                    {
                                        pendingAvatars.Remove(ModelSaberAPI.cachedAvatars[playerInfo.avatarHash]);
                                        AvatarLoaded?.Invoke(ModelSaberAPI.cachedAvatars.First(x => x.Value == loadedAvatar).Key);
                                    }
                                });
                                AvatarLoaded += AvatarController_AvatarLoaded;
                            }
                            else
                            {
                                if (avatar != null)
                                {
                                    Destroy(avatar.GameObject);
                                }

                                avatar          = AvatarSpawner.SpawnAvatar(defaultAvatarInstance, this);
                                exclusionScript = avatar.GameObject.GetComponentsInChildren <AvatarScriptPack.FirstPersonExclusion>().FirstOrDefault();
                                if (exclusionScript != null)
                                {
                                    exclusionScript.SetVisible();
                                }

                                AvatarLoaded -= AvatarController_AvatarLoaded;
                                AvatarLoaded += AvatarController_AvatarLoaded;
                            }
                        }
                    }
                    else
                    {
                        if (Config.Instance.DownloadAvatars)
                        {
                            if (avatar != null)
                            {
                                Destroy(avatar.GameObject);
                            }

                            avatar          = AvatarSpawner.SpawnAvatar(defaultAvatarInstance, this);
                            exclusionScript = avatar.GameObject.GetComponentsInChildren <AvatarScriptPack.FirstPersonExclusion>().FirstOrDefault();
                            if (exclusionScript != null)
                            {
                                exclusionScript.SetVisible();
                            }

                            if (ModelSaberAPI.queuedAvatars.Contains(playerInfo.avatarHash))
                            {
                                ModelSaberAPI.avatarDownloaded += AvatarDownloaded;
                            }
                            else
                            {
                                SharedCoroutineStarter.instance.StartCoroutine(ModelSaberAPI.DownloadAvatarCoroutine(playerInfo.avatarHash, (string hash) => { AvatarDownloaded(hash); }));
                            }
                        }
                    }
                }

                if (isLocal)
                {
                    playerNameText.gameObject.SetActive(false);
#if !DEBUG
                    if (rendererEnabled)
                    {
                        SetRendererInChilds(avatar.GameObject.transform, false);
                        rendererEnabled = false;
                    }
#endif
                }
                else
                {
                    playerNameText.gameObject.SetActive(true);
                    if (!rendererEnabled)
                    {
                        SetRendererInChilds(avatar.GameObject.transform, true);
                        rendererEnabled = true;
                    }
                }

                interpolationProgress = 0f;

                Vector3 offsetVector = new Vector3(offset, 0f, 0f);

                lastHeadPos   = targetHeadPos;
                targetHeadPos = _playerInfo.headPos + offsetVector;

                lastRightHandPos   = targetRightHandPos;
                targetRightHandPos = _playerInfo.rightHandPos + offsetVector;

                lastLeftHandPos   = targetLeftHandPos;
                targetLeftHandPos = _playerInfo.leftHandPos + offsetVector;

                lastHeadRot   = targetHeadRot;
                targetHeadRot = _playerInfo.headRot;

                lastRightHandRot   = targetRightHandRot;
                targetRightHandRot = _playerInfo.rightHandRot;

                lastLeftHandRot   = targetLeftHandRot;
                targetLeftHandRot = _playerInfo.leftHandRot;

                playerNameText.text = playerInfo.playerName;

                if (forcePlayerInfo)
                {
                    interpHeadPos      = targetHeadPos;
                    interpLeftHandPos  = targetLeftHandPos;
                    interpRightHandPos = targetRightHandPos;

                    interpHeadRot      = targetHeadRot;
                    interpLeftHandRot  = targetLeftHandRot;
                    interpRightHandRot = targetRightHandRot;

                    transform.position = interpHeadPos;
                }
            }
            catch (Exception e)
            {
                Misc.Logger.Exception($"Avatar controller exception: {_playerInfo.playerName}: {e}");
            }
        }
        public void GeneratePreview(int AvatarIndex)
        {
            if (PreviewStatus)
            {
                return;
            }
            PreviewStatus = true;
            if (PreviewAvatar != null)
            {
                DestroyPreview();
            }

            if (__AvatarLoadResults[AvatarIndex] == AvatarLoadResult.Completed)
            {
                PreviewAvatar = __AvatarPrefabs[AvatarIndex];

                _previewParent = new GameObject();
                _previewParent.transform.Translate(2, 0, 1.15f);
                _previewParent.transform.Rotate(0, -120, 0);
                _avatarPreview = Instantiate(PreviewAvatar, _previewParent.transform);

                _VRIK = _avatarPreview.GetComponentsInChildren <AvatarScriptPack.VRIK>().FirstOrDefault();

                if (_VRIK != null)
                {
                    //_center = _avatarPreview.GetComponentInChildren<Renderer>().bounds.center;
                    _previewHeight = (AvatarList[AvatarIndex].Height > 0) ? AvatarList[AvatarIndex].Height : _avatarPreview.GetComponentInChildren <Renderer>().bounds.size.y;
                    //_previewHeightOffset = _avatarPreview.GetComponentInChildren<Renderer>().bounds.min.y;
                    _previewHeightOffset = 0;
                    _previewScale        = (0.85f / _previewHeight);
                }
                else
                {
                    foreach (Transform child in _avatarPreview.transform)
                    {
                        try
                        {
                            _center += child.gameObject.GetComponentInChildren <Renderer>().bounds.center;
                        } catch
                        {
                            _center = Vector3.zero;
                        }
                    }
                    _center /= _avatarPreview.transform.childCount;
                    Bounds bounds = new Bounds(_center, Vector3.zero);

                    foreach (Transform child in _avatarPreview.transform)
                    {
                        try
                        {
                            bounds.Encapsulate(child.gameObject.GetComponentInChildren <Renderer>().bounds);
                        } catch
                        {
                            bounds = new Bounds(_center, Vector3.one);
                        }
                    }

                    _previewHeight       = bounds.size.y;
                    _previewHeightOffset = bounds.min.y;
                    _previewScale        = (1f / _previewHeight);
                }

                _previewParent.transform.Translate(0, 1 - (_previewHeightOffset), 0);
                _previewParent.transform.localScale = new Vector3(_previewScale, _previewScale, _previewScale);

                Destroy(_avatarPreview);
                _avatarPreview = Instantiate(PreviewAvatar, _previewParent.transform);
                _avatarPreview.AddComponent <AvatarPreviewRotation>();
                _avatarPreview.SetActive(true);
                _VRIK            = _avatarPreview.GetComponentsInChildren <AvatarScriptPack.VRIK>().FirstOrDefault();
                _exclusionScript = _avatarPreview.GetComponentsInChildren <AvatarScriptPack.FirstPersonExclusion>().FirstOrDefault();

                if (_VRIK != null)
                {
                    Destroy(_VRIK);
                }
                else
                {
                    _avatarPreview.transform.Find("LeftHand").transform.Translate(-0.333f, -0.475f, 0);
                    _avatarPreview.transform.Find("LeftHand").transform.Rotate(0, 0, -30);
                    _avatarPreview.transform.Find("RightHand").transform.Translate(0.333f, -0.475f, 0);
                    _avatarPreview.transform.Find("RightHand").transform.Rotate(0, 0, 30);
                }
                if (_exclusionScript != null)
                {
                    _exclusionScript.SetVisible();
                }
            }
            else
            {
                Console.WriteLine("Failed to load preview. Status: " + __AvatarLoadResults[AvatarIndex]);
            }
            PreviewStatus = false;
        }