清理 Player 以及相关组件
This commit is contained in:
@@ -13,8 +13,8 @@ namespace SepCore.Components
|
||||
[SerializeField] private Vector3 _direction;
|
||||
[SerializeField] private Transform _cachedTransform;
|
||||
[SerializeField] private bool _avoidEnemyOverlap;
|
||||
[SerializeField] private float _enemyBodyRadius = 0.45f;
|
||||
[SerializeField] private int _separationIterations = 2;
|
||||
[SerializeField] private float _enemyBodyRadius;
|
||||
[SerializeField] private int _separationIterations;
|
||||
|
||||
public float Speed => (_speedBase + _movementStat.Value) * _movementStat.Percent;
|
||||
public bool AvoidEnemyOverlap => _avoidEnemyOverlap;
|
||||
@@ -26,19 +26,24 @@ namespace SepCore.Components
|
||||
[SerializeField] private float _speedBase;
|
||||
|
||||
private StatComponent _statComponent;
|
||||
private Player _player;
|
||||
private EnemyBase _enemy;
|
||||
|
||||
private StatProperty _movementStat;
|
||||
private Action<modifier, bool> _movementStatCallback;
|
||||
|
||||
public void OnInit(float speed, Transform target, StatComponent statComponent = null,
|
||||
bool avoidEnemyOverlap = false, float enemyBodyRadius = 0.45f, int separationIterations = 2)
|
||||
bool avoidEnemyOverlap = false, float? enemyBodyRadius = null, int? separationIterations = null)
|
||||
{
|
||||
_speedBase = speed;
|
||||
_cachedTransform = target;
|
||||
_direction = Vector3.forward;
|
||||
_avoidEnemyOverlap = avoidEnemyOverlap;
|
||||
_enemyBodyRadius = Mathf.Max(0.01f, enemyBodyRadius);
|
||||
_separationIterations = Mathf.Max(1, separationIterations);
|
||||
_enemyBodyRadius = Mathf.Max(0.01f, enemyBodyRadius ?? (GameEntry.Luban.Global.EnemyBodyRadius / 1000f));
|
||||
_separationIterations = Mathf.Max(1, separationIterations ?? GameEntry.Luban.Global.EnemySeparationIterations);
|
||||
|
||||
TryGetComponent(out _player);
|
||||
TryGetComponent(out _enemy);
|
||||
|
||||
_statComponent = statComponent;
|
||||
if (_statComponent != null)
|
||||
@@ -73,8 +78,10 @@ namespace SepCore.Components
|
||||
_direction = Vector3.zero;
|
||||
_isMoving = false;
|
||||
_avoidEnemyOverlap = false;
|
||||
_enemyBodyRadius = 0.45f;
|
||||
_separationIterations = 2;
|
||||
_enemyBodyRadius = GameEntry.Luban.Global.EnemyBodyRadius / 1000f;
|
||||
_separationIterations = GameEntry.Luban.Global.EnemySeparationIterations;
|
||||
_player = null;
|
||||
_enemy = null;
|
||||
|
||||
if (_statComponent != null)
|
||||
{
|
||||
@@ -86,8 +93,7 @@ namespace SepCore.Components
|
||||
|
||||
if (transformToUnregister != null)
|
||||
{
|
||||
var simulationWorld = GameEntry.SimulationWorld;
|
||||
simulationWorld?.UnregisterPlayerMovement(transformToUnregister);
|
||||
GameEntry.SimulationWorld.UnregisterPlayerMovement(transformToUnregister);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,12 +118,6 @@ namespace SepCore.Components
|
||||
return;
|
||||
}
|
||||
|
||||
SimulationWorld simulationWorld = GameEntry.SimulationWorld;
|
||||
if (simulationWorld == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Vector3 direction = _direction;
|
||||
direction.y = 0f;
|
||||
if (direction.sqrMagnitude > Mathf.Epsilon)
|
||||
@@ -125,15 +125,15 @@ namespace SepCore.Components
|
||||
direction.Normalize();
|
||||
}
|
||||
|
||||
if (TryGetComponent(out Player _))
|
||||
if (_player != null)
|
||||
{
|
||||
simulationWorld.SyncPlayerMovementInput(_cachedTransform, _isMoving, direction, Speed);
|
||||
GameEntry.SimulationWorld.SyncPlayerMovementInput(_cachedTransform, _isMoving, direction, Speed);
|
||||
return;
|
||||
}
|
||||
|
||||
if (TryGetComponent(out EnemyBase enemy))
|
||||
if (_enemy != null)
|
||||
{
|
||||
simulationWorld.SyncEnemyMovementInput(enemy.Id, _isMoving, direction, Speed,
|
||||
GameEntry.SimulationWorld.SyncEnemyMovementInput(_enemy.Id, _isMoving, direction, Speed,
|
||||
_avoidEnemyOverlap, _enemyBodyRadius, _separationIterations);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user