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); }
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)); }
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); }
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 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); }
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); }
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; }
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); }
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; } }