Skip to content

Commit

Permalink
Fix zoom and bad delegate subscribtion execution ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
Fueredoriku authored and toberge committed Nov 17, 2024
1 parent b0b7c2c commit 044aa46
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
14 changes: 13 additions & 1 deletion Assets/Prefabs/Gamestate/StaticInfo.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
21 changes: 20 additions & 1 deletion Assets/Scripts/Augment/GunController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions Assets/Scripts/Gamestate/PlayerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<GunController>().DeSubscribeDelegates();
for (int i = GunOrigin.transform.childCount - 1; i >= 0; i--)
{
Destroy(GunOrigin.transform.GetChild(i).gameObject);
}

}

private void SetLayerOnSubtree(GameObject node, int layer)
Expand Down
2 changes: 0 additions & 2 deletions Assets/Scripts/Interactables/TrainingModeAugmentPlacer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ public class TrainingModeAugmentPlacer : MonoBehaviour

private void Start()
{
#if UNITY_EDITOR
SpawnAugments();
#endif
}

private void SpawnAugments()
Expand Down

0 comments on commit 044aa46

Please sign in to comment.