Added a unity editor script to toggle ragdoll via animation on your avatar

This commit is contained in:
kafeijao 2023-04-08 19:31:57 +01:00
parent 76f9244d9c
commit e426418806
No known key found for this signature in database
GPG key ID: E99978723E454B4C
6 changed files with 39 additions and 0 deletions

View file

@ -3,7 +3,9 @@ using ABI_RC.Core.InteractionSystem;
using ABI_RC.Core.Player;
using ABI_RC.Systems.IK.SubSystems;
using System;
using System.Collections.Generic;
using System.Reflection;
using ABI_RC.Core.Util.AssetFiltering;
namespace ml_prm
{
@ -46,6 +48,10 @@ namespace ml_prm
null
);
// Whitelist the toggle script
var l_localComponentWhitelist = typeof(SharedFilter).GetField("_localComponentWhitelist", BindingFlags.NonPublic | BindingFlags.Static)!.GetValue(null) as HashSet<Type>;
l_localComponentWhitelist!.Add(typeof(RagdollToggle));
MelonLoader.MelonCoroutines.Start(WaitForLocalPlayer());
}

View file

@ -23,3 +23,15 @@ Optional mod's settings with [BTKUILib](https://github.com/BTK-Development/BTKUI
* Incompatible with `Follow hips on IK override` option in AvatarMotionTweaker.
* Not suggested to activate fly mode with enabled ragdoll state.
* Can't be activated in worlds that don't allow flying and spawnables.
# Unity Editor Script
You can also trigger the ragdoll via animations on your avatar. To do this you need to download and import the
`ml_prm_editor_script.unitypackage` into your unity project. Then add the component `Ragdoll Toggle` anywhere inside of
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)
**Note:** In order to work the game object needs to be active and the component enabled.

View file

@ -30,6 +30,8 @@ namespace ml_prm
Vector3 m_lastPosition = Vector3.zero;
Vector3 m_velocity = Vector3.zero;
RagdollToggle m_avatarRagdollToggle = null;
internal RagdollController()
{
m_rigidBodies = new List<Rigidbody>();
@ -67,6 +69,11 @@ namespace ml_prm
if(Settings.Hotkey && Input.GetKeyDown(KeyCode.R) && !ViewManager.Instance.isGameMenuOpen())
SwitchRagdoll();
if (m_avatarRagdollToggle != null && m_avatarRagdollToggle.isActiveAndEnabled && m_avatarRagdollToggle.shouldOverride) {
if (m_enabled != m_avatarRagdollToggle.isOn)
SwitchRagdoll();
}
}
void LateUpdate()
@ -182,6 +189,8 @@ namespace ml_prm
m_vrIK.onPostSolverUpdate.AddListener(this.OnIKPostUpdate);
}
m_avatarRagdollToggle = PlayerSetup.Instance._avatar.GetComponentInChildren<RagdollToggle>(true);
m_avatarReady = true;
}
}

12
ml_prm/RagdollToggle.cs Normal file
View file

@ -0,0 +1,12 @@
using UnityEngine;
namespace ml_prm
{
public class RagdollToggle : MonoBehaviour
{
[Tooltip("Whether or not is should use the isOn property to override the current Ragdoll State of the Avatar.")]
[SerializeField] public bool shouldOverride;
[Tooltip("Whether Ragdoll State is active or not on the Avatar. Requires shouldOverride to be true to work.")]
[SerializeField] public bool isOn;
}
}

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB