diff --git a/ml_prm/RagdollController.cs b/ml_prm/RagdollController.cs index 00b5543..db0e46c 100644 --- a/ml_prm/RagdollController.cs +++ b/ml_prm/RagdollController.cs @@ -31,6 +31,7 @@ public class RagdollController : MonoBehaviour Vector3 m_velocity = Vector3.zero; RagdollToggle m_avatarRagdollToggle = null; + RagdollTrigger m_customTrigger = null; internal RagdollController() { @@ -55,6 +56,8 @@ void Start() m_puppetRoot.localPosition = Vector3.zero; m_puppetRoot.localRotation = Quaternion.identity; + m_customTrigger = MovementSystem.Instance.proxyCollider.gameObject.AddComponent(); + Settings.SwitchChange += this.SwitchRagdoll; Settings.MovementDragChange += this.OnMovementDragChange; Settings.AngularDragChange += this.OnAngularDragChange; @@ -63,6 +66,12 @@ void Start() void OnDestroy() { + if(m_customTrigger != null) + { + Object.Destroy(m_customTrigger); + m_customTrigger = null; + } + Settings.SwitchChange -= this.SwitchRagdoll; Settings.MovementDragChange -= this.OnMovementDragChange; Settings.AngularDragChange -= this.OnAngularDragChange; @@ -83,6 +92,9 @@ void Update() if(m_enabled && m_avatarReady && BodySystem.isCalibratedAsFullBody) BodySystem.TrackingPositionWeight = 0f; + + if(!m_enabled && m_avatarReady && (m_customTrigger != null) && m_customTrigger.GetStateWithReset() && Settings.PointersReaction) + SwitchRagdoll(); } void LateUpdate() diff --git a/ml_prm/RagdollTrigger.cs b/ml_prm/RagdollTrigger.cs new file mode 100644 index 0000000..4b05c67 --- /dev/null +++ b/ml_prm/RagdollTrigger.cs @@ -0,0 +1,42 @@ +using ABI.CCK.Components; +using UnityEngine; + +namespace ml_prm +{ + [DisallowMultipleComponent] + class RagdollTrigger : MonoBehaviour + { + static int ms_localPlayerLayer = 0; + + Collider m_lastCollider = null; + bool m_triggered = false; + + void Start() + { + ms_localPlayerLayer = LayerMask.NameToLayer("PlayerLocal"); + } + + void OnTriggerEnter(Collider p_other) + { + CVRPointer l_pointer = p_other.gameObject.GetComponent(); + if((l_pointer != null) && l_pointer.type == "ragdoll" && p_other.gameObject.layer == ms_localPlayerLayer && (m_lastCollider != p_other)) + { + m_lastCollider = p_other; + m_triggered = true; + } + } + + void OnTriggerExit(Collider p_other) + { + if(m_lastCollider == p_other) + m_lastCollider = null; + } + + public bool GetStateWithReset() + { + bool l_state = m_triggered; + m_triggered = false; + return l_state; + } + } +} diff --git a/ml_prm/Settings.cs b/ml_prm/Settings.cs index 7171f5e..bd44fd3 100644 --- a/ml_prm/Settings.cs +++ b/ml_prm/Settings.cs @@ -13,7 +13,8 @@ enum ModSetting RestorePosition, MovementDrag, AngularDrag, - Gravity + Gravity, + PointersReaction } enum UiElementIndex @@ -21,6 +22,7 @@ enum UiElementIndex Hotkey = 0, RestorePosition, Gravity, + PointersReaction, VelocityMultiplier, MovementDrag, AngularDrag @@ -32,6 +34,7 @@ enum UiElementIndex public static float MovementDrag { get; private set; } = 2f; public static float AngularDrag { get; private set; } = 2f; public static bool Gravity { get; private set; } = true; + public static bool PointersReaction { get; private set; } = true; static public event Action SwitchChange; static public event Action HotkeyChange; @@ -40,6 +43,7 @@ enum UiElementIndex static public event Action MovementDragChange; static public event Action AngularDragChange; static public event Action GravityChange; + static public event Action PointersReactionChange; static MelonLoader.MelonPreferences_Category ms_category = null; static List ms_entries = null; @@ -57,6 +61,7 @@ internal static void Init() ms_category.CreateEntry(ModSetting.MovementDrag.ToString(), MovementDrag), ms_category.CreateEntry(ModSetting.AngularDrag.ToString(), AngularDrag), ms_category.CreateEntry(ModSetting.Gravity.ToString(), Gravity), + ms_category.CreateEntry(ModSetting.PointersReaction.ToString(), PointersReaction) }; Hotkey = (bool)ms_entries[(int)ModSetting.Hotkey].BoxedValue; @@ -65,6 +70,7 @@ internal static void Init() MovementDrag = UnityEngine.Mathf.Clamp((float)ms_entries[(int)ModSetting.MovementDrag].BoxedValue, 0f, 50f); AngularDrag = UnityEngine.Mathf.Clamp((float)ms_entries[(int)ModSetting.MovementDrag].BoxedValue, 0f, 50f); Gravity = (bool)ms_entries[(int)ModSetting.Gravity].BoxedValue; + PointersReaction = (bool)ms_entries[(int)ModSetting.PointersReaction].BoxedValue; if(MelonLoader.MelonMod.RegisteredMelons.FirstOrDefault(m => m.Info.Name == "BTKUILib") != null) { @@ -108,6 +114,14 @@ static void CreateBtkUi() GravityChange?.Invoke(state); }; + ms_uiElements.Add(l_categoryMod.AddToggle("Pointers reaction", "React to CVRPointer components with 'ragdoll' type", PointersReaction)); + (ms_uiElements[(int)UiElementIndex.PointersReaction] as BTKUILib.UIObjects.Components.ToggleButton).OnValueUpdated += (state) => + { + PointersReaction = state; + ms_entries[(int)ModSetting.PointersReaction].BoxedValue = state; + PointersReactionChange?.Invoke(state); + }; + ms_uiElements.Add(l_page.AddSlider("Velocity multiplier", "Velocity multiplier upon entering ragdoll state", VelocityMultiplier, 1f, 50f)); (ms_uiElements[(int)UiElementIndex.VelocityMultiplier] as BTKUILib.UIObjects.Components.SliderFloat).OnValueUpdated += (value) => { @@ -149,6 +163,11 @@ static void CreateBtkUi() (ms_uiElements[(int)UiElementIndex.Gravity] as BTKUILib.UIObjects.Components.ToggleButton).ToggleValue = true; GravityChange?.Invoke(true); + PointersReaction = true; + ms_entries[(int)ModSetting.PointersReaction].BoxedValue = true; + (ms_uiElements[(int)UiElementIndex.PointersReaction] as BTKUILib.UIObjects.Components.ToggleButton).ToggleValue = true; + PointersReactionChange?.Invoke(true); + VelocityMultiplier = 2f; ms_entries[(int)ModSetting.VelocityMultiplier].BoxedValue = 2f; (ms_uiElements[(int)UiElementIndex.VelocityMultiplier] as BTKUILib.UIObjects.Components.SliderFloat).SetSliderValue(2f); diff --git a/ml_prm/ml_prm.csproj b/ml_prm/ml_prm.csproj index d2d89ba..4a041d1 100644 --- a/ml_prm/ml_prm.csproj +++ b/ml_prm/ml_prm.csproj @@ -86,6 +86,7 @@ +