From dfa7da50d65f4b8470adb92ca82afa0961256c0f Mon Sep 17 00:00:00 2001 From: SDraw Date: Mon, 10 Apr 2023 15:36:37 +0300 Subject: [PATCH] Ragdoll controller public instance access Settings fix --- .../img_01.png} | Bin ml_prm/README.md | 12 ++++++-- ml_prm/RagdollController.cs | 17 ++++++++--- ml_prm/Settings.cs | 28 +++++++++--------- 4 files changed, 37 insertions(+), 20 deletions(-) rename ml_prm/{resources/ragdoll_toggle_editor_script.png => .github/img_01.png} (100%) diff --git a/ml_prm/resources/ragdoll_toggle_editor_script.png b/ml_prm/.github/img_01.png similarity index 100% rename from ml_prm/resources/ragdoll_toggle_editor_script.png rename to ml_prm/.github/img_01.png diff --git a/ml_prm/README.md b/ml_prm/README.md index 81a3f7f..f1a6571 100644 --- a/ml_prm/README.md +++ b/ml_prm/README.md @@ -27,7 +27,7 @@ Optional mod's settings with [BTKUILib](https://github.com/BTK-Development/BTKUI * Not suggested to activate fly mode with enabled ragdoll state. * If ragdoll state is enabled during emote, remote players see whole emote playing while local player sees ragdolling. It's tied to how game handles remote players, currently can be prevented with (choose one): * Renaming avatar emote animations to not have default name or containing `Emote` substring. - * Holding any movement key when activating ragdoll state. + * Holding any movement key right after activating ragdoll state. # Unity Editor Script You can also trigger the ragdoll via animations on your avatar. To do this you need to download and import the @@ -37,6 +37,14 @@ your avatar's hierarchy. Now you can animate both parameters available: - **Should Override:** Whether the animation should override the toggled state of the ragdoll. - **Is On:** Whether the ragdoll state is On or Off (only works if `Should Override` is also On). -![](resources/ragdoll_toggle_editor_script.png) +![](.github/img_01.png) **Note:** In order to work the game object needs to be active and the component enabled. + +# Mods Integration +* Add mod's dll as reference in your project +* Access ragdoll controller with `ml_prm.RagdollController.Instance`. + +Available methods: +* ```bool IsRagdolled()``` +* ```void SwitchRagdoll()``` diff --git a/ml_prm/RagdollController.cs b/ml_prm/RagdollController.cs index 3ff666f..00b5543 100644 --- a/ml_prm/RagdollController.cs +++ b/ml_prm/RagdollController.cs @@ -9,8 +9,11 @@ using UnityEngine; namespace ml_prm { - class RagdollController : MonoBehaviour + [DisallowMultipleComponent] + public class RagdollController : MonoBehaviour { + public static RagdollController Instance { get; private set; } = null; + VRIK m_vrIK = null; float m_vrIkWeight = 1f; @@ -31,10 +34,18 @@ namespace ml_prm internal RagdollController() { + if(Instance == null) + Instance = this; + m_rigidBodies = new List(); m_colliders = new List(); m_boneLinks = new List>(); } + ~RagdollController() + { + if(Instance == this) + Instance = null; + } // Unity events void Start() @@ -227,9 +238,7 @@ namespace ml_prm if(m_avatarReady) { foreach(Rigidbody l_body in m_rigidBodies) - { l_body.useGravity = (!Utils.IsWorldSafe() || Settings.Gravity); - } } } @@ -317,7 +326,7 @@ namespace ml_prm foreach(Rigidbody l_body in m_rigidBodies) l_body.isKinematic = true; - if((m_puppetReferences.hips != null)) + if(m_puppetReferences.hips != null) { Vector3 l_hipsPos = m_puppetReferences.hips.position; diff --git a/ml_prm/Settings.cs b/ml_prm/Settings.cs index e1fef82..7171f5e 100644 --- a/ml_prm/Settings.cs +++ b/ml_prm/Settings.cs @@ -6,7 +6,7 @@ namespace ml_prm { static class Settings { - public enum ModSetting + enum ModSetting { Hotkey = 0, VelocityMultiplier, @@ -29,8 +29,8 @@ namespace ml_prm public static bool Hotkey { get; private set; } = true; public static float VelocityMultiplier { get; private set; } = 2f; public static bool RestorePosition { get; private set; } = false; - public static float MovementDrag { get; private set; } = 1f; - public static float AngularDrag { get; private set; } = 0.5f; + public static float MovementDrag { get; private set; } = 2f; + public static float AngularDrag { get; private set; } = 2f; public static bool Gravity { get; private set; } = true; static public event Action SwitchChange; @@ -60,10 +60,10 @@ namespace ml_prm }; Hotkey = (bool)ms_entries[(int)ModSetting.Hotkey].BoxedValue; - VelocityMultiplier = UnityEngine.Mathf.Clamp((float)ms_entries[(int)ModSetting.VelocityMultiplier].BoxedValue, 0f, 50f); + VelocityMultiplier = UnityEngine.Mathf.Clamp((float)ms_entries[(int)ModSetting.VelocityMultiplier].BoxedValue, 1f, 50f); RestorePosition = (bool)ms_entries[(int)ModSetting.RestorePosition].BoxedValue; MovementDrag = UnityEngine.Mathf.Clamp((float)ms_entries[(int)ModSetting.MovementDrag].BoxedValue, 0f, 50f); - AngularDrag = UnityEngine.Mathf.Clamp((float)ms_entries[(int)ModSetting.MovementDrag].BoxedValue, 0.5f, 50f); + AngularDrag = UnityEngine.Mathf.Clamp((float)ms_entries[(int)ModSetting.MovementDrag].BoxedValue, 0f, 50f); Gravity = (bool)ms_entries[(int)ModSetting.Gravity].BoxedValue; if(MelonLoader.MelonMod.RegisteredMelons.FirstOrDefault(m => m.Info.Name == "BTKUILib") != null) @@ -124,7 +124,7 @@ namespace ml_prm MovementDragChange?.Invoke(value); }; - ms_uiElements.Add(l_page.AddSlider("Angular movement drag", "Rotation movement resistance", AngularDrag, 0.5f, 50f)); + ms_uiElements.Add(l_page.AddSlider("Angular movement drag", "Rotation movement resistance", AngularDrag, 0f, 50f)); (ms_uiElements[(int)UiElementIndex.AngularDrag] as BTKUILib.UIObjects.Components.SliderFloat).OnValueUpdated += (value) => { AngularDrag = value; @@ -154,15 +154,15 @@ namespace ml_prm (ms_uiElements[(int)UiElementIndex.VelocityMultiplier] as BTKUILib.UIObjects.Components.SliderFloat).SetSliderValue(2f); VelocityMultiplierChange?.Invoke(2f); - MovementDrag = 1f; - ms_entries[(int)ModSetting.MovementDrag].BoxedValue = 1f; - (ms_uiElements[(int)UiElementIndex.MovementDrag] as BTKUILib.UIObjects.Components.SliderFloat).SetSliderValue(1f); - MovementDragChange?.Invoke(1f); + MovementDrag = 2f; + ms_entries[(int)ModSetting.MovementDrag].BoxedValue = 2f; + (ms_uiElements[(int)UiElementIndex.MovementDrag] as BTKUILib.UIObjects.Components.SliderFloat).SetSliderValue(2f); + MovementDragChange?.Invoke(2f); - AngularDrag = 0.5f; - ms_entries[(int)ModSetting.MovementDrag].BoxedValue = 0.5f; - (ms_uiElements[(int)UiElementIndex.AngularDrag] as BTKUILib.UIObjects.Components.SliderFloat).SetSliderValue(0.5f); - AngularDragChange?.Invoke(0.5f); + AngularDrag = 2f; + ms_entries[(int)ModSetting.MovementDrag].BoxedValue = 2f; + (ms_uiElements[(int)UiElementIndex.AngularDrag] as BTKUILib.UIObjects.Components.SliderFloat).SetSliderValue(2f); + AngularDragChange?.Invoke(2f); }; } }