清理 Player 以及相关组件

This commit is contained in:
2026-09-15 11:31:20 +08:00
parent 88ed35e757
commit 1e4d3ef8d7
15 changed files with 150 additions and 134 deletions
@@ -7,11 +7,7 @@ namespace SepCore.Components
{
public class AbsorbComponent : MonoBehaviour
{
[SerializeField] private float _absorbRangeBase = 3f;
[SerializeField] private float _absorbSpeed = 15f;
[SerializeField] private float _collectDistance = 0.35f;
[SerializeField] private int _maxDetectCount = 64;
[SerializeField] private LayerMask _detectLayerMask = ~0;
private Player _player;
private Transform _target;
@@ -21,38 +17,34 @@ namespace SepCore.Components
private StatProperty _absorbRangeStat;
private Action<modifier, bool> _absorbRangeStatCallback;
private float AbsorbRange => Mathf.Max(0f, (_absorbRangeBase + _absorbRangeStat.Value) * _absorbRangeStat.Percent);
private float AbsorbRangeBase => GameEntry.Luban.Global.DefaultAbsorbRange / 1000f;
private float AbsorbSpeed => GameEntry.Luban.Global.AbsorbSpeed / 1000f;
private float CollectDistance => GameEntry.Luban.Global.CollectDistance / 1000f;
public void OnInit(Player player, StatComponent statComponent = null)
private float AbsorbRange => Mathf.Max(0f, (AbsorbRangeBase + _absorbRangeStat.Value) * _absorbRangeStat.Percent);
public void OnInit(Player player, StatComponent statComponent)
{
_player = player;
_target = player != null ? player.CachedTransform : null;
_target = player.CachedTransform;
_statComponent = statComponent;
_buffer = new Collider[Mathf.Max(1, _maxDetectCount)];
if (_statComponent != null)
{
_absorbRangeStat = _statComponent.GetStat(StatType.AbsorbRange);
_absorbRangeStatCallback = (modifier, isApply) =>
_statComponent.UpdateStat(_absorbRangeStat, modifier, isApply);
_statComponent.Subscribe(StatType.AbsorbRange, _absorbRangeStatCallback);
}
else
{
_absorbRangeStat = new StatProperty();
}
_absorbRangeStat = _statComponent.GetStat(StatType.AbsorbRange);
_absorbRangeStatCallback = (modifier, isApply) =>
_statComponent.UpdateStat(_absorbRangeStat, modifier, isApply);
_statComponent.Subscribe(StatType.AbsorbRange, _absorbRangeStatCallback);
}
public void OnUpdate(float elapseSeconds, float realElapseSeconds)
{
if (_player == null || !_player.Available || _target == null || _buffer == null) return;
if (!_player.Available) return;
int hitCount = Physics.OverlapSphereNonAlloc(
_target.position,
AbsorbRange,
_buffer,
_detectLayerMask,
QueryTriggerInteraction.Collide
Constant.Layer.DropLayerMask
);
for (int i = 0; i < hitCount; i++)
@@ -64,7 +56,7 @@ namespace SepCore.Components
if (coin != null && coin.Available)
{
AbsorbDrop(coin.CachedTransform, elapseSeconds);
coin.TryCollect(_player, _collectDistance);
coin.TryCollect(_player, CollectDistance);
continue;
}
@@ -72,7 +64,7 @@ namespace SepCore.Components
if (exp != null && exp.Available)
{
AbsorbDrop(exp.CachedTransform, elapseSeconds);
exp.TryCollect(_player, _collectDistance);
exp.TryCollect(_player, CollectDistance);
}
}
}
@@ -93,8 +85,7 @@ namespace SepCore.Components
private void AbsorbDrop(Transform drop, float deltaTime)
{
if (drop == null || _target == null) return;
drop.position = Vector3.MoveTowards(drop.position, _target.position, _absorbSpeed * deltaTime);
drop.position = Vector3.MoveTowards(drop.position, _target.position, AbsorbSpeed * deltaTime);
}
}
}