fix test sample

This commit is contained in:
SepComet 2026-04-02 12:52:23 +08:00
parent ffcd4e6b54
commit af1fb7bf9d
3 changed files with 37 additions and 24 deletions

View File

@ -22,25 +22,23 @@ namespace Simulation
}
var enemyManager = GameEntry.EnemyManager;
if (enemyManager == null || enemyManager.Enemies == null)
if (enemyManager != null && enemyManager.Enemies != null)
{
return;
}
var enemies = enemyManager.Enemies;
foreach (var enemy in enemies)
{
if (enemy is not EnemyBase enemyEntity || !enemyEntity.Available)
var enemies = enemyManager.Enemies;
foreach (var enemy in enemies)
{
continue;
}
if (enemy is not EnemyBase enemyEntity || !enemyEntity.Available)
{
continue;
}
if (!_world.TryGetEnemyData(enemyEntity.Id, out EnemySimData enemyData))
{
continue;
}
if (!_world.TryGetEnemyData(enemyEntity.Id, out EnemySimData enemyData))
{
continue;
}
ApplyEnemyPresentation(enemyEntity, enemyData);
ApplyEnemyPresentation(enemyEntity, enemyData);
}
}
var projectiles = _world._projectiles;

View File

@ -16,6 +16,7 @@ namespace Simulation
private const string EnemyProjectileGroupName = "EnemyProjectile";
private readonly SimulationWorld _world;
private bool _isEventSubscribed;
public EntitySync(SimulationWorld world)
{
@ -24,14 +25,32 @@ namespace Simulation
public void OnStart()
{
GameEntry.Event.Subscribe(ShowEntitySuccessEventArgs.EventId, OnShowEntitySuccess);
GameEntry.Event.Subscribe(HideEntityCompleteEventArgs.EventId, OnHideEntityComplete);
var eventComponent = GameEntry.Event;
if (eventComponent == null)
{
return;
}
eventComponent.Subscribe(ShowEntitySuccessEventArgs.EventId, OnShowEntitySuccess);
eventComponent.Subscribe(HideEntityCompleteEventArgs.EventId, OnHideEntityComplete);
_isEventSubscribed = true;
}
public void OnDestroy()
{
GameEntry.Event.Unsubscribe(ShowEntitySuccessEventArgs.EventId, OnShowEntitySuccess);
GameEntry.Event.Unsubscribe(HideEntityCompleteEventArgs.EventId, OnHideEntityComplete);
if (!_isEventSubscribed)
{
return;
}
var eventComponent = GameEntry.Event;
if (eventComponent != null)
{
eventComponent.Unsubscribe(ShowEntitySuccessEventArgs.EventId, OnShowEntitySuccess);
eventComponent.Unsubscribe(HideEntityCompleteEventArgs.EventId, OnHideEntityComplete);
}
_isEventSubscribed = false;
}
private void OnShowEntitySuccess(object sender, GameEventArgs e)

View File

@ -133,11 +133,7 @@ namespace Simulation.Tests.Editor
_world.Tick(new SimulationTickContext(0.5f, 0.5f, Vector3.zero));
Assert.That(_world.Projectiles.Count, Is.EqualTo(1));
ProjectileSimData projectile = _world.Projectiles[0];
Assert.That(projectile.Active, Is.False);
Assert.That(projectile.State, Is.EqualTo(1));
Assert.That(projectile.Age, Is.GreaterThanOrEqualTo(projectile.LifeTime));
Assert.That(_world.Projectiles, Is.Empty);
}
[Test]