|
| 1 | +using MelonLoader; |
| 2 | +using UIExpansionKit.API; |
| 3 | +using UnityEngine; |
| 4 | + |
| 5 | +namespace TrackingRotator { |
| 6 | + |
| 7 | + public static class ModBuildInfo { |
| 8 | + public const string Name = "TrackingRotator"; |
| 9 | + public const string Author = "nitro."; |
| 10 | + public const string Version = "1.0.0"; |
| 11 | + public const string DownloadLink = "https://github.com/nitrog0d/TrackingRotator/releases/latest/download/TrackingRotator.dll"; |
| 12 | + public const string GameDeveloper = "VRChat"; |
| 13 | + public const string Game = "VRChat"; |
| 14 | + } |
| 15 | + |
| 16 | + public class TrackingRotatorMod : MelonMod { |
| 17 | + private const string ModCategory = "TrackingRotator"; |
| 18 | + private const string RotationValuePref = "RotationValue"; |
| 19 | + private const string HighPrecisionRotationValuePref = "HighPrecisionRotationValue"; |
| 20 | + private const string ResetRotationOnSceneChangePref = "ResetRotationOnSceneChange"; |
| 21 | + |
| 22 | + private static float rotationValue = 0f; |
| 23 | + private static float highPrecisionRotationValue = 0f; |
| 24 | + private static bool highPrecision = false; |
| 25 | + private static bool resetRotationOnSceneChange = false; |
| 26 | + |
| 27 | + private static Transform cameraTransform = null; |
| 28 | + private static Quaternion originalRotation; |
| 29 | + |
| 30 | + public override void OnApplicationStart() { |
| 31 | + MelonLogger.Msg("Mod loaded."); |
| 32 | + MelonPreferences.CreateCategory(ModCategory, "Tracking Rotator"); |
| 33 | + MelonPreferences.CreateEntry(ModCategory, RotationValuePref, 22.5f, "Rotation value"); |
| 34 | + MelonPreferences.CreateEntry(ModCategory, HighPrecisionRotationValuePref, 1f, "High precision rotation value"); |
| 35 | + MelonPreferences.CreateEntry(ModCategory, ResetRotationOnSceneChangePref, false, "Reset rotation when a new world loads"); |
| 36 | + ExpansionKitApi.GetExpandedMenu(ExpandedMenu.QuickMenu).AddSimpleButton("Tracking rotation", ShowRotationMenu); |
| 37 | + OnPreferencesSaved(); |
| 38 | + } |
| 39 | + |
| 40 | + public override void OnSceneWasLoaded(int buildIndex, string sceneName) { |
| 41 | + if (resetRotationOnSceneChange) { |
| 42 | + if (cameraTransform) { |
| 43 | + cameraTransform.localRotation = originalRotation; |
| 44 | + } |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + public override void OnPreferencesSaved() { |
| 49 | + rotationValue = MelonPreferences.GetEntryValue<float>(ModCategory, RotationValuePref); |
| 50 | + highPrecisionRotationValue = MelonPreferences.GetEntryValue<float>(ModCategory, HighPrecisionRotationValuePref); |
| 51 | + resetRotationOnSceneChange = MelonPreferences.GetEntryValue<bool>(ModCategory, ResetRotationOnSceneChangePref); |
| 52 | + } |
| 53 | + |
| 54 | + public override void VRChat_OnUiManagerInit() { |
| 55 | + cameraTransform = Object.FindObjectOfType<VRCVrCameraSteam>().field_Public_Transform_0; |
| 56 | + originalRotation = cameraTransform.localRotation; |
| 57 | + } |
| 58 | + |
| 59 | + private static ICustomShowableLayoutedMenu rotationMenu = null; |
| 60 | + |
| 61 | + // Based on knah's ViewPointTweaker mod, https://github.com/knah/VRCMods/blob/master/ViewPointTweaker |
| 62 | + private void ShowRotationMenu() { |
| 63 | + if (rotationMenu == null) { |
| 64 | + rotationMenu = ExpansionKitApi.CreateCustomQuickMenuPage(LayoutDescription.QuickMenu4Columns); |
| 65 | + |
| 66 | + void Move(Vector3 direction) { |
| 67 | + cameraTransform.Rotate(direction, highPrecision ? highPrecisionRotationValue : rotationValue, Space.World); |
| 68 | + } |
| 69 | + |
| 70 | + var transform = Camera.main.transform; |
| 71 | + |
| 72 | + rotationMenu.AddSpacer(); |
| 73 | + rotationMenu.AddSimpleButton("Forward", () => Move(transform.right)); |
| 74 | + rotationMenu.AddSpacer(); |
| 75 | + rotationMenu.AddSpacer(); |
| 76 | + |
| 77 | + rotationMenu.AddSimpleButton("Tilt Left", () => Move(transform.forward)); |
| 78 | + rotationMenu.AddSimpleButton("Reset", () => cameraTransform.localRotation = originalRotation); |
| 79 | + rotationMenu.AddSimpleButton("Tilt Right", () => Move(-transform.forward)); |
| 80 | + rotationMenu.AddSpacer(); |
| 81 | + |
| 82 | + rotationMenu.AddSpacer(); |
| 83 | + rotationMenu.AddSimpleButton("Backward", () => Move(-transform.right)); |
| 84 | + rotationMenu.AddSimpleButton("Left", () => Move(-transform.up)); |
| 85 | + rotationMenu.AddSimpleButton("Right", () => Move(transform.up)); |
| 86 | + |
| 87 | + rotationMenu.AddToggleButton("High precision", b => highPrecision = b, () => highPrecision); |
| 88 | + rotationMenu.AddSpacer(); |
| 89 | + rotationMenu.AddSpacer(); |
| 90 | + rotationMenu.AddSimpleButton("Back", rotationMenu.Hide); |
| 91 | + } |
| 92 | + |
| 93 | + rotationMenu.Show(); |
| 94 | + } |
| 95 | + } |
| 96 | +} |
0 commit comments