Merge pull request #4 from NotAKidOnSteam/prm-avatar-scaling

[PRM] Avatar Scaling Support
This commit is contained in:
SDraw 2023-05-02 08:20:21 +03:00 committed by GitHub
commit 988abd7d53
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 0 deletions

View file

@ -36,6 +36,11 @@ namespace ml_prm
null,
new HarmonyLib.HarmonyMethod(typeof(PlayerRagdollMod).GetMethod(nameof(OnSetupAvatar_Postfix), BindingFlags.Static | BindingFlags.NonPublic))
);
HarmonyInstance.Patch(
typeof(PlayerSetup).GetMethod("SetupIKScaling", BindingFlags.NonPublic | BindingFlags.Instance),
null,
new HarmonyLib.HarmonyMethod(typeof(PlayerRagdollMod).GetMethod(nameof(OnSetupIKScaling_Postfix), BindingFlags.Static | BindingFlags.NonPublic))
);
HarmonyInstance.Patch(
typeof(CVRSeat).GetMethod(nameof(CVRSeat.SitDown)),
new HarmonyLib.HarmonyMethod(typeof(PlayerRagdollMod).GetMethod(nameof(OnCVRSeatSitDown_Prefix), BindingFlags.Static | BindingFlags.NonPublic)),
@ -120,6 +125,20 @@ namespace ml_prm
}
}
static void OnSetupIKScaling_Postfix(ref UnityEngine.Vector3 ___scaleDifference) => ms_instance?.OnSetupIKScaling(___scaleDifference.y);
void OnSetupIKScaling(float scaleDifference)
{
try
{
if (m_localController != null)
m_localController.OnAvatarScaling(1f + scaleDifference);
}
catch (Exception e)
{
MelonLoader.MelonLogger.Error(e);
}
}
static void OnCVRSeatSitDown_Prefix(ref CVRSeat __instance) => ms_instance?.OnCVRSeatSitDown(__instance);
void OnCVRSeatSitDown(CVRSeat p_seat)
{

View file

@ -28,6 +28,7 @@ namespace ml_prm
Transform m_puppet = null;
BipedRagdollReferences m_puppetReferences;
readonly List<System.Tuple<Transform, Transform>> m_boneLinks = null;
readonly List<System.Tuple<CharacterJoint, Vector3>> m_jointAnchors = null;
bool m_avatarReady = false;
Vector3 m_lastPosition = Vector3.zero;
@ -50,6 +51,7 @@ namespace ml_prm
m_rigidBodies = new List<Rigidbody>();
m_colliders = new List<Collider>();
m_boneLinks = new List<System.Tuple<Transform, Transform>>();
m_jointAnchors = new List<System.Tuple<CharacterJoint, Vector3>>();
m_physicsMaterial = new PhysicMaterial("Ragdoll");
m_physicsMaterial.dynamicFriction = 0.5f;
@ -172,8 +174,10 @@ namespace ml_prm
m_colliders.Clear();
m_puppetReferences = new BipedRagdollReferences();
m_boneLinks.Clear();
m_jointAnchors.Clear();
m_reachedGround = true;
m_downTime = float.MinValue;
m_puppetRoot.localScale = Vector3.one;
}
internal void OnAvatarSetup()
@ -244,6 +248,7 @@ namespace ml_prm
{
l_joint.enablePreprocessing = false;
l_joint.enableProjection = true;
m_jointAnchors.Add(System.Tuple.Create(l_joint, l_joint.connectedAnchor));
}
Collider l_collider = l_puppetTransforms[i].GetComponent<Collider>();
@ -282,6 +287,18 @@ namespace ml_prm
}
}
internal void OnAvatarScaling(float scaleDifference)
{
if(m_avatarReady)
{
m_puppetRoot.localScale = Vector3.one * scaleDifference;
for(int i = 0; i < m_jointAnchors.Count; i++)
{
m_jointAnchors[i].Item1.connectedAnchor = m_jointAnchors[i].Item2 * scaleDifference;
}
}
}
internal void OnSeatSitDown(CVRSeat p_seat)
{
if(m_avatarReady && m_enabled && !p_seat.occupied)