コード例 #1
0
 internal AvatarListItem(CustomAvatar avatar)
 {
     name        = avatar.descriptor.name;
     author      = avatar.descriptor.author;
     icon        = avatar.descriptor.cover?.texture;
     this.avatar = avatar;
 }
コード例 #2
0
        public static void LoadAvatars()
        {
            if (defaultAvatarInstance == null)
            {
                defaultAvatarInstance = CustomAvatar.Plugin.Instance.AvatarLoader.Avatars.FirstOrDefault(x => x.FullPath.ToLower().Contains("template.avatar"));
            }
            Logger.Debug($"Found avatar, isLoaded={defaultAvatarInstance.IsLoaded}");
            if (!defaultAvatarInstance.IsLoaded)
            {
                defaultAvatarInstance.Load(null);
            }

            foreach (CustomAvatar.CustomAvatar avatar in CustomAvatar.Plugin.Instance.AvatarLoader.Avatars)
            {
                Task.Run(() =>
                {
                    string hash;
                    if (CreateMD5FromFile(avatar.FullPath, out hash))
                    {
                        ModelSaberAPI.cachedAvatars.Add(hash, avatar);
                        Logger.Debug("Hashed avatar " + avatar.Name + "! Hash: " + hash);
                    }
                }).ConfigureAwait(false);
            }
        }
コード例 #3
0
        private void CustomAvatarLoaded(CustomAvatar loadedAvatar, AvatarLoadResult result)
        {
            if (result != AvatarLoadResult.Completed)
            {
                Plugin.Log("Avatar " + loadedAvatar.FullPath + " failed to load");
                return;
            }

            Plugin.Log("Loaded avatar " + loadedAvatar.Name + " by " + loadedAvatar.AuthorName);

            if (_currentSpawnedPlayerAvatar?.GameObject != null)
            {
                Object.Destroy(_currentSpawnedPlayerAvatar.GameObject);
            }

            _currentSpawnedPlayerAvatar = AvatarSpawner.SpawnAvatar(loadedAvatar, _playerAvatarInput);

            if (AvatarChanged != null)
            {
                AvatarChanged(loadedAvatar);
            }

            _startAvatarLocalScale = _currentSpawnedPlayerAvatar.GameObject.transform.localScale;
            _prevPlayerHeight      = -1;
            ResizePlayerAvatar();
            OnFirstPersonEnabledChanged(Plugin.Instance.FirstPersonEnabled);
        }
コード例 #4
0
        public CustomAvatar SwitchToPreviousAvatar()
        {
            var avatars = _avatarLoader.Avatars;

            if (avatars.Count == 0)
            {
                return(null);
            }

            if (CurrentPlayerAvatar == null)
            {
                CurrentPlayerAvatar = avatars[0];
                return(avatars[0]);
            }

            var currentIndex = _avatarLoader.IndexOf(CurrentPlayerAvatar);

            if (currentIndex < 0)
            {
                currentIndex = 0;
            }

            var nextIndex = currentIndex - 1;

            if (nextIndex < 0)
            {
                nextIndex = avatars.Count - 1;
            }

            var nextAvatar = avatars[nextIndex];

            CurrentPlayerAvatar = nextAvatar;
            return(nextAvatar);
        }
コード例 #5
0
        public void GetAvatarsAsync(Action <CustomAvatar> success, Action <Exception> error)
        {
            Plugin.logger.Info("Loading all avatars from " + kCustomAvatarsPath);

            foreach (string fileName in GetAvatarFileNames())
            {
                SharedCoroutineStarter.instance.StartCoroutine(CustomAvatar.FromFileCoroutine(fileName, success, error));
            }
        }
コード例 #6
0
        public static SpawnedAvatar SpawnAvatar(CustomAvatar customAvatar, IAvatarInput avatarInput)
        {
            if (customAvatar.GameObject == null)
            {
                Plugin.Log("Can't spawn " + customAvatar.FullPath + " because it hasn't been loaded!");
                return(null);
            }

            var avatarGameObject = Object.Instantiate(customAvatar.GameObject);

            var behaviour = avatarGameObject.AddComponent <AvatarBehaviour>();

            behaviour.Init(avatarInput);

            avatarGameObject.AddComponent <AvatarEventsPlayer>();

            /* Don't have the patience to make this work rn
             *
             * var mainCamera = Camera.main;
             *
             * foreach (Camera cam in avatarGameObject.GetComponentsInChildren<Camera>())
             * {
             *      if(mainCamera)
             *      {
             *              var newCamObj = Object.Instantiate(mainCamera, cam.transform);
             *              newCamObj.tag = "Untagged";
             *              while (newCamObj.transform.childCount > 0) Object.DestroyImmediate(newCamObj.transform.GetChild(0).gameObject);
             *              Object.DestroyImmediate(newCamObj.GetComponent("CameraRenderCallbacksManager"));
             *              Object.DestroyImmediate(newCamObj.GetComponent("AudioListener"));
             *              Object.DestroyImmediate(newCamObj.GetComponent("MeshCollider"));
             *
             *              var newCam = newCamObj.GetComponent<Camera>();
             *              newCam.stereoTargetEye = StereoTargetEyeMask.None;
             *              newCam.cullingMask = cam.cullingMask;
             *
             *              var _liv = newCam.GetComponent<LIV.SDK.Unity.LIV>();
             *              if (_liv)
             *                      Object.Destroy(_liv);
             *
             *              var _screenCamera = new GameObject("Screen Camera").AddComponent<ScreenCameraBehaviour>();
             *
             *              if (_previewMaterial == null)
             *                      _previewMaterial = new Material(Shader.Find("Hidden/BlitCopyWithDepth"));
             *
             *
             *              cam.enabled = false;
             *      }
             * }
             */

            Object.DontDestroyOnLoad(avatarGameObject);

            var spawnedAvatar = new SpawnedAvatar(customAvatar, avatarGameObject);

            return(spawnedAvatar);
        }
コード例 #7
0
        public SpawnedAvatar(CustomAvatar customAvatar)
        {
            this.customAvatar = customAvatar ?? throw new ArgumentNullException(nameof(customAvatar));
            _gameObject       = Object.Instantiate(customAvatar.gameObject);

            eventsPlayer = _gameObject.AddComponent <AvatarEventsPlayer>();
            behaviour    = _gameObject.AddComponent <AvatarBehaviour>();

            Object.DontDestroyOnLoad(_gameObject);
        }
コード例 #8
0
 public void SwitchToAvatarAsync(string filePath)
 {
     SharedCoroutineStarter.instance.StartCoroutine(CustomAvatar.FromFileCoroutine(filePath, avatar =>
     {
         SwitchToAvatar(avatar);
     }, ex =>
     {
         Plugin.logger.Error("Failed to load avatar: " + ex.Message);
     }));
 }
コード例 #9
0
 public void SwitchToAvatarAsync(string filePath)
 {
     SharedCoroutineStarter.instance.StartCoroutine(CustomAvatar.FromFileCoroutine(filePath, avatar =>
     {
         Plugin.logger.Info("Successfully loaded avatar " + avatar.descriptor.name);
         SwitchToAvatar(avatar);
     }, ex =>
     {
         Plugin.logger.Error("Failed to load avatar: " + ex.Message);
     }));
 }
コード例 #10
0
        private void PlayerAvatarManager_AvatarChanged(CustomAvatar.CustomAvatar obj)
        {
            if (!Config.Instance.SeparateAvatarForMultiplayer && Client.Instance.connected)
            {
                Client.Instance.playerInfo.avatarHash = ModelSaberAPI.cachedAvatars.FirstOrDefault(x => x.Value == CustomAvatar.Plugin.Instance.PlayerAvatarManager.GetCurrentAvatar()).Key;

                if (string.IsNullOrEmpty(Client.Instance.playerInfo.avatarHash))
                {
                    Client.Instance.playerInfo.avatarHash = PlayerInfo.avatarHashPlaceholder;
                }
            }
        }
コード例 #11
0
        private void PlayerAvatarManager_AvatarChanged(CustomAvatar.CustomAvatar obj)
        {
            if (!Config.Instance.SeparateAvatarForMultiplayer)
            {
                Client.Instance.playerInfo.avatarHash = ModelSaberAPI.cachedAvatars.FirstOrDefault(x => x.Value == CustomAvatar.Plugin.Instance.PlayerAvatarManager.GetCurrentAvatar()).Key;

                if (Client.Instance.playerInfo.avatarHash == null)
                {
                    Client.Instance.playerInfo.avatarHash = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF";
                }
            }
        }
コード例 #12
0
        public PlayerAvatarManager(AvatarLoader avatarLoader, CustomAvatar startAvatar = null)
        {
            _playerAvatarInput = new PlayerAvatarInput();
            _avatarLoader      = avatarLoader;

            if (startAvatar != null)
            {
                CurrentPlayerAvatar = startAvatar;
            }

            Plugin.Instance.FirstPersonEnabledChanged += OnFirstPersonEnabledChanged;
            SceneManager.sceneLoaded += SceneManagerOnSceneLoaded;
        }
コード例 #13
0
        private void SelectRowWithAvatar(CustomAvatar avatar, bool reload, bool scroll)
        {
            int currentRow = Plugin.Instance.AvatarLoader.IndexOf(avatar);

            if (scroll)
            {
                _tableView.ScrollToCellWithIdx(currentRow, TableView.ScrollPositionType.Center, false);
            }
            if (reload)
            {
                _tableView.ReloadData();
            }
            _tableView.SelectCellWithIdx(currentRow);
        }
コード例 #14
0
        private void AvatarDownloaded(string hash, CustomAvatar.CustomAvatar downloadedAvatar)
        {
            if (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(downloadedAvatar, this);
            }
        }
コード例 #15
0
        private static SpawnedAvatar SpawnAvatar(CustomAvatar customAvatar, AvatarInput input)
        {
            if (customAvatar == null)
            {
                throw new ArgumentNullException(nameof(customAvatar));
            }
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            var spawnedAvatar = new SpawnedAvatar(customAvatar, input);

            return(spawnedAvatar);
        }
コード例 #16
0
        public static void LoadAvatars()
        {
            if (defaultAvatarInstance == null)
            {
                if (Config.Instance.DownloadAvatars)
                {
                    defaultAvatarInstance = CustomAvatar.Plugin.Instance.AvatarLoader.Avatars.FirstOrDefault(x => x.FullPath.ToLower().Contains("loading.avatar"));

                    if (defaultAvatarInstance == null)//fallback to multiplayer avatar
                    {
                        defaultAvatarInstance = CustomAvatar.Plugin.Instance.AvatarLoader.Avatars.FirstOrDefault(x => x.FullPath.ToLower().Contains("multiplayer.avatar"));
                    }

                    if (defaultAvatarInstance == null)//fallback to default avatar
                    {
                        defaultAvatarInstance = CustomAvatar.Plugin.Instance.AvatarLoader.Avatars.FirstOrDefault(x => x.FullPath.ToLower().Contains("templatefullbody.avatar"));
                    }

                    if (defaultAvatarInstance == null)//fallback to ANY avatar
                    {
                        defaultAvatarInstance = CustomAvatar.Plugin.Instance.AvatarLoader.Avatars.FirstOrDefault();
                    }
                }
                else
                {
                    defaultAvatarInstance = CustomAvatar.Plugin.Instance.AvatarLoader.Avatars.FirstOrDefault(x => x.FullPath.ToLower().Contains("multiplayer.avatar"));

                    if (defaultAvatarInstance == null)//fallback to default avatar
                    {
                        defaultAvatarInstance = CustomAvatar.Plugin.Instance.AvatarLoader.Avatars.FirstOrDefault(x => x.FullPath.ToLower().Contains("templatefullbody.avatar"));
                    }

                    if (defaultAvatarInstance == null)//fallback to ANY avatar
                    {
                        defaultAvatarInstance = CustomAvatar.Plugin.Instance.AvatarLoader.Avatars.FirstOrDefault();
                    }
                }
            }
#if DEBUG
            Plugin.log.Info($"Found avatar, isLoaded={defaultAvatarInstance.IsLoaded}");
#endif
            if (defaultAvatarInstance != null && !defaultAvatarInstance.IsLoaded)
            {
                defaultAvatarInstance.Load(null);
            }
        }
コード例 #17
0
        public AvatarLoader(string customAvatarsPath, Action <IReadOnlyList <CustomAvatar> > loadedCallback)
        {
            void AvatarPathsLoaded(FileBrowserItem[] items)
            {
                foreach (var item in items)
                {
                    if (item.isDirectory)
                    {
                        continue;
                    }
                    var newAvatar = new CustomAvatar(item.fullPath);
                    _avatars.Add(newAvatar);
                }

                loadedCallback(_avatars.ToArray());
            }

            GetAvatarsInPath(customAvatarsPath, AvatarPathsLoaded);
        }
コード例 #18
0
        public void SwitchToAvatar(CustomAvatar avatar)
        {
            if (avatar == null)
            {
                return;
            }
            if (currentlySpawnedAvatar?.customAvatar == avatar)
            {
                return;
            }

            currentlySpawnedAvatar?.Destroy();

            currentlySpawnedAvatar = SpawnAvatar(avatar);

            avatarChanged?.Invoke(currentlySpawnedAvatar);

            ResizeCurrentAvatar();
            currentlySpawnedAvatar?.OnFirstPersonEnabledChanged();

            SettingsManager.settings.previousAvatarPath = avatar.fullPath;
        }
コード例 #19
0
        public static SpawnedAvatar SpawnAvatar(CustomAvatar customAvatar, IAvatarInput avatarInput)
        {
            if (customAvatar.GameObject == null)
            {
                Plugin.Log("Can't spawn " + customAvatar.FullPath + " because it hasn't been loaded!");
                return(null);
            }

            var avatarGameObject = Object.Instantiate(customAvatar.GameObject);

            var behaviour = avatarGameObject.AddComponent <AvatarBehaviour>();

            behaviour.Init(avatarInput);

            avatarGameObject.AddComponent <AvatarEventsPlayer>();

            Object.DontDestroyOnLoad(avatarGameObject);

            var spawnedAvatar = new SpawnedAvatar(customAvatar, avatarGameObject);

            return(spawnedAvatar);
        }
コード例 #20
0
        private void CustomAvatarLoaded(CustomAvatar loadedAvatar, AvatarLoadResult result)
        {
            if (result != AvatarLoadResult.Completed)
            {
                Logger.Log("Avatar " + loadedAvatar.FullPath + " failed to load");
                return;
            }

            Logger.Log("Loaded avatar " + loadedAvatar.Name + " by " + loadedAvatar.AuthorName);

            if (_currentSpawnedPlayerAvatar?.GameObject != null)
            {
                Object.Destroy(_currentSpawnedPlayerAvatar.GameObject);
            }

            _currentSpawnedPlayerAvatar = AvatarSpawner.SpawnAvatar(loadedAvatar, _playerAvatarInput);

            AvatarChanged?.Invoke(loadedAvatar);

            _avatarTailor.OnAvatarLoaded(_currentSpawnedPlayerAvatar);
            ResizePlayerAvatar();
            OnFirstPersonEnabledChanged(Plugin.Instance.FirstPersonEnabled);
        }
コード例 #21
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}");
            }
        }
コード例 #22
0
 public SpawnedAvatar(CustomAvatar customAvatar, GameObject gameObject)
 {
     CustomAvatar = customAvatar;
     GameObject   = gameObject;
 }
コード例 #23
0
 public void SwitchToAvatar(CustomAvatar customAvatar)
 {
     CurrentPlayerAvatar = customAvatar;
 }
コード例 #24
0
        public static void LoadAvatar()
        {
            if (defaultAvatarInstance == null)
            {
                if (Config.Instance.DownloadAvatars)
                {
                    defaultAvatarInstance = CustomAvatar.Plugin.Instance.AvatarLoader.Avatars.FirstOrDefault(x => x.FullPath.ToLower().Contains("loading.avatar"));

                    if (defaultAvatarInstance == null)//fallback to multiplayer avatar
                    {
                        defaultAvatarInstance = CustomAvatar.Plugin.Instance.AvatarLoader.Avatars.FirstOrDefault(x => x.FullPath.ToLower().Contains("multiplayer.avatar"));
                    }

                    if (defaultAvatarInstance == null)//fallback to default avatar
                    {
                        defaultAvatarInstance = CustomAvatar.Plugin.Instance.AvatarLoader.Avatars.FirstOrDefault(x => x.FullPath.ToLower().Contains("templatefullbody.avatar"));
                    }

                    if (defaultAvatarInstance == null)//fallback to ANY avatar
                    {
                        defaultAvatarInstance = CustomAvatar.Plugin.Instance.AvatarLoader.Avatars.FirstOrDefault();
                    }
                }
                else
                {
                    defaultAvatarInstance = CustomAvatar.Plugin.Instance.AvatarLoader.Avatars.FirstOrDefault(x => x.FullPath.ToLower().Contains("multiplayer.avatar"));

                    if (defaultAvatarInstance == null)//fallback to default avatar
                    {
                        defaultAvatarInstance = CustomAvatar.Plugin.Instance.AvatarLoader.Avatars.FirstOrDefault(x => x.FullPath.ToLower().Contains("templatefullbody.avatar"));
                    }

                    if (defaultAvatarInstance == null)//fallback to ANY avatar
                    {
                        defaultAvatarInstance = CustomAvatar.Plugin.Instance.AvatarLoader.Avatars.FirstOrDefault();
                    }
                }
            }
#if DEBUG
            Misc.Logger.Info($"Found avatar, isLoaded={defaultAvatarInstance.IsLoaded}");
#endif
            if (!defaultAvatarInstance.IsLoaded)
            {
                defaultAvatarInstance.Load(null);
            }

            foreach (CustomAvatar.CustomAvatar avatar in CustomAvatar.Plugin.Instance.AvatarLoader.Avatars)
            {
                Task.Run(() =>
                {
                    string hash;
                    if (SongDownloader.CreateMD5FromFile(avatar.FullPath, out hash))
                    {
                        ModelSaberAPI.cachedAvatars.Add(hash, avatar);
#if DEBUG
                        Misc.Logger.Info("Hashed avatar " + avatar.Name + "! Hash: " + hash);
#endif
                    }
                }).ConfigureAwait(false);
            }
        }
コード例 #25
0
        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}");
            }
        }
コード例 #26
0
 public int IndexOf(CustomAvatar customAvatar)
 {
     return(_avatars.IndexOf(customAvatar));
 }
コード例 #27
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.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);
            }
        }
コード例 #28
0
 private void PlayerAvatarManagerOnAvatarChanged(CustomAvatar newAvatar)
 {
     PlayerPrefs.SetString(PreviousAvatarKey, newAvatar.FullPath);
 }
コード例 #29
0
 private static SpawnedAvatar SpawnAvatar(CustomAvatar customAvatar)
 {
     return(new SpawnedAvatar(customAvatar));
 }
コード例 #30
0
 private void OnAvatarChanged(CustomAvatar avatar)
 {
     SelectRowWithAvatar(avatar, true, false);
     PreviewCurrent();
 }