Attack animation, colliders, triggering

This commit is contained in:
ThomasCharester committed 2026-10-25 19:14:56 +03:00
1 parent 3e631899ea
commit e61fcb78cf
94 files changed
+142319 -25861

No files matched your search

@@ -0,0 +1,27 @@
using Code.Infrastructure.Generators;
using Code.OfficeGame.BattleMode.HitBoxes;
using UnityEngine;
namespace Code.OfficeGame.BattleMode.Actions.Attacks
{
[Config("Configs/AttackAction", true)]
[CreateAssetMenu(fileName = "AttackActionConfig", menuName = "Configs/AttackAction")]
public class AttackActionConfig : ScriptableObject
{
public BattleActionType ActionType;
public AnimationClip AnimationClip;
public int StateHash => Animator.StringToHash(AnimationClip.name);
public int TotalFrames;
public int HitboxStartFrame;
public int HitboxEndFrame;
public HitBoxPartType AttackingBodyPart;
public int Damage;
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 6d47fdf0c6f444c087bcc6f2492746af
timeCreated: 1792938807
@@ -0,0 +1,76 @@
using System.Linq;
using Code.Infrastructure.Utils;
using Code.OfficeGame.BattleMode.HitBoxes;
using Cysharp.Threading.Tasks;
using Reflex.Attributes;
using UnityEngine;
namespace Code.OfficeGame.BattleMode.Actions.Attacks
{
public class BattleActionPlayerAttackMMA : BattleAction
{
private Animator _animator;
private EntityHitBoxes _entityHitBoxes;
private AttackActionConfig _attackData;
public int EntryStateHash => Animator.StringToHash("WalkBlend");
private int _currentFrame;
[Inject]
public void Construct(MultipleConfig<AttackActionConfig> attackData)
{
_animator = GetComponentInChildren<Animator>();
_entityHitBoxes = GetComponent<EntityHitBoxes>();
_attackData = attackData.Configs.SingleOrDefault(x=>x.ActionType == ActionType);
}
public override async UniTask<BattleActionDecisionResultCode> DecideAction()
{
_currentFrame = 0;
Finished = false;
return BattleActionDecisionResultCode.Decided;
}
public override BattleActionType ActionType => BattleActionType.PlayerAttackMMA;
public override void Tick(float tickDelta)
{
if (Finished) return;
if (_currentFrame == 0)
{
_animator.Play(_attackData.StateHash, 0, 0f);
}
_currentFrame++;
if (_currentFrame >= _attackData.HitboxStartFrame && _currentFrame <= _attackData.HitboxEndFrame)
{
_entityHitBoxes.EnableHitbox(_attackData.AttackingBodyPart);
_entityHitBoxes.CheckHitsForCurrentFrame(OnEnemyHit);
}
else
{
_entityHitBoxes.DisableAllHitboxes();
}
if (_currentFrame >= _attackData.TotalFrames)
{
CompleteOrInterruptAction();
}
}
private void OnEnemyHit(Collider enemyCollider)
{
Debug.Log($"Попадание в {enemyCollider.name} на {_currentFrame}-м кадре! Урон: {_attackData.Damage}");
}
public void CompleteOrInterruptAction()
{
_animator.Play(EntryStateHash, 0, 0f); // Создать None State и кинуть эту штуку туда
_entityHitBoxes.DisableAllHitboxes();
Finished = true;
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a1803413768b4cf990d25732721300ea
timeCreated: 1792938407