mirror of
https://github.com/hanetzer/sdraw_mods_cvr.git
synced 2025-09-03 18:39:23 +00:00
Reaction to CVRPointer component with ragdoll
type
This commit is contained in:
parent
dfa7da50d6
commit
faac28fb88
4 changed files with 75 additions and 1 deletions
|
@ -31,6 +31,7 @@ namespace ml_prm
|
|||
Vector3 m_velocity = Vector3.zero;
|
||||
|
||||
RagdollToggle m_avatarRagdollToggle = null;
|
||||
RagdollTrigger m_customTrigger = null;
|
||||
|
||||
internal RagdollController()
|
||||
{
|
||||
|
@ -55,6 +56,8 @@ namespace ml_prm
|
|||
m_puppetRoot.localPosition = Vector3.zero;
|
||||
m_puppetRoot.localRotation = Quaternion.identity;
|
||||
|
||||
m_customTrigger = MovementSystem.Instance.proxyCollider.gameObject.AddComponent<RagdollTrigger>();
|
||||
|
||||
Settings.SwitchChange += this.SwitchRagdoll;
|
||||
Settings.MovementDragChange += this.OnMovementDragChange;
|
||||
Settings.AngularDragChange += this.OnAngularDragChange;
|
||||
|
@ -63,6 +66,12 @@ namespace ml_prm
|
|||
|
||||
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 @@ namespace ml_prm
|
|||
|
||||
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()
|
||||
|
|
42
ml_prm/RagdollTrigger.cs
Normal file
42
ml_prm/RagdollTrigger.cs
Normal file
|
@ -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<CVRPointer>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -13,7 +13,8 @@ namespace ml_prm
|
|||
RestorePosition,
|
||||
MovementDrag,
|
||||
AngularDrag,
|
||||
Gravity
|
||||
Gravity,
|
||||
PointersReaction
|
||||
}
|
||||
|
||||
enum UiElementIndex
|
||||
|
@ -21,6 +22,7 @@ namespace ml_prm
|
|||
Hotkey = 0,
|
||||
RestorePosition,
|
||||
Gravity,
|
||||
PointersReaction,
|
||||
VelocityMultiplier,
|
||||
MovementDrag,
|
||||
AngularDrag
|
||||
|
@ -32,6 +34,7 @@ namespace ml_prm
|
|||
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<bool> HotkeyChange;
|
||||
|
@ -40,6 +43,7 @@ namespace ml_prm
|
|||
static public event Action<float> MovementDragChange;
|
||||
static public event Action<float> AngularDragChange;
|
||||
static public event Action<bool> GravityChange;
|
||||
static public event Action<bool> PointersReactionChange;
|
||||
|
||||
static MelonLoader.MelonPreferences_Category ms_category = null;
|
||||
static List<MelonLoader.MelonPreferences_Entry> ms_entries = null;
|
||||
|
@ -57,6 +61,7 @@ namespace ml_prm
|
|||
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 @@ namespace ml_prm
|
|||
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 @@ namespace ml_prm
|
|||
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 @@ namespace ml_prm
|
|||
(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);
|
||||
|
|
|
@ -86,6 +86,7 @@
|
|||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="RagdollTrigger.cs" />
|
||||
<Compile Include="Main.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="RagdollController.cs" />
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue