Пример #1
0
        private void UpdateCalibrationButtons(SpawnedAvatar avatar)
        {
            if (!avatar)
            {
                _calibrateButton.interactable  = false;
                _clearButton.interactable      = false;
                _calibrateButtonHoverHint.text = "No avatar selected";
                _calibrateButtonText.text      = "Calibrate";
                _clearButtonText.text          = "Clear";

                return;
            }

            if (!_playerInput.TryGetUncalibratedPose(DeviceUse.Waist, out Pose _) &&
                !_playerInput.TryGetUncalibratedPose(DeviceUse.LeftFoot, out Pose _) &&
                !_playerInput.TryGetUncalibratedPose(DeviceUse.RightFoot, out Pose _))
            {
                _calibrateButton.interactable  = false;
                _clearButton.interactable      = _currentAvatarManualCalibration?.isCalibrated == true;
                _calibrateButtonHoverHint.text = "No trackers detected";
                _calibrateButtonText.text      = "Calibrate";
                _clearButtonText.text          = "Clear";

                return;
            }

            _calibrateButton.interactable  = true;
            _clearButton.interactable      = _calibrating || _currentAvatarManualCalibration?.isCalibrated == true;
            _calibrateButtonHoverHint.text = "Start manual full body calibration";
            _calibrateButtonText.text      = _calibrating ? "Save" : "Calibrate";
            _clearButtonText.text          = _calibrating ? "Cancel" : "Clear";
        }
Пример #2
0
        public void UpdateUI(SpawnedAvatar avatar)
        {
            if (_currentAvatarSettings != null)
            {
                _currentAvatarSettings.useAutomaticCalibration.changed -= OnUseAutomaticCalibrationChanged;
            }

            UpdateCalibrationButtons(avatar);

            if (!avatar)
            {
                _clearButton.interactable                 = false;
                _calibrateButton.interactable             = false;
                _automaticCalibrationSetting.interactable = false;
                _automaticCalibrationHoverHint.text       = "No avatar selected";

                return;
            }

            _currentAvatarSettings          = _settings.GetAvatarSettings(avatar.prefab.fileName);
            _currentAvatarManualCalibration = _calibrationData.GetAvatarManualCalibration(avatar.prefab.fileName);

            _currentAvatarSettings.useAutomaticCalibration.changed += OnUseAutomaticCalibrationChanged;

            _ignoreExclusionsSetting.Value = _currentAvatarSettings.ignoreExclusions;

            _bypassCalibration.Value = _currentAvatarSettings.bypassCalibration;

            _automaticCalibrationSetting.Value        = _currentAvatarSettings.useAutomaticCalibration;
            _automaticCalibrationSetting.interactable = avatar.prefab.descriptor.supportsAutomaticCalibration;
            _automaticCalibrationHoverHint.text       = avatar.prefab.descriptor.supportsAutomaticCalibration ? "Use automatic calibration instead of manual calibration." : "Not supported by current avatar";
        }
Пример #3
0
        internal void CalibrateFullBodyTrackingManual(SpawnedAvatar spawnedAvatar)
        {
            _logger.Info("Running manual full body tracking calibration");

            CalibrationData.FullBodyCalibration fullBodyCalibration = _calibrationData.GetAvatarManualCalibration(spawnedAvatar.avatar.fileName);

            if (TryGetUncalibratedPoseForAvatar(DeviceUse.Waist, spawnedAvatar, out Pose waist))
            {
                Vector3    positionOffset = Quaternion.Inverse(waist.rotation) * (spawnedAvatar.pelvis.position - waist.position);
                Quaternion rotationOffset = Quaternion.Inverse(waist.rotation) * spawnedAvatar.pelvis.rotation;

                fullBodyCalibration.waist = new Pose(positionOffset, rotationOffset);
                _logger.Info("Set waist pose correction " + fullBodyCalibration.waist);
            }

            if (TryGetUncalibratedPoseForAvatar(DeviceUse.LeftFoot, spawnedAvatar, out Pose leftFoot))
            {
                Vector3    positionOffset = Quaternion.Inverse(leftFoot.rotation) * (spawnedAvatar.leftLeg.position - leftFoot.position);
                Quaternion rotationOffset = Quaternion.Inverse(leftFoot.rotation) * spawnedAvatar.leftLeg.rotation;

                fullBodyCalibration.leftFoot = new Pose(positionOffset, rotationOffset);
                _logger.Info("Set left foot pose correction " + fullBodyCalibration.leftFoot);
            }

            if (TryGetUncalibratedPoseForAvatar(DeviceUse.RightFoot, spawnedAvatar, out Pose rightFoot))
            {
                Vector3    positionOffset = Quaternion.Inverse(rightFoot.rotation) * (spawnedAvatar.rightLeg.position - rightFoot.position);
                Quaternion rotationOffset = Quaternion.Inverse(rightFoot.rotation) * spawnedAvatar.rightLeg.rotation;

                fullBodyCalibration.rightFoot = new Pose(positionOffset, rotationOffset);
                _logger.Info("Set right foot pose correction " + fullBodyCalibration.rightFoot);
            }

            inputChanged?.Invoke();
        }
Пример #4
0
        internal bool TryGetUncalibratedPose(DeviceUse use, out Pose pose)
        {
            if (!_deviceManager.TryGetDeviceState(use, out TrackedDevice device) || !device.isTracking)
            {
                pose = Pose.identity;
                return(false);
            }

            pose = new Pose(device.position, device.rotation);

            _trackingHelper.ApplyRoomAdjust(ref pose.position, ref pose.rotation);

            SpawnedAvatar spawnedAvatar = _avatarManager.currentlySpawnedAvatar;

            switch (use)
            {
            case DeviceUse.Head:
            case DeviceUse.LeftHand:
            case DeviceUse.RightHand:
                _trackingHelper.ApplyFloorOffset(spawnedAvatar, ref pose.position);
                break;

            default:
                _trackingHelper.ApplyTrackerFloorOffset(spawnedAvatar, ref pose.position);
                break;
            }

            return(true);
        }
Пример #5
0
        IEnumerator InitializeAvatarController()
        {
            if (!defaultAvatarInstance.IsLoaded)
            {
                Logger.Debug("Waiting for avatar to load");
                yield return(new WaitWhile(delegate() { return !defaultAvatarInstance.IsLoaded; }));
            }
            else
            {
                yield return(null);
            }

            Logger.Debug("Spawning avatar");
            _centerAdjust = FindObjectOfType <VRCenterAdjust>();

            avatar = AvatarSpawner.SpawnAvatar(defaultAvatarInstance, this);

            playerNameText = CreateWorldText(transform, "Loading");
            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);
        }
Пример #6
0
        public void UpdateUI(SpawnedAvatar avatar)
        {
            if (!avatar)
            {
                _autoCalibrateButton.interactable  = false;
                _autoClearButton.interactable      = false;
                _autoCalibrateButtonHoverHint.text = "No avatar selected";

                return;
            }

            if (!_playerInput.TryGetUncalibratedPose(DeviceUse.Waist, out Pose _) &&
                !_playerInput.TryGetUncalibratedPose(DeviceUse.LeftFoot, out Pose _) &&
                !_playerInput.TryGetUncalibratedPose(DeviceUse.RightFoot, out Pose _))
            {
                _autoCalibrateButton.interactable  = false;
                _autoClearButton.interactable      = _calibrationData.automaticCalibration.isCalibrated;
                _autoCalibrateButtonHoverHint.text = "No trackers detected";

                return;
            }

            if (avatar.prefab.descriptor.supportsAutomaticCalibration)
            {
                _autoCalibrateButton.interactable  = true;
                _autoClearButton.interactable      = _calibrationData.automaticCalibration.isCalibrated;
                _autoCalibrateButtonHoverHint.text = "Calibrate full body tracking automatically";
            }
            else
            {
                _autoCalibrateButton.interactable  = false;
                _autoClearButton.interactable      = false;
                _autoCalibrateButtonHoverHint.text = "Not supported by current avatar";
            }
        }
        public void SwitchToAvatarAsync(string fileName)
        {
            if (currentlySpawnedAvatar)
            {
                Object.Destroy(currentlySpawnedAvatar.prefab.gameObject);
            }
            Object.Destroy(currentlySpawnedAvatar);
            currentlySpawnedAvatar = null;
            _currentAvatarSettings = null;

            if (string.IsNullOrEmpty(fileName))
            {
                _switchingToPath = null;
                avatarStartedLoading?.Invoke(null);
                SwitchToAvatar(null);
                return;
            }

            string fullPath = Path.Combine(kCustomAvatarsPath, fileName);

            _switchingToPath = fullPath;

            avatarStartedLoading?.Invoke(fullPath);

            SharedCoroutineStarter.instance.StartCoroutine(_avatarLoader.LoadFromFileAsync(fullPath, SwitchToAvatar, OnAvatarLoadFailed));
        }
Пример #8
0
        /// <summary>
        /// Scales the vertical movement of a tracked point based on the quotient of avatar height and player height.
        /// This moves the trackers as if the player was the height of the avatar, but only vertically (no horizontal scaling).
        /// </summary>
        public void ApplyTrackerFloorOffset(SpawnedAvatar spawnedAvatar, ref Vector3 position)
        {
            if (_settings.floorHeightAdjust == FloorHeightAdjust.Off || !spawnedAvatar)
            {
                return;
            }

            position.y *= spawnedAvatar.scaledEyeHeight / _beatSaberUtilities.GetRoomAdjustedPlayerEyeHeight();
        }
Пример #9
0
 void OnDestroy()
 {
     Plugin.log.Debug("Destroying avatar");
     if (avatar != null && avatar.eventsPlayer != null)
     {
         avatar.Destroy();
         avatar = null;
     }
 }
Пример #10
0
        /// <summary>
        /// Move tracked point upwards based on the difference between avatar height and player height.
        /// This essentially moves the trackers up as if the player was on stilts.
        /// </summary>
        public void ApplyFloorOffset(SpawnedAvatar spawnedAvatar, ref Vector3 position)
        {
            if (!_settings.enableFloorAdjust || !spawnedAvatar)
            {
                return;
            }

            position.y += spawnedAvatar.scaledEyeHeight - _beatSaberUtilities.GetRoomAdjustedPlayerEyeHeight();
        }
Пример #11
0
        internal void ClearManualFullBodyTrackingData(SpawnedAvatar spawnedAvatar)
        {
            CalibrationData.FullBodyCalibration fullBodyCalibration = _calibrationData.GetAvatarManualCalibration(spawnedAvatar.avatar.fileName);

            fullBodyCalibration.leftFoot  = Pose.identity;
            fullBodyCalibration.rightFoot = Pose.identity;
            fullBodyCalibration.waist     = Pose.identity;

            inputChanged?.Invoke();
        }
 public void UpdateUI(SpawnedAvatar avatar)
 {
     if (_playerInput.TryGetUncalibratedPose(DeviceUse.LeftHand, out Pose _) && _playerInput.TryGetUncalibratedPose(DeviceUse.RightHand, out Pose _))
     {
         _measureButton.interactable  = true;
         _measureButtonHoverHint.text = "For optimal results, hold your arms out to either side of your body and point the ends of the controllers outwards as far as possible (turn your hands if necessary).";
     }
     else
     {
         _measureButton.interactable  = false;
         _measureButtonHoverHint.text = "Controllers not detected";
     }
 }
        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";
            }
        }
        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);
        }
Пример #15
0
        internal bool TryGetUncalibratedPoseForAvatar(DeviceUse use, SpawnedAvatar spawnedAvatar, out Pose pose)
        {
            if (!TryGetUncalibratedPose(use, out pose))
            {
                return(false);
            }

            if (spawnedAvatar)
            {
                _trackingHelper.ApplyLocalPose(ref pose.position, ref pose.rotation, spawnedAvatar.transform.parent);
            }

            return(true);
        }
Пример #16
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);
            }
        }
Пример #17
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;
            }
        }
        private void OnAvatarChanged(SpawnedAvatar avatar)
        {
            if (!avatar)
            {
                return;
            }
            if (!hashesCalculated)
            {
                _avatarProvider.hashesCalculated += (x, y) => OnAvatarChanged(avatar);
                return;
            }

            Plugin.Log?.Warn($"Attempting to hash {avatar.avatar.fullPath}");
            _avatarProvider.HashAvatar(avatar.avatar).ContinueWith(r =>
            {
                localAvatar.hash  = r.Result;
                localAvatar.scale = avatar.scale;
            });
        }
Пример #19
0
        void InitializeAvatarController()
        {
#if DEBUG
            Plugin.log.Info("Spawning avatar");
#endif
            centerAdjust = GameObject.FindObjectOfType <VRCenterAdjust>();

            avatarInput = new MultiplayerAvatarInput();

            avatar = AvatarManager.SpawnAvatar(defaultAvatarInstance, avatarInput);

            /*
             * 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.eventsPlayer.gameObject.transform.SetParent(centerAdjust.transform, false);
            transform.SetParent(centerAdjust.transform, false);

            if (ModelSaberAPI.cachedAvatars.Any(x => x.Value.fullPath == avatar.customAvatar.fullPath))
            {
                currentAvatarHash = ModelSaberAPI.cachedAvatars.First(x => x.Value.fullPath == avatar.customAvatar.fullPath).Key;
            }
            else
            {
                currentAvatarHash = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF";
            }
        }
Пример #20
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;
            }
        }
Пример #22
0
        private void SwitchToAvatar(LoadedAvatar avatar)
        {
            if ((currentlySpawnedAvatar && currentlySpawnedAvatar.avatar == avatar) || avatar?.fullPath != _switchingToPath)
            {
                avatar?.Dispose();
                return;
            }

            if (avatar == null)
            {
                _logger.Info("No avatar selected");
                avatarChanged?.Invoke(null);
                _settings.previousAvatarPath = null;
                UpdateFloorOffsetForCurrentAvatar();
                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);
            }

            currentlySpawnedAvatar = _spawner.SpawnAvatar(avatar, _container.Resolve <VRPlayerInput>(), _avatarContainer.transform);
            _currentAvatarSettings = _settings.GetAvatarSettings(avatar.fileName);

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

            avatarChanged?.Invoke(currentlySpawnedAvatar);
        }
Пример #23
0
        IEnumerator InitializeReplayManager()
        {
            if (!defaultAvatar.IsLoaded)
            {
                Logger.Debug("Waiting for avatar to load");
                yield return(new WaitWhile(delegate() { return !defaultAvatar.IsLoaded; }));
            }
            else
            {
                yield return(null);
            }

            Logger.Debug("Spawning avatar");
            _centerAdjust = FindObjectOfType <VRCenterAdjust>();

            avatar = AvatarSpawner.SpawnAvatar(defaultAvatar, this);

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

            InvokeRepeating("MovementPlay", 0f, UPDATE_INTERVAL);
        }
Пример #24
0
        private void OnAvatarChanged(SpawnedAvatar spawnedAvatar)
        {
            if (_avatarSettings != null)
            {
                _avatarSettings.useAutomaticCalibration.changed -= OnUseAutomaticCalibrationChanged;
                _avatarSettings.bypassCalibration.changed       -= OnBypassCalibrationChanged;
            }

            if (!spawnedAvatar)
            {
                _avatarSettings    = null;
                _manualCalibration = null;

                return;
            }

            _avatarSettings    = _settings.GetAvatarSettings(spawnedAvatar.avatar.fileName);
            _manualCalibration = _calibrationData.GetAvatarManualCalibration(spawnedAvatar.avatar.fileName);

            _avatarSettings.useAutomaticCalibration.changed += OnUseAutomaticCalibrationChanged;
            _avatarSettings.bypassCalibration.changed       += OnBypassCalibrationChanged;
        }
        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;
        }
Пример #26
0
        public void SetPlayerPacket(PlayerPacket _playerInfo, Vector3 offsetVector, bool isLocal)
        {
            if (_playerInfo == null)
            {
                playerNameText.gameObject.SetActive(false);
                if (rendererEnabled)
                {
                    SetRendererInChilds(avatar.GameObject.transform, false);
                    rendererEnabled = false;
                }
                return;
            }

            try
            {
                playerInfo = _playerInfo;

                if (!playerNameText)
                {
                    return;
                }
                if (avatar == null || ModelSaberAPI.cachedAvatars.First(x => x.Value == avatar.CustomAvatar).Key != playerInfo.avatarHash)
                {
                    if (ModelSaberAPI.cachedAvatars.ContainsKey(playerInfo.avatarHash))
                    {
                        if (ModelSaberAPI.cachedAvatars[playerInfo.avatarHash].IsLoaded)
                        {
                            if (avatar != null)
                            {
                                Destroy(avatar.GameObject);
                            }

                            avatar = AvatarSpawner.SpawnAvatar(ModelSaberAPI.cachedAvatars[playerInfo.avatarHash], this);
                        }
                        else if (!pendingAvatars.Contains(ModelSaberAPI.cachedAvatars[playerInfo.avatarHash]))
                        {
                            pendingAvatars.Add(ModelSaberAPI.cachedAvatars[playerInfo.avatarHash]);
                            ModelSaberAPI.cachedAvatars[playerInfo.avatarHash].Load((CustomAvatar.CustomAvatar loadedAvatar, AvatarLoadResult result) =>
                            {
                                if (result == AvatarLoadResult.Completed)
                                {
                                    pendingAvatars.Remove(ModelSaberAPI.cachedAvatars[playerInfo.avatarHash]);
                                    AvatarLoaded?.Invoke(ModelSaberAPI.cachedAvatars.First(x => x.Value == avatar.CustomAvatar).Key, loadedAvatar);
                                }
                            });
                            AvatarLoaded += AvatarController_AvatarLoaded;
                        }
                        else
                        {
                            AvatarLoaded -= AvatarController_AvatarLoaded;
                            AvatarLoaded += AvatarController_AvatarLoaded;
                        }
                    }
                    else
                    {
                        if (ModelSaberAPI.queuedAvatars.Contains(playerInfo.avatarHash))
                        {
                            ModelSaberAPI.avatarDownloaded += AvatarDownloaded;
                        }
                        else
                        {
                            SharedCoroutineStarter.instance.StartCoroutine(ModelSaberAPI.DownloadAvatarCoroutine(playerInfo.avatarHash, (CustomAvatar.CustomAvatar avatar) => { AvatarDownloaded(playerInfo.avatarHash, avatar); }));
                        }
                    }
                }

                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;


                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 (forcePlayerPacket)
                {
                    interpHeadPos      = targetHeadPos;
                    interpLeftHandPos  = targetLeftHandPos;
                    interpRightHandPos = targetRightHandPos;

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

                    transform.position = interpHeadPos;
                }
            }
            catch (Exception e)
            {
                Logger.Error($"Avatar controller exception: {_playerInfo.playerName}: {e}");
            }
        }
 private void OnAvatarChanged(SpawnedAvatar spawnedAvatar)
 {
     UpdateUI(spawnedAvatar?.avatar);
 }
 private void OnAvatarChanged(SpawnedAvatar avatar)
 {
     SetLoading(false);
 }
 private void OnAvatarChanged(SpawnedAvatar avatar)
 {
     ReloadData();
 }
 private void OnAvatarChanged(SpawnedAvatar spawnedAvatar)
 {
     SetLoading(false);
     DisableCalibrationMode(false);
     UpdateUI(spawnedAvatar?.avatar);
 }