Better avatar setup detection

This commit is contained in:
SDraw 2022-09-02 21:25:40 +03:00
parent 2f9a46e471
commit 0794564563
No known key found for this signature in database
GPG key ID: BB95B4DAB2BB8BB5
5 changed files with 38 additions and 50 deletions

View file

@ -1,7 +1,6 @@
using ABI_RC.Core.Player;
using ABI_RC.Core.Savior;
using RootMotion.FinalIK;
using System.Linq;
using UnityEngine;
namespace ml_lme
@ -19,15 +18,9 @@ namespace ml_lme
Transform m_leftHand = null;
Transform m_rightHand = null;
bool m_knucklesInUse = false;
void Start()
{
m_indexIK = this.GetComponent<IndexIK>();
m_knucklesInUse = PlayerSetup.Instance._trackerManager.trackerNames.Contains("knuckles");
if(PlayerSetup.Instance._inVr)
PlayerSetup.Instance.avatarSetupCompleted.AddListener(this.OnAvatarSetup);
}
public void SetEnabled(bool p_state)
@ -36,8 +29,8 @@ namespace ml_lme
if(m_indexIK != null)
{
m_indexIK.activeControl = (m_enabled || m_knucklesInUse);
CVRInputManager.Instance.individualFingerTracking = (m_enabled || m_knucklesInUse);
m_indexIK.activeControl = (m_enabled || Utils.AreKnucklesInUse());
CVRInputManager.Instance.individualFingerTracking = (m_enabled || Utils.AreKnucklesInUse());
}
if(m_leapIK != null)
@ -56,6 +49,9 @@ namespace ml_lme
{
m_leftHand = p_left;
m_rightHand = p_right;
if(m_leapIK != null)
m_leapIK.SetHands(m_leftHand, m_rightHand);
}
public void UpdateTracking(GestureMatcher.GesturesData p_gesturesData)
@ -145,13 +141,13 @@ namespace ml_lme
m_vrIK = null;
}
public void OnAvatarSetup()
public void OnSetupAvatarGeneral()
{
m_knucklesInUse = PlayerSetup.Instance._trackerManager.trackerNames.Contains("knuckles");
if(m_indexIK != null)
m_indexIK.activeControl = (m_enabled || m_knucklesInUse);
CVRInputManager.Instance.individualFingerTracking = (m_enabled || m_knucklesInUse);
m_indexIK.activeControl = (m_enabled || Utils.AreKnucklesInUse());
CVRInputManager.Instance.individualFingerTracking = (m_enabled || Utils.AreKnucklesInUse());
m_vrIK = PlayerSetup.Instance._animator.GetComponent<VRIK>();
if(!PlayerSetup.Instance._inVr)
{
@ -160,8 +156,6 @@ namespace ml_lme
m_leapIK.SetFingersOnly(m_fingersOnly);
m_leapIK.SetHands(m_leftHand, m_rightHand);
}
else
m_vrIK = PlayerSetup.Instance._animator.GetComponent<VRIK>();
}
}
}

View file

@ -50,11 +50,6 @@ namespace ml_lme
m_leapHands = new GameObject[GestureMatcher.GesturesData.ms_handsCount];
// Patches
HarmonyInstance.Patch(
typeof(PlayerSetup).GetMethod(nameof(PlayerSetup.SetupAvatar)),
null,
new HarmonyLib.HarmonyMethod(typeof(LeapMotionExtension).GetMethod(nameof(OnAvatarSetup_Postfix), System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic))
);
HarmonyInstance.Patch(
typeof(PlayerSetup).GetMethod(nameof(PlayerSetup.ClearAvatar)),
null,
@ -66,6 +61,7 @@ namespace ml_lme
new HarmonyLib.HarmonyMethod(typeof(LeapMotionExtension).GetMethod(nameof(OnSetupAvatarGeneral_Postfix), System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic))
);
MelonLoader.MelonCoroutines.Start(CreateTrackingObjects());
}
@ -334,15 +330,6 @@ namespace ml_lme
m_leapTracked.OnAvatarClear();
}
static void OnAvatarSetup_Postfix() => ms_instance?.OnAvatarSetup();
void OnAvatarSetup()
{
if(!PlayerSetup.Instance._inVr && (m_leapTracked != null))
m_leapTracked.OnAvatarSetup();
OnSettingsHeadAttachChange(Settings.HeadAttach);
}
// Sneaky forced IndexIK calibration
static void OnSetupAvatarGeneral_Prefix(ref PlayerSetup __instance)
{
@ -353,6 +340,15 @@ namespace ml_lme
{
if(__instance != null)
__instance._inVr = ms_vrState;
ms_instance?.OnSetupAvatarGeneral();
}
void OnSetupAvatarGeneral()
{
if(m_leapTracked != null)
m_leapTracked.OnSetupAvatarGeneral();
OnSettingsHeadAttachChange(Settings.HeadAttach);
}
// Utilities

View file

@ -1,7 +1,12 @@
namespace ml_lme
using ABI_RC.Core.Player;
using System.Linq;
namespace ml_lme
{
static class Utils
{
public static bool AreKnucklesInUse() => PlayerSetup.Instance._trackerManager.trackerNames.Contains("knuckles");
public static void Swap<T>(ref T lhs, ref T rhs)
{
T temp = lhs;