Exemple #1
0
        private void AvatarDownloaded(string hash)
        {
            ModelSaberAPI.avatarDownloaded -= AvatarDownloaded;

            if (this != null && playerAvatarHash == hash)
            {
                Plugin.log.Debug($"Avatar with hash \"{hash}\" loaded! (2)");

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

                avatar = AvatarManager.SpawnAvatar(ModelSaberAPI.cachedAvatars[hash], avatarInput);
                avatar.SetChildrenToLayer(10);

                currentAvatarHash = hash;
            }
        }
Exemple #2
0
        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.eventsPlayer != null)
                {
                    avatar.Destroy();
                    avatar = null;
                }
                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 && avatar.eventsPlayer != null)
                        {
                            avatar.Destroy();
                        }
#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 (unableToSpawnAvatar)
                    {
                        if (retryTimeCounter + 5f > Time.realtimeSinceStartup)
                        {
                            retryTimeCounter    = -1f;
                            unableToSpawnAvatar = false;
                        }
                    }
                    else
                    {
                        if (ModelSaberAPI.cachedAvatars.ContainsKey(playerAvatarHash))
                        {
                            LoadedAvatar cachedAvatar = ModelSaberAPI.cachedAvatars[playerAvatarHash];

                            if (cachedAvatar != null)
                            {
                                if (avatar != null && avatar.eventsPlayer != null)
                                {
                                    avatar.Destroy();
                                    avatar = null;
                                }

                                avatar = AvatarManager.SpawnAvatar(cachedAvatar, avatarInput);
                                avatar.SetChildrenToLayer(10);

                                currentAvatarHash = playerAvatarHash;
                            }
                            else
                            {
                                unableToSpawnAvatar = true;
                                retryTimeCounter    = Time.realtimeSinceStartup;
                            }
                        }
                        else
                        {
                            if (Config.Instance.DownloadAvatars)
                            {
                                if (!Config.Instance.DownloadNSFWAvatars && ModelSaberAPI.nsfwAvatars.Contains(playerAvatarHash))
                                {
                                    unableToSpawnAvatar = true;
                                    retryTimeCounter    = Time.realtimeSinceStartup;
                                }
                                else
                                {
                                    ModelSaberAPI.avatarDownloaded -= AvatarDownloaded;
                                    ModelSaberAPI.avatarDownloaded += AvatarDownloaded;

                                    if (!ModelSaberAPI.queuedAvatars.Contains(playerAvatarHash))
                                    {
                                        SharedCoroutineStarter.instance.StartCoroutine(ModelSaberAPI.DownloadAvatarCoroutine(playerAvatarHash));

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

                                        avatar = AvatarManager.SpawnAvatar(defaultAvatarInstance, avatarInput);
                                        avatar.SetChildrenToLayer(10);
                                    }
                                }
                            }
                        }
                    }
                }

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

                avatarInput.headPos      = playerInfo.headPos + offsetVector;
                avatarInput.rightHandPos = playerInfo.rightHandPos + offsetVector;
                avatarInput.leftHandPos  = playerInfo.leftHandPos + offsetVector;

                avatarInput.headRot      = playerInfo.headRot;
                avatarInput.rightHandRot = playerInfo.rightHandRot;
                avatarInput.leftHandRot  = playerInfo.leftHandRot;

                avatarInput.poseValid = true;

                avatarInput.fullBodyTracking = playerInfo.fullBodyTracking;
                if (playerInfo.fullBodyTracking)
                {
                    avatarInput.rightLegPos = playerInfo.rightLegPos + offsetVector;
                    avatarInput.leftLegPos  = playerInfo.leftLegPos + offsetVector;
                    avatarInput.pelvisPos   = playerInfo.pelvisPos + offsetVector;
                    avatarInput.rightLegRot = playerInfo.rightLegRot;
                    avatarInput.leftLegRot  = playerInfo.leftLegRot;
                    avatarInput.pelvisRot   = playerInfo.pelvisRot;
                }

                transform.position = avatarInput.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);
            }
        }