Read the description for detailed changes.

- Added `Sandbox.Players`: a synchronized list of `NetworkPlayerId` structs representing connected players.
- Added `Sandbox.Events.OnPlayerJoined` and `Sandbox.Events.OnPlayerLeft` callbacks, synchronized across all clients.
- Changed internal interpolation of quaternions to use `Slerp` instead of `Lerp`.
- Fixed a potential crash caused by undefined behavior when reaching `NetickConfig.MaxPlayers` and destroying network objects.
- Fixed an issue where sandbox-loaded scenes were not being unloaded during shutdown.
- Fixed a bug preventing Prediction Error Correction from functioning correctly.
This commit is contained in:
Karrar
2025-06-27 05:47:00 +03:00
parent 8e2db0f357
commit 1b0d33d8f0
25 changed files with 1843 additions and 1529 deletions

View File

@@ -5,68 +5,68 @@ using Netick.Unity;
namespace Netick.Samples.Bomberman
{
public class Bomb : NetworkBehaviour
{
public GameObject ExplosionPrefab;
public class Bomb : NetworkBehaviour
{
public GameObject ExplosionPrefab;
public BombermanController Bomber;
public float ExplosionDelay = 3.0f;
public BombermanController Bomber;
public float ExplosionDelay = 3.0f;
private readonly Vector3[] _directionsAroundBomb = new Vector3[4] { Vector3.right, Vector3.left, Vector3.up, Vector3.down };
private static RaycastHit[] _hits = new RaycastHit[20];
private readonly Vector3[] _directionsAroundBomb = new Vector3[4] { Vector3.right, Vector3.left, Vector3.up, Vector3.down };
private static RaycastHit[] _hits = new RaycastHit[20];
public override void NetworkStart()
{
Bomber?.SpawnedBombs.Add(this);
GetComponent<Renderer>().enabled = true;
public override void NetworkStart()
{
Bomber?.SpawnedBombs.Add(this);
GetComponent<Renderer>().enabled = true;
}
public override void NetworkDestroy()
{
Bomber?.SpawnedBombs.Remove(this);
public override void NetworkDestroy()
{
Bomber?.SpawnedBombs.Remove(this);
// spawn explosion.
if (ExplosionPrefab != null)
Instantiate(ExplosionPrefab, transform.position, Quaternion.identity);
}
// spawn explosion.
if (ExplosionPrefab != null)
Instantiate(ExplosionPrefab, transform.position, Quaternion.identity);
}
public override void NetworkFixedUpdate()
{
if (Sandbox.TickToTime(Sandbox.Tick - Object.SpawnTick) >= ExplosionDelay)
Explode();
}
public override void NetworkFixedUpdate()
{
if (Sandbox.TickToTime(Sandbox.Tick - Object.SpawnTick) >= ExplosionDelay)
Explode();
}
private void Explode()
{
// hide bomb after delay.
GetComponent<Renderer>().enabled = false;
private void Explode()
{
// hide bomb after delay.
GetComponent<Renderer>().enabled = false;
// dealing damage is done on the server only.
if (IsServer)
{
DamageTargetsAroundBomb(transform.position);
Sandbox.Destroy(Object);
}
}
private void DamageTargetsAroundBomb(Vector3 pos)
{
// find all objects around the bomb position.
foreach (var dir in _directionsAroundBomb)
{
var hitsCount = Sandbox.Physics.Raycast(pos, dir, _hits, 1f);
// dealing damage is done on the server only.
if (IsServer)
{
DamageTargetsAroundBomb(transform.position);
Sandbox.Destroy(Object);
}
}
for (int i = 0; i < hitsCount; i++)
{
var target =_hits[i].collider.gameObject;
var block = target.GetComponent<Block>();
var bomber = target.GetComponent<BombermanController>();
private void DamageTargetsAroundBomb(Vector3 pos)
{
// find all objects around the bomb position.
foreach (var dir in _directionsAroundBomb)
{
var hitsCount = Sandbox.Physics.Raycast(pos, dir, _hits, 1f);
if (block != null)
block.Visible = false;
bomber?.Die();
}
}
}
}
for (int i = 0; i < hitsCount; i++)
{
var target = _hits[i].collider.gameObject;
var block = target.GetComponent<Block>();
var bomber = target.GetComponent<BombermanController>();
if (block != null)
block.Visible = false;
bomber?.Die();
}
}
}
}
}