引入属性、伤害管线
This commit is contained in:
@@ -16,7 +16,7 @@ namespace SepCore.Components
|
||||
[SerializeField] private float _enemyBodyRadius;
|
||||
[SerializeField] private int _separationIterations;
|
||||
|
||||
public float Speed => (_speedBase + _movementStat.Value) * _movementStat.Percent;
|
||||
public float Speed => _statComponent != null ? _statComponent.GetStatValue(StatType.MoveSpeed) : _speedBase;
|
||||
public bool AvoidEnemyOverlap => _avoidEnemyOverlap;
|
||||
public float EnemyBodyRadius => _enemyBodyRadius;
|
||||
public int SeparationIterations => _separationIterations;
|
||||
@@ -28,9 +28,7 @@ namespace SepCore.Components
|
||||
private StatComponent _statComponent;
|
||||
private Player _player;
|
||||
private EnemyBase _enemy;
|
||||
|
||||
private StatProperty _movementStat;
|
||||
private Action<modifier, bool> _movementStatCallback;
|
||||
private Action<StatType, float> _onStatChangedAction;
|
||||
|
||||
public void OnInit(float speed, Transform target, StatComponent statComponent = null,
|
||||
bool avoidEnemyOverlap = false, float? enemyBodyRadius = null, int? separationIterations = null)
|
||||
@@ -39,8 +37,15 @@ namespace SepCore.Components
|
||||
_cachedTransform = target;
|
||||
_direction = Vector3.forward;
|
||||
_avoidEnemyOverlap = avoidEnemyOverlap;
|
||||
_enemyBodyRadius = Mathf.Max(0.01f, enemyBodyRadius ?? (GameEntry.Luban.Global.EnemyBodyRadius / 1000f));
|
||||
_separationIterations = Mathf.Max(1, separationIterations ?? GameEntry.Luban.Global.EnemySeparationIterations);
|
||||
float defaultRadius = GameEntry.Luban != null && GameEntry.Luban.IsReady
|
||||
? GameEntry.Luban.Global.EnemyBodyRadius / 1000f
|
||||
: 0.5f;
|
||||
int defaultIterations = GameEntry.Luban != null && GameEntry.Luban.IsReady
|
||||
? GameEntry.Luban.Global.EnemySeparationIterations
|
||||
: 4;
|
||||
|
||||
_enemyBodyRadius = Mathf.Max(0.01f, enemyBodyRadius ?? defaultRadius);
|
||||
_separationIterations = Mathf.Max(1, separationIterations ?? defaultIterations);
|
||||
|
||||
TryGetComponent(out _player);
|
||||
TryGetComponent(out _enemy);
|
||||
@@ -48,17 +53,9 @@ namespace SepCore.Components
|
||||
_statComponent = statComponent;
|
||||
if (_statComponent != null)
|
||||
{
|
||||
_movementStat = _statComponent.GetStat(StatType.MovementSpeed);
|
||||
_movementStatCallback = (modifier, isApply) =>
|
||||
{
|
||||
_statComponent.UpdateStat(_movementStat, modifier, isApply);
|
||||
SyncToSimulationWorld();
|
||||
};
|
||||
_statComponent.Subscribe(StatType.MovementSpeed, _movementStatCallback);
|
||||
}
|
||||
else
|
||||
{
|
||||
_movementStat = new StatProperty();
|
||||
_statComponent.Pipeline.SetBaseValue(StatType.MoveSpeed, speed);
|
||||
_onStatChangedAction = OnStatChanged;
|
||||
_statComponent.Pipeline.OnStatChanged += _onStatChangedAction;
|
||||
}
|
||||
|
||||
SyncToSimulationWorld();
|
||||
@@ -73,25 +70,32 @@ namespace SepCore.Components
|
||||
{
|
||||
Transform transformToUnregister = _cachedTransform;
|
||||
|
||||
float defaultRadius = GameEntry.Luban != null && GameEntry.Luban.IsReady
|
||||
? GameEntry.Luban.Global.EnemyBodyRadius / 1000f
|
||||
: 0.5f;
|
||||
int defaultIterations = GameEntry.Luban != null && GameEntry.Luban.IsReady
|
||||
? GameEntry.Luban.Global.EnemySeparationIterations
|
||||
: 4;
|
||||
|
||||
_speedBase = 0;
|
||||
_cachedTransform = null;
|
||||
_direction = Vector3.zero;
|
||||
_isMoving = false;
|
||||
_avoidEnemyOverlap = false;
|
||||
_enemyBodyRadius = GameEntry.Luban.Global.EnemyBodyRadius / 1000f;
|
||||
_separationIterations = GameEntry.Luban.Global.EnemySeparationIterations;
|
||||
_enemyBodyRadius = defaultRadius;
|
||||
_separationIterations = defaultIterations;
|
||||
_player = null;
|
||||
_enemy = null;
|
||||
|
||||
if (_statComponent != null)
|
||||
if (_statComponent != null && _onStatChangedAction != null)
|
||||
{
|
||||
_statComponent.Unsubscribe(StatType.MovementSpeed, _movementStatCallback);
|
||||
_movementStatCallback = null;
|
||||
_statComponent.Pipeline.OnStatChanged -= _onStatChangedAction;
|
||||
_onStatChangedAction = null;
|
||||
}
|
||||
|
||||
_statComponent = null;
|
||||
|
||||
if (transformToUnregister != null)
|
||||
if (transformToUnregister != null && GameEntry.SimulationWorld != null)
|
||||
{
|
||||
GameEntry.SimulationWorld.UnregisterPlayerMovement(transformToUnregister);
|
||||
}
|
||||
@@ -113,7 +117,7 @@ namespace SepCore.Components
|
||||
{
|
||||
using (CustomProfilerMarker.Movement_Update.Auto())
|
||||
{
|
||||
if (_cachedTransform == null)
|
||||
if (_cachedTransform == null || GameEntry.SimulationWorld == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -138,5 +142,13 @@ namespace SepCore.Components
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnStatChanged(StatType statType, float newValue)
|
||||
{
|
||||
if (statType == StatType.MoveSpeed)
|
||||
{
|
||||
SyncToSimulationWorld();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user