Ragdoll controller public instance access

Settings fix
This commit is contained in:
SDraw 2023-04-10 15:36:37 +03:00 committed by SDraw
parent 6a73e7f2ce
commit dfa7da50d6
No known key found for this signature in database
GPG key ID: BB95B4DAB2BB8BB5
4 changed files with 37 additions and 20 deletions

View file

Before

Width:  |  Height:  |  Size: 6.2 KiB

After

Width:  |  Height:  |  Size: 6.2 KiB

Before After
Before After

View file

@ -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()```

View file

@ -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<Rigidbody>();
m_colliders = new List<Collider>();
m_boneLinks = new List<System.Tuple<Transform, Transform>>();
}
~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;

View file

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