From 28aca1bb4925f8357ecdd1195402df400f0a31cc Mon Sep 17 00:00:00 2001 From: SDraw Date: Fri, 3 Mar 2023 00:44:17 +0300 Subject: [PATCH] Scaled locomotion steps Funny C# properties Minor fixes --- ml_amt/Main.cs | 20 ++-- ml_amt/MotionTweaker.cs | 71 +++++++++++--- ml_amt/Settings.cs | 207 ++++++++++++++++----------------------- ml_amt/Utils.cs | 9 +- ml_amt/resources/menu.js | 7 ++ ml_dht/HeadTracked.cs | 18 ++-- ml_dht/Settings.cs | 99 +++++++------------ ml_lme/LeapTracked.cs | 86 ++++++++-------- ml_lme/Settings.cs | 205 +++++++++++++++----------------------- ml_pam/ArmMover.cs | 2 + ml_pam/Settings.cs | 29 ++---- 11 files changed, 343 insertions(+), 410 deletions(-) diff --git a/ml_amt/Main.cs b/ml_amt/Main.cs index 3a1ea73..3999cb9 100644 --- a/ml_amt/Main.cs +++ b/ml_amt/Main.cs @@ -98,7 +98,7 @@ namespace ml_amt m_localTweaker = PlayerSetup.Instance.gameObject.AddComponent(); m_localTweaker.SetIKOverrideCrouch(Settings.IKOverrideCrouch); m_localTweaker.SetCrouchLimit(Settings.CrouchLimit); - m_localTweaker.SetIKOverrideCrouch(Settings.IKOverrideProne); + m_localTweaker.SetIKOverrideProne(Settings.IKOverrideProne); m_localTweaker.SetProneLimit(Settings.ProneLimit); m_localTweaker.SetPoseTransitions(Settings.PoseTransitions); m_localTweaker.SetAdjustedMovement(Settings.AdjustedMovement); @@ -260,13 +260,10 @@ namespace ml_amt { try { - if(Settings.OverrideFix) + if(Settings.OverrideFix && (__instance.animator != null)) { - if(__instance.animator != null) - { - __instance.animator.enabled = false; - __instance.animator.WriteDefaultValues(); - } + __instance.animator.enabled = false; + __instance.animator.WriteDefaultValues(); } } catch(System.Exception l_exception) @@ -278,13 +275,10 @@ namespace ml_amt { try { - if(Settings.OverrideFix) + if(Settings.OverrideFix && (__instance.animator != null)) { - if(__instance.animator != null) - { - __instance.animator.enabled = true; - __instance.animator.Update(0f); - } + __instance.animator.enabled = true; + __instance.animator.Update(0f); } } catch(System.Exception l_exception) diff --git a/ml_amt/MotionTweaker.cs b/ml_amt/MotionTweaker.cs index 79247eb..a0e7922 100644 --- a/ml_amt/MotionTweaker.cs +++ b/ml_amt/MotionTweaker.cs @@ -1,4 +1,5 @@ using ABI_RC.Core.Player; +using ABI_RC.Systems.IK; using ABI_RC.Systems.IK.SubSystems; using ABI_RC.Systems.MovementSystem; using RootMotion.FinalIK; @@ -65,6 +66,7 @@ namespace ml_amt bool m_followHips = true; Vector3 m_hipsToPlayer = Vector3.zero; + Vector2 m_stepDistance = Vector2.zero; Vector3 m_massCenter = Vector3.zero; readonly List m_parameters = null; @@ -74,6 +76,7 @@ namespace ml_amt m_parameters = new List(); } + // Unity events void Start() { m_inVR = Utils.IsInVR(); @@ -88,7 +91,8 @@ namespace ml_amt Settings.IKOverrideJumpChange += this.SetIKOverrideJump; Settings.DetectEmotesChange += this.SetDetectEmotes; Settings.FollowHipsChange += this.SetFollowHips; - Settings.MassCenterChange += this.SetMassCenter; + Settings.MassCenterChange += this.OnMassCenterChange; + Settings.ScaledStepsChange += this.OnScaledStepsChange; } void OnDestroy() @@ -103,7 +107,7 @@ namespace ml_amt Settings.IKOverrideJumpChange -= this.SetIKOverrideJump; Settings.DetectEmotesChange -= this.SetDetectEmotes; Settings.FollowHipsChange -= this.SetFollowHips; - Settings.MassCenterChange -= this.SetMassCenter; + Settings.MassCenterChange -= this.OnMassCenterChange; } void Update() @@ -163,6 +167,7 @@ namespace ml_amt } } + // Game events internal void OnAvatarClear() { m_vrIk = null; @@ -183,6 +188,7 @@ namespace ml_amt m_avatarHips = null; m_viewPointHeight = 1f; m_massCenter = Vector3.zero; + m_stepDistance = Vector2.zero; m_parameters.Clear(); } @@ -253,6 +259,8 @@ namespace ml_amt m_vrIk.solver.locomotion.offset = (Settings.MassCenter ? m_massCenter : m_locomotionOffset); + m_stepDistance.Set(m_vrIk.solver.locomotion.stepThreshold, m_vrIk.solver.locomotion.footDistance); + m_vrIk.onPreSolverUpdate.AddListener(this.OnIKPreUpdate); m_vrIk.onPostSolverUpdate.AddListener(this.OnIKPostUpdate); } @@ -276,12 +284,23 @@ namespace ml_amt internal void OnPlayspaceScale() { - if((m_vrIk != null) && Settings.MassCenter) + if(m_vrIk != null) { - m_vrIk.solver.locomotion.offset = m_massCenter * GetRelativeScale(); + if(Settings.MassCenter) + m_vrIk.solver.locomotion.offset = m_massCenter * GetRelativeScale(); + + if(Settings.ScaledSteps) + { + m_vrIk.solver.locomotion.stepThreshold = m_stepDistance.x * GetRelativeScale(); + m_vrIk.solver.locomotion.footDistance = m_stepDistance.y * GetRelativeScale(); + + m_vrIk.solver.locomotion.stepHeight.keys = Utils.GetSineKeyframes(Mathf.Clamp01(PlayerSetup.Instance.GetAvatarHeight()) * 0.03f); + m_vrIk.solver.locomotion.heelHeight.keys = Utils.GetSineKeyframes(Mathf.Clamp01(PlayerSetup.Instance.GetAvatarHeight()) * 0.03f); + } } } + // IK events void OnIKPreUpdate() { bool l_locomotionOverride = false; @@ -342,25 +361,26 @@ namespace ml_amt m_vrIk.solver.rightLeg.useAnimatedBendNormal = m_bendNormalRight; } - public void SetIKOverrideCrouch(bool p_state) + // Settings + internal void SetIKOverrideCrouch(bool p_state) { m_ikOverrideCrouch = p_state; } - public void SetCrouchLimit(float p_value) + internal void SetCrouchLimit(float p_value) { if(!m_customCrouchLimit) m_crouchLimit = Mathf.Clamp01(p_value); } - public void SetIKOverrideProne(bool p_state) + internal void SetIKOverrideProne(bool p_state) { m_ikOverrideProne = p_state; } - public void SetProneLimit(float p_value) + internal void SetProneLimit(float p_value) { if(!m_customProneLimit) m_proneLimit = Mathf.Clamp01(p_value); } - public void SetPoseTransitions(bool p_state) + internal void SetPoseTransitions(bool p_state) { m_poseTransitions = p_state; @@ -370,7 +390,7 @@ namespace ml_amt PlayerSetup.Instance.animatorManager.SetAnimatorParameterBool("Prone", false); } } - public void SetAdjustedMovement(bool p_state) + internal void SetAdjustedMovement(bool p_state) { m_adjustedMovement = p_state; @@ -380,33 +400,54 @@ namespace ml_amt MovementSystem.Instance.ChangeProne(false); } } - public void SetIKOverrideFly(bool p_state) + internal void SetIKOverrideFly(bool p_state) { m_ikOverrideFly = p_state; } - public void SetIKOverrideJump(bool p_state) + internal void SetIKOverrideJump(bool p_state) { m_ikOverrideJump = p_state; } - public void SetDetectEmotes(bool p_state) + internal void SetDetectEmotes(bool p_state) { m_detectEmotes = p_state; } - public void SetFollowHips(bool p_state) + internal void SetFollowHips(bool p_state) { m_followHips = p_state; } - public void SetMassCenter(bool p_state) + void OnMassCenterChange(bool p_state) { if(m_vrIk != null) m_vrIk.solver.locomotion.offset = (Settings.MassCenter ? (m_massCenter * GetRelativeScale()) : m_locomotionOffset); } + void OnScaledStepsChange(bool p_state) + { + if(m_vrIk != null) + { + if(p_state) + { + m_vrIk.solver.locomotion.stepThreshold = m_stepDistance.x * GetRelativeScale(); + m_vrIk.solver.locomotion.footDistance = m_stepDistance.y * GetRelativeScale(); + m_vrIk.solver.locomotion.stepHeight.keys = Utils.GetSineKeyframes(Mathf.Clamp01(PlayerSetup.Instance.GetAvatarHeight()) * 0.03f); + m_vrIk.solver.locomotion.heelHeight.keys = Utils.GetSineKeyframes(Mathf.Clamp01(PlayerSetup.Instance.GetAvatarHeight()) * 0.03f); + } + else + { + IKSystem.Instance.ApplyAvatarScaleToIk(PlayerSetup.Instance.GetAvatarHeight()); + m_vrIk.solver.locomotion.stepHeight.keys = Utils.GetSineKeyframes(0.03f); + m_vrIk.solver.locomotion.heelHeight.keys = Utils.GetSineKeyframes(0.03f); + } + } + } + // Arbitrary float GetRelativeScale() { return ((m_avatarScale > 0f) ? (PlayerSetup.Instance._avatar.transform.localScale.y / m_avatarScale) : 0f); } + // Parameters access public float GetUpright() => m_upright; public bool GetGroundedRaw() => m_groundedRaw; public bool GetMoving() => m_moving; diff --git a/ml_amt/Settings.cs b/ml_amt/Settings.cs index 8a2cb9b..930a83d 100644 --- a/ml_amt/Settings.cs +++ b/ml_amt/Settings.cs @@ -20,23 +20,25 @@ namespace ml_amt DetectEmotes, FollowHips, CollisionScale, + ScaledSteps, MassCenter, OverrideFix }; - static bool ms_ikOverrideCrouch = true; - static float ms_crouchLimit = 0.65f; - static bool ms_ikOverrideProne = true; - static float ms_proneLimit = 0.3f; - static bool ms_poseTransitions = true; - static bool ms_adjustedMovement = true; - static bool ms_ikOverrideFly = true; - static bool ms_ikOverrideJump = true; - static bool ms_detectEmotes = true; - static bool ms_followHips = true; - static bool ms_collisionScale = true; - static bool ms_massCenter = true; - static bool ms_overrideFix = true; + public static bool IKOverrideCrouch { get; private set; } = true; + public static float CrouchLimit { get; private set; } = 0.65f; + public static bool IKOverrideProne { get; private set; } = true; + public static float ProneLimit { get; private set; } = 0.3f; + public static bool PoseTransitions { get; private set; } = true; + public static bool AdjustedMovement { get; private set; } = true; + public static bool IKOverrideFly { get; private set; } = true; + public static bool IKOverrideJump { get; private set; } = true; + public static bool DetectEmotes { get; private set; } = true; + public static bool FollowHips { get; private set; } = true; + public static bool MassCenter { get; private set; } = true; + public static bool ScaledSteps { get; private set; } = true; + public static bool CollisionScale { get; private set; } = true; + public static bool OverrideFix { get; private set; } = true; static MelonLoader.MelonPreferences_Category ms_category = null; static List ms_entries = null; @@ -51,8 +53,9 @@ namespace ml_amt static public event Action IKOverrideJumpChange; static public event Action DetectEmotesChange; static public event Action FollowHipsChange; - static public event Action CollisionScaleChange; static public event Action MassCenterChange; + static public event Action ScaledStepsChange; + static public event Action CollisionScaleChange; static public event Action OverrideFixChange; internal static void Init() @@ -61,19 +64,20 @@ namespace ml_amt ms_entries = new List() { - ms_category.CreateEntry(ModSetting.IKOverrideCrouch.ToString(), true), - ms_category.CreateEntry(ModSetting.CrouchLimit.ToString(), 65), - ms_category.CreateEntry(ModSetting.IKOverrideProne.ToString(), true), - ms_category.CreateEntry(ModSetting.ProneLimit.ToString(), 30), - ms_category.CreateEntry(ModSetting.PoseTransitions.ToString(), true), - ms_category.CreateEntry(ModSetting.AdjustedMovement.ToString(), true), - ms_category.CreateEntry(ModSetting.IKOverrideFly.ToString(), true), - ms_category.CreateEntry(ModSetting.IKOverrideJump.ToString(), true), - ms_category.CreateEntry(ModSetting.DetectEmotes.ToString(), true), - ms_category.CreateEntry(ModSetting.FollowHips.ToString(), true), - ms_category.CreateEntry(ModSetting.CollisionScale.ToString(), true), - ms_category.CreateEntry(ModSetting.MassCenter.ToString(), true), - ms_category.CreateEntry(ModSetting.OverrideFix.ToString(), true) + ms_category.CreateEntry(ModSetting.IKOverrideCrouch.ToString(), IKOverrideCrouch), + ms_category.CreateEntry(ModSetting.CrouchLimit.ToString(), (int)(CrouchLimit * 100f)), + ms_category.CreateEntry(ModSetting.IKOverrideProne.ToString(), IKOverrideProne), + ms_category.CreateEntry(ModSetting.ProneLimit.ToString(), (int)(ProneLimit * 100f)), + ms_category.CreateEntry(ModSetting.PoseTransitions.ToString(), PoseTransitions), + ms_category.CreateEntry(ModSetting.AdjustedMovement.ToString(), AdjustedMovement), + ms_category.CreateEntry(ModSetting.IKOverrideFly.ToString(), IKOverrideFly), + ms_category.CreateEntry(ModSetting.IKOverrideJump.ToString(), IKOverrideJump), + ms_category.CreateEntry(ModSetting.DetectEmotes.ToString(), DetectEmotes), + ms_category.CreateEntry(ModSetting.FollowHips.ToString(), FollowHips), + ms_category.CreateEntry(ModSetting.MassCenter.ToString(), MassCenter), + ms_category.CreateEntry(ModSetting.ScaledSteps.ToString(), ScaledSteps), + ms_category.CreateEntry(ModSetting.CollisionScale.ToString(), CollisionScale), + ms_category.CreateEntry(ModSetting.OverrideFix.ToString(), OverrideFix) }; Load(); @@ -105,19 +109,20 @@ namespace ml_amt static void Load() { - ms_ikOverrideCrouch = (bool)ms_entries[(int)ModSetting.IKOverrideCrouch].BoxedValue; - ms_crouchLimit = ((int)ms_entries[(int)ModSetting.CrouchLimit].BoxedValue) * 0.01f; - ms_ikOverrideProne = (bool)ms_entries[(int)ModSetting.IKOverrideProne].BoxedValue; - ms_proneLimit = ((int)ms_entries[(int)ModSetting.ProneLimit].BoxedValue) * 0.01f; - ms_poseTransitions = (bool)ms_entries[(int)ModSetting.PoseTransitions].BoxedValue; - ms_adjustedMovement = (bool)ms_entries[(int)ModSetting.AdjustedMovement].BoxedValue; - ms_ikOverrideFly = (bool)ms_entries[(int)ModSetting.IKOverrideFly].BoxedValue; - ms_ikOverrideJump = (bool)ms_entries[(int)ModSetting.IKOverrideJump].BoxedValue; - ms_detectEmotes = (bool)ms_entries[(int)ModSetting.DetectEmotes].BoxedValue; - ms_followHips = (bool)ms_entries[(int)ModSetting.FollowHips].BoxedValue; - ms_collisionScale = (bool)ms_entries[(int)ModSetting.CollisionScale].BoxedValue; - ms_massCenter = (bool)ms_entries[(int)ModSetting.MassCenter].BoxedValue; - ms_overrideFix = (bool)ms_entries[(int)ModSetting.OverrideFix].BoxedValue; + IKOverrideCrouch = (bool)ms_entries[(int)ModSetting.IKOverrideCrouch].BoxedValue; + CrouchLimit = ((int)ms_entries[(int)ModSetting.CrouchLimit].BoxedValue) * 0.01f; + IKOverrideProne = (bool)ms_entries[(int)ModSetting.IKOverrideProne].BoxedValue; + ProneLimit = ((int)ms_entries[(int)ModSetting.ProneLimit].BoxedValue) * 0.01f; + PoseTransitions = (bool)ms_entries[(int)ModSetting.PoseTransitions].BoxedValue; + AdjustedMovement = (bool)ms_entries[(int)ModSetting.AdjustedMovement].BoxedValue; + IKOverrideFly = (bool)ms_entries[(int)ModSetting.IKOverrideFly].BoxedValue; + IKOverrideJump = (bool)ms_entries[(int)ModSetting.IKOverrideJump].BoxedValue; + DetectEmotes = (bool)ms_entries[(int)ModSetting.DetectEmotes].BoxedValue; + FollowHips = (bool)ms_entries[(int)ModSetting.FollowHips].BoxedValue; + MassCenter = (bool)ms_entries[(int)ModSetting.MassCenter].BoxedValue; + ScaledSteps = (bool)ms_entries[(int)ModSetting.ScaledSteps].BoxedValue; + CollisionScale = (bool)ms_entries[(int)ModSetting.CollisionScale].BoxedValue; + OverrideFix = (bool)ms_entries[(int)ModSetting.OverrideFix].BoxedValue; } static void OnSliderUpdate(string p_name, string p_value) @@ -128,15 +133,15 @@ namespace ml_amt { case ModSetting.CrouchLimit: { - ms_crouchLimit = int.Parse(p_value) * 0.01f; - CrouchLimitChange?.Invoke(ms_crouchLimit); + CrouchLimit = int.Parse(p_value) * 0.01f; + CrouchLimitChange?.Invoke(CrouchLimit); } break; case ModSetting.ProneLimit: { - ms_proneLimit = int.Parse(p_value) * 0.01f; - ProneLimitChange?.Invoke(ms_proneLimit); + ProneLimit = int.Parse(p_value) * 0.01f; + ProneLimitChange?.Invoke(ProneLimit); } break; } @@ -153,78 +158,85 @@ namespace ml_amt { case ModSetting.IKOverrideCrouch: { - ms_ikOverrideCrouch = bool.Parse(p_value); - IKOverrideCrouchChange?.Invoke(ms_ikOverrideCrouch); + IKOverrideCrouch = bool.Parse(p_value); + IKOverrideCrouchChange?.Invoke(IKOverrideCrouch); } break; case ModSetting.IKOverrideProne: { - ms_ikOverrideProne = bool.Parse(p_value); - IKOverrideProneChange?.Invoke(ms_ikOverrideProne); + IKOverrideProne = bool.Parse(p_value); + IKOverrideProneChange?.Invoke(IKOverrideProne); } break; case ModSetting.PoseTransitions: { - ms_poseTransitions = bool.Parse(p_value); - PoseTransitionsChange?.Invoke(ms_poseTransitions); + PoseTransitions = bool.Parse(p_value); + PoseTransitionsChange?.Invoke(PoseTransitions); } break; case ModSetting.AdjustedMovement: { - ms_adjustedMovement = bool.Parse(p_value); - AdjustedMovementChange?.Invoke(ms_adjustedMovement); + AdjustedMovement = bool.Parse(p_value); + AdjustedMovementChange?.Invoke(AdjustedMovement); } break; case ModSetting.IKOverrideFly: { - ms_ikOverrideFly = bool.Parse(p_value); - IKOverrideFlyChange?.Invoke(ms_ikOverrideFly); + IKOverrideFly = bool.Parse(p_value); + IKOverrideFlyChange?.Invoke(IKOverrideFly); } break; case ModSetting.IKOverrideJump: { - ms_ikOverrideJump = bool.Parse(p_value); - IKOverrideJumpChange?.Invoke(ms_ikOverrideJump); + IKOverrideJump = bool.Parse(p_value); + IKOverrideJumpChange?.Invoke(IKOverrideJump); } break; case ModSetting.DetectEmotes: { - ms_detectEmotes = bool.Parse(p_value); - DetectEmotesChange?.Invoke(ms_detectEmotes); + DetectEmotes = bool.Parse(p_value); + DetectEmotesChange?.Invoke(DetectEmotes); } break; case ModSetting.FollowHips: { - ms_followHips = bool.Parse(p_value); - FollowHipsChange?.Invoke(ms_followHips); - } - break; - - case ModSetting.CollisionScale: - { - ms_collisionScale = bool.Parse(p_value); - CollisionScaleChange?.Invoke(ms_collisionScale); + FollowHips = bool.Parse(p_value); + FollowHipsChange?.Invoke(FollowHips); } break; case ModSetting.MassCenter: { - ms_massCenter = bool.Parse(p_value); - MassCenterChange?.Invoke(ms_massCenter); + MassCenter = bool.Parse(p_value); + MassCenterChange?.Invoke(MassCenter); + } + break; + + case ModSetting.ScaledSteps: + { + ScaledSteps = bool.Parse(p_value); + ScaledStepsChange?.Invoke(ScaledSteps); + } + break; + + case ModSetting.CollisionScale: + { + CollisionScale = bool.Parse(p_value); + CollisionScaleChange?.Invoke(CollisionScale); } break; case ModSetting.OverrideFix: { - ms_overrideFix = bool.Parse(p_value); - OverrideFixChange?.Invoke(ms_overrideFix); + OverrideFix = bool.Parse(p_value); + OverrideFixChange?.Invoke(OverrideFix); } break; } @@ -232,58 +244,5 @@ namespace ml_amt ms_entries[(int)l_setting].BoxedValue = bool.Parse(p_value); } } - - public static bool IKOverrideCrouch - { - get => ms_ikOverrideCrouch; - } - public static float CrouchLimit - { - get => ms_crouchLimit; - } - public static bool IKOverrideProne - { - get => ms_ikOverrideProne; - } - public static float ProneLimit - { - get => ms_proneLimit; - } - public static bool PoseTransitions - { - get => ms_poseTransitions; - } - public static bool AdjustedMovement - { - get => ms_adjustedMovement; - } - public static bool IKOverrideFly - { - get => ms_ikOverrideFly; - } - public static bool IKOverrideJump - { - get => ms_ikOverrideJump; - } - public static bool DetectEmotes - { - get => ms_detectEmotes; - } - public static bool FollowHips - { - get => ms_followHips; - } - public static bool CollisionScale - { - get => ms_collisionScale; - } - public static bool MassCenter - { - get => ms_massCenter; - } - public static bool OverrideFix - { - get => ms_overrideFix; - } } } diff --git a/ml_amt/Utils.cs b/ml_amt/Utils.cs index 31b75d8..140cadc 100644 --- a/ml_amt/Utils.cs +++ b/ml_amt/Utils.cs @@ -1,10 +1,12 @@ using UnityEngine; -using ABI_RC.Systems.IK; +using System.Reflection; namespace ml_amt { static class Utils { + static MethodInfo ms_getSineKeyframes = typeof(RootMotion.FinalIK.IKSolverVR).GetMethod("GetSineKeyframes", BindingFlags.NonPublic | BindingFlags.Static); + public static bool IsInVR() => ((ABI_RC.Core.Savior.CheckVR.Instance != null) && ABI_RC.Core.Savior.CheckVR.Instance.hasVrDeviceLoaded); // Extensions @@ -12,5 +14,10 @@ namespace ml_amt { return Matrix4x4.TRS(p_pos ? p_transform.position : Vector3.zero, p_rot ? p_transform.rotation : Quaternion.identity, p_scl ? p_transform.localScale : Vector3.one); } + + public static Keyframe[] GetSineKeyframes(float p_mag) + { + return (Keyframe[])ms_getSineKeyframes.Invoke(null, new object[] { p_mag }); + } } } diff --git a/ml_amt/resources/menu.js b/ml_amt/resources/menu.js index 9298fff..152a75c 100644 --- a/ml_amt/resources/menu.js +++ b/ml_amt/resources/menu.js @@ -256,6 +256,13 @@ function inp_toggle_mod_amt(_obj, _callbackName) {
+ +
+
Scaled locomotion steps:
+
+
+
+
Alternative avatar collider scale:
diff --git a/ml_dht/HeadTracked.cs b/ml_dht/HeadTracked.cs index a7ac529..00b116d 100644 --- a/ml_dht/HeadTracked.cs +++ b/ml_dht/HeadTracked.cs @@ -34,6 +34,7 @@ namespace ml_dht Quaternion m_bindRotation; Quaternion m_lastHeadRotation; + // Unity events void Start() { Settings.EnabledChange += this.SetEnabled; @@ -56,6 +57,7 @@ namespace ml_dht Settings.FaceOverrideChange -= this.SetFaceOverride; } + // Tracking updates public void UpdateTrackingData(ref TrackingData p_data) { m_headPosition.Set(p_data.m_headPositionX * (m_mirrored ? -1f : 1f), p_data.m_headPositionY, p_data.m_headPositionZ); @@ -77,6 +79,7 @@ namespace ml_dht } } + // Game events internal void OnEyeControllerUpdate(CVREyeController p_component) { if(m_enabled) @@ -139,7 +142,8 @@ namespace ml_dht m_bindRotation = Quaternion.identity; } - public void SetEnabled(bool p_state) + // Settings + internal void SetEnabled(bool p_state) { if(m_enabled != p_state) { @@ -148,7 +152,7 @@ namespace ml_dht m_lastHeadRotation = ((m_headBone != null) ? m_headBone.rotation : m_bindRotation); } } - public void SetHeadTracking(bool p_state) + internal void SetHeadTracking(bool p_state) { if(m_headTracking != p_state) { @@ -157,23 +161,23 @@ namespace ml_dht m_lastHeadRotation = ((m_headBone != null) ? m_headBone.rotation : m_bindRotation); } } - public void SetEyeTracking(bool p_state) + internal void SetEyeTracking(bool p_state) { m_eyeTracking = p_state; } - public void SetBlinking(bool p_state) + internal void SetBlinking(bool p_state) { m_blinking = p_state; } - public void SetSmoothing(float p_value) + internal void SetSmoothing(float p_value) { m_smoothing = 1f - Mathf.Clamp(p_value, 0f, 0.99f); } - public void SetMirrored(bool p_state) + internal void SetMirrored(bool p_state) { m_mirrored = p_state; } - public void SetFaceOverride(bool p_state) + internal void SetFaceOverride(bool p_state) { m_faceOverride = p_state; } diff --git a/ml_dht/Settings.cs b/ml_dht/Settings.cs index 12057f2..7251fed 100644 --- a/ml_dht/Settings.cs +++ b/ml_dht/Settings.cs @@ -18,13 +18,13 @@ namespace ml_dht FaceOverride } - static bool ms_enabled = false; - static bool ms_headTracking = true; - static bool ms_eyeTracking = true; - static bool ms_blinking = true; - static bool ms_mirrored = false; - static float ms_smoothing = 0.5f; - static bool ms_faceOverride = true; + public static bool Enabled { get; private set; } = false; + public static bool HeadTracking { get; private set; } = true; + public static bool EyeTracking { get; private set; } = true; + public static bool Blinking { get; private set; } = true; + public static bool Mirrored { get; private set; } = false; + public static float Smoothing { get; private set; } = 0.5f; + public static bool FaceOverride { get; private set; } = true; static MelonLoader.MelonPreferences_Category ms_category = null; static List ms_entries = null; @@ -43,13 +43,13 @@ namespace ml_dht ms_entries = new List() { - ms_category.CreateEntry(ModSetting.Enabled.ToString(), false), - ms_category.CreateEntry(ModSetting.HeadTracking.ToString(), false), - ms_category.CreateEntry(ModSetting.EyeTracking.ToString(), true), - ms_category.CreateEntry(ModSetting.Blinking.ToString(), true), - ms_category.CreateEntry(ModSetting.Mirrored.ToString(), false), - ms_category.CreateEntry(ModSetting.Smoothing.ToString(), 50), - ms_category.CreateEntry(ModSetting.FaceOverride.ToString(), true) + ms_category.CreateEntry(ModSetting.Enabled.ToString(), Enabled), + ms_category.CreateEntry(ModSetting.HeadTracking.ToString(), HeadTracking), + ms_category.CreateEntry(ModSetting.EyeTracking.ToString(), EyeTracking), + ms_category.CreateEntry(ModSetting.Blinking.ToString(), Blinking), + ms_category.CreateEntry(ModSetting.Mirrored.ToString(), Mirrored), + ms_category.CreateEntry(ModSetting.Smoothing.ToString(), (int)(Smoothing * 50f)), + ms_category.CreateEntry(ModSetting.FaceOverride.ToString(), FaceOverride) }; Load(); @@ -81,13 +81,13 @@ namespace ml_dht static void Load() { - ms_enabled = (bool)ms_entries[(int)ModSetting.Enabled].BoxedValue; - ms_headTracking = (bool)ms_entries[(int)ModSetting.HeadTracking].BoxedValue; - ms_eyeTracking = (bool)ms_entries[(int)ModSetting.EyeTracking].BoxedValue; - ms_blinking = (bool)ms_entries[(int)ModSetting.Blinking].BoxedValue; - ms_mirrored = (bool)ms_entries[(int)ModSetting.Mirrored].BoxedValue; - ms_smoothing = ((int)ms_entries[(int)ModSetting.Smoothing].BoxedValue) * 0.01f; - ms_faceOverride = (bool)ms_entries[(int)ModSetting.FaceOverride].BoxedValue; + Enabled = (bool)ms_entries[(int)ModSetting.Enabled].BoxedValue; + HeadTracking = (bool)ms_entries[(int)ModSetting.HeadTracking].BoxedValue; + EyeTracking = (bool)ms_entries[(int)ModSetting.EyeTracking].BoxedValue; + Blinking = (bool)ms_entries[(int)ModSetting.Blinking].BoxedValue; + Mirrored = (bool)ms_entries[(int)ModSetting.Mirrored].BoxedValue; + Smoothing = ((int)ms_entries[(int)ModSetting.Smoothing].BoxedValue) * 0.01f; + FaceOverride = (bool)ms_entries[(int)ModSetting.FaceOverride].BoxedValue; } static void OnSliderUpdate(string p_name, string p_value) @@ -98,8 +98,8 @@ namespace ml_dht { case ModSetting.Smoothing: { - ms_smoothing = int.Parse(p_value) * 0.01f; - SmoothingChange?.Invoke(ms_smoothing); + Smoothing = int.Parse(p_value) * 0.01f; + SmoothingChange?.Invoke(Smoothing); } break; } @@ -116,43 +116,43 @@ namespace ml_dht { case ModSetting.Enabled: { - ms_enabled = bool.Parse(p_value); - EnabledChange?.Invoke(ms_enabled); + Enabled = bool.Parse(p_value); + EnabledChange?.Invoke(Enabled); } break; case ModSetting.HeadTracking: { - ms_headTracking = bool.Parse(p_value); - HeadTrackingChange?.Invoke(ms_headTracking); + HeadTracking = bool.Parse(p_value); + HeadTrackingChange?.Invoke(HeadTracking); } break; case ModSetting.EyeTracking: { - ms_eyeTracking = bool.Parse(p_value); - EyeTrackingChange?.Invoke(ms_eyeTracking); + EyeTracking = bool.Parse(p_value); + EyeTrackingChange?.Invoke(EyeTracking); } break; case ModSetting.Blinking: { - ms_blinking = bool.Parse(p_value); - BlinkingChange?.Invoke(ms_blinking); + Blinking = bool.Parse(p_value); + BlinkingChange?.Invoke(Blinking); } break; case ModSetting.Mirrored: { - ms_mirrored = bool.Parse(p_value); - MirroredChange?.Invoke(ms_mirrored); + Mirrored = bool.Parse(p_value); + MirroredChange?.Invoke(Mirrored); } break; case ModSetting.FaceOverride: { - ms_faceOverride = bool.Parse(p_value); - FaceOverrideChange?.Invoke(ms_faceOverride); + FaceOverride = bool.Parse(p_value); + FaceOverrideChange?.Invoke(FaceOverride); } break; } @@ -160,34 +160,5 @@ namespace ml_dht ms_entries[(int)l_setting].BoxedValue = bool.Parse(p_value); } } - - public static bool Enabled - { - get => ms_enabled; - } - public static bool HeadTracking - { - get => ms_headTracking; - } - public static bool EyeTracking - { - get => ms_eyeTracking; - } - public static bool Blinking - { - get => ms_blinking; - } - public static bool Mirrored - { - get => ms_mirrored; - } - public static float Smoothing - { - get => ms_smoothing; - } - public static bool FaceOverride - { - get => ms_faceOverride; - } } } diff --git a/ml_lme/LeapTracked.cs b/ml_lme/LeapTracked.cs index 4725404..3c66318 100644 --- a/ml_lme/LeapTracked.cs +++ b/ml_lme/LeapTracked.cs @@ -37,6 +37,7 @@ namespace ml_lme bool m_leftTargetActive = false; bool m_rightTargetActive = false; + // Unity events void Start() { m_inVR = Utils.IsInVR(); @@ -51,51 +52,20 @@ namespace ml_lme m_rightHandTarget.localPosition = Vector3.zero; m_rightHandTarget.localRotation = Quaternion.identity; - Settings.EnabledChange += this.SetEnabled; - Settings.FingersOnlyChange += this.SetFingersOnly; - Settings.TrackElbowsChange += this.SetTrackElbows; + Settings.EnabledChange += this.OnEnabledChange; + Settings.FingersOnlyChange += this.OnFingersOnlyChange; + Settings.TrackElbowsChange += this.OnTrackElbowsChange; - SetEnabled(Settings.Enabled); - SetFingersOnly(Settings.FingersOnly); - SetTrackElbows(Settings.TrackElbows); + OnEnabledChange(Settings.Enabled); + OnFingersOnlyChange(Settings.FingersOnly); + OnTrackElbowsChange(Settings.TrackElbows); } void OnDestroy() { - Settings.EnabledChange -= this.SetEnabled; - Settings.FingersOnlyChange -= this.SetFingersOnly; - Settings.TrackElbowsChange -= this.SetTrackElbows; - } - - void SetEnabled(bool p_state) - { - m_enabled = p_state; - - RefreshArmIK(); - if(!m_enabled || m_fingersOnly) - RestoreVRIK(); - } - - void SetFingersOnly(bool p_state) - { - m_fingersOnly = p_state; - - RefreshArmIK(); - if(!m_enabled || m_fingersOnly) - RestoreVRIK(); - } - - void SetTrackElbows(bool p_state) - { - m_trackElbows = p_state; - - if((m_leftArmIK != null) && (m_rightArmIK != null)) - { - m_leftArmIK.solver.arm.bendGoalWeight = (m_trackElbows ? 1f : 0f); - m_rightArmIK.solver.arm.bendGoalWeight = (m_trackElbows ? 1f : 0f); - } - - RestoreVRIK(); + Settings.EnabledChange -= this.OnEnabledChange; + Settings.FingersOnlyChange -= this.OnFingersOnlyChange; + Settings.TrackElbowsChange -= this.OnTrackElbowsChange; } void Update() @@ -168,6 +138,7 @@ namespace ml_lme } } + // Tracking update void UpdateFingers(GestureMatcher.LeapData p_data) { if(p_data.m_leftHand.m_present) @@ -227,6 +198,7 @@ namespace ml_lme } } + // Game events internal void OnAvatarClear() { m_vrIK = null; @@ -348,6 +320,7 @@ namespace ml_lme } } + // IK updates void OnIKPreUpdate() { m_armsWeights.Set( @@ -376,6 +349,39 @@ namespace ml_lme m_vrIK.solver.rightArm.rotationWeight = m_armsWeights.w; } + // Settings + void OnEnabledChange(bool p_state) + { + m_enabled = p_state; + + RefreshArmIK(); + if(!m_enabled || m_fingersOnly) + RestoreVRIK(); + } + + void OnFingersOnlyChange(bool p_state) + { + m_fingersOnly = p_state; + + RefreshArmIK(); + if(!m_enabled || m_fingersOnly) + RestoreVRIK(); + } + + void OnTrackElbowsChange(bool p_state) + { + m_trackElbows = p_state; + + if((m_leftArmIK != null) && (m_rightArmIK != null)) + { + m_leftArmIK.solver.arm.bendGoalWeight = (m_trackElbows ? 1f : 0f); + m_rightArmIK.solver.arm.bendGoalWeight = (m_trackElbows ? 1f : 0f); + } + + RestoreVRIK(); + } + + // Arbitrary void RestoreVRIK() { if(m_vrIK != null) diff --git a/ml_lme/Settings.cs b/ml_lme/Settings.cs index 0015b43..2ebbaa6 100644 --- a/ml_lme/Settings.cs +++ b/ml_lme/Settings.cs @@ -37,18 +37,18 @@ namespace ml_lme GripThreadhold }; - static bool ms_enabled = false; - static Vector3 ms_desktopOffset = new Vector3(0f, -0.45f, 0.3f); - static bool ms_fingersOnly = false; - static bool ms_modelVisibility = false; - static LeapTrackingMode ms_trackingMode = LeapTrackingMode.Desktop; - static Vector3 ms_rootAngle = Vector3.zero; - static bool ms_headAttach = false; - static Vector3 ms_headOffset = new Vector3(0f, -0.3f, 0.15f); - static bool ms_trackElbows = true; - static bool ms_input = true; - static float ms_interactThreadhold = 0.8f; - static float ms_gripThreadhold = 0.4f; + public static bool Enabled { get; private set; } = false; + public static Vector3 DesktopOffset { get; private set; } = new Vector3(0f, -0.45f, 0.3f); + public static bool FingersOnly { get; private set; } = false; + public static bool ModelVisibility { get; private set; } = false; + public static LeapTrackingMode TrackingMode { get; private set; } = LeapTrackingMode.Desktop; + public static Vector3 RootAngle { get; private set; } = Vector3.zero; + public static bool HeadAttach { get; private set; } = false; + public static Vector3 HeadOffset { get; private set; } = new Vector3(0f, -0.3f, 0.15f); + public static bool TrackElbows { get; private set; } = true; + public static bool Input { get; private set; } = true; + public static float InteractThreadhold { get; private set; } = 0.8f; + public static float GripThreadhold { get; private set; } = 0.4f; static MelonLoader.MelonPreferences_Category ms_category = null; static List ms_entries = null; @@ -72,24 +72,24 @@ namespace ml_lme ms_entries = new List() { - ms_category.CreateEntry(ModSetting.Enabled.ToString(), ms_enabled), - ms_category.CreateEntry(ModSetting.DesktopX.ToString(), 0), - ms_category.CreateEntry(ModSetting.DesktopY.ToString(), -45), - ms_category.CreateEntry(ModSetting.DesktopZ.ToString(), 30), - ms_category.CreateEntry(ModSetting.FingersOnly.ToString(), ms_modelVisibility), - ms_category.CreateEntry(ModSetting.Model.ToString(), ms_modelVisibility), - ms_category.CreateEntry(ModSetting.Mode.ToString(), (int)ms_trackingMode), - ms_category.CreateEntry(ModSetting.AngleX.ToString(), 0), - ms_category.CreateEntry(ModSetting.AngleY.ToString(), 0), - ms_category.CreateEntry(ModSetting.AngleZ.ToString(), 0), - ms_category.CreateEntry(ModSetting.Head.ToString(), ms_headAttach), - ms_category.CreateEntry(ModSetting.HeadX.ToString(), 0), - ms_category.CreateEntry(ModSetting.HeadY.ToString(), -30), - ms_category.CreateEntry(ModSetting.HeadZ.ToString(), 15), - ms_category.CreateEntry(ModSetting.TrackElbows.ToString(), true), - ms_category.CreateEntry(ModSetting.Input.ToString(), true), - ms_category.CreateEntry(ModSetting.InteractThreadhold.ToString(), 80), - ms_category.CreateEntry(ModSetting.GripThreadhold.ToString(), 40), + ms_category.CreateEntry(ModSetting.Enabled.ToString(), Enabled), + ms_category.CreateEntry(ModSetting.DesktopX.ToString(), (int)(DesktopOffset.x * 100f)), + ms_category.CreateEntry(ModSetting.DesktopY.ToString(), (int)(DesktopOffset.y * 100f)), + ms_category.CreateEntry(ModSetting.DesktopZ.ToString(), (int)(DesktopOffset.z * 100f)), + ms_category.CreateEntry(ModSetting.FingersOnly.ToString(), FingersOnly), + ms_category.CreateEntry(ModSetting.Model.ToString(), ModelVisibility), + ms_category.CreateEntry(ModSetting.Mode.ToString(), (int)TrackingMode), + ms_category.CreateEntry(ModSetting.AngleX.ToString(), (int)(RootAngle.x * 100f)), + ms_category.CreateEntry(ModSetting.AngleY.ToString(), (int)(RootAngle.y * 100f)), + ms_category.CreateEntry(ModSetting.AngleZ.ToString(), (int)(RootAngle.z * 100f)), + ms_category.CreateEntry(ModSetting.Head.ToString(), HeadAttach), + ms_category.CreateEntry(ModSetting.HeadX.ToString(), (int)(HeadOffset.x * 100f)), + ms_category.CreateEntry(ModSetting.HeadY.ToString(), (int)(HeadOffset.y * 100f)), + ms_category.CreateEntry(ModSetting.HeadZ.ToString(), (int)(HeadOffset.z * 100f)), + ms_category.CreateEntry(ModSetting.TrackElbows.ToString(), TrackElbows), + ms_category.CreateEntry(ModSetting.Input.ToString(), Input), + ms_category.CreateEntry(ModSetting.InteractThreadhold.ToString(), (int)(InteractThreadhold * 100f)), + ms_category.CreateEntry(ModSetting.GripThreadhold.ToString(), (int)(GripThreadhold * 100f)), }; Load(); @@ -122,30 +122,30 @@ namespace ml_lme static void Load() { - ms_enabled = (bool)ms_entries[(int)ModSetting.Enabled].BoxedValue; - ms_desktopOffset = new Vector3( + Enabled = (bool)ms_entries[(int)ModSetting.Enabled].BoxedValue; + DesktopOffset = new Vector3( (int)ms_entries[(int)ModSetting.DesktopX].BoxedValue, (int)ms_entries[(int)ModSetting.DesktopY].BoxedValue, (int)ms_entries[(int)ModSetting.DesktopZ].BoxedValue ) * 0.01f; - ms_fingersOnly = (bool)ms_entries[(int)ModSetting.FingersOnly].BoxedValue; - ms_modelVisibility = (bool)ms_entries[(int)ModSetting.Model].BoxedValue; - ms_trackingMode = (LeapTrackingMode)(int)ms_entries[(int)ModSetting.Mode].BoxedValue; - ms_rootAngle = new Vector3( + FingersOnly = (bool)ms_entries[(int)ModSetting.FingersOnly].BoxedValue; + ModelVisibility = (bool)ms_entries[(int)ModSetting.Model].BoxedValue; + TrackingMode = (LeapTrackingMode)(int)ms_entries[(int)ModSetting.Mode].BoxedValue; + RootAngle = new Vector3( (int)ms_entries[(int)ModSetting.AngleX].BoxedValue, (int)ms_entries[(int)ModSetting.AngleY].BoxedValue, (int)ms_entries[(int)ModSetting.AngleZ].BoxedValue ); - ms_headAttach = (bool)ms_entries[(int)ModSetting.Head].BoxedValue; - ms_headOffset = new Vector3( + HeadAttach = (bool)ms_entries[(int)ModSetting.Head].BoxedValue; + HeadOffset = new Vector3( (int)ms_entries[(int)ModSetting.HeadX].BoxedValue, (int)ms_entries[(int)ModSetting.HeadY].BoxedValue, (int)ms_entries[(int)ModSetting.HeadZ].BoxedValue ) * 0.01f; - ms_trackElbows = (bool)ms_entries[(int)ModSetting.TrackElbows].BoxedValue; - ms_input = (bool)ms_entries[(int)ModSetting.Input].BoxedValue; - ms_interactThreadhold = (int)ms_entries[(int)ModSetting.InteractThreadhold].BoxedValue * 0.01f; - ms_gripThreadhold = (int)ms_entries[(int)ModSetting.GripThreadhold].BoxedValue * 0.01f; + TrackElbows = (bool)ms_entries[(int)ModSetting.TrackElbows].BoxedValue; + Input = (bool)ms_entries[(int)ModSetting.Input].BoxedValue; + InteractThreadhold = (int)ms_entries[(int)ModSetting.InteractThreadhold].BoxedValue * 0.01f; + GripThreadhold = (int)ms_entries[(int)ModSetting.GripThreadhold].BoxedValue * 0.01f; } static void OnToggleUpdate(string p_name, string p_value) @@ -156,43 +156,43 @@ namespace ml_lme { case ModSetting.Enabled: { - ms_enabled = bool.Parse(p_value); - EnabledChange?.Invoke(ms_enabled); + Enabled = bool.Parse(p_value); + EnabledChange?.Invoke(Enabled); } break; case ModSetting.FingersOnly: { - ms_fingersOnly = bool.Parse(p_value); - FingersOnlyChange?.Invoke(ms_fingersOnly); + FingersOnly = bool.Parse(p_value); + FingersOnlyChange?.Invoke(FingersOnly); } break; case ModSetting.Model: { - ms_modelVisibility = bool.Parse(p_value); - ModelVisibilityChange?.Invoke(ms_modelVisibility); + ModelVisibility = bool.Parse(p_value); + ModelVisibilityChange?.Invoke(ModelVisibility); } break; case ModSetting.Head: { - ms_headAttach = bool.Parse(p_value); - HeadAttachChange?.Invoke(ms_headAttach); + HeadAttach = bool.Parse(p_value); + HeadAttachChange?.Invoke(HeadAttach); } break; case ModSetting.TrackElbows: { - ms_trackElbows = bool.Parse(p_value); - TrackElbowsChange?.Invoke(ms_trackElbows); + TrackElbows = bool.Parse(p_value); + TrackElbowsChange?.Invoke(TrackElbows); } break; case ModSetting.Input: { - ms_input = bool.Parse(p_value); - InputChange?.Invoke(ms_input); + Input = bool.Parse(p_value); + InputChange?.Invoke(Input); } break; } @@ -209,72 +209,72 @@ namespace ml_lme { case ModSetting.DesktopX: { - ms_desktopOffset.x = int.Parse(p_value) * 0.01f; - DesktopOffsetChange?.Invoke(ms_desktopOffset); + DesktopOffset.Set(int.Parse(p_value) * 0.01f, DesktopOffset.y, DesktopOffset.z); + DesktopOffsetChange?.Invoke(DesktopOffset); } break; case ModSetting.DesktopY: { - ms_desktopOffset.y = int.Parse(p_value) * 0.01f; - DesktopOffsetChange?.Invoke(ms_desktopOffset); + DesktopOffset.Set(DesktopOffset.x, int.Parse(p_value) * 0.01f, DesktopOffset.z); + DesktopOffsetChange?.Invoke(DesktopOffset); } break; case ModSetting.DesktopZ: { - ms_desktopOffset.z = int.Parse(p_value) * 0.01f; - DesktopOffsetChange?.Invoke(ms_desktopOffset); + DesktopOffset.Set(DesktopOffset.x, DesktopOffset.y, int.Parse(p_value) * 0.01f); + DesktopOffsetChange?.Invoke(DesktopOffset); } break; case ModSetting.AngleX: { - ms_rootAngle.x = int.Parse(p_value); - RootAngleChange?.Invoke(ms_rootAngle); + RootAngle.Set(int.Parse(p_value), RootAngle.y, RootAngle.z); + RootAngleChange?.Invoke(RootAngle); } break; case ModSetting.AngleY: { - ms_rootAngle.y = int.Parse(p_value); - RootAngleChange?.Invoke(ms_rootAngle); + RootAngle.Set(RootAngle.x, int.Parse(p_value), RootAngle.z); + RootAngleChange?.Invoke(RootAngle); } break; case ModSetting.AngleZ: { - ms_rootAngle.z = int.Parse(p_value); - RootAngleChange?.Invoke(ms_rootAngle); + RootAngle.Set(RootAngle.x, RootAngle.y, int.Parse(p_value)); + RootAngleChange?.Invoke(RootAngle); } break; case ModSetting.HeadX: { - ms_headOffset.x = int.Parse(p_value) * 0.01f; - HeadOffsetChange?.Invoke(ms_headOffset); + HeadOffset.Set(int.Parse(p_value) * 0.01f, HeadOffset.y, HeadOffset.z); + HeadOffsetChange?.Invoke(HeadOffset); } break; case ModSetting.HeadY: { - ms_headOffset.y = int.Parse(p_value) * 0.01f; - HeadOffsetChange?.Invoke(ms_headOffset); + HeadOffset.Set(HeadOffset.x, int.Parse(p_value) * 0.01f, HeadOffset.z); + HeadOffsetChange?.Invoke(HeadOffset); } break; case ModSetting.HeadZ: { - ms_headOffset.z = int.Parse(p_value) * 0.01f; - HeadOffsetChange?.Invoke(ms_headOffset); + HeadOffset.Set(HeadOffset.x, HeadOffset.y, int.Parse(p_value) * 0.01f); + HeadOffsetChange?.Invoke(HeadOffset); } break; case ModSetting.InteractThreadhold: { - ms_interactThreadhold = int.Parse(p_value) * 0.01f; - InteractThreadholdChange?.Invoke(ms_interactThreadhold); + InteractThreadhold = int.Parse(p_value) * 0.01f; + InteractThreadholdChange?.Invoke(InteractThreadhold); } break; case ModSetting.GripThreadhold: { - ms_gripThreadhold = int.Parse(p_value) * 0.01f; - GripThreadholdChange?.Invoke(ms_gripThreadhold); + GripThreadhold = int.Parse(p_value) * 0.01f; + GripThreadholdChange?.Invoke(GripThreadhold); } break; } @@ -291,8 +291,8 @@ namespace ml_lme { case ModSetting.Mode: { - ms_trackingMode = (LeapTrackingMode)int.Parse(p_value); - TrackingModeChange?.Invoke(ms_trackingMode); + TrackingMode = (LeapTrackingMode)int.Parse(p_value); + TrackingModeChange?.Invoke(TrackingMode); } break; } @@ -300,54 +300,5 @@ namespace ml_lme ms_entries[(int)l_setting].BoxedValue = int.Parse(p_value); } } - - public static bool Enabled - { - get => ms_enabled; - } - public static Vector3 DesktopOffset - { - get => ms_desktopOffset; - } - public static bool FingersOnly - { - get => ms_fingersOnly; - } - public static bool ModelVisibility - { - get => ms_modelVisibility; - } - public static LeapTrackingMode TrackingMode - { - get => ms_trackingMode; - } - public static Vector3 RootAngle - { - get => ms_rootAngle; - } - public static bool HeadAttach - { - get => ms_headAttach; - } - public static Vector3 HeadOffset - { - get => ms_headOffset; - } - public static bool TrackElbows - { - get => ms_trackElbows; - } - public static bool Input - { - get => ms_input; - } - public static float InteractThreadhold - { - get => ms_interactThreadhold; - } - public static float GripThreadhold - { - get => ms_gripThreadhold; - } } } diff --git a/ml_pam/ArmMover.cs b/ml_pam/ArmMover.cs index 01db46d..d9c5f7f 100644 --- a/ml_pam/ArmMover.cs +++ b/ml_pam/ArmMover.cs @@ -32,6 +32,7 @@ namespace ml_pam Matrix4x4 m_offset = Matrix4x4.identity; bool m_targetActive = false; + // Unity events void Start() { m_inVR = Utils.IsInVR(); @@ -67,6 +68,7 @@ namespace ml_pam } } + // IK updates void OnIKPreUpdate() { m_armWeight.Set(m_vrIK.solver.rightArm.positionWeight, m_vrIK.solver.rightArm.rotationWeight); diff --git a/ml_pam/Settings.cs b/ml_pam/Settings.cs index c3fc659..488f2df 100644 --- a/ml_pam/Settings.cs +++ b/ml_pam/Settings.cs @@ -13,8 +13,8 @@ namespace ml_pam GrabOffset } - static bool ms_enabled = true; - static float ms_grabOffset = 0.25f; + public static bool Enabled { get; private set; } = true; + public static float GrabOffset { get; private set; } = 0.25f; static MelonLoader.MelonPreferences_Category ms_category = null; static List ms_entries = null; @@ -28,8 +28,8 @@ namespace ml_pam ms_entries = new List() { - ms_category.CreateEntry(ModSetting.Enabled.ToString(), ms_enabled), - ms_category.CreateEntry(ModSetting.GrabOffset.ToString(), 25), + ms_category.CreateEntry(ModSetting.Enabled.ToString(), Enabled), + ms_category.CreateEntry(ModSetting.GrabOffset.ToString(), (int)(GrabOffset * 100f)), }; Load(); @@ -61,8 +61,8 @@ namespace ml_pam static void Load() { - ms_enabled = (bool)ms_entries[(int)ModSetting.Enabled].BoxedValue; - ms_grabOffset = (int)ms_entries[(int)ModSetting.GrabOffset].BoxedValue * 0.01f; + Enabled = (bool)ms_entries[(int)ModSetting.Enabled].BoxedValue; + GrabOffset = (int)ms_entries[(int)ModSetting.GrabOffset].BoxedValue * 0.01f; } static void OnToggleUpdate(string p_name, string p_value) @@ -73,8 +73,8 @@ namespace ml_pam { case ModSetting.Enabled: { - ms_enabled = bool.Parse(p_value); - EnabledChange?.Invoke(ms_enabled); + Enabled = bool.Parse(p_value); + EnabledChange?.Invoke(Enabled); } break; } @@ -91,8 +91,8 @@ namespace ml_pam { case ModSetting.GrabOffset: { - ms_grabOffset = int.Parse(p_value) * 0.01f; - GrabOffsetChange?.Invoke(ms_grabOffset); + GrabOffset = int.Parse(p_value) * 0.01f; + GrabOffsetChange?.Invoke(GrabOffset); } break; } @@ -100,14 +100,5 @@ namespace ml_pam ms_entries[(int)l_setting].BoxedValue = int.Parse(p_value); } } - - public static bool Enabled - { - get => ms_enabled; - } - public static float GrabOffset - { - get => ms_grabOffset; - } } }