mirror of
https://github.com/hanetzer/sdraw_mods_cvr.git
synced 2025-09-03 18:39:23 +00:00
Minor code improvements
This commit is contained in:
parent
a2f9c1303e
commit
45557943c4
35 changed files with 557 additions and 835 deletions
|
@ -8,36 +8,35 @@ namespace ml_prm
|
|||
{
|
||||
public class PlayerRagdollMod : MelonLoader.MelonMod
|
||||
{
|
||||
RagdollController m_localController = null;
|
||||
RagdollController m_controller = null;
|
||||
|
||||
public override void OnInitializeMelon()
|
||||
{
|
||||
Settings.Init();
|
||||
ModUi.Init();
|
||||
GameEvents.Init(HarmonyInstance);
|
||||
WorldHandler.Init();
|
||||
RemoteGestureManager.Init();
|
||||
WorldManager.Init();
|
||||
|
||||
MelonLoader.MelonCoroutines.Start(WaitForLocalPlayer());
|
||||
MelonLoader.MelonCoroutines.Start(WaitForRootLogic());
|
||||
MelonLoader.MelonCoroutines.Start(WaitForWhitelist());
|
||||
}
|
||||
|
||||
public override void OnDeinitializeMelon()
|
||||
{
|
||||
WorldHandler.DeInit();
|
||||
RemoteGestureManager.DeInit();
|
||||
WorldManager.DeInit();
|
||||
|
||||
if(m_localController != null)
|
||||
UnityEngine.Object.Destroy(m_localController);
|
||||
m_localController = null;
|
||||
if(m_controller != null)
|
||||
UnityEngine.Object.Destroy(m_controller.gameObject);
|
||||
m_controller = null;
|
||||
}
|
||||
|
||||
System.Collections.IEnumerator WaitForLocalPlayer()
|
||||
System.Collections.IEnumerator WaitForRootLogic()
|
||||
{
|
||||
while(PlayerSetup.Instance == null)
|
||||
while(ABI_RC.Core.RootLogic.Instance == null)
|
||||
yield return null;
|
||||
|
||||
m_localController = PlayerSetup.Instance.gameObject.AddComponent<RagdollController>();
|
||||
m_controller = new UnityEngine.GameObject("[PlayerRagdollMod]").AddComponent<RagdollController>();
|
||||
m_controller.gameObject.AddComponent<RemoteGesturesManager>();
|
||||
}
|
||||
|
||||
System.Collections.IEnumerator WaitForWhitelist()
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
[assembly: MelonLoader.MelonInfo(typeof(ml_prm.PlayerRagdollMod), "PlayerRagdollMod", "1.1.9", "SDraw", "https://github.com/SDraw/ml_mods_cvr")]
|
||||
[assembly: MelonLoader.MelonInfo(typeof(ml_prm.PlayerRagdollMod), "PlayerRagdollMod", "1.2.0", "SDraw", "https://github.com/SDraw/ml_mods_cvr")]
|
||||
[assembly: MelonLoader.MelonGame(null, "ChilloutVR")]
|
||||
[assembly: MelonLoader.MelonPriority(2)]
|
||||
[assembly: MelonLoader.MelonAdditionalDependencies("BTKUILib")]
|
||||
|
|
|
@ -4,7 +4,7 @@ This mod turns player's avatar into ragdoll puppet.
|
|||
# Installation
|
||||
* Install [latest MelonLoader](https://github.com/LavaGang/MelonLoader)
|
||||
* Get [latest release DLL](../../../releases/latest):
|
||||
* Put `ml_prm.dll` in `Mods` folder of game
|
||||
* Put `PlayerRagdollMod.dll` in `Mods` folder of game
|
||||
|
||||
# Usage
|
||||
* Press `R` to turn into ragdoll and back.
|
||||
|
@ -73,6 +73,8 @@ You can use this mod's functions within your mod. To do this you need:
|
|||
Available methods:
|
||||
* ```bool IsRagdolled()```
|
||||
* ```void SwitchRagdoll()```
|
||||
* ```void Ragdoll()```
|
||||
* ```void Unragdoll()```
|
||||
|
||||
# Notes
|
||||
* 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):
|
||||
|
|
|
@ -64,6 +64,8 @@ namespace ml_prm
|
|||
m_rigidBody.mass = mass;
|
||||
m_physicsInfluencer.volume = mass * 0.005f;
|
||||
m_physicsInfluencer.enableLocalGravity = true;
|
||||
|
||||
this.gameObject.name = string.Format("{0} [NoGizmo]", this.gameObject.name);
|
||||
}
|
||||
|
||||
if(collider != null)
|
||||
|
@ -109,11 +111,11 @@ namespace ml_prm
|
|||
|
||||
void OnTriggerEnter(Collider p_col)
|
||||
{
|
||||
if(Settings.PointersReaction && (RagdollController.Instance != null))
|
||||
if(Settings.PointersReaction && (RagdollController.Instance != null) && !RagdollController.Instance.IsRagdolled())
|
||||
{
|
||||
CVRPointer l_pointer = p_col.GetComponent<CVRPointer>();
|
||||
if((l_pointer != null) && (l_pointer.type == c_ragdollPointerType) && l_pointer.enabled && !IsIgnored(l_pointer.transform) && !RagdollController.Instance.IsRagdolled())
|
||||
RagdollController.Instance.SwitchRagdoll();
|
||||
if((l_pointer != null) && (l_pointer.type == c_ragdollPointerType) && l_pointer.enabled && !IsIgnored(l_pointer.transform))
|
||||
RagdollController.Instance.Ragdoll();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,15 +20,17 @@ namespace ml_prm
|
|||
|
||||
public static RagdollController Instance { get; private set; } = null;
|
||||
|
||||
Transform m_avatarTransform = null;
|
||||
Transform m_hips = null;
|
||||
VRIK m_vrIK = null;
|
||||
bool m_applyHipsPosition = false;
|
||||
bool m_applyHipsRotation = false;
|
||||
|
||||
bool m_enabled = false;
|
||||
bool m_ragdolled = false;
|
||||
bool m_forcedSwitch = false;
|
||||
|
||||
Transform m_puppetRoot = null;
|
||||
Transform m_puppet = null;
|
||||
Transform m_puppetRoot = null;
|
||||
BipedRagdollReferences m_puppetReferences;
|
||||
readonly List<RagdollBodypartHandler> m_ragdollBodyHandlers = null;
|
||||
readonly List<System.Tuple<Transform, Transform>> m_boneLinks = null;
|
||||
|
@ -36,21 +38,17 @@ namespace ml_prm
|
|||
|
||||
bool m_avatarReady = false;
|
||||
Coroutine m_initCoroutine = null;
|
||||
Vector3 m_lastPosition = Vector3.zero;
|
||||
Vector3 m_velocity = Vector3.zero;
|
||||
Vector3 m_ragdollLastPos = Vector3.zero;
|
||||
bool m_wasSwimming = false;
|
||||
|
||||
RagdollToggle m_avatarRagdollToggle = null; // Custom component available for editor
|
||||
AvatarBoolParameter m_ragdolledParameter = null;
|
||||
PhysicMaterial m_physicsMaterial = null;
|
||||
|
||||
bool m_inAir = false;
|
||||
bool m_reachedGround = true;
|
||||
float m_groundedTime = 0f;
|
||||
float m_downTime = float.MinValue;
|
||||
|
||||
bool m_inAir = false;
|
||||
|
||||
internal RagdollController()
|
||||
{
|
||||
m_ragdollBodyHandlers = new List<RagdollBodypartHandler>();
|
||||
|
@ -69,6 +67,8 @@ namespace ml_prm
|
|||
|
||||
void Start()
|
||||
{
|
||||
this.gameObject.layer = LayerMask.NameToLayer("PlayerLocal");
|
||||
|
||||
m_physicsMaterial = new PhysicMaterial("Ragdoll");
|
||||
m_physicsMaterial.dynamicFriction = c_defaultFriction;
|
||||
m_physicsMaterial.staticFriction = c_defaultFriction;
|
||||
|
@ -76,10 +76,10 @@ namespace ml_prm
|
|||
m_physicsMaterial.bounciness = 0f;
|
||||
m_physicsMaterial.bounceCombine = PhysicMaterialCombine.Average;
|
||||
|
||||
m_puppetRoot = new GameObject("[PlayerAvatarPuppet]").transform;
|
||||
m_puppetRoot.parent = PlayerSetup.Instance.transform;
|
||||
m_puppetRoot.localPosition = Vector3.zero;
|
||||
m_puppetRoot.localRotation = Quaternion.identity;
|
||||
m_puppet = new GameObject("[Puppet]").transform;
|
||||
m_puppet.parent = this.transform;
|
||||
m_puppet.localPosition = Vector3.zero;
|
||||
m_puppet.localRotation = Quaternion.identity;
|
||||
|
||||
Settings.OnMovementDragChanged.AddListener(this.OnMovementDragChanged);
|
||||
Settings.OnAngularDragChanged.AddListener(this.OnAngularDragChanged);
|
||||
|
@ -104,7 +104,7 @@ namespace ml_prm
|
|||
BetterBetterCharacterController.OnTeleport.AddListener(this.OnPlayerTeleport);
|
||||
|
||||
ModUi.OnSwitchChanged.AddListener(this.SwitchRagdoll);
|
||||
RemoteGestureHandler.OnGestureState.AddListener(this.OnRemotePlayerGestureStateChanged);
|
||||
RemoteGesturesManager.OnGestureState.AddListener(this.OnRemoteGestureStateChanged);
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
|
@ -116,11 +116,11 @@ namespace ml_prm
|
|||
StopCoroutine(m_initCoroutine);
|
||||
m_initCoroutine = null;
|
||||
|
||||
if(m_puppetRoot != null)
|
||||
Object.Destroy(m_puppetRoot);
|
||||
m_puppetRoot = null;
|
||||
|
||||
if(m_puppet != null)
|
||||
Object.Destroy(m_puppet);
|
||||
m_puppet = null;
|
||||
|
||||
m_puppetRoot = null;
|
||||
m_ragdollBodyHandlers.Clear();
|
||||
m_boneLinks.Clear();
|
||||
m_jointAnchors.Clear();
|
||||
|
@ -153,70 +153,66 @@ namespace ml_prm
|
|||
BetterBetterCharacterController.OnTeleport.RemoveListener(this.OnPlayerTeleport);
|
||||
|
||||
ModUi.OnSwitchChanged.RemoveListener(this.SwitchRagdoll);
|
||||
RemoteGestureHandler.OnGestureState.RemoveListener(this.OnRemotePlayerGestureStateChanged);
|
||||
RemoteGesturesManager.OnGestureState.RemoveListener(this.OnRemoteGestureStateChanged);
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if(m_avatarReady && !m_enabled && Settings.FallDamage && !BetterBetterCharacterController.Instance.IsFlying())
|
||||
if(m_avatarReady)
|
||||
{
|
||||
bool l_grounded = BetterBetterCharacterController.Instance.IsGrounded();
|
||||
bool l_inWater = BetterBetterCharacterController.Instance.IsInWater();
|
||||
if(m_inAir && l_grounded && !l_inWater && (m_velocity.magnitude >= Settings.FallLimit))
|
||||
SwitchRagdoll();
|
||||
|
||||
m_inAir = !(l_grounded || l_inWater);
|
||||
}
|
||||
|
||||
if(m_avatarReady && m_enabled)
|
||||
{
|
||||
BodySystem.TrackingPositionWeight = 0f;
|
||||
BetterBetterCharacterController.Instance.PauseGroundConstraint();
|
||||
BetterBetterCharacterController.Instance.ResetAllForces();
|
||||
}
|
||||
|
||||
if(m_avatarReady && !m_enabled)
|
||||
{
|
||||
Vector3 l_pos = PlayerSetup.Instance.transform.position;
|
||||
m_velocity = (m_velocity + (l_pos - m_lastPosition) / Time.deltaTime) * 0.5f;
|
||||
m_lastPosition = l_pos;
|
||||
|
||||
if(!m_reachedGround && BetterBetterCharacterController.Instance.IsOnGround())
|
||||
if(!m_ragdolled && Settings.FallDamage && !BetterBetterCharacterController.Instance.IsFlying())
|
||||
{
|
||||
m_groundedTime += Time.deltaTime;
|
||||
bool l_grounded = BetterBetterCharacterController.Instance.IsGrounded();
|
||||
bool l_inWater = BetterBetterCharacterController.Instance.IsInWater();
|
||||
if(m_inAir && l_grounded && !l_inWater && (BetterBetterCharacterController.Instance.characterMovement.landedVelocity.magnitude >= Settings.FallLimit))
|
||||
Ragdoll();
|
||||
|
||||
m_inAir = !(l_grounded || l_inWater);
|
||||
}
|
||||
|
||||
if(m_ragdolled)
|
||||
{
|
||||
BodySystem.TrackingPositionWeight = 0f;
|
||||
BetterBetterCharacterController.Instance.PauseGroundConstraint();
|
||||
BetterBetterCharacterController.Instance.ResetAllForces();
|
||||
PlayerSetup.Instance.animatorManager.CancelEmote = true;
|
||||
}
|
||||
|
||||
if(!m_ragdolled && !m_reachedGround && (BetterBetterCharacterController.Instance.IsOnGround() || BetterBetterCharacterController.Instance.IsInWater()))
|
||||
{
|
||||
m_groundedTime += Time.unscaledDeltaTime;
|
||||
if(m_groundedTime >= 0.25f)
|
||||
m_reachedGround = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(m_avatarReady && m_enabled && Settings.AutoRecover)
|
||||
{
|
||||
m_downTime += Time.deltaTime;
|
||||
if(m_downTime >= Settings.RecoverDelay)
|
||||
if(m_ragdolled && Settings.AutoRecover)
|
||||
{
|
||||
SwitchRagdoll();
|
||||
m_downTime = float.MinValue; // One attempt to recover
|
||||
m_downTime += Time.unscaledDeltaTime;
|
||||
if(m_downTime >= Settings.RecoverDelay)
|
||||
{
|
||||
Unragdoll();
|
||||
m_downTime = float.MinValue; // One attempt to recover
|
||||
}
|
||||
}
|
||||
|
||||
if((m_avatarRagdollToggle != null) && m_avatarRagdollToggle.isActiveAndEnabled && m_avatarRagdollToggle.shouldOverride && (m_ragdolled != m_avatarRagdollToggle.isOn))
|
||||
SwitchRagdoll();
|
||||
|
||||
if(Settings.Hotkey && Input.GetKeyDown(Settings.HotkeyKey) && !ViewManager.Instance.IsAnyMenuOpen)
|
||||
SwitchRagdoll();
|
||||
|
||||
if(m_ragdolled && CVRInputManager.Instance.jump && Settings.JumpRecover)
|
||||
Unragdoll();
|
||||
}
|
||||
|
||||
if((m_avatarRagdollToggle != null) && m_avatarRagdollToggle.isActiveAndEnabled && m_avatarRagdollToggle.shouldOverride && (m_enabled != m_avatarRagdollToggle.isOn))
|
||||
SwitchRagdoll();
|
||||
|
||||
if(Settings.Hotkey && Input.GetKeyDown(Settings.HotkeyKey) && !ViewManager.Instance.IsAnyMenuOpen)
|
||||
SwitchRagdoll();
|
||||
|
||||
if(m_avatarReady && m_enabled && CVRInputManager.Instance.jump && Settings.JumpRecover)
|
||||
SwitchRagdoll();
|
||||
}
|
||||
|
||||
void FixedUpdate()
|
||||
{
|
||||
if(m_avatarReady && m_enabled)
|
||||
if(m_avatarReady && m_ragdolled)
|
||||
{
|
||||
Vector3 l_dif = m_puppetReferences.hips.position - m_ragdollLastPos;
|
||||
PlayerSetup.Instance.transform.position += l_dif;
|
||||
m_puppetReferences.hips.position -= l_dif;
|
||||
m_ragdollLastPos = m_puppetReferences.hips.position;
|
||||
Vector3 l_currentPos = m_puppetReferences.hips.position;
|
||||
PlayerSetup.Instance.transform.position += (l_currentPos - m_ragdollLastPos);
|
||||
m_ragdollLastPos = l_currentPos;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -224,15 +220,21 @@ namespace ml_prm
|
|||
{
|
||||
if(m_avatarReady)
|
||||
{
|
||||
if(m_enabled)
|
||||
if(m_ragdolled)
|
||||
{
|
||||
foreach(var l_link in m_boneLinks)
|
||||
l_link.Item1.CopyGlobal(l_link.Item2);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach(var l_link in m_boneLinks)
|
||||
l_link.Item2.CopyGlobal(l_link.Item1);
|
||||
if(m_vrIK == null)
|
||||
{
|
||||
m_puppetRoot.position = m_avatarTransform.position;
|
||||
m_puppetRoot.rotation = m_avatarTransform.rotation;
|
||||
|
||||
foreach(var l_link in m_boneLinks)
|
||||
l_link.Item2.CopyGlobal(l_link.Item1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -246,19 +248,21 @@ namespace ml_prm
|
|||
m_initCoroutine = null;
|
||||
}
|
||||
|
||||
if(m_enabled)
|
||||
if(m_ragdolled)
|
||||
{
|
||||
TryRestoreMovement();
|
||||
BodySystem.TrackingPositionWeight = 1f;
|
||||
}
|
||||
|
||||
if(m_puppet != null)
|
||||
Object.Destroy(m_puppet.gameObject);
|
||||
m_puppet = null;
|
||||
if(m_puppetRoot != null)
|
||||
Object.Destroy(m_puppetRoot.gameObject);
|
||||
m_puppetRoot = null;
|
||||
|
||||
m_avatarTransform = null;
|
||||
m_hips = null;
|
||||
m_vrIK = null;
|
||||
m_applyHipsPosition = false;
|
||||
m_enabled = false;
|
||||
m_ragdolled = false;
|
||||
m_avatarReady = false;
|
||||
m_avatarRagdollToggle = null;
|
||||
m_ragdolledParameter = null;
|
||||
|
@ -269,25 +273,26 @@ namespace ml_prm
|
|||
m_reachedGround = true;
|
||||
m_groundedTime = 0f;
|
||||
m_downTime = float.MinValue;
|
||||
m_puppetRoot.localScale = Vector3.one;
|
||||
m_puppet.localScale = Vector3.one;
|
||||
m_inAir = false;
|
||||
m_wasSwimming = false;
|
||||
}
|
||||
|
||||
void OnAvatarSetup()
|
||||
{
|
||||
if(PlayerSetup.Instance._animator.isHuman)
|
||||
{
|
||||
m_avatarTransform = PlayerSetup.Instance._avatar.transform;
|
||||
m_hips = PlayerSetup.Instance._animator.GetBoneTransform(HumanBodyBones.Hips);
|
||||
Utils.SetAvatarTPose();
|
||||
|
||||
BipedRagdollReferences l_avatarReferences = BipedRagdollReferences.FromAvatar(PlayerSetup.Instance._animator);
|
||||
|
||||
m_puppet = new GameObject("Root").transform;
|
||||
m_puppet.parent = m_puppetRoot;
|
||||
m_puppet.localPosition = Vector3.zero;
|
||||
m_puppet.localRotation = Quaternion.identity;
|
||||
m_puppetRoot = new GameObject("Root").transform;
|
||||
m_puppetRoot.parent = m_puppet;
|
||||
m_puppetRoot.position = m_avatarTransform.position;
|
||||
m_puppetRoot.rotation = m_avatarTransform.rotation;
|
||||
|
||||
m_puppetReferences.root = m_puppet;
|
||||
m_puppetReferences.root = m_puppetRoot;
|
||||
m_puppetReferences.hips = CloneTransform(l_avatarReferences.hips, m_puppetReferences.root, "Hips");
|
||||
m_puppetReferences.spine = CloneTransform(l_avatarReferences.spine, m_puppetReferences.hips, "Spine");
|
||||
|
||||
|
@ -312,7 +317,7 @@ namespace ml_prm
|
|||
m_puppetReferences.rightLowerLeg = CloneTransform(l_avatarReferences.rightLowerLeg, m_puppetReferences.rightUpperLeg, "RightLowerLeg");
|
||||
m_puppetReferences.rightFoot = CloneTransform(l_avatarReferences.rightFoot, m_puppetReferences.rightLowerLeg, "RightFoot");
|
||||
|
||||
// Move to world origin to overcome possible issues, maybe?
|
||||
// Move to world origin to overcome possible issues
|
||||
m_puppetRoot.position = Vector3.zero;
|
||||
m_puppetRoot.rotation = Quaternion.identity;
|
||||
|
||||
|
@ -350,8 +355,8 @@ namespace ml_prm
|
|||
}
|
||||
|
||||
// And return back
|
||||
m_puppetRoot.localPosition = Vector3.zero;
|
||||
m_puppetRoot.localRotation = Quaternion.identity;
|
||||
m_puppetRoot.position = m_avatarTransform.position;
|
||||
m_puppetRoot.rotation = m_avatarTransform.rotation;
|
||||
|
||||
m_vrIK = PlayerSetup.Instance._avatar.GetComponent<VRIK>();
|
||||
if(m_vrIK != null)
|
||||
|
@ -386,12 +391,9 @@ namespace ml_prm
|
|||
|
||||
void OnAvatarPreReuse()
|
||||
{
|
||||
if(m_avatarReady && m_enabled)
|
||||
{
|
||||
m_forcedSwitch = true;
|
||||
SwitchRagdoll();
|
||||
m_forcedSwitch = false;
|
||||
}
|
||||
m_forcedSwitch = true;
|
||||
Unragdoll();
|
||||
m_forcedSwitch = false;
|
||||
}
|
||||
void OnAvatarPostReuse()
|
||||
{
|
||||
|
@ -412,32 +414,27 @@ namespace ml_prm
|
|||
|
||||
void OnSeatPreSit(CVRSeat p_seat)
|
||||
{
|
||||
if(m_avatarReady && m_enabled && !p_seat.occupied)
|
||||
if(!p_seat.occupied)
|
||||
{
|
||||
m_forcedSwitch = true;
|
||||
SwitchRagdoll();
|
||||
Unragdoll();
|
||||
m_forcedSwitch = false;
|
||||
ResetStates();
|
||||
m_inAir = false;
|
||||
}
|
||||
}
|
||||
|
||||
void OnCalibrationStart()
|
||||
{
|
||||
if(m_avatarReady && m_enabled)
|
||||
{
|
||||
m_forcedSwitch = true;
|
||||
SwitchRagdoll();
|
||||
m_forcedSwitch = false;
|
||||
ResetStates();
|
||||
}
|
||||
m_forcedSwitch = true;
|
||||
Unragdoll();
|
||||
m_forcedSwitch = false;
|
||||
m_inAir = false;
|
||||
}
|
||||
|
||||
void OnWorldPreSpawn()
|
||||
{
|
||||
if(m_avatarReady && m_enabled)
|
||||
SwitchRagdoll();
|
||||
|
||||
ResetStates();
|
||||
Unragdoll();
|
||||
m_inAir = false;
|
||||
|
||||
OnGravityChanged(Settings.Gravity);
|
||||
OnPhysicsMaterialChanged(true);
|
||||
|
@ -447,25 +444,24 @@ namespace ml_prm
|
|||
|
||||
void OnCombatPreDown()
|
||||
{
|
||||
if(m_avatarReady && !m_enabled && CombatSystem.Instance.isDown && Settings.CombatReaction)
|
||||
if(CombatSystem.Instance.isDown && Settings.CombatReaction)
|
||||
{
|
||||
m_reachedGround = true;
|
||||
m_forcedSwitch = true;
|
||||
SwitchRagdoll();
|
||||
Ragdoll();
|
||||
m_forcedSwitch = false;
|
||||
ResetStates(false);
|
||||
m_inAir = false;
|
||||
}
|
||||
}
|
||||
|
||||
void OnFlightChange()
|
||||
{
|
||||
if(m_avatarReady && m_enabled && BetterBetterCharacterController.Instance.IsFlying())
|
||||
if(BetterBetterCharacterController.Instance.IsFlying())
|
||||
{
|
||||
m_forcedSwitch = true;
|
||||
SwitchRagdoll();
|
||||
Unragdoll();
|
||||
m_forcedSwitch = false;
|
||||
|
||||
ResetStates(false);
|
||||
m_inAir = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -473,10 +469,14 @@ namespace ml_prm
|
|||
{
|
||||
try
|
||||
{
|
||||
ResetStates();
|
||||
m_inAir = false;
|
||||
|
||||
if(m_avatarReady && m_enabled)
|
||||
m_ragdollLastPos = m_puppetReferences.hips.position;
|
||||
if(m_avatarReady && m_ragdolled)
|
||||
{
|
||||
Vector3 l_pos = m_hips.position;
|
||||
m_puppetReferences.hips.position = l_pos;
|
||||
m_ragdollLastPos = l_pos;
|
||||
}
|
||||
}
|
||||
catch(System.Exception e)
|
||||
{
|
||||
|
@ -486,26 +486,20 @@ namespace ml_prm
|
|||
|
||||
void OnIKOffsetUpdate(GameEvents.EventResult p_result)
|
||||
{
|
||||
p_result.m_result |= (m_enabled && (m_vrIK != null));
|
||||
p_result.m_result |= (m_ragdolled && (m_vrIK != null));
|
||||
}
|
||||
|
||||
// Custom game events
|
||||
void OnRemotePlayerGestureStateChanged(ABI_RC.Core.Player.PuppetMaster p_master, bool p_left, bool p_state)
|
||||
void OnRemoteGestureStateChanged(ABI_RC.Core.Player.PuppetMaster p_master, RemoteGesturesManager.GestureHand p_hand, bool p_state)
|
||||
{
|
||||
if(m_avatarReady && m_enabled && Settings.GestureGrab && (p_master.animatorManager.Animator != null))
|
||||
if(m_avatarReady && m_ragdolled && Settings.GestureGrab && (p_master.animatorManager.Animator != null))
|
||||
{
|
||||
Transform l_hand = p_master.animatorManager.Animator.GetBoneTransform(p_left ? HumanBodyBones.LeftHand : HumanBodyBones.RightHand);
|
||||
Transform l_finger = p_master.animatorManager.Animator.GetBoneTransform(p_left ? HumanBodyBones.LeftMiddleProximal : HumanBodyBones.RightMiddleProximal);
|
||||
Transform l_hand = p_master.animatorManager.Animator.GetBoneTransform((p_hand == RemoteGesturesManager.GestureHand.Left) ? HumanBodyBones.LeftHand : HumanBodyBones.RightHand);
|
||||
Transform l_finger = p_master.animatorManager.Animator.GetBoneTransform((p_hand == RemoteGesturesManager.GestureHand.Left) ? HumanBodyBones.LeftMiddleProximal : HumanBodyBones.RightMiddleProximal);
|
||||
|
||||
if(l_hand != null)
|
||||
{
|
||||
Vector3 l_pos = l_hand.position;
|
||||
if(l_finger != null)
|
||||
{
|
||||
l_pos += l_finger.position;
|
||||
l_pos *= 0.5f;
|
||||
}
|
||||
|
||||
Vector3 l_pos = (l_finger != null) ? ((l_hand.position + l_finger.position) * 0.5f) : l_hand.position;
|
||||
foreach(var l_bodyHandler in m_ragdollBodyHandlers)
|
||||
{
|
||||
if(p_state)
|
||||
|
@ -523,8 +517,11 @@ namespace ml_prm
|
|||
// VRIK updates
|
||||
void OnIKPostSolverUpdate()
|
||||
{
|
||||
if(!m_enabled)
|
||||
if(!m_ragdolled)
|
||||
{
|
||||
m_puppetRoot.position = m_avatarTransform.position;
|
||||
m_puppetRoot.rotation = m_avatarTransform.rotation;
|
||||
|
||||
foreach(var l_link in m_boneLinks)
|
||||
l_link.Item2.CopyGlobal(l_link.Item1);
|
||||
}
|
||||
|
@ -535,7 +532,7 @@ namespace ml_prm
|
|||
{
|
||||
if(m_avatarReady)
|
||||
{
|
||||
float l_drag = (WorldHandler.IsSafeWorld() ? p_value : 1f);
|
||||
float l_drag = (WorldManager.IsSafeWorld() ? p_value : 1f);
|
||||
foreach(RagdollBodypartHandler l_handler in m_ragdollBodyHandlers)
|
||||
l_handler.SetDrag(l_drag);
|
||||
}
|
||||
|
@ -554,7 +551,7 @@ namespace ml_prm
|
|||
{
|
||||
if(m_avatarReady)
|
||||
{
|
||||
bool l_gravity = (!WorldHandler.IsSafeWorld() || p_state);
|
||||
bool l_gravity = (!WorldManager.IsSafeWorld() || p_state);
|
||||
foreach(RagdollBodypartHandler l_handler in m_ragdollBodyHandlers)
|
||||
l_handler.SetActiveGravity(l_gravity);
|
||||
|
||||
|
@ -570,8 +567,8 @@ namespace ml_prm
|
|||
{
|
||||
if(m_physicsMaterial != null)
|
||||
{
|
||||
bool l_slipperiness = (Settings.Slipperiness && WorldHandler.IsSafeWorld());
|
||||
bool l_bounciness = (Settings.Bounciness && WorldHandler.IsSafeWorld());
|
||||
bool l_slipperiness = (Settings.Slipperiness && WorldManager.IsSafeWorld());
|
||||
bool l_bounciness = (Settings.Bounciness && WorldManager.IsSafeWorld());
|
||||
m_physicsMaterial.dynamicFriction = (l_slipperiness ? 0f : c_defaultFriction);
|
||||
m_physicsMaterial.staticFriction = (l_slipperiness ? 0f : c_defaultFriction);
|
||||
m_physicsMaterial.frictionCombine = (l_slipperiness ? PhysicMaterialCombine.Minimum : PhysicMaterialCombine.Average);
|
||||
|
@ -584,7 +581,7 @@ namespace ml_prm
|
|||
{
|
||||
if(m_avatarReady)
|
||||
{
|
||||
bool l_buoyancy = (!WorldHandler.IsSafeWorld() || p_state);
|
||||
bool l_buoyancy = (!WorldManager.IsSafeWorld() || p_state);
|
||||
foreach(RagdollBodypartHandler l_handler in m_ragdollBodyHandlers)
|
||||
l_handler.SetBuoyancy(l_buoyancy);
|
||||
|
||||
|
@ -603,7 +600,7 @@ namespace ml_prm
|
|||
|
||||
void OnGestureGrabChanged(bool p_state)
|
||||
{
|
||||
if(m_avatarReady && m_enabled & !p_state)
|
||||
if(m_avatarReady && m_ragdolled & !p_state)
|
||||
{
|
||||
foreach(var l_hanlder in m_ragdollBodyHandlers)
|
||||
l_hanlder.Detach();
|
||||
|
@ -611,122 +608,106 @@ namespace ml_prm
|
|||
}
|
||||
|
||||
// Arbitrary
|
||||
public bool IsRagdolled() => (m_avatarReady && m_ragdolled);
|
||||
|
||||
public void SwitchRagdoll()
|
||||
{
|
||||
if(m_avatarReady)
|
||||
if(m_ragdolled)
|
||||
Unragdoll();
|
||||
else
|
||||
Ragdoll();
|
||||
}
|
||||
|
||||
public void Ragdoll()
|
||||
{
|
||||
if(m_avatarReady && !m_ragdolled && CanRagdoll())
|
||||
{
|
||||
if(!m_enabled)
|
||||
Vector3 l_velocity = Vector3.ClampMagnitude(BetterBetterCharacterController.Instance.velocity * (WorldManager.IsSafeWorld() ? Settings.VelocityMultiplier : 1f), WorldManager.GetMovementLimit());
|
||||
if(Settings.ViewVelocity && WorldManager.IsSafeWorld())
|
||||
{
|
||||
if(CanRagdoll())
|
||||
{
|
||||
m_wasSwimming = BetterBetterCharacterController.Instance.IsSwimming();
|
||||
|
||||
if(BetterBetterCharacterController.Instance.IsFlying())
|
||||
BetterBetterCharacterController.Instance.ChangeFlight(false, true);
|
||||
BetterBetterCharacterController.Instance.SetImmobilized(true);
|
||||
BetterBetterCharacterController.Instance.ClearFluidVolumes();
|
||||
BetterBetterCharacterController.Instance.ResetAllForces();
|
||||
BetterBetterCharacterController.Instance.PauseGroundConstraint();
|
||||
BodySystem.TrackingPositionWeight = 0f;
|
||||
m_applyHipsPosition = IKSystem.Instance.applyOriginalHipPosition;
|
||||
IKSystem.Instance.applyOriginalHipPosition = true;
|
||||
m_applyHipsRotation = IKSystem.Instance.applyOriginalHipRotation;
|
||||
IKSystem.Instance.applyOriginalHipRotation = true;
|
||||
|
||||
PlayerSetup.Instance.animatorManager.CancelEmote = true;
|
||||
m_ragdolledParameter.SetValue(true);
|
||||
|
||||
if(!WorldHandler.IsSafeWorld())
|
||||
{
|
||||
m_reachedGround = false; // Force player to unragdoll and reach ground first
|
||||
m_groundedTime = 0f;
|
||||
}
|
||||
|
||||
foreach(RagdollBodypartHandler l_handler in m_ragdollBodyHandlers)
|
||||
l_handler.SetAsKinematic(false);
|
||||
|
||||
m_puppetRoot.gameObject.SetActive(false); //
|
||||
m_puppetRoot.gameObject.SetActive(true); // Resets rigidbodies and joints inner physics states
|
||||
|
||||
Vector3 l_velocity = Vector3.ClampMagnitude(m_velocity * (WorldHandler.IsSafeWorld() ? Settings.VelocityMultiplier : 1f), WorldHandler.GetMovementLimit());
|
||||
if(Settings.ViewVelocity && WorldHandler.IsSafeWorld())
|
||||
{
|
||||
float l_mag = l_velocity.magnitude;
|
||||
l_velocity = PlayerSetup.Instance.GetActiveCamera().transform.forward * l_mag;
|
||||
}
|
||||
|
||||
foreach(RagdollBodypartHandler l_handler in m_ragdollBodyHandlers)
|
||||
{
|
||||
l_handler.SetVelocity(l_velocity);
|
||||
l_handler.SetAngularVelocity(Vector3.zero);
|
||||
}
|
||||
|
||||
m_ragdollLastPos = m_puppetReferences.hips.position;
|
||||
m_downTime = 0f;
|
||||
|
||||
m_enabled = true;
|
||||
}
|
||||
float l_mag = l_velocity.magnitude;
|
||||
l_velocity = PlayerSetup.Instance.GetActiveCamera().transform.forward * l_mag;
|
||||
}
|
||||
else
|
||||
|
||||
if(BetterBetterCharacterController.Instance.IsFlying())
|
||||
BetterBetterCharacterController.Instance.ChangeFlight(false, true);
|
||||
BetterBetterCharacterController.Instance.SetImmobilized(true);
|
||||
BetterBetterCharacterController.Instance.ClearFluidVolumes();
|
||||
BetterBetterCharacterController.Instance.ResetAllForces();
|
||||
BetterBetterCharacterController.Instance.PauseGroundConstraint();
|
||||
BodySystem.TrackingPositionWeight = 0f;
|
||||
m_applyHipsPosition = IKSystem.Instance.applyOriginalHipPosition;
|
||||
IKSystem.Instance.applyOriginalHipPosition = true;
|
||||
m_applyHipsRotation = IKSystem.Instance.applyOriginalHipRotation;
|
||||
IKSystem.Instance.applyOriginalHipRotation = true;
|
||||
|
||||
PlayerSetup.Instance.animatorManager.CancelEmote = true;
|
||||
m_ragdolledParameter.SetValue(true);
|
||||
|
||||
if(!WorldManager.IsSafeWorld())
|
||||
{
|
||||
if(CanUnragdoll())
|
||||
{
|
||||
BetterBetterCharacterController.Instance.TeleportPlayerTo(m_puppetReferences.hips.position, PlayerSetup.Instance.GetPlayerRotation().eulerAngles, false, false);
|
||||
TryRestoreMovement();
|
||||
if(!WorldHandler.IsSafeWorld())
|
||||
{
|
||||
Vector3 l_vec = BetterBetterCharacterController.Instance.GetVelocity();
|
||||
l_vec.y = Mathf.Clamp(l_vec.y, float.MinValue, 0f);
|
||||
BetterBetterCharacterController.Instance.SetVelocity(l_vec);
|
||||
}
|
||||
BodySystem.TrackingPositionWeight = 1f;
|
||||
IKSystem.Instance.applyOriginalHipPosition = m_applyHipsPosition;
|
||||
IKSystem.Instance.applyOriginalHipRotation = m_applyHipsRotation;
|
||||
|
||||
if(m_vrIK != null)
|
||||
m_vrIK.solver.Reset();
|
||||
|
||||
m_ragdolledParameter.SetValue(false);
|
||||
|
||||
m_puppetRoot.localPosition = Vector3.zero;
|
||||
m_puppetRoot.localRotation = Quaternion.identity;
|
||||
|
||||
foreach(RagdollBodypartHandler l_handler in m_ragdollBodyHandlers)
|
||||
{
|
||||
l_handler.Detach();
|
||||
l_handler.ClearFluidVolumes();
|
||||
l_handler.SetAsKinematic(true);
|
||||
}
|
||||
|
||||
m_lastPosition = PlayerSetup.Instance.transform.position;
|
||||
m_velocity = Vector3.zero;
|
||||
m_downTime = float.MinValue;
|
||||
|
||||
// Restore rigidbody properties that could be affected by buoyancy
|
||||
OnMovementDragChanged(Settings.MovementDrag);
|
||||
OnAngularDragChanged(Settings.AngularDrag);
|
||||
|
||||
// Restore movement if was ragdolled in water and left it
|
||||
if(m_wasSwimming)
|
||||
BetterBetterCharacterController.Instance.SetMovementMode(ECM2.Character.MovementMode.Swimming);
|
||||
|
||||
m_enabled = false;
|
||||
}
|
||||
m_reachedGround = false; // Force player to unragdoll and reach ground first
|
||||
m_groundedTime = 0f;
|
||||
}
|
||||
|
||||
foreach(RagdollBodypartHandler l_handler in m_ragdollBodyHandlers)
|
||||
l_handler.SetAsKinematic(false);
|
||||
|
||||
m_puppet.gameObject.SetActive(false); //
|
||||
m_puppet.gameObject.SetActive(true); // Resets rigidbodies and joints inner physics states
|
||||
|
||||
foreach(RagdollBodypartHandler l_handler in m_ragdollBodyHandlers)
|
||||
{
|
||||
l_handler.SetVelocity(l_velocity);
|
||||
l_handler.SetAngularVelocity(Vector3.zero);
|
||||
}
|
||||
|
||||
m_ragdollLastPos = m_puppetReferences.hips.position;
|
||||
m_downTime = 0f;
|
||||
|
||||
m_ragdolled = true;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsRagdolled() => (m_avatarReady && m_enabled);
|
||||
|
||||
void ResetStates(bool p_resetVelocity = true)
|
||||
public void Unragdoll()
|
||||
{
|
||||
if(p_resetVelocity)
|
||||
if(m_avatarReady && m_ragdolled && CanUnragdoll())
|
||||
{
|
||||
m_lastPosition = this.transform.position;
|
||||
m_velocity = Vector3.zero;
|
||||
}
|
||||
BetterBetterCharacterController.Instance.TeleportPlayerTo(m_puppetReferences.hips.position, PlayerSetup.Instance.GetPlayerRotation().eulerAngles, false, false);
|
||||
TryRestoreMovement();
|
||||
if(!WorldManager.IsSafeWorld())
|
||||
{
|
||||
Vector3 l_vec = BetterBetterCharacterController.Instance.GetVelocity();
|
||||
l_vec.y = Mathf.Clamp(l_vec.y, float.MinValue, 0f);
|
||||
BetterBetterCharacterController.Instance.SetVelocity(l_vec);
|
||||
}
|
||||
BodySystem.TrackingPositionWeight = 1f;
|
||||
IKSystem.Instance.applyOriginalHipPosition = m_applyHipsPosition;
|
||||
IKSystem.Instance.applyOriginalHipRotation = m_applyHipsRotation;
|
||||
|
||||
m_inAir = false;
|
||||
if(m_vrIK != null)
|
||||
m_vrIK.solver.Reset();
|
||||
|
||||
m_ragdolledParameter.SetValue(false);
|
||||
|
||||
m_puppet.localPosition = Vector3.zero;
|
||||
m_puppet.localRotation = Quaternion.identity;
|
||||
|
||||
foreach(RagdollBodypartHandler l_handler in m_ragdollBodyHandlers)
|
||||
{
|
||||
l_handler.Detach();
|
||||
l_handler.ClearFluidVolumes();
|
||||
l_handler.SetAsKinematic(true);
|
||||
}
|
||||
|
||||
m_downTime = float.MinValue;
|
||||
|
||||
// Restore rigidbody properties that could be affected by buoyancy
|
||||
OnMovementDragChanged(Settings.MovementDrag);
|
||||
OnAngularDragChanged(Settings.AngularDrag);
|
||||
|
||||
m_ragdolled = false;
|
||||
}
|
||||
}
|
||||
|
||||
static Transform CloneTransform(Transform p_source, Transform p_parent, string p_name)
|
||||
|
@ -739,7 +720,7 @@ namespace ml_prm
|
|||
|
||||
bool CanRagdoll()
|
||||
{
|
||||
if(WorldHandler.IsRestrictedWorld())
|
||||
if(WorldManager.IsRestrictedWorld())
|
||||
return false;
|
||||
|
||||
bool l_result = m_reachedGround;
|
||||
|
|
|
@ -1,48 +0,0 @@
|
|||
using ABI_RC.Core.Networking.IO.Social;
|
||||
using ABI_RC.Core.Player;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ml_prm
|
||||
{
|
||||
class RemoteGestureHandler : MonoBehaviour
|
||||
{
|
||||
internal class GestureEvent<T1, T2, T3>
|
||||
{
|
||||
event Action<T1, T2, T3> m_action;
|
||||
public void AddListener(Action<T1, T2, T3> p_listener) => m_action += p_listener;
|
||||
public void RemoveListener(Action<T1, T2, T3> p_listener) => m_action -= p_listener;
|
||||
public void Invoke(T1 p_objA, T2 p_objB, T3 p_objC) => m_action?.Invoke(p_objA, p_objB, p_objC);
|
||||
}
|
||||
|
||||
public static readonly GestureEvent<PuppetMaster, bool, bool> OnGestureState = new GestureEvent<PuppetMaster, bool, bool>();
|
||||
|
||||
PuppetMaster m_puppetMaster = null;
|
||||
bool m_stateLeft = false;
|
||||
bool m_stateRight = false;
|
||||
|
||||
void Start()
|
||||
{
|
||||
m_puppetMaster = this.GetComponent<PuppetMaster>();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
bool l_state = m_puppetMaster.IsLeftGrabPointerActive();
|
||||
if(m_stateLeft != l_state)
|
||||
{
|
||||
m_stateLeft = l_state;
|
||||
if(!Settings.FriendsGrab || Friends.FriendsWith(m_puppetMaster.CVRPlayerEntity.PlayerDescriptor.ownerId))
|
||||
OnGestureState.Invoke(m_puppetMaster, true, m_stateLeft);
|
||||
}
|
||||
|
||||
l_state = m_puppetMaster.IsRightGrabPointerActive();
|
||||
if(m_stateRight != l_state)
|
||||
{
|
||||
m_stateRight = l_state;
|
||||
if(!Settings.FriendsGrab || Friends.FriendsWith(m_puppetMaster.CVRPlayerEntity.PlayerDescriptor.ownerId))
|
||||
OnGestureState.Invoke(m_puppetMaster, false, m_stateRight);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,79 +0,0 @@
|
|||
using ABI_RC.Core.Player;
|
||||
using ABI_RC.Systems.GameEventSystem;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ml_prm
|
||||
{
|
||||
static class RemoteGestureManager
|
||||
{
|
||||
static readonly Dictionary<CVRPlayerEntity, RemoteGestureHandler> ms_remoteHandlers = new Dictionary<CVRPlayerEntity, RemoteGestureHandler>();
|
||||
|
||||
internal static void Init()
|
||||
{
|
||||
CVRGameEventSystem.Player.OnJoinEntity.AddListener(OnRemotePlayerCreated);
|
||||
CVRGameEventSystem.Player.OnLeaveEntity.AddListener(OnRemotePlayerDestroyed);
|
||||
Settings.OnGestureGrabChanged.AddListener(OnGestureGrabChanged);
|
||||
}
|
||||
|
||||
internal static void DeInit()
|
||||
{
|
||||
CVRGameEventSystem.Player.OnJoinEntity.RemoveListener(OnRemotePlayerCreated);
|
||||
CVRGameEventSystem.Player.OnLeaveEntity.RemoveListener(OnRemotePlayerDestroyed);
|
||||
Settings.OnGestureGrabChanged.RemoveListener(OnGestureGrabChanged);
|
||||
}
|
||||
|
||||
static void OnRemotePlayerCreated(CVRPlayerEntity p_player)
|
||||
{
|
||||
try
|
||||
{
|
||||
if(Settings.GestureGrab && (p_player != null) && (p_player.PuppetMaster != null))
|
||||
{
|
||||
RemoteGestureHandler l_handler = p_player.PuppetMaster.gameObject.AddComponent<RemoteGestureHandler>();
|
||||
ms_remoteHandlers.Add(p_player, l_handler);
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
MelonLoader.MelonLogger.Error(e);
|
||||
}
|
||||
}
|
||||
|
||||
static void OnRemotePlayerDestroyed(CVRPlayerEntity p_player)
|
||||
{
|
||||
try
|
||||
{
|
||||
if(p_player != null)
|
||||
ms_remoteHandlers.Remove(p_player);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
MelonLoader.MelonLogger.Error(e);
|
||||
}
|
||||
}
|
||||
|
||||
static void OnGestureGrabChanged(bool p_state)
|
||||
{
|
||||
if(p_state)
|
||||
{
|
||||
foreach(var l_player in CVRPlayerManager.Instance.NetworkPlayers)
|
||||
{
|
||||
if(!ms_remoteHandlers.ContainsKey(l_player) && (l_player.PuppetMaster != null))
|
||||
{
|
||||
RemoteGestureHandler l_handler = l_player.PuppetMaster.gameObject.AddComponent<RemoteGestureHandler>();
|
||||
ms_remoteHandlers.Add(l_player, l_handler);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach(var l_pair in ms_remoteHandlers)
|
||||
{
|
||||
if(l_pair.Value != null)
|
||||
UnityEngine.Object.Destroy(l_pair.Value);
|
||||
}
|
||||
ms_remoteHandlers.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
132
ml_prm/RemoteGesturesManager.cs
Normal file
132
ml_prm/RemoteGesturesManager.cs
Normal file
|
@ -0,0 +1,132 @@
|
|||
using ABI_RC.Core.Networking.IO.Social;
|
||||
using ABI_RC.Core.Player;
|
||||
using ABI_RC.Systems.GameEventSystem;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ml_prm
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
class RemoteGesturesManager : MonoBehaviour
|
||||
{
|
||||
public enum GestureHand
|
||||
{
|
||||
Left = 0,
|
||||
Right
|
||||
}
|
||||
internal class GestureEvent<T1, T2, T3>
|
||||
{
|
||||
event Action<T1, T2, T3> m_action;
|
||||
public void AddListener(Action<T1, T2, T3> p_listener) => m_action += p_listener;
|
||||
public void RemoveListener(Action<T1, T2, T3> p_listener) => m_action -= p_listener;
|
||||
public void Invoke(T1 p_objA, T2 p_objB, T3 p_objC) => m_action?.Invoke(p_objA, p_objB, p_objC);
|
||||
}
|
||||
public static readonly GestureEvent<PuppetMaster, GestureHand, bool> OnGestureState = new GestureEvent<PuppetMaster, GestureHand, bool>();
|
||||
|
||||
class PlayerEntry
|
||||
{
|
||||
public CVRPlayerEntity m_entity = null;
|
||||
public PuppetMaster m_puppetMaster = null;
|
||||
public bool m_stateLeft = false;
|
||||
public bool m_stateRight = false;
|
||||
}
|
||||
|
||||
readonly List<PlayerEntry> m_entries = null;
|
||||
|
||||
internal RemoteGesturesManager()
|
||||
{
|
||||
m_entries = new List<PlayerEntry>();
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
DontDestroyOnLoad(this);
|
||||
|
||||
CVRGameEventSystem.Player.OnJoinEntity.AddListener(OnRemotePlayerCreated);
|
||||
CVRGameEventSystem.Player.OnLeaveEntity.AddListener(OnRemotePlayerDestroyed);
|
||||
Settings.OnGestureGrabChanged.AddListener(OnGestureGrabChanged);
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
m_entries.Clear();
|
||||
|
||||
CVRGameEventSystem.Player.OnJoinEntity.RemoveListener(OnRemotePlayerCreated);
|
||||
CVRGameEventSystem.Player.OnLeaveEntity.RemoveListener(OnRemotePlayerDestroyed);
|
||||
Settings.OnGestureGrabChanged.RemoveListener(OnGestureGrabChanged);
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if(Settings.GestureGrab)
|
||||
{
|
||||
foreach(var l_entry in m_entries)
|
||||
{
|
||||
bool l_state = l_entry.m_puppetMaster.IsLeftGrabPointerActive();
|
||||
if(l_entry.m_stateLeft != l_state)
|
||||
{
|
||||
l_entry.m_stateLeft = l_state;
|
||||
if(!Settings.FriendsGrab || Friends.FriendsWith(l_entry.m_entity.PlayerDescriptor.ownerId))
|
||||
OnGestureState.Invoke(l_entry.m_puppetMaster, GestureHand.Left, l_entry.m_stateLeft);
|
||||
}
|
||||
|
||||
l_state = l_entry.m_puppetMaster.IsRightGrabPointerActive();
|
||||
if(l_entry.m_stateRight != l_state)
|
||||
{
|
||||
l_entry.m_stateRight = l_state;
|
||||
if(!Settings.FriendsGrab || Friends.FriendsWith(l_entry.m_entity.PlayerDescriptor.ownerId))
|
||||
OnGestureState.Invoke(l_entry.m_puppetMaster, GestureHand.Right, l_entry.m_stateRight);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnRemotePlayerCreated(CVRPlayerEntity p_player)
|
||||
{
|
||||
try
|
||||
{
|
||||
if((p_player != null) && (p_player.PuppetMaster != null))
|
||||
{
|
||||
PlayerEntry l_entry = new PlayerEntry()
|
||||
{
|
||||
m_entity = p_player,
|
||||
m_puppetMaster = p_player.PuppetMaster,
|
||||
m_stateLeft = false,
|
||||
m_stateRight = false
|
||||
};
|
||||
m_entries.Add(l_entry);
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
MelonLoader.MelonLogger.Error(e);
|
||||
}
|
||||
}
|
||||
|
||||
void OnRemotePlayerDestroyed(CVRPlayerEntity p_player)
|
||||
{
|
||||
try
|
||||
{
|
||||
if(p_player != null)
|
||||
m_entries.RemoveAll(e => ReferenceEquals(e.m_puppetMaster, p_player.PuppetMaster));
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
MelonLoader.MelonLogger.Error(e);
|
||||
}
|
||||
}
|
||||
|
||||
void OnGestureGrabChanged(bool p_state)
|
||||
{
|
||||
if(!p_state)
|
||||
{
|
||||
foreach(var l_entry in m_entries)
|
||||
{
|
||||
l_entry.m_stateLeft = false;
|
||||
l_entry.m_stateRight = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,44 +1,44 @@
|
|||
using ABI.CCK.Components;
|
||||
using ABI_RC.Systems.GameEventSystem;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ml_prm
|
||||
{
|
||||
static class WorldHandler
|
||||
{
|
||||
static bool ms_safeWorld = true;
|
||||
static bool ms_restrictedWorld = false;
|
||||
static float ms_movementLimit = 1f;
|
||||
|
||||
internal static void Init()
|
||||
{
|
||||
CVRGameEventSystem.World.OnLoad.AddListener(OnWorldLoad);
|
||||
}
|
||||
|
||||
internal static void DeInit()
|
||||
{
|
||||
CVRGameEventSystem.World.OnLoad.RemoveListener(OnWorldLoad);
|
||||
}
|
||||
|
||||
static void OnWorldLoad(string p_id)
|
||||
{
|
||||
ms_safeWorld = ((CVRWorld.Instance != null) && CVRWorld.Instance.allowFlying);
|
||||
ms_movementLimit = 1f;
|
||||
|
||||
GameObject l_restrictObj = GameObject.Find("[RagdollRestriction]");
|
||||
ms_restrictedWorld = ((l_restrictObj == null) ? false : (l_restrictObj.scene.name != "DontDestroyOnLoad"));
|
||||
|
||||
if(CVRWorld.Instance != null)
|
||||
{
|
||||
ms_movementLimit = CVRWorld.Instance.baseMovementSpeed;
|
||||
ms_movementLimit *= CVRWorld.Instance.sprintMultiplier;
|
||||
ms_movementLimit *= CVRWorld.Instance.inAirMovementMultiplier;
|
||||
ms_movementLimit *= CVRWorld.Instance.flyMultiplier;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsSafeWorld() => ms_safeWorld;
|
||||
public static bool IsRestrictedWorld() => ms_restrictedWorld;
|
||||
public static float GetMovementLimit() => ms_movementLimit;
|
||||
}
|
||||
}
|
||||
using ABI.CCK.Components;
|
||||
using ABI_RC.Systems.GameEventSystem;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ml_prm
|
||||
{
|
||||
static class WorldManager
|
||||
{
|
||||
static bool ms_safeWorld = true;
|
||||
static bool ms_restrictedWorld = false;
|
||||
static float ms_movementLimit = 1f;
|
||||
|
||||
internal static void Init()
|
||||
{
|
||||
CVRGameEventSystem.World.OnLoad.AddListener(OnWorldLoad);
|
||||
}
|
||||
|
||||
internal static void DeInit()
|
||||
{
|
||||
CVRGameEventSystem.World.OnLoad.RemoveListener(OnWorldLoad);
|
||||
}
|
||||
|
||||
static void OnWorldLoad(string p_id)
|
||||
{
|
||||
ms_safeWorld = ((CVRWorld.Instance != null) && CVRWorld.Instance.allowFlying);
|
||||
ms_movementLimit = 1f;
|
||||
|
||||
GameObject l_restrictObj = GameObject.Find("[RagdollRestriction]");
|
||||
ms_restrictedWorld = ((l_restrictObj == null) ? false : (l_restrictObj.scene.name != "DontDestroyOnLoad"));
|
||||
|
||||
if(CVRWorld.Instance != null)
|
||||
{
|
||||
ms_movementLimit = CVRWorld.Instance.baseMovementSpeed;
|
||||
ms_movementLimit *= CVRWorld.Instance.sprintMultiplier;
|
||||
ms_movementLimit *= CVRWorld.Instance.inAirMovementMultiplier;
|
||||
ms_movementLimit *= CVRWorld.Instance.flyMultiplier;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsSafeWorld() => ms_safeWorld;
|
||||
public static bool IsRestrictedWorld() => ms_restrictedWorld;
|
||||
public static float GetMovementLimit() => ms_movementLimit;
|
||||
}
|
||||
}
|
|
@ -4,10 +4,11 @@
|
|||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
<Platforms>x64</Platforms>
|
||||
<PackageId>PlayerRagdollMod</PackageId>
|
||||
<Version>1.1.9</Version>
|
||||
<Version>1.2.0</Version>
|
||||
<Authors>SDraw</Authors>
|
||||
<Company>None</Company>
|
||||
<Company>SDraw</Company>
|
||||
<Product>PlayerRagdollMod</Product>
|
||||
<AssemblyName>PlayerRagdollMod</AssemblyName>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue