public void ResizeAvatar(SpawnedAvatar avatar) { if (!avatar.customAvatar.descriptor.allowHeightCalibration) { return; } // compute scale float scale; AvatarResizeMode resizeMode = SettingsManager.settings.resizeMode; switch (resizeMode) { case AvatarResizeMode.ArmSpan: float playerArmLength = SettingsManager.settings.playerArmSpan; var avatarArmLength = avatar.customAvatar.GetArmSpan(); scale = playerArmLength / avatarArmLength; break; case AvatarResizeMode.Height: scale = BeatSaberUtil.GetPlayerEyeHeight() / avatar.customAvatar.eyeHeight; break; default: scale = 1.0f; break; } // apply scale avatar.behaviour.scale = scale; SharedCoroutineStarter.instance.StartCoroutine(FloorMendingWithDelay(avatar)); }
public void ResizeAvatar(SpawnedAvatar avatar) { if (!avatar.customAvatar.descriptor.allowHeightCalibration || !avatar.customAvatar.isIKAvatar) { return; } // compute scale float scale; AvatarResizeMode resizeMode = SettingsManager.settings.resizeMode; switch (resizeMode) { case AvatarResizeMode.ArmSpan: float avatarArmLength = avatar.customAvatar.GetArmSpan(); if (avatarArmLength > 0) { scale = SettingsManager.settings.playerArmSpan / avatarArmLength; } else { scale = 1.0f; } break; case AvatarResizeMode.Height: float avatarEyeHeight = avatar.customAvatar.eyeHeight; if (avatarEyeHeight > 0) { scale = BeatSaberUtil.GetPlayerEyeHeight() / avatarEyeHeight; } else { scale = 1.0f; } break; default: scale = 1.0f; break; } if (scale <= 0) { Plugin.logger.Warn("Calculated scale is <= 0; reverting to 1"); scale = 1.0f; } // apply scale avatar.tracking.scale = scale; SharedCoroutineStarter.instance.StartCoroutine(FloorMendingWithDelay(avatar)); }
private IEnumerator FloorMendingWithDelay(SpawnedAvatar avatar) { yield return(new WaitForEndOfFrame()); // wait for CustomFloorPlugin:PlatformManager:Start to hide original platform float floorOffset = 0f; if (SettingsManager.settings.enableFloorAdjust && avatar.customAvatar.isIKAvatar) { float playerEyeHeight = BeatSaberUtil.GetPlayerEyeHeight(); float avatarEyeHeight = avatar.customAvatar.eyeHeight; floorOffset = playerEyeHeight - avatarEyeHeight * avatar.tracking.scale; if (SettingsManager.settings.moveFloorWithRoomAdjust) { floorOffset += BeatSaberUtil.GetRoomCenter().y; } } floorOffset = (float)Math.Round(floorOffset, 3); // round to millimeter // apply offset avatar.tracking.verticalPosition = floorOffset; // ReSharper disable Unity.PerformanceCriticalCodeInvocation GameObject menuPlayersPlace = GameObject.Find("MenuPlayersPlace"); GameObject originalFloor = GameObject.Find("Environment/PlayersPlace"); GameObject customFloor = GameObject.Find("Platform Loader"); // ReSharper disable restore Unity.PerformanceCriticalCodeInvocation if (menuPlayersPlace) { Plugin.logger.Info($"Moving MenuPlayersPlace floor {Math.Abs(floorOffset)} m {(floorOffset >= 0 ? "up" : "down")}"); menuPlayersPlace.transform.position = new Vector3(0, floorOffset, 0); } if (originalFloor) { Plugin.logger.Info($"Moving PlayersPlace {Math.Abs(floorOffset)} m {(floorOffset >= 0 ? "up" : "down")}"); originalFloor.transform.position = new Vector3(0, floorOffset, 0); } if (customFloor) { Plugin.logger.Info($"Moving Custom Platforms floor {Math.Abs(floorOffset)} m {(floorOffset >= 0 ? "up" : "down")}"); _initialPlatformPosition = _initialPlatformPosition ?? customFloor.transform.position; customFloor.transform.position = (Vector3.up * floorOffset) + _initialPlatformPosition ?? Vector3.zero; } }
private IEnumerator FloorMendingWithDelay(SpawnedAvatar avatar) { yield return(new WaitForEndOfFrame()); // wait for CustomFloorPlugin:PlatformManager:Start to hide original platform float floorOffset = 0f; if (SettingsManager.settings.enableFloorAdjust && avatar.customAvatar.isIKAvatar) { float playerViewPointHeight = BeatSaberUtil.GetPlayerEyeHeight(); float avatarViewPointHeight = avatar.customAvatar.viewPoint.position.y; floorOffset = playerViewPointHeight - avatarViewPointHeight * avatar.behaviour.scale; } // apply offset avatar.behaviour.position = new Vector3(0, floorOffset, 0); // ReSharper disable Unity.PerformanceCriticalCodeInvocation var originalFloor = GameObject.Find("MenuPlayersPlace") ?? GameObject.Find("Static/PlayersPlace"); var customFloor = GameObject.Find("Platform Loader"); // ReSharper disable restore Unity.PerformanceCriticalCodeInvocation if (originalFloor) { Plugin.logger.Info($"Moving original floor {Math.Abs(floorOffset)} m {(floorOffset >= 0 ? "up" : "down")}"); originalFloor.transform.position = new Vector3(0, floorOffset, 0); } if (customFloor) { Plugin.logger.Info($"Moving Custom Platforms floor {Math.Abs(floorOffset)} m {(floorOffset >= 0 ? "up" : "down")}"); _initialPlatformPosition = _initialPlatformPosition ?? customFloor.transform.position; customFloor.transform.position = (Vector3.up * floorOffset) + _initialPlatformPosition ?? Vector3.zero; } }