From 044aa463f32910e6edb091aedfad89b815cdb8f0 Mon Sep 17 00:00:00 2001 From: Fredrik Lillemoen Eiding Date: Sun, 17 Nov 2024 15:05:44 +0100 Subject: [PATCH] Fix zoom and bad delegate subscribtion execution ordering --- Assets/Prefabs/Gamestate/StaticInfo.prefab | 14 ++++++++++++- Assets/Scripts/Augment/GunController.cs | 21 ++++++++++++++++++- Assets/Scripts/Gamestate/PlayerManager.cs | 3 +++ .../TrainingModeAugmentPlacer.cs | 2 -- 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/Assets/Prefabs/Gamestate/StaticInfo.prefab b/Assets/Prefabs/Gamestate/StaticInfo.prefab index a19e2ce35..ab7dc22b1 100644 --- a/Assets/Prefabs/Gamestate/StaticInfo.prefab +++ b/Assets/Prefabs/Gamestate/StaticInfo.prefab @@ -16,6 +16,7 @@ GameObject: - component: {fileID: 5022952277509122877} - component: {fileID: 6572921195520930000} - component: {fileID: 3780314087357157891} + - component: {fileID: 9056613597413866774} m_Layer: 0 m_Name: StaticInfo m_TagString: Untagged @@ -239,4 +240,15 @@ MonoBehaviour: UpperZoomFOVLimit: 50 LowerCrosshairLimit: 0.01 UpperCrosshairLimit: 3 - actions: {fileID: -944628639613478452, guid: 243a37e9744e079e7a1be1b16e3abd19, type: 3} +--- !u!114 &9056613597413866774 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 8579357797008554893} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: a305033fb95a67347ae087ba35c9202c, type: 3} + m_Name: + m_EditorClassIdentifier: diff --git a/Assets/Scripts/Augment/GunController.cs b/Assets/Scripts/Augment/GunController.cs index 51e153515..98bd92956 100644 --- a/Assets/Scripts/Augment/GunController.cs +++ b/Assets/Scripts/Augment/GunController.cs @@ -105,10 +105,22 @@ public void Initialize() private void OnDestroy() { + DeSubscribeDelegates(); + } + + public void DeSubscribeDelegates() + { + onFire = null; + onFireEnd = null; + onFireNoAmmo = null; + onFireStart = null; + onInitializeBullet = null; + onReload = null; + if (!barrelAnimator) return; - if (HasRecoil) + barrelAnimator.OnShotFiredAnimation -= PlayRecoil; barrelAnimator.OnShotFiredAnimation -= ShotFired; barrelAnimator.OnAnimationEnd -= FireEnd; @@ -216,8 +228,11 @@ private void RpcFireWithNoAmmo() private void FireGun() { + if (stats == null) + return; if (stats.Ammo <= 0) { + Debug.Log("No Ammo"); CmdFireWithNoAmmo(); // Handle this immediately yourself onFireNoAmmo?.Invoke(stats); @@ -226,11 +241,15 @@ private void FireGun() try { + Debug.Log("Invoking onFireStart"); onFireStart?.Invoke(stats); + Debug.Log("Running aimattarget"); AimAtTarget(); // Tell server to fire + Debug.Log("Trying to fire at server side"); CmdFire(projectile.projectileRotation); // but fire immediately yourself! + Debug.Log("trying to fire at client"); ActuallyFire(); } catch (Exception e) diff --git a/Assets/Scripts/Gamestate/PlayerManager.cs b/Assets/Scripts/Gamestate/PlayerManager.cs index 1411823dd..300ecd302 100644 --- a/Assets/Scripts/Gamestate/PlayerManager.cs +++ b/Assets/Scripts/Gamestate/PlayerManager.cs @@ -528,15 +528,18 @@ public void SetGunNetwork(Transform offset) public void RemoveGun() { + gunController.DeSubscribeDelegates(); for (int i = gunController.transform.childCount - 1; i >= 0; i--) { Destroy(gunController.transform.GetChild(i).gameObject); } Destroy(gunController.gameObject); + GunOrigin.GetComponent().DeSubscribeDelegates(); for (int i = GunOrigin.transform.childCount - 1; i >= 0; i--) { Destroy(GunOrigin.transform.GetChild(i).gameObject); } + } private void SetLayerOnSubtree(GameObject node, int layer) diff --git a/Assets/Scripts/Interactables/TrainingModeAugmentPlacer.cs b/Assets/Scripts/Interactables/TrainingModeAugmentPlacer.cs index c112c406a..3848feb5e 100644 --- a/Assets/Scripts/Interactables/TrainingModeAugmentPlacer.cs +++ b/Assets/Scripts/Interactables/TrainingModeAugmentPlacer.cs @@ -16,9 +16,7 @@ public class TrainingModeAugmentPlacer : MonoBehaviour private void Start() { -#if UNITY_EDITOR SpawnAugments(); -#endif } private void SpawnAugments()