mirror of
https://github.com/hanetzer/sdraw_mods_cvr.git
synced 2025-09-03 18:39:23 +00:00
Mode switch handling, attempt two
This commit is contained in:
parent
66b448a2c3
commit
84b0de7065
13 changed files with 256 additions and 288 deletions
|
@ -36,7 +36,7 @@ namespace ml_pmc
|
|||
);
|
||||
HarmonyInstance.Patch(
|
||||
typeof(IKSystem).GetMethod(nameof(IKSystem.ReinitializeAvatar), BindingFlags.Instance | BindingFlags.Public),
|
||||
null,
|
||||
new HarmonyLib.HarmonyMethod(typeof(PlayerMovementCopycat).GetMethod(nameof(OnAvatarReinitialize_Prefix), BindingFlags.Static | BindingFlags.NonPublic)),
|
||||
new HarmonyLib.HarmonyMethod(typeof(PlayerMovementCopycat).GetMethod(nameof(OnAvatarReinitialize_Postfix), BindingFlags.Static | BindingFlags.NonPublic))
|
||||
);
|
||||
|
||||
|
@ -140,13 +140,27 @@ namespace ml_pmc
|
|||
}
|
||||
}
|
||||
|
||||
static void OnAvatarReinitialize_Postfix() => ms_instance?.OnAvatarReinitialize();
|
||||
void OnAvatarReinitialize()
|
||||
static void OnAvatarReinitialize_Prefix() => ms_instance?.OnPreAvatarReinitialize();
|
||||
void OnPreAvatarReinitialize()
|
||||
{
|
||||
try
|
||||
{
|
||||
if(m_localCopycat != null)
|
||||
m_localCopycat.OnAvatarReinitialize();
|
||||
m_localCopycat.OnPreAvatarReinitialize();
|
||||
}
|
||||
catch(System.Exception e)
|
||||
{
|
||||
MelonLoader.MelonLogger.Error(e);
|
||||
}
|
||||
}
|
||||
|
||||
static void OnAvatarReinitialize_Postfix() => ms_instance?.OnPostAvatarReinitialize();
|
||||
void OnPostAvatarReinitialize()
|
||||
{
|
||||
try
|
||||
{
|
||||
if(m_localCopycat != null)
|
||||
m_localCopycat.OnPostAvatarReinitialize();
|
||||
}
|
||||
catch(System.Exception e)
|
||||
{
|
||||
|
|
|
@ -37,9 +37,6 @@ namespace ml_pmc
|
|||
{
|
||||
if(Instance == null)
|
||||
Instance = this;
|
||||
|
||||
VRModeSwitchEvents.OnInitializeXR.AddListener(this.OnSwitchToVR);
|
||||
VRModeSwitchEvents.OnDeinitializeXR.AddListener(this.OnSwitchToDesktop);
|
||||
}
|
||||
void OnDestroy()
|
||||
{
|
||||
|
@ -56,9 +53,6 @@ namespace ml_pmc
|
|||
m_animator = null;
|
||||
m_vrIk = null;
|
||||
m_lookAtIk = null;
|
||||
|
||||
VRModeSwitchEvents.OnInitializeXR.RemoveListener(this.OnSwitchToVR);
|
||||
VRModeSwitchEvents.OnDeinitializeXR.RemoveListener(this.OnSwitchToDesktop);
|
||||
}
|
||||
|
||||
// Unity events
|
||||
|
@ -201,6 +195,7 @@ namespace ml_pmc
|
|||
}
|
||||
internal void OnAvatarSetup()
|
||||
{
|
||||
m_inVr = Utils.IsInVR();
|
||||
m_animator = PlayerSetup.Instance._animator;
|
||||
m_vrIk = PlayerSetup.Instance._avatar.GetComponent<VRIK>();
|
||||
m_lookAtIk = PlayerSetup.Instance._avatar.GetComponent<LookAtIK>();
|
||||
|
@ -225,8 +220,16 @@ namespace ml_pmc
|
|||
else
|
||||
m_animator = null;
|
||||
}
|
||||
internal void OnAvatarReinitialize()
|
||||
|
||||
internal void OnPreAvatarReinitialize()
|
||||
{
|
||||
if(m_active)
|
||||
SetTarget(null);
|
||||
}
|
||||
internal void OnPostAvatarReinitialize()
|
||||
{
|
||||
m_inVr = Utils.IsInVR();
|
||||
|
||||
// Old VRIK and LookAtIK are destroyed by game
|
||||
m_vrIk = PlayerSetup.Instance._avatar.GetComponent<VRIK>();
|
||||
m_lookAtIk = PlayerSetup.Instance._avatar.GetComponent<LookAtIK>();
|
||||
|
@ -244,15 +247,6 @@ namespace ml_pmc
|
|||
}
|
||||
}
|
||||
|
||||
void OnSwitchToVR()
|
||||
{
|
||||
m_inVr = true;
|
||||
}
|
||||
void OnSwitchToDesktop()
|
||||
{
|
||||
m_inVr = false;
|
||||
}
|
||||
|
||||
// IK updates
|
||||
void OnVRIKPreUpdate()
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue