This commit is contained in:
CortexCore
2023-10-29 15:27:13 +08:00
parent c5f638d9d2
commit c7b6ddbf70
73 changed files with 2158 additions and 494 deletions

View File

@@ -0,0 +1,58 @@
using System.Collections;
using System.Collections.Generic;using BITFALL.Entities.Equipment;
using BITKit;
using BITKit.Entities;
using Cysharp.Threading.Tasks;
using UnityEngine;
using IEntity = BITKit.Core.Entites.IEntity;
namespace BITFALL.Entities.Equipment
{
public class AIEquipController : MonoBehaviour,IEquipBase
{
[SerializeField] protected AssetableItem assetableItem;
public bool IsEntered { get; set; }
public virtual void Entry()
{
}
public virtual UniTask EntryAsync()
{
return UniTask.CompletedTask;
}
public virtual void Exit()
{
}
public virtual UniTask ExitAsync()
{
return UniTask.CompletedTask;
}
public virtual void OnAwake()
{
}
public virtual void OnStart()
{
}
public virtual void OnUpdate(float deltaTime)
{
}
public string AddressablePath => assetableItem.AddressablePath;
public IEntity Entity { get; set; }
public Entity UnityEntity=>Entity as Entity;
public IBasicItem Item { get; set; }
public bool IsSupportItem(IBasicItem item) => item?.AddressablePath == AddressablePath;
public void PlayAudio(string name)
{
}
}
}

View 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);
}
}
}

View File

@@ -0,0 +1,42 @@
using System.Collections;
using System.Collections.Generic;
using BITFALL.Bullet;
using BITFALL.Guns;
using BITKit;
using BITKit.Entities.Melee;
using UnityEngine;
namespace BITFALL.Entities.Equipment
{
public class AIMeleeController : AIEquipController
{
[SerializeReference,SubclassSelector] private IMeleeService meleeService;
[SerializeField] private bool forceAttack;
private readonly IntervalUpdate interval = new(1);
public override void Entry()
{
base.Entry();
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 (forceAttack && interval.AllowUpdate)
{
OnAttack(new BITConstant.Command.AttackCommand());
}
}
private void OnAttack(BITConstant.Command.AttackCommand obj)
{
UnityEntity.Invoke(Constant.Animation.Play, BITConstant.Player.Melee);
}
}
}

View File

@@ -26,7 +26,8 @@
"GUID:42a9827d94e00374aa52e51f0a1b035c",
"GUID:87bea3a21c744b1478660b70494160ba",
"GUID:ef0bb553b58b90b488bdbe8672e3be0b",
"GUID:48ef04d98836e2640bf90b524bdff904"
"GUID:48ef04d98836e2640bf90b524bdff904",
"GUID:1eb13dc7c3cb5a444877a995967ed591"
],
"includePlatforms": [],
"excludePlatforms": [],

View File

@@ -74,7 +74,6 @@ namespace BITFALL.Guns
[SerializeField] private Transform cameraView;
// 引用组件
[Header(Constant.Header.Components)]
[SerializeField] private VFXPlayer vfxPlayer;
[SerializeField] private LocationAdditive locationAdditive;
// 引用预制体
@@ -163,8 +162,6 @@ namespace BITFALL.Guns
base.EntryAsync();
isHolstered = false;
var animName = animator.animator.GetCurrentAnimatorStateInfo(0).shortNameHash;
animator.animator.Play(animName,-1,0);
inputActionGroup.allowInput.AddElement(this);
expectFiring.Reset();
Enabled = true;
@@ -260,7 +257,7 @@ namespace BITFALL.Guns
}
//播放射击动画
animator.Play(BITConstant.Player.Fire);
UnityEntity.Invoke(Constant.Animation.Play, BITConstant.Player.Fire);
//调用BulletManager生成子弹
var _transform = transform;
@@ -275,9 +272,6 @@ namespace BITFALL.Guns
InitialForce = _gun.InitialBulletForce,
});
//播放枪口MuzzleFlash
vfxPlayer.Execute();
//开火模式逻辑判断
switch (assetable.FireMode)
{

View File

@@ -260,7 +260,8 @@ namespace BITFALL.Guns.States
base.OnStateEntry(old);
_entityMovement.ExecuteCommand<PlayerCancelRunCommand>();
root.animator.Play(BITConstant.Player.Reload);
root.UnityEntity.Invoke(Constant.Animation.Play, BITConstant.Player.Reload);
}
public override void OnMovementStateChanged(IEntityMovementState old, IEntityMovementState newState)
{

View File

@@ -58,16 +58,27 @@ namespace BITFALL.Entities.Equipment.Melee
[Inject]
private IEntityMovement _movement;
[Inject]
[Inject(true)]
private IPlayerMovement _playerMovement;
[Inject] private IHealth _health;
public override void OnAwake()
{
base.OnAwake();
inputActionGroup.RegisterCallback(attackAction, OnAttack);
inputActionGroup.RegisterCallback(blockAction, OnBlock);
_health.OnDamageFactory += OnDamageFactory;
if (attackAction is not null)
{
inputActionGroup.RegisterCallback(attackAction, OnAttack);
}
if (blockAction is not null)
{
inputActionGroup.RegisterCallback(blockAction, OnBlock);
}
if (_playerMovement is not null)
_health.OnDamageFactory += OnDamageFactory;
_movement.OnStateChanged += OnMovementStateChanged;
}

View File

@@ -24,7 +24,7 @@ namespace BITFALL.Player.Equip
public void OnAwake()
{
_entityEquipment.OnEquip += OnEquip;
_entityEquipment.OnDeEquip += OnDeEquip;
_entityEquipment.OnUnEquip += OnUnEquip;
}
public void OnStart()
{
@@ -58,7 +58,7 @@ namespace BITFALL.Player.Equip
{
return UniTask.CompletedTask;
}
private void OnDeEquip(IBasicItem obj)
private void OnUnEquip(IBasicItem obj)
{
foreach (var x in modelDictionary.Values)
{

View File

@@ -80,10 +80,10 @@ namespace BITFALL.Throws
if (IsEntered is false) return;
if (eventName is not BITConstant.Player.Throw) return;
if (!_equipmentContainer.TryUseEquip<EquipmentAsThrow>()) return;
var instance = _assetableThrow.GetInstance();
var instance =Instantiate(_assetableThrow.Prefab,
throwPoint.position + throwPoint.forward * 0.016f,
throwPoint.rotation) ;
if (!instance.TryGetComponent<Rigidbody>(out var _rigidbody)) return;
_rigidbody.rotation = throwPoint.rotation;
_rigidbody.position = throwPoint.position;
_rigidbody.AddForce(throwPoint.forward * throwForce, ForceMode.VelocityChange);
}
}