From 9e841cef1c06d7662c8a8553b520e7bb0e3536dd Mon Sep 17 00:00:00 2001 From: SDraw Date: Mon, 25 Dec 2023 02:02:45 +0300 Subject: [PATCH] Minor cleanup --- ml_amt/Utils.cs | 1 - ml_asl/Utils.cs | 1 - ml_lme/AssetsHandler.cs | 4 +- ml_lme/LeapInput.cs | 4 +- ml_lme/Main.cs | 1 - ml_lme/ModSupporter.cs | 6 +- ml_lme/VisualHand.cs | 11 +- ml_pin/Main.cs | 20 +--- ml_pmc/PoseCopycat.cs | 5 +- ml_pmc/PuppetParser.cs | 8 +- ml_pmc/Utils.cs | 3 - ml_prm/RagdollController.cs | 6 - ml_prm/RagdollTrigger.cs | 202 ++++++++++++++++----------------- ml_prm/RagdollTriggerVolume.cs | 38 +++---- ml_vei/Settings.cs | 3 +- 15 files changed, 142 insertions(+), 171 deletions(-) diff --git a/ml_amt/Utils.cs b/ml_amt/Utils.cs index 989bc4a..1d649a7 100644 --- a/ml_amt/Utils.cs +++ b/ml_amt/Utils.cs @@ -2,7 +2,6 @@ using ABI_RC.Core.UI; using ABI_RC.Systems.MovementSystem; using RootMotion.FinalIK; -using System.Collections.Generic; using System.Reflection; using UnityEngine; diff --git a/ml_asl/Utils.cs b/ml_asl/Utils.cs index ad7ddb3..2266e47 100644 --- a/ml_asl/Utils.cs +++ b/ml_asl/Utils.cs @@ -1,6 +1,5 @@ using ABI_RC.Core.UI; using System.Reflection; -using UnityEngine; namespace ml_asl { diff --git a/ml_lme/AssetsHandler.cs b/ml_lme/AssetsHandler.cs index a56affb..8aaf1f9 100644 --- a/ml_lme/AssetsHandler.cs +++ b/ml_lme/AssetsHandler.cs @@ -13,8 +13,8 @@ namespace ml_lme "leapmotion_hands.asset" }; - static Dictionary ms_loadedAssets = new Dictionary(); - static Dictionary ms_loadedObjects = new Dictionary(); + static readonly Dictionary ms_loadedAssets = new Dictionary(); + static readonly Dictionary ms_loadedObjects = new Dictionary(); public static void Load() { diff --git a/ml_lme/LeapInput.cs b/ml_lme/LeapInput.cs index dab03f7..7836502 100644 --- a/ml_lme/LeapInput.cs +++ b/ml_lme/LeapInput.cs @@ -283,7 +283,7 @@ namespace ml_lme { float l_strength = l_data.m_leftHand.m_grabStrength; - float l_interactValue = 0f; + float l_interactValue; if(m_gripToGrab) l_interactValue = Mathf.Clamp01(Mathf.InverseLerp(Mathf.Min(Settings.GripThreadhold, Settings.InteractThreadhold), Mathf.Max(Settings.GripThreadhold, Settings.InteractThreadhold), l_strength)); else @@ -311,7 +311,7 @@ namespace ml_lme { float l_strength = l_data.m_rightHand.m_grabStrength; - float l_interactValue = 0f; + float l_interactValue; if(m_gripToGrab) l_interactValue = Mathf.Clamp01(Mathf.InverseLerp(Mathf.Min(Settings.GripThreadhold, Settings.InteractThreadhold), Mathf.Max(Settings.GripThreadhold, Settings.InteractThreadhold), l_strength)); else diff --git a/ml_lme/Main.cs b/ml_lme/Main.cs index 1891cfc..d317b77 100644 --- a/ml_lme/Main.cs +++ b/ml_lme/Main.cs @@ -1,5 +1,4 @@ using ABI_RC.Core.Player; -using ABI_RC.Systems.IK.SubSystems; using System.Collections; using System.Reflection; using UnityEngine; diff --git a/ml_lme/ModSupporter.cs b/ml_lme/ModSupporter.cs index 9747c8d..d957c58 100644 --- a/ml_lme/ModSupporter.cs +++ b/ml_lme/ModSupporter.cs @@ -1,9 +1,5 @@ -using System; -using System.Collections; -using System.Collections.Generic; +using System.Collections; using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace ml_lme { diff --git a/ml_lme/VisualHand.cs b/ml_lme/VisualHand.cs index 1966559..e9453f2 100644 --- a/ml_lme/VisualHand.cs +++ b/ml_lme/VisualHand.cs @@ -4,17 +4,14 @@ namespace ml_lme { class VisualHand { - Transform m_root = null; - Transform m_wrist = null; - Transform[] m_fingers = null; + readonly Transform m_wrist = null; + readonly Transform[] m_fingers = null; public VisualHand(Transform p_root, bool p_left) { - m_root = p_root; - - if(m_root != null) + if(p_root != null) { - m_wrist = m_root.Find(p_left ? "LeftHand/Wrist" : "RightHand/Wrist"); + m_wrist = p_root.Find(p_left ? "LeftHand/Wrist" : "RightHand/Wrist"); if(m_wrist != null) { m_fingers = new Transform[20]; diff --git a/ml_pin/Main.cs b/ml_pin/Main.cs index 17a7c51..662ca9b 100644 --- a/ml_pin/Main.cs +++ b/ml_pin/Main.cs @@ -59,12 +59,7 @@ namespace ml_pin l_notify |= (Settings.FriendsAlways && l_isFriend); if(l_notify) - { - if(l_isFriend) - m_soundManager?.PlaySound(SoundManager.SoundType.FriendJoin); - else - m_soundManager?.PlaySound(SoundManager.SoundType.PlayerJoin); - } + m_soundManager?.PlaySound(l_isFriend ? SoundManager.SoundType.FriendJoin : SoundManager.SoundType.PlayerJoin); } catch(Exception e) { @@ -93,12 +88,7 @@ namespace ml_pin l_notify |= (Settings.FriendsAlways && l_isFriend); if(l_notify) - { - if(l_isFriend) - m_soundManager?.PlaySound(SoundManager.SoundType.FriendLeave); - else - m_soundManager?.PlaySound(SoundManager.SoundType.PlayerLeave); - } + m_soundManager?.PlaySound(l_isFriend ? SoundManager.SoundType.FriendLeave : SoundManager.SoundType.PlayerLeave); } catch(Exception e) { @@ -108,9 +98,9 @@ namespace ml_pin bool ShouldNotifyInCurrentInstance() { - bool l_isInPublic = Settings.NotifyInPublic && MetaPort.Instance.CurrentInstancePrivacy.Contains("Public"); - bool l_isInFriends = Settings.NotifyInFriends && MetaPort.Instance.CurrentInstancePrivacy.Contains("Friends"); - bool l_isInPrivate = Settings.NotifyInPrivate && MetaPort.Instance.CurrentInstancePrivacy.Contains("invite"); + bool l_isInPublic = (Settings.NotifyInPublic && MetaPort.Instance.CurrentInstancePrivacy.Contains("Public")); + bool l_isInFriends = (Settings.NotifyInFriends && MetaPort.Instance.CurrentInstancePrivacy.Contains("Friends")); + bool l_isInPrivate = (Settings.NotifyInPrivate && MetaPort.Instance.CurrentInstancePrivacy.Contains("invite")); return (l_isInPublic || l_isInFriends || l_isInPrivate); } } diff --git a/ml_pmc/PoseCopycat.cs b/ml_pmc/PoseCopycat.cs index 87373f3..16a4ece 100644 --- a/ml_pmc/PoseCopycat.cs +++ b/ml_pmc/PoseCopycat.cs @@ -1,5 +1,4 @@ using ABI_RC.Core.Player; -using ABI_RC.Core.Savior; using ABI_RC.Systems.IK; using ABI_RC.Systems.IK.SubSystems; using ABI_RC.Systems.InputManagement; @@ -81,8 +80,8 @@ namespace ml_pmc CVRInputManager.Instance.individualFingerTracking = true; IKSystem.Instance.FingerSystem.controlActive = true; - ref float[] l_curls = ref m_puppetParser.GetFingerCurls(); - ref float[] l_spreads = ref m_puppetParser.GetFingerSpreads(); + ref readonly float[] l_curls = ref m_puppetParser.GetFingerCurls(); + ref readonly float[] l_spreads = ref m_puppetParser.GetFingerSpreads(); CVRInputManager.Instance.fingerCurlLeftThumb = l_curls[l_mirror ? 5 : 0]; CVRInputManager.Instance.fingerCurlLeftIndex = l_curls[l_mirror ? 6 : 1]; diff --git a/ml_pmc/PuppetParser.cs b/ml_pmc/PuppetParser.cs index 414dd08..fece340 100644 --- a/ml_pmc/PuppetParser.cs +++ b/ml_pmc/PuppetParser.cs @@ -20,8 +20,8 @@ namespace ml_pmc float m_leftGesture = 0f; float m_rightGesture = 0f; bool m_fingerTracking = false; - float[] m_fingerCurls = null; - float[] m_fingerSpreads = null; + readonly float[] m_fingerCurls = null; + readonly float[] m_fingerSpreads = null; internal PuppetParser() { @@ -102,7 +102,7 @@ namespace ml_pmc public float GetLeftGesture() => m_leftGesture; public float GetRightGesture() => m_rightGesture; public bool HasFingerTracking() => m_fingerTracking; - public ref float[] GetFingerCurls() => ref m_fingerCurls; - public ref float[] GetFingerSpreads() => ref m_fingerSpreads; + public ref readonly float[] GetFingerCurls() => ref m_fingerCurls; + public ref readonly float[] GetFingerSpreads() => ref m_fingerSpreads; } } diff --git a/ml_pmc/Utils.cs b/ml_pmc/Utils.cs index 19fc92c..c09cc09 100644 --- a/ml_pmc/Utils.cs +++ b/ml_pmc/Utils.cs @@ -1,9 +1,6 @@ using ABI.CCK.Components; -using ABI_RC.Core.Player; using ABI_RC.Core.Savior; using ABI_RC.Systems.InputManagement; -using System.Linq; -using System.Reflection; using UnityEngine; namespace ml_pmc diff --git a/ml_prm/RagdollController.cs b/ml_prm/RagdollController.cs index ec116af..b41cf14 100644 --- a/ml_prm/RagdollController.cs +++ b/ml_prm/RagdollController.cs @@ -1,7 +1,6 @@ using ABI.CCK.Components; using ABI_RC.Core.InteractionSystem; using ABI_RC.Core.Player; -using ABI_RC.Core.Savior; using ABI_RC.Systems.Camera; using ABI_RC.Systems.IK; using ABI_RC.Systems.IK.SubSystems; @@ -22,7 +21,6 @@ namespace ml_prm public static RagdollController Instance { get; private set; } = null; - bool m_inVr = false; VRIK m_vrIK = null; bool m_applyHipsPosition = false; bool m_applyHipsRotation = false; @@ -69,8 +67,6 @@ namespace ml_prm if(Instance == null) Instance = this; - m_inVr = Utils.IsInVR(); - m_physicsMaterial = new PhysicMaterial("Ragdoll"); m_physicsMaterial.dynamicFriction = c_defaultFriction; m_physicsMaterial.staticFriction = c_defaultFriction; @@ -241,8 +237,6 @@ namespace ml_prm internal void OnAvatarSetup() { - m_inVr = Utils.IsInVR(); - if(PlayerSetup.Instance._animator.isHuman) { BipedRagdollReferences l_avatarReferences = BipedRagdollReferences.FromAvatar(PlayerSetup.Instance._animator); diff --git a/ml_prm/RagdollTrigger.cs b/ml_prm/RagdollTrigger.cs index 3498ffe..6f914be 100644 --- a/ml_prm/RagdollTrigger.cs +++ b/ml_prm/RagdollTrigger.cs @@ -1,108 +1,108 @@ -using ABI.CCK.Components; -using ABI_RC.Core.Player; -using ABI_RC.Core.Savior; -using UnityEngine; - -namespace ml_prm -{ - [DisallowMultipleComponent] - class RagdollTrigger : MonoBehaviour - { - const string c_ragdollPointerType = "ragdoll"; - - Collider m_collider = null; - Collider m_lastColliderTrigger = null; - ParticleSystem m_lastParticleSystemTrigger = null; - bool m_triggered = false; - - void Start() - { - m_collider = this.GetComponent(); - - CVRParticlePointerManager.volumes.Add(new RagdollTriggerVolume(m_collider, this)); - CVRParticlePointerManager.UpdateParticleSystems(); - } - +using ABI.CCK.Components; +using ABI_RC.Core.Player; +using ABI_RC.Core.Savior; +using UnityEngine; + +namespace ml_prm +{ + [DisallowMultipleComponent] + class RagdollTrigger : MonoBehaviour + { + const string c_ragdollPointerType = "ragdoll"; + + Collider m_collider = null; + Collider m_lastColliderTrigger = null; + ParticleSystem m_lastParticleSystemTrigger = null; + bool m_triggered = false; + + void Start() + { + m_collider = this.GetComponent(); + + CVRParticlePointerManager.volumes.Add(new RagdollTriggerVolume(m_collider, this)); + CVRParticlePointerManager.UpdateParticleSystems(); + } + void OnDestroy() - { + { if(m_collider != null) CVRParticlePointerManager.RemoveTrigger(m_collider); m_collider = null; m_lastColliderTrigger = null; - m_lastParticleSystemTrigger = null; - } - - void Update() - { - if(!ReferenceEquals(m_lastColliderTrigger, null)) - { - if(m_lastColliderTrigger != null) - { - if(!m_collider.bounds.Intersects(m_lastColliderTrigger.bounds)) - m_lastColliderTrigger = null; - } - else - m_lastColliderTrigger = null; - } - if(!ReferenceEquals(m_lastParticleSystemTrigger, null)) - { - if(m_lastParticleSystemTrigger != null) - { - if(m_lastParticleSystemTrigger.particleCount == 0) - m_lastParticleSystemTrigger = null; - } - else - m_lastParticleSystemTrigger = null; - } - } - - void OnTriggerEnter(Collider p_other) - { - CVRPointer l_pointer = p_other.GetComponent(); - if((l_pointer != null) && (l_pointer.type == c_ragdollPointerType) && !IsIgnored(l_pointer.transform) && (m_lastColliderTrigger != p_other)) - { - m_lastColliderTrigger = p_other; - m_triggered = true; - } - } - - void OnTriggerExit(Collider p_other) - { - if(m_lastColliderTrigger == p_other) - m_lastColliderTrigger = null; - } - - public void OnPointerParticleEnter(CVRPointer p_pointer) - { + m_lastParticleSystemTrigger = null; + } + + void Update() + { + if(!ReferenceEquals(m_lastColliderTrigger, null)) + { + if(m_lastColliderTrigger != null) + { + if(!m_collider.bounds.Intersects(m_lastColliderTrigger.bounds)) + m_lastColliderTrigger = null; + } + else + m_lastColliderTrigger = null; + } + if(!ReferenceEquals(m_lastParticleSystemTrigger, null)) + { + if(m_lastParticleSystemTrigger != null) + { + if(m_lastParticleSystemTrigger.particleCount == 0) + m_lastParticleSystemTrigger = null; + } + else + m_lastParticleSystemTrigger = null; + } + } + + void OnTriggerEnter(Collider p_other) + { + CVRPointer l_pointer = p_other.GetComponent(); + if((l_pointer != null) && (l_pointer.type == c_ragdollPointerType) && !IsIgnored(l_pointer.transform) && (m_lastColliderTrigger != p_other)) + { + m_lastColliderTrigger = p_other; + m_triggered = true; + } + } + + void OnTriggerExit(Collider p_other) + { + if(m_lastColliderTrigger == p_other) + m_lastColliderTrigger = null; + } + + public void OnPointerParticleEnter(CVRPointer p_pointer) + { if(!this.gameObject.activeInHierarchy) - return; - - if((p_pointer.type == c_ragdollPointerType) && !IsIgnored(p_pointer.transform) && (m_lastParticleSystemTrigger != p_pointer.particleSystem)) - { - m_lastParticleSystemTrigger = p_pointer.particleSystem; - m_triggered = true; - } - } - - public void OnPointerParticleExit(CVRPointer p_pointer) - { - // This seems to be very unreliable, and it's causing weird behavior - // if (!gameObject.activeInHierarchy) return; - // if(m_lastParticleSystemTrigger == p_pointer.particleSystem) - // m_lastParticleSystemTrigger = null; - } - - public bool GetStateWithReset() - { - bool l_state = m_triggered; - m_triggered = false; - return l_state; - } - - static bool IsIgnored(Transform p_transform) - { - return (Settings.IgnoreLocal && (p_transform.root == PlayerSetup.Instance.transform)); - } - } -} + return; + + if((p_pointer.type == c_ragdollPointerType) && !IsIgnored(p_pointer.transform) && (m_lastParticleSystemTrigger != p_pointer.particleSystem)) + { + m_lastParticleSystemTrigger = p_pointer.particleSystem; + m_triggered = true; + } + } + + public void OnPointerParticleExit(CVRPointer p_pointer) + { + // This seems to be very unreliable, and it's causing weird behavior + // if (!gameObject.activeInHierarchy) return; + // if(m_lastParticleSystemTrigger == p_pointer.particleSystem) + // m_lastParticleSystemTrigger = null; + } + + public bool GetStateWithReset() + { + bool l_state = m_triggered; + m_triggered = false; + return l_state; + } + + static bool IsIgnored(Transform p_transform) + { + return (Settings.IgnoreLocal && (p_transform.root == PlayerSetup.Instance.transform)); + } + } +} diff --git a/ml_prm/RagdollTriggerVolume.cs b/ml_prm/RagdollTriggerVolume.cs index 8216728..5030ae1 100644 --- a/ml_prm/RagdollTriggerVolume.cs +++ b/ml_prm/RagdollTriggerVolume.cs @@ -1,22 +1,22 @@ -using ABI_RC.Core.Savior; -using ABI.CCK.Components; -using UnityEngine; - +using ABI_RC.Core.Savior; +using ABI.CCK.Components; +using UnityEngine; + namespace ml_prm -{ - class RagdollTriggerVolume : CVRTriggerVolume - { - readonly RagdollTrigger m_trigger = null; - - public Collider collider { get; set; } - +{ + class RagdollTriggerVolume : CVRTriggerVolume + { + readonly RagdollTrigger m_trigger = null; + + public Collider collider { get; set; } + internal RagdollTriggerVolume(Collider p_collider, RagdollTrigger p_trigger) { - collider = p_collider; - m_trigger = p_trigger; - } - - public void TriggerEnter(CVRPointer pointer) => m_trigger.OnPointerParticleEnter(pointer); - public void TriggerExit(CVRPointer pointer) => m_trigger.OnPointerParticleExit(pointer); - } -} + collider = p_collider; + m_trigger = p_trigger; + } + + public void TriggerEnter(CVRPointer pointer) => m_trigger.OnPointerParticleEnter(pointer); + public void TriggerExit(CVRPointer pointer) => m_trigger.OnPointerParticleExit(pointer); + } +} diff --git a/ml_vei/Settings.cs b/ml_vei/Settings.cs index 72f9d6c2..7a412c0 100644 --- a/ml_vei/Settings.cs +++ b/ml_vei/Settings.cs @@ -88,7 +88,8 @@ namespace ml_vei { GripTrigger = bool.Parse(p_value); GripTriggerChange?.Invoke(GripTrigger); - } break; + } + break; } ms_entries[(int)l_setting].BoxedValue = bool.Parse(p_value);