Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Assets/RicochetModifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

public class RicochetModifier : MonoBehaviour, ProjectileModifier
{
public void ricochetProjectile(RaycastHit other, ref ProjectileState state)
private void RicochetProjectile(RaycastHit other, ref ProjectileState state)
{
state.direction = Vector3.Reflect(state.direction, other.normal);
}

public void Attach(ProjectileController projectile)
{
projectile.OnColliderHit += ricochetProjectile;
projectile.OnColliderHit += RicochetProjectile;
}
public void Detach(ProjectileController projectile)
{
projectile.OnColliderHit -= ricochetProjectile;
projectile.OnColliderHit -= RicochetProjectile;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ protected override void OnDestroy()
base.OnDestroy();
positionActiveBuffer?.Dispose();
rotationBuffer?.Dispose();
UpdateProjectileMovement -= ProjectileMotions.MoveWithGravity;
if (animator)
animator.OnShotFiredAnimation -= FireProjectile;
}

protected override void OnInitialize(GunStats gunstats)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

Expand All @@ -12,7 +10,7 @@ public class RevolverAnimator : AugmentAnimator
private GunBarrel barrel;
private GunExtension extension;

public override void OnFire(GunStats stats){}
public override void OnFire(GunStats stats) { }

public override void OnInitialize(GunStats stats)
{
Expand All @@ -36,7 +34,5 @@ public override void OnReload(GunStats stats)

if (extension)
extension.transform.SetParent(attachmentSite, true);

animator.SetTrigger("Reload");
}
}
7 changes: 2 additions & 5 deletions Assets/Scripts/Augment/BulletModifiers/DecalModifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ public void Detach(ProjectileController projectile)
{
projectile.OnRicochet -= OnHit;
}
decalPool.Flush();
decalPool = null;
OnDestroy();
}

private void OnHit(RaycastHit target, ref ProjectileState state)
Expand Down Expand Up @@ -94,9 +93,7 @@ private Quaternion DetermineRotation(Collider target, ProjectileState state)

private void OnDestroy()
{
if (decalPool == null)
return;
decalPool.Flush();
decalPool?.Flush();
decalPool = null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ public void Attach(ProjectileController projectile)
projectile.OnProjectileInit += OnProjectileInit;
}

public void Detach(ProjectileController projectile)
{
if (!projectile.GunController.Player)
return;
projectile.OnNetworkInit -= OnNetworkInit;
projectile.OnProjectileInit -= OnProjectileInit;
}

private void OnNetworkInit(ref ProjectileFireData data, GunStats _)
{
var speed = playerBody.velocity.magnitude;
Expand All @@ -67,12 +75,4 @@ private void OnProjectileInit(ref ProjectileState state, GunStats stats)
state.additionalProperties[ExplosionModifier.AreaDamagePropertyName] = damage * (1 - projectileToAreaDamageRatio);
state.speed = Mathf.Max(1f, speed * speedMultiplier);
}

public void Detach(ProjectileController projectile)
{
if (!projectile.GunController.Player)
return;
projectile.OnNetworkInit -= OnNetworkInit;
projectile.OnProjectileInit -= OnProjectileInit;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,9 @@ public class KnockbackOnShotModifier : MonoBehaviour, ProjectileModifier

private (ProjectileState shot, List<HitboxController> colliders) collidersHitWithShot = (null, new());

private void Awake()
{
gunController = transform.parent.GetComponent<GunController>();
if (!gunController)
return;
}
public void Attach(ProjectileController projectile)
{
gunController = projectile.GunController;
projectile.OnHitboxCollision += KnockAwayTargets;
bulletAmount = projectile.stats.ProjectilesPerShot;
calculatedPushPower = (pushPower / bulletAmount) * (1f + (float)Math.Log10(bulletAmount));
Expand Down
7 changes: 1 addition & 6 deletions Assets/Scripts/Augment/BulletModifiers/RecoilModifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,9 @@ public class RecoilModifier : MonoBehaviour, ProjectileModifier

private float calculatedPushPower;

private void Awake()
{
gunController = transform.parent.GetComponent<GunController>();
if (!gunController)
return;
}
public void Attach(ProjectileController projectile)
{
gunController = projectile.GunController;
projectile.OnProjectileInit += KnockAwayOnShot;
bulletAmount = projectile.stats.ProjectilesPerShot;
calculatedPushPower = (pushPower / bulletAmount) * (1f + (float)Math.Log10(bulletAmount));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,16 @@ public void Detach(ProjectileController projectile)
{
projectile.OnColliderHit -= StickToTarget;
OnStuckToTarget = null;
stuckObjects.Flush();
stuckObjects = null;
OnDestroy();
}

public void StickToTarget(RaycastHit hit, ref ProjectileState state)
{
if (!(affectedLayers == (affectedLayers | (1 << hit.collider.gameObject.layer))))
return;

var stuck = isDespawnedAfterTime ?
stuckObjects.GetAndReturnLater(stuckLifeTime)
var stuck = isDespawnedAfterTime ?
stuckObjects.GetAndReturnLater(stuckLifeTime)
: stuckObjects.Get();

stuck.transform.position = hit.ClosestPoint(state.oldPosition);
Expand All @@ -91,10 +90,7 @@ public StuckObject InstantiateManual(Vector3 position)

private void OnDestroy()
{
if (stuckObjects == null)
return;

stuckObjects.Flush();
stuckObjects?.Flush();
stuckObjects = null;
}
}
25 changes: 23 additions & 2 deletions Assets/Scripts/Augment/GunController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Mirror;
using UnityEngine;
Expand Down Expand Up @@ -106,11 +107,31 @@ public void Initialize()

private void OnDestroy()
{
UnsubscribeDelegates();
Detach();
}

public void UnsubscribeDelegates()
// TODO perhaps avoid too many duplacte detach calls?
Comment thread
toberge marked this conversation as resolved.
public void Detach()
{
// TODO remember these after init?
var body = GetComponentInChildren<GunBody>();
var barrel = GetComponentInChildren<GunBarrel>();
var extension = GetComponentInChildren<GunExtension>();

if (barrel == null)
{
Debug.LogWarning("Gun already detached!");
return;
}

var modifiers = new List<ProjectileModifier>();
if (barrel)
modifiers.AddRange(barrel.GetModifiers());
if (extension)
modifiers.AddRange(extension.GetModifiers());
modifiers.ForEach(m => m.Detach(projectile));

// TODO the null-ing is hopefully not necessary?
onInitializeGun = null;
onFire = null;
onFireEnd = null;
Expand Down
1 change: 1 addition & 0 deletions Assets/Scripts/Augment/GunStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public enum FireModes
/// </summary>
[HideInInspector]
public int Ammo = 0;
public float AmmoPercent => (Ammo < 1 ? 0 : Ammo) / (float)MagazineSize;

[SerializeField]
[Tooltip("Damage of each projectile")]
Expand Down
5 changes: 3 additions & 2 deletions Assets/Scripts/Augment/ProjectileModifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public enum Priority
EXTENSION,
ARBITRARY
}

/// <summary>
/// An interface that can be implemented in order to give additional functional property to any projectile created by any set of parts.
/// Why? Because putting a copy of every needed bullet script on every single bullet that is created is very inefficient.
Expand All @@ -16,12 +17,12 @@ public enum Priority
///
/// Note: Behaviour tied to updating the projectile every frame (Update), should be done with ProjectileController delegates instead!
/// </summary>
public interface ProjectileModifier
public interface ProjectileModifier
{

public abstract void Attach(ProjectileController projectile);
public abstract void Detach(ProjectileController projectile);
public Priority GetPriority()
public Priority GetPriority()
{
return Priority.ARBITRARY;
}
Expand Down
57 changes: 17 additions & 40 deletions Assets/Scripts/Gamestate/PlayerManager.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Mirror;
using System.Collections;
using System.Linq;
using Unity.VisualScripting.Antlr3.Runtime.Misc;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.Rendering.Universal;
Expand Down Expand Up @@ -263,6 +262,8 @@ public void SetPlayerInput(InputManager playerInput)
var canvas = hudController.GetComponent<Canvas>();
canvas.worldCamera = inputManager.GetComponentInChildren<Camera>();
canvas.planeDistance = 0.21f;
// TODO pivot inside HUDController (for respawning)
// and remember -=
Comment thread
toberge marked this conversation as resolved.
identity.onChipChange += hudController.OnChipChange;

// Disable arena camera so we don't render the entire scene twice
Expand Down Expand Up @@ -326,12 +327,7 @@ void OnDestroy()
}
if (gunController)
{
gunController.onFireStart -= UpdateAimTarget;
gunController.onFire -= UpdateAimTarget;
gunController.onFireEnd -= UpdateHudFire;
gunController.onReload -= UpdateHudReload;
//Remove the gun
Destroy(gunController.gameObject);
RemoveGun();
}
if (TryGetComponent(out PlayerMovement playerMovement))
{
Expand Down Expand Up @@ -411,26 +407,6 @@ private void PlayLeapAudio(Rigidbody body)
leapSounds.Play(audioSource);
}

private void UpdateHudFire(GunStats stats)
{
// stats variables must be dereferenced
float ammo = stats.Ammo < 1 ? 0 : stats.Ammo;
float magazine = stats.MagazineSize;
hudController.UpdateOnFire(ammo / magazine);
}

private void UpdateHudReload(GunStats stats)
{
float ammo = stats.Ammo;
float magazine = stats.MagazineSize;
hudController.UpdateOnReload(ammo / magazine);
}

private void UpdateHudCrosshair(GunStats stats)
{
HUDController.UpdateOnInitialize(stats);
}

private void TryPlaceBid(InputAction.CallbackContext ctx)
{
if (!selectedBiddingPlatform) return;
Expand Down Expand Up @@ -515,13 +491,7 @@ public virtual void SetGun(Transform offset)
var hadGunBefore = gunController != null;
if (hadGunBefore && inputManager)
{
gunController.onFireStart -= UpdateAimTarget;
gunController.onFire -= UpdateAimTarget;
gunController.onFire -= ScreenShake;
gunController.onFireEnd -= UpdateHudFire;
gunController.onReload -= UpdateHudReload;
gunController.projectile.OnHitboxCollision -= hudController.HitAnimation;
GunFactory.UnsubscribeAnimators(gunController.gameObject);
UnsubscribeGun();
}
overrideAimTarget = false;
var gun = GunFactory.InstantiateGun(identity.Body, identity.Barrel, identity.Extension, this, offset);
Expand All @@ -535,10 +505,7 @@ public virtual void SetGun(Transform offset)
gunController.onFireStart += UpdateAimTarget;
gunController.onFire += UpdateAimTarget;
gunController.onFire += ScreenShake;
gunController.onFireEnd += UpdateHudFire;
gunController.onReload += UpdateHudReload;
UpdateHudCrosshair(gunController.stats);
gunController.projectile.OnHitboxCollision += hudController.HitAnimation;
hudController.Attach(gunController);
}
playerIK.LeftHandIKTarget = gunController.LeftHandTarget;
if (gunController.RightHandTarget)
Expand All @@ -549,6 +516,16 @@ public virtual void SetGun(Transform offset)
GetComponent<NetworkIdentity>().InitializeNetworkBehaviours();
}

private void UnsubscribeGun()
{
gunController.onFireStart -= UpdateAimTarget;
gunController.onFire -= UpdateAimTarget;
gunController.onFire -= ScreenShake;
hudController.Detach(gunController);
gunController.Detach();
GunOrigin.GetComponent<GunController>().Detach();
}

public void SetGunNetwork(Transform offset)
{
overrideAimTarget = false;
Expand All @@ -566,17 +543,17 @@ public void SetGunNetwork(Transform offset)

public void RemoveGun()
{
gunController.UnsubscribeDelegates();
UnsubscribeGun();
for (int i = gunController.transform.childCount - 1; i >= 0; i--)
{
Destroy(gunController.transform.GetChild(i).gameObject);
}
Destroy(gunController.gameObject);
GunOrigin.GetComponent<GunController>().UnsubscribeDelegates();
for (int i = GunOrigin.transform.childCount - 1; i >= 0; i--)
{
Destroy(GunOrigin.transform.GetChild(i).gameObject);
}
// TODO ok and why don't we destroy the guncontroller for the display gun
Comment thread
toberge marked this conversation as resolved.
}

private void SetLayerOnSubtree(GameObject node, int layer)
Expand Down
5 changes: 5 additions & 0 deletions Assets/Scripts/Gamestate/PlayerSubscriber.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public interface PlayerSubscriber
{
void Subscribe(PlayerManager player);
void Unsubscribe(PlayerManager player);
}
11 changes: 11 additions & 0 deletions Assets/Scripts/Gamestate/PlayerSubscriber.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Assets/Scripts/UI/MainMenu/MainMenuController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ private void Awake()
private void Start()
{
aiButtonOriginalPosition = aIButton.transform.localPosition;
Debug.Log(aiButtonOriginalPosition);
PlayerInputManagerController.Singleton.MatchHasAI = false;
audioSource = GetComponent<AudioSource>();
versionText.text = $"Early Access {Application.version}";
Expand Down
Loading