1
This commit is contained in:
59
Assets/Artists/Scripts/Equip/AIGunController.cs
Normal file
59
Assets/Artists/Scripts/Equip/AIGunController.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using BITFALL.Bullet;
|
||||
using BITFALL.Entities.Equipment;
|
||||
using BITKit;
|
||||
using BITKit.Entities;
|
||||
using BITKit.StateMachine;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BITFALL.Guns
|
||||
{
|
||||
public class AIGunController : AIEquipController
|
||||
{
|
||||
[SerializeField] private Transform firePoint;
|
||||
[SerializeReference,SubclassSelector] private IBulletService bulletService;
|
||||
[SerializeField] private bool forceFire;
|
||||
private AssetableGun _gun=>assetableItem as AssetableGun;
|
||||
|
||||
private readonly IntervalUpdate fireInterval = new();
|
||||
|
||||
public override void Entry()
|
||||
{
|
||||
base.Entry();
|
||||
fireInterval.Interval = _gun.FireMode.FireRate is 0 ? 1 : 1f/_gun.FireMode.FireRate;
|
||||
UnityEntity.AddListener<BITConstant.Command.AttackCommand>(OnAttack);
|
||||
}
|
||||
public override void Exit()
|
||||
{
|
||||
base.Exit();
|
||||
UnityEntity.RemoveListener<BITConstant.Command.AttackCommand>(OnAttack);
|
||||
}
|
||||
|
||||
public override void OnUpdate(float deltaTime)
|
||||
{
|
||||
if (forceFire && fireInterval.AllowUpdate)
|
||||
{
|
||||
OnAttack(new BITConstant.Command.AttackCommand());
|
||||
}
|
||||
}
|
||||
|
||||
private void OnAttack(BITConstant.Command.AttackCommand obj)
|
||||
{
|
||||
bulletService.Spawn(new SpawnBullet()
|
||||
{
|
||||
forward = firePoint.forward,
|
||||
initialDamage = _gun.InitialDamage,
|
||||
initiator = Entity.Id,
|
||||
pos = firePoint.position,
|
||||
rot = firePoint.rotation,
|
||||
startSpeed = _gun.InitialBulletSpeed,
|
||||
InitialForce = _gun.InitialBulletForce,
|
||||
});
|
||||
UnityEntity.Invoke(Constant.Animation.Play, BITConstant.Player.Fire);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user