Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
SDraw committed Nov 27, 2023
1 parent aebf6c2 commit 914bca2
Show file tree
Hide file tree
Showing 14 changed files with 226 additions and 54 deletions.
2 changes: 2 additions & 0 deletions ml_amt/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public override void OnDeinitializeMelon()
if(ms_instance == this)
ms_instance = null;

if(m_localTweaker != null)
UnityEngine.Object.Destroy(m_localTweaker);
m_localTweaker = null;
}

Expand Down
4 changes: 4 additions & 0 deletions ml_amt/MotionTweaker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ void Start()

void OnDestroy()
{
m_vrIk = null;
m_ikLimits = null;
m_parameters.Clear();

Settings.CrouchLimitChange -= this.SetCrouchLimit;
Settings.ProneLimitChange -= this.SetProneLimit;
Settings.IKOverrideFlyChange -= this.SetIKOverrideFly;
Expand Down
38 changes: 28 additions & 10 deletions ml_lme/LeapInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,6 @@ class LeapInput : CVRInputModule
bool m_gripLeft = false;
bool m_gripRight = false;

~LeapInput()
{
Settings.EnabledChange -= this.OnEnableChange;
Settings.InteractionChange -= this.OnInteractionChange;
Settings.GesturesChange -= this.OnGesturesChange;
Settings.FingersOnlyChange -= this.OnFingersOnlyChange;

MetaPort.Instance.settings.settingBoolChanged.RemoveListener(this.OnGameSettingBoolChange);
}

public override void ModuleAdded()
{
base.ModuleAdded();
Expand Down Expand Up @@ -122,6 +112,34 @@ IEnumerator WaitForMaterial()
m_lineRight.gameObject.layer = PlayerSetup.Instance.vrRayLeft.gameObject.layer;
}

public override void ModuleDestroyed()
{
base.ModuleDestroyed();

if(m_handRayLeft != null)
Object.Destroy(m_handRayLeft);
m_handRayLeft = null;

if(m_handRayRight != null)
Object.Destroy(m_handRayRight);
m_handRayRight = null;

if(m_lineLeft != null)
Object.Destroy(m_lineLeft);
m_lineLeft = null;

if(m_lineRight != null)
Object.Destroy(m_lineRight);
m_lineRight = null;

Settings.EnabledChange -= this.OnEnableChange;
Settings.InteractionChange -= this.OnInteractionChange;
Settings.GesturesChange -= this.OnGesturesChange;
Settings.FingersOnlyChange -= this.OnFingersOnlyChange;

MetaPort.Instance.settings.settingBoolChanged.RemoveListener(this.OnGameSettingBoolChange);
}

public override void UpdateInput()
{
if(base.InputEnabled)
Expand Down
18 changes: 17 additions & 1 deletion ml_lme/LeapManager.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using ABI_RC.Core.Player;
using ABI_RC.Core.Savior;
using ABI_RC.Systems.InputManagement;
using System.Collections;
using UnityEngine;
Expand Down Expand Up @@ -60,6 +59,23 @@ void OnDestroy()
m_leapController.Dispose();
m_leapController = null;

if(m_leapTracking != null)
Object.Destroy(m_leapTracking);
m_leapTracking = null;

if(m_leapTracked != null)
Object.Destroy(m_leapTracked);
m_leapTracked = null;

if(m_leapInput != null)
{
if(CVRInputManager.Instance != null)
CVRInputManager.Instance.DestroyInputModule(m_leapInput);
else
m_leapInput.ModuleDestroyed();
}
m_leapInput = null;

Settings.EnabledChange -= this.OnEnableChange;
Settings.TrackingModeChange -= this.OnTrackingModeChange;
}
Expand Down
55 changes: 43 additions & 12 deletions ml_lme/LeapTracked.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class LeapTracked : MonoBehaviour
static readonly Quaternion ms_offsetRight = Quaternion.Euler(0f, 270f, 0f);

VRIK m_vrIK = null;
Vector4 m_vrIKWeights = Vector2.zero;
Vector4 m_vrIKWeights = Vector4.zero;
bool m_inVR = false;
Transform m_hips = null;
Transform m_origLeftHand = null;
Expand Down Expand Up @@ -61,6 +61,31 @@ void Start()

void OnDestroy()
{
if(m_leftArmIK != null)
Destroy(m_leftArmIK);
m_leftArmIK = null;

if(m_rightArmIK != null)
Destroy(m_rightArmIK);
m_rightArmIK = null;

if(m_leftHandTarget != null)
Destroy(m_leftHandTarget);
m_leftHandTarget = null;

if(m_rightHandTarget != null)
Destroy(m_rightHandTarget);
m_rightHandTarget = null;

m_poseHandler?.Dispose();
m_poseHandler = null;

m_vrIK = null;
m_origLeftHand = null;
m_origRightHand = null;
m_origLeftElbow = null;
m_origRightElbow = null;

Settings.EnabledChange -= this.OnEnabledChange;
Settings.FingersOnlyChange -= this.OnFingersOnlyChange;
Settings.TrackElbowsChange -= this.OnTrackElbowsChange;
Expand Down Expand Up @@ -180,7 +205,7 @@ internal void OnAvatarClear()
m_origLeftElbow = null;
m_origRightElbow = null;
m_hips = null;
m_vrIKWeights = Vector2.zero;
m_vrIKWeights = Vector4.zero;
m_leftArmIK = null;
m_rightArmIK = null;
m_leftTargetActive = false;
Expand Down Expand Up @@ -328,16 +353,22 @@ void OnIKPreUpdate()
}
void OnIKPostUpdate()
{
m_vrIK.solver.leftArm.positionWeight = m_vrIKWeights.x;
m_vrIK.solver.leftArm.rotationWeight = m_vrIKWeights.y;
m_vrIK.solver.leftArm.target = m_origLeftHand;
m_vrIK.solver.leftArm.bendGoal = m_origLeftElbow;
m_vrIK.solver.leftArm.bendGoalWeight = ((m_origLeftElbow != null) ? 1f : 0f);
m_vrIK.solver.rightArm.positionWeight = m_vrIKWeights.z;
m_vrIK.solver.rightArm.rotationWeight = m_vrIKWeights.w;
m_vrIK.solver.rightArm.target = m_origRightHand;
m_vrIK.solver.rightArm.bendGoal = m_origRightElbow;
m_vrIK.solver.rightArm.bendGoalWeight = ((m_origRightElbow != null) ? 1f : 0f);
if(m_leftTargetActive)
{
m_vrIK.solver.leftArm.positionWeight = m_vrIKWeights.x;
m_vrIK.solver.leftArm.rotationWeight = m_vrIKWeights.y;
m_vrIK.solver.leftArm.target = m_origLeftHand;
m_vrIK.solver.leftArm.bendGoal = m_origLeftElbow;
m_vrIK.solver.leftArm.bendGoalWeight = ((m_origLeftElbow != null) ? 1f : 0f);
}
if(m_rightTargetActive)
{
m_vrIK.solver.rightArm.positionWeight = m_vrIKWeights.z;
m_vrIK.solver.rightArm.rotationWeight = m_vrIKWeights.w;
m_vrIK.solver.rightArm.target = m_origRightHand;
m_vrIK.solver.rightArm.bendGoal = m_origRightElbow;
m_vrIK.solver.rightArm.bendGoalWeight = ((m_origRightElbow != null) ? 1f : 0f);
}
}

// Settings
Expand Down
28 changes: 28 additions & 0 deletions ml_lme/LeapTracking.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,36 @@ void OnDestroy()
if(Instance == this)
Instance = null;

if(m_leapHandLeft != null)
Object.Destroy(m_leapHandLeft);
m_leapHandLeft = null;

if(m_leapHandRight != null)
Object.Destroy(m_leapHandRight);
m_leapHandRight = null;

if(m_leapElbowLeft != null)
Object.Destroy(m_leapElbowLeft);
m_leapElbowLeft = null;

if(m_leapElbowRight != null)
Object.Destroy(m_leapElbowRight);
m_leapElbowRight = null;

if(m_leapControllerModel != null)
Object.Destroy(m_leapControllerModel);
m_leapControllerModel = null;

if(m_visualHands != null)
Object.Destroy(m_visualHands);
m_visualHands = null;

m_visualHandLeft = null;
m_visualHandRight = null;

Settings.DesktopOffsetChange -= this.OnDesktopOffsetChange;
Settings.ModelVisibilityChange -= this.OnModelVisibilityChange;
Settings.VisualHandsChange -= this.OnVisualHandsChange;
Settings.TrackingModeChange -= this.OnTrackingModeChange;
Settings.RootAngleChange -= this.OnRootAngleChange;
Settings.HeadAttachChange -= this.OnHeadAttachChange;
Expand Down
4 changes: 4 additions & 0 deletions ml_lme/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ public override void OnDeinitializeMelon()
{
if(ms_instance == this)
ms_instance = null;

if(m_leapManager != null)
Object.Destroy(m_leapManager);
m_leapManager = null;
}

IEnumerator WaitForRootLogic()
Expand Down
25 changes: 25 additions & 0 deletions ml_pam/ArmMover.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,33 @@ void Start()

void OnDestroy()
{
if(m_armIKLeft != null)
Destroy(m_armIKLeft);
m_armIKLeft = null;

if(m_armIKRight != null)
Destroy(m_armIKRight);
m_armIKRight = null;

if(m_rootLeft != null)
Destroy(m_rootLeft);
m_rootLeft = null;
m_leftTarget = null;

if(m_rootRight != null)
Destroy(m_rootRight);
m_rootRight = null;
m_rightTarget = null;

m_pickup = null;
m_vrIK = null;
m_origLeftHand = null;
m_origRightHand = null;

Settings.EnabledChange -= this.SetEnabled;
Settings.GrabOffsetChange -= this.SetGrabOffset;
Settings.LeadingHandChange -= this.OnLeadingHandChange;
Settings.HandsExtensionChange -= this.OnHandsExtensionChange;
}

void Update()
Expand Down
4 changes: 4 additions & 0 deletions ml_pam/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ public override void OnDeinitializeMelon()
{
if(ms_instance == this)
ms_instance = null;

if(m_localMover != null)
UnityEngine.Object.Destroy(m_localMover);
m_localMover = null;
}

static void OnAvatarClear_Postfix() => ms_instance?.OnAvatarClear();
Expand Down
4 changes: 4 additions & 0 deletions ml_pmc/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ public override void OnDeinitializeMelon()
if(ms_instance == this)
ms_instance = null;

ModUi.CopySwitch -= this.OnTargetSelect;

if(m_localCopycat != null)
UnityEngine.Object.Destroy(m_localCopycat);
m_localCopycat = null;
}

Expand Down
15 changes: 13 additions & 2 deletions ml_pmc/PoseCopycat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,26 @@ public class PoseCopycat : MonoBehaviour
HumanPose m_pose;
PuppetParser m_puppetParser = null;

internal PoseCopycat()
void Start()
{
if(Instance == null)
Instance = this;
}
~PoseCopycat()
void OnDestroy()
{
if(Instance == this)
Instance = null;

m_poseHandler?.Dispose();
m_poseHandler = null;

if(m_puppetParser != null)
Object.Destroy(m_puppetParser);
m_puppetParser = null;

m_animator = null;
m_vrIk = null;
m_lookAtIk = null;
}

// Unity events
Expand Down
4 changes: 4 additions & 0 deletions ml_prm/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ public override void OnDeinitializeMelon()
if(ms_instance == this)
ms_instance = null;

ModUi.SwitchChange -= this.OnSwitchActivation;

if(m_localController != null)
UnityEngine.Object.Destroy(m_localController);
m_localController = null;
}

Expand Down
Loading

0 comments on commit 914bca2

Please sign in to comment.