private void SwitchToAvatar(AvatarPrefab avatar)
        {
            if ((currentlySpawnedAvatar && currentlySpawnedAvatar.prefab == avatar) || avatar?.fullPath != _switchingToPath)
            {
                Object.Destroy(avatar.gameObject);
                return;
            }

            if (avatar == null)
            {
                _logger.Info("No avatar selected");
                if (_currentAvatarSettings != null)
                {
                    _currentAvatarSettings.ignoreExclusions.changed -= OnIgnoreFirstPersonExclusionsChanged;
                }
                _currentAvatarSettings = null;
                avatarChanged?.Invoke(null);
                _settings.previousAvatarPath = null;
                UpdateAvatarVerticalPosition();
                return;
            }

            var avatarInfo = new AvatarInfo(avatar);

            _settings.previousAvatarPath = avatarInfo.fileName;

            // cache avatar info since loading asset bundles is expensive
            if (_avatarInfos.ContainsKey(avatarInfo.fileName))
            {
                _avatarInfos[avatarInfo.fileName] = avatarInfo;
            }
            else
            {
                _avatarInfos.Add(avatarInfo.fileName, avatarInfo);
            }

            if (_currentAvatarSettings != null)
            {
                _currentAvatarSettings.ignoreExclusions.changed -= OnIgnoreFirstPersonExclusionsChanged;
            }
            currentlySpawnedAvatar = _spawner.SpawnAvatar(avatar, _container.Resolve <VRPlayerInputInternal>(), _avatarContainer.transform);
            _currentAvatarSettings = _settings.GetAvatarSettings(avatar.fileName);
            _currentAvatarSettings.ignoreExclusions.changed += OnIgnoreFirstPersonExclusionsChanged;

            ResizeCurrentAvatar();
            UpdateFirstPersonVisibility();
            UpdateLocomotionEnabled();

            avatarChanged?.Invoke(currentlySpawnedAvatar);
        }
示例#2
0
        private void CreateAvatar(AvatarPrefab avatar)
        {
            _ = avatarData ?? throw new InvalidOperationException("avatarData is not loaded.");
            _ = poseController ?? throw new InvalidOperationException("Pose controller is not loaded.");

            loadedAvatar = avatar;
            if (spawnedAvatar != null)
            {
                Destroy(spawnedAvatar);
            }

            spawnedAvatar = _avatarSpawner.SpawnAvatar(avatar, new MultiplayerAvatarInput(poseController, transform.name != "MultiplayerLobbyAvatar(Clone)"), poseController.transform);
            spawnedAvatar.GetComponent <AvatarIK>().isLocomotionEnabled = true;
            spawnedAvatar.scale = avatarData.scale;
        }