diff --git a/ml_amt/Main.cs b/ml_amt/Main.cs index 4c75be3..7e73e3d 100644 --- a/ml_amt/Main.cs +++ b/ml_amt/Main.cs @@ -56,6 +56,8 @@ namespace ml_amt if(ms_instance == this) ms_instance = null; + if(m_localTweaker != null) + UnityEngine.Object.Destroy(m_localTweaker); m_localTweaker = null; } diff --git a/ml_amt/MotionTweaker.cs b/ml_amt/MotionTweaker.cs index 5ec749e..cdc9e72 100644 --- a/ml_amt/MotionTweaker.cs +++ b/ml_amt/MotionTweaker.cs @@ -74,6 +74,10 @@ namespace ml_amt void OnDestroy() { + m_vrIk = null; + m_ikLimits = null; + m_parameters.Clear(); + Settings.CrouchLimitChange -= this.SetCrouchLimit; Settings.ProneLimitChange -= this.SetProneLimit; Settings.IKOverrideFlyChange -= this.SetIKOverrideFly; diff --git a/ml_lme/LeapInput.cs b/ml_lme/LeapInput.cs index db15cf8..dab03f7 100644 --- a/ml_lme/LeapInput.cs +++ b/ml_lme/LeapInput.cs @@ -24,16 +24,6 @@ namespace ml_lme 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(); @@ -122,6 +112,34 @@ namespace ml_lme 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) diff --git a/ml_lme/LeapManager.cs b/ml_lme/LeapManager.cs index 9d8733e..f6ff4f6 100644 --- a/ml_lme/LeapManager.cs +++ b/ml_lme/LeapManager.cs @@ -1,5 +1,4 @@ using ABI_RC.Core.Player; -using ABI_RC.Core.Savior; using ABI_RC.Systems.InputManagement; using System.Collections; using UnityEngine; @@ -60,6 +59,23 @@ namespace ml_lme 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; } diff --git a/ml_lme/LeapTracked.cs b/ml_lme/LeapTracked.cs index 7661cd3..291e5e1 100644 --- a/ml_lme/LeapTracked.cs +++ b/ml_lme/LeapTracked.cs @@ -14,7 +14,7 @@ namespace ml_lme 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; @@ -61,6 +61,31 @@ namespace ml_lme 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; @@ -180,7 +205,7 @@ namespace ml_lme 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; @@ -328,16 +353,22 @@ namespace ml_lme } 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 diff --git a/ml_lme/LeapTracking.cs b/ml_lme/LeapTracking.cs index dfcfc13..684c679 100644 --- a/ml_lme/LeapTracking.cs +++ b/ml_lme/LeapTracking.cs @@ -102,8 +102,36 @@ namespace ml_lme 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; diff --git a/ml_lme/Main.cs b/ml_lme/Main.cs index a2c9635..2c2ab83 100644 --- a/ml_lme/Main.cs +++ b/ml_lme/Main.cs @@ -57,6 +57,10 @@ namespace ml_lme { if(ms_instance == this) ms_instance = null; + + if(m_leapManager != null) + Object.Destroy(m_leapManager); + m_leapManager = null; } IEnumerator WaitForRootLogic() diff --git a/ml_pam/ArmMover.cs b/ml_pam/ArmMover.cs index 531c331..73134ba 100644 --- a/ml_pam/ArmMover.cs +++ b/ml_pam/ArmMover.cs @@ -79,8 +79,33 @@ namespace ml_pam 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() diff --git a/ml_pam/Main.cs b/ml_pam/Main.cs index 728e91b..9ad1bc5 100644 --- a/ml_pam/Main.cs +++ b/ml_pam/Main.cs @@ -61,6 +61,10 @@ namespace ml_pam { 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(); diff --git a/ml_pmc/Main.cs b/ml_pmc/Main.cs index 7c1826b..d660e2c 100644 --- a/ml_pmc/Main.cs +++ b/ml_pmc/Main.cs @@ -42,6 +42,10 @@ namespace ml_pmc if(ms_instance == this) ms_instance = null; + ModUi.CopySwitch -= this.OnTargetSelect; + + if(m_localCopycat != null) + UnityEngine.Object.Destroy(m_localCopycat); m_localCopycat = null; } diff --git a/ml_pmc/PoseCopycat.cs b/ml_pmc/PoseCopycat.cs index 028b49d..87373f3 100644 --- a/ml_pmc/PoseCopycat.cs +++ b/ml_pmc/PoseCopycat.cs @@ -33,15 +33,26 @@ namespace ml_pmc 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 diff --git a/ml_prm/Main.cs b/ml_prm/Main.cs index 26303da..f27879a 100644 --- a/ml_prm/Main.cs +++ b/ml_prm/Main.cs @@ -89,6 +89,10 @@ namespace ml_prm if(ms_instance == this) ms_instance = null; + ModUi.SwitchChange -= this.OnSwitchActivation; + + if(m_localController != null) + UnityEngine.Object.Destroy(m_localController); m_localController = null; } diff --git a/ml_prm/RagdollController.cs b/ml_prm/RagdollController.cs index 29ba988..ec116af 100644 --- a/ml_prm/RagdollController.cs +++ b/ml_prm/RagdollController.cs @@ -46,9 +46,9 @@ namespace ml_prm Vector3 m_ragdollLastPos = Vector3.zero; RagdollToggle m_avatarRagdollToggle = null; - RagdollTrigger m_customTrigger = null; + RagdollTrigger m_ragdollTrigger = null; AvatarBoolParameter m_ragdolledParameter = null; - readonly PhysicMaterial m_physicsMaterial = null; + PhysicMaterial m_physicsMaterial = null; bool m_reachedGround = true; float m_groundedTime = 0f; @@ -56,14 +56,20 @@ namespace ml_prm internal RagdollController() { - if(Instance == null) - Instance = this; - m_rigidBodies = new List(); m_colliders = new List(); m_boneLinks = new List>(); m_jointAnchors = new List>(); m_physicsInfluencers = new List(); + } + + // Unity events + void Start() + { + if(Instance == null) + Instance = this; + + m_inVr = Utils.IsInVR(); m_physicsMaterial = new PhysicMaterial("Ragdoll"); m_physicsMaterial.dynamicFriction = c_defaultFriction; @@ -71,25 +77,14 @@ namespace ml_prm m_physicsMaterial.frictionCombine = PhysicMaterialCombine.Average; m_physicsMaterial.bounciness = 0f; m_physicsMaterial.bounceCombine = PhysicMaterialCombine.Average; - } - ~RagdollController() - { - if(Instance == this) - Instance = null; - } - - // Unity events - void Start() - { - m_inVr = Utils.IsInVR(); m_puppetRoot = new GameObject("[PlayerAvatarPuppet]").transform; m_puppetRoot.parent = PlayerSetup.Instance.transform; m_puppetRoot.localPosition = Vector3.zero; m_puppetRoot.localRotation = Quaternion.identity; - m_customTrigger = MovementSystem.Instance.proxyCollider.gameObject.AddComponent(); - m_customTrigger.enabled = false; + m_ragdollTrigger = MovementSystem.Instance.proxyCollider.gameObject.AddComponent(); + m_ragdollTrigger.enabled = false; Settings.MovementDragChange += this.OnMovementDragChange; Settings.AngularDragChange += this.OnAngularDragChange; @@ -101,17 +96,38 @@ namespace ml_prm void OnDestroy() { - if(m_customTrigger != null) - { - Object.Destroy(m_customTrigger); - m_customTrigger = null; - } + if(Instance == this) + Instance = null; + + if(m_initCoroutine != null) + StopCoroutine(m_initCoroutine); + m_initCoroutine = null; + + if(m_puppetRoot != null) + Object.Destroy(m_puppetRoot); + m_puppetRoot = null; + m_puppet = null; + m_rigidBodies.Clear(); + m_colliders.Clear(); + m_boneLinks.Clear(); + m_jointAnchors.Clear(); + m_physicsInfluencers.Clear(); + m_avatarRagdollToggle = null; + + if(m_ragdollTrigger != null) + Object.Destroy(m_ragdollTrigger); + m_ragdollTrigger = null; + + if(m_physicsMaterial != null) + Object.Destroy(m_physicsMaterial); + m_physicsMaterial = null; Settings.MovementDragChange -= this.OnMovementDragChange; Settings.AngularDragChange -= this.OnAngularDragChange; Settings.GravityChange -= this.OnGravityChange; Settings.SlipperinessChange -= this.OnPhysicsMaterialChange; Settings.BouncinessChange -= this.OnPhysicsMaterialChange; + Settings.BuoyancyChange -= this.OnBuoyancyChange; } void Update() @@ -153,7 +169,7 @@ namespace ml_prm if((m_avatarRagdollToggle != null) && m_avatarRagdollToggle.isActiveAndEnabled && m_avatarRagdollToggle.shouldOverride && (m_enabled != m_avatarRagdollToggle.isOn)) SwitchRagdoll(); - if((m_customTrigger != null) && m_customTrigger.GetStateWithReset() && m_avatarReady && !m_enabled && Settings.PointersReaction) + if((m_ragdollTrigger != null) && m_ragdollTrigger.GetStateWithReset() && m_avatarReady && !m_enabled && Settings.PointersReaction) SwitchRagdoll(); if(Settings.Hotkey && Input.GetKeyDown(Settings.HotkeyKey) && !ViewManager.Instance.isGameMenuOpen()) @@ -199,10 +215,10 @@ namespace ml_prm Object.Destroy(m_puppet.gameObject); m_puppet = null; - if(m_customTrigger != null) + if(m_ragdollTrigger != null) { - m_customTrigger.GetStateWithReset(); - m_customTrigger.enabled = false; + m_ragdollTrigger.GetStateWithReset(); + m_ragdollTrigger.enabled = false; } m_vrIK = null; @@ -352,7 +368,7 @@ namespace ml_prm m_puppetRoot.gameObject.SetActive(false); - m_customTrigger.enabled = true; + m_ragdollTrigger.enabled = true; m_avatarReady = true; m_initCoroutine = null; diff --git a/ml_prm/RagdollTrigger.cs b/ml_prm/RagdollTrigger.cs index 8afe3f7..3498ffe 100644 --- a/ml_prm/RagdollTrigger.cs +++ b/ml_prm/RagdollTrigger.cs @@ -25,7 +25,12 @@ namespace ml_prm void OnDestroy() { - CVRParticlePointerManager.RemoveTrigger(m_collider); + if(m_collider != null) + CVRParticlePointerManager.RemoveTrigger(m_collider); + m_collider = null; + + m_lastColliderTrigger = null; + m_lastParticleSystemTrigger = null; } void Update()