From 77b8395ecd28a6a6a5736730db398721a662c16d Mon Sep 17 00:00:00 2001 From: Rafa Date: Tue, 15 Dec 2020 10:36:52 -0300 Subject: [PATCH] 1.1.0 Support to UIX --- PlayerspaceMover.cs => Main.cs | 52 ++++++++++++++----- ...pace Mover.csproj => PlayspaceMover.csproj | 6 +-- Properties/AssemblyInfo.cs | 4 +- 3 files changed, 43 insertions(+), 19 deletions(-) rename PlayerspaceMover.cs => Main.cs (67%) rename Playerspace Mover.csproj => PlayspaceMover.csproj (95%) diff --git a/PlayerspaceMover.cs b/Main.cs similarity index 67% rename from PlayerspaceMover.cs rename to Main.cs index 866ded1..44c87e0 100644 --- a/PlayerspaceMover.cs +++ b/Main.cs @@ -5,21 +5,46 @@ using UnityEngine; #endregion -namespace Playerspace_Mover +namespace PlayspaceMover { public static class ModInfo { - public const string Name = "PlayerspaceMover"; - public const string Description = "A SteamVR Playerspace clone for Oculus Users"; + public const string Name = "PlayspaceMover"; + public const string Description = "A SteamVR's Playspace clone for Oculus Users"; public const string Author = "Rafa"; public const string Company = "RBX"; - public const string Version = "1.0.1"; + public const string Version = "1.1.0"; public const string DownloadLink = null; } - public class PlayerspaceMover : MelonMod + public class Main : MelonMod { - public override void OnApplicationStart() => MelonCoroutines.Start(WaitInitialization()); + #region Settings + private bool Enabled = true; + private float Strength = 1f; + private float DoubleClickTime = 0.25f; + #endregion + + private readonly string Category = "PlayspaceMover"; + public override void OnApplicationStart() + { + MelonPrefs.RegisterCategory(Category, "Playspace Mover"); + MelonPrefs.RegisterBool(Category, nameof(Enabled), Enabled, "Enabled"); + MelonPrefs.RegisterFloat(Category, nameof(Strength), Strength, "Strength"); + MelonPrefs.RegisterFloat(Category, nameof(DoubleClickTime), DoubleClickTime, "Double Click Time"); + ApplySettings(); + + MelonCoroutines.Start(WaitInitialization()); + } + + private void ApplySettings() + { + Enabled = MelonPrefs.GetBool(Category, nameof(Enabled)); + Strength = MelonPrefs.GetFloat(Category, nameof(Strength)); + DoubleClickTime = MelonPrefs.GetFloat(Category, nameof(DoubleClickTime)); + } + + public override void OnModSettingsApplied() => ApplySettings(); private VRCVrCameraOculus Camera; private bool isLeftPressed, isRightPressed = false; @@ -37,14 +62,15 @@ private IEnumerator WaitInitialization() yield break; } - MelonLogger.LogError("VRCVrCameraOculus has not found, this mod only work in Oculus for now!"); + MelonLogger.LogError("VRCVrCameraOculus not found, this mod only work in Oculus for now!"); yield break; } + public override void OnUpdate() { - if (Camera == null) return; + if (!Enabled || Camera == null) return; if (HasDoubleClicked(OVRInput.Button.Three, DoubleClickTime) || HasDoubleClicked(OVRInput.Button.One, DoubleClickTime)) { @@ -62,9 +88,8 @@ public override void OnUpdate() if (leftTrigger) { - Vector3 currentOffset = OVRInput.GetLocalControllerPosition(OVRInput.Controller.LTouch); - Vector3 calculatedOffset = (currentOffset - startingOffset) * -1.0f; + Vector3 calculatedOffset = (currentOffset - startingOffset) * -Strength; startingOffset = currentOffset; Camera.cameraLiftTransform.localPosition += calculatedOffset; } @@ -72,13 +97,13 @@ public override void OnUpdate() if (rightTrigger) { Vector3 currentOffset = OVRInput.GetLocalControllerPosition(OVRInput.Controller.RTouch); - Vector3 calculatedOffset = (currentOffset - startingOffset) * -1.0f; + Vector3 calculatedOffset = (currentOffset - startingOffset) * -Strength; startingOffset = currentOffset; Camera.cameraLiftTransform.localPosition += calculatedOffset; } } - private static Dictionary PreviousStates = new Dictionary() + private static readonly Dictionary PreviousStates = new Dictionary() { { OVRInput.Button.Three, false }, { OVRInput.Button.One, false } }; @@ -91,8 +116,7 @@ private static bool IsKeyJustPressed(OVRInput.Button key) else return PreviousStates[key] = false; } - private readonly float DoubleClickTime = 0.25f; - private static Dictionary lastTime = new Dictionary(); + private static readonly Dictionary lastTime = new Dictionary(); // Thanks to Psychloor! // https://github.com/Psychloor/DoubleTapRunner/blob/master/DoubleTapSpeed/Utilities.cs#L30 diff --git a/Playerspace Mover.csproj b/PlayspaceMover.csproj similarity index 95% rename from Playerspace Mover.csproj rename to PlayspaceMover.csproj index 903a59e..eab0d89 100644 --- a/Playerspace Mover.csproj +++ b/PlayspaceMover.csproj @@ -7,8 +7,8 @@ {23CF827E-3738-42E7-AAEF-225CB734A7A8} Library Properties - Playerspace_Mover - Playerspace Mover + PlayspaceMover + PlayspaceMover v4.7.2 512 true @@ -65,7 +65,7 @@ - + diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index 54966cf..b7664a0 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -1,6 +1,6 @@ using System.Reflection; using MelonLoader; -using Playerspace_Mover; +using PlayspaceMover; [assembly: AssemblyTitle(ModInfo.Description)] [assembly: AssemblyDescription(ModInfo.Description)] @@ -10,6 +10,6 @@ [assembly: AssemblyTrademark(ModInfo.Company)] [assembly: AssemblyVersion(ModInfo.Version)] [assembly: AssemblyFileVersion(ModInfo.Version)] -[assembly: MelonInfo(typeof(PlayerspaceMover), ModInfo.Name, ModInfo.Version, ModInfo.Author, ModInfo.DownloadLink)] +[assembly: MelonInfo(typeof(PlayspaceMover.Main), ModInfo.Name, ModInfo.Version, ModInfo.Author, ModInfo.DownloadLink)] [assembly: MelonGame("VRChat", "VRChat")] \ No newline at end of file