Rays layer fix

Desktop tracking scale fix
More notifications
This commit is contained in:
SDraw 2023-01-29 19:55:22 +03:00
parent fbad3fdf8e
commit 6bc448d41d
No known key found for this signature in database
GPG key ID: BB95B4DAB2BB8BB5
8 changed files with 118 additions and 45 deletions

View file

@ -31,7 +31,7 @@ namespace ml_lme
base.Start();
m_inputManager = CVRInputManager.Instance; // _inputManager is stripped out, cool beans
m_steamVrModule = this.GetComponent<InputModuleSteamVR>();
m_steamVrModule = m_inputManager.GetComponent<InputModuleSteamVR>();
m_inVR = Utils.IsInVR();
m_handRayLeft = LeapTracking.GetInstance().GetLeftHand().gameObject.AddComponent<ControllerRay>();
@ -91,7 +91,9 @@ namespace ml_lme
yield return null;
m_lineLeft.material = PlayerSetup.Instance.leftRay.lineRenderer.material;
m_lineLeft.gameObject.layer = PlayerSetup.Instance.leftRay.gameObject.layer;
m_lineRight.material = PlayerSetup.Instance.leftRay.lineRenderer.material;
m_lineRight.gameObject.layer = PlayerSetup.Instance.leftRay.gameObject.layer;
}
void OnDestroy()

View file

@ -158,6 +158,8 @@ namespace ml_lme
// Game events
internal void OnAvatarClear()
{
if(m_leapTracking != null)
m_leapTracking.OnAvatarClear();
if(m_leapTracked != null)
m_leapTracked.OnAvatarClear();
}
@ -184,6 +186,12 @@ namespace ml_lme
m_leapInput.OnRayScale(p_scale);
}
internal void OnPlayspaceScale(float p_relation)
{
if(m_leapTracking != null)
m_leapTracking.OnPlayspaceScale(p_relation);
}
// Arbitrary
void UpdateDeviceTrackingMode()
{

View file

@ -18,6 +18,8 @@ namespace ml_lme
GameObject m_leapElbowRight = null;
GameObject m_leapControllerModel = null;
float m_scaleRelation = 1f;
public static LeapTracking GetInstance() => ms_instance;
void Start()
@ -75,9 +77,7 @@ namespace ml_lme
while(PlayerSetup.Instance == null)
yield return null;
OnDesktopOffsetChange(Settings.DesktopOffset);
OnHeadAttachChange(Settings.HeadAttach);
OnHeadOffsetChange(Settings.HeadOffset);
}
void OnDestroy()
@ -130,12 +130,7 @@ namespace ml_lme
void OnDesktopOffsetChange(Vector3 p_offset)
{
if(!Settings.HeadAttach)
{
if(!m_inVR)
this.transform.localPosition = p_offset * PlayerSetup.Instance.vrCameraRig.transform.localScale.x;
else
this.transform.localPosition = p_offset;
}
this.transform.localPosition = p_offset * (!m_inVR ? m_scaleRelation : 1f);
}
void OnModelVisibilityChange(bool p_state)
@ -166,56 +161,44 @@ namespace ml_lme
void OnHeadAttachChange(bool p_state)
{
if(p_state)
if(!m_inVR)
{
if(!m_inVR)
{
this.transform.parent = PlayerSetup.Instance.desktopCamera.transform;
this.transform.localPosition = Settings.HeadOffset * PlayerSetup.Instance.vrCameraRig.transform.localScale.x;
this.transform.localScale = PlayerSetup.Instance.vrCameraRig.transform.localScale;
}
else
{
this.transform.parent = PlayerSetup.Instance.vrCamera.transform;
this.transform.localPosition = Settings.HeadOffset;
this.transform.localScale = Vector3.one;
}
this.transform.parent = (p_state ? PlayerSetup.Instance.desktopCamera.transform : PlayerSetup.Instance.desktopCameraRig.transform);
this.transform.localPosition = (p_state ? Settings.HeadOffset : Settings.DesktopOffset) * m_scaleRelation;
}
else
{
if(!m_inVR)
{
this.transform.parent = PlayerSetup.Instance.desktopCameraRig.transform;
this.transform.localPosition = Settings.DesktopOffset * PlayerSetup.Instance.vrCameraRig.transform.localScale.x;
this.transform.localScale = PlayerSetup.Instance.vrCameraRig.transform.localScale;
}
else
{
this.transform.parent = PlayerSetup.Instance.vrCameraRig.transform;
this.transform.localPosition = Settings.DesktopOffset;
this.transform.localScale = Vector3.one;
}
this.transform.parent = (p_state ? PlayerSetup.Instance.vrCamera.transform : PlayerSetup.Instance.vrCameraRig.transform);
this.transform.localPosition = (p_state ? Settings.HeadOffset : Settings.DesktopOffset);
}
this.transform.localScale = Vector3.one * (!m_inVR ? m_scaleRelation : 1f);
this.transform.localRotation = Quaternion.Euler(Settings.RootAngle);
}
void OnHeadOffsetChange(Vector3 p_offset)
{
if(Settings.HeadAttach)
{
if(!m_inVR)
this.transform.localPosition = p_offset * PlayerSetup.Instance.vrCameraRig.transform.localScale.x;
else
this.transform.localPosition = p_offset;
}
this.transform.localPosition = p_offset * (!m_inVR ? m_scaleRelation : 1f);
}
// Game events
internal void OnAvatarClear()
{
m_scaleRelation = 1f;
OnHeadAttachChange(Settings.HeadAttach);
}
internal void OnAvatarSetup()
{
m_inVR = Utils.IsInVR();
OnHeadAttachChange(Settings.HeadAttach);
}
internal void OnPlayspaceScale(float p_relation)
{
m_scaleRelation = p_relation;
OnHeadAttachChange(Settings.HeadAttach);
}
}
}

View file

@ -43,6 +43,11 @@ namespace ml_lme
null,
new HarmonyLib.HarmonyMethod(typeof(LeapMotionExtension).GetMethod(nameof(OnRayScale_Postfix), BindingFlags.Static | BindingFlags.NonPublic))
);
HarmonyInstance.Patch(
typeof(PlayerSetup).GetMethod("SetPlaySpaceScale", BindingFlags.NonPublic | BindingFlags.Instance),
null,
new HarmonyLib.HarmonyMethod(typeof(LeapMotionExtension).GetMethod(nameof(OnPlayspaceScale_Postfix), BindingFlags.Static | BindingFlags.NonPublic))
);
MelonLoader.MelonCoroutines.Start(WaitForRootLogic());
}
@ -117,5 +122,19 @@ namespace ml_lme
MelonLoader.MelonLogger.Error(e);
}
}
static void OnPlayspaceScale_Postfix(float ____avatarScaleRelation) => ms_instance?.OnPlayspaceScale(____avatarScaleRelation);
void OnPlayspaceScale(float p_relation)
{
try
{
if(m_leapManager != null)
m_leapManager.OnPlayspaceScale(p_relation);
}
catch(System.Exception e)
{
MelonLoader.MelonLogger.Error(e);
}
}
}
}