1
This commit is contained in:
@@ -6,10 +6,12 @@ using BITKit;
|
||||
using BITKit.Animations;
|
||||
using BITKit.StateMachine;
|
||||
using System.Linq;
|
||||
using System.Security.Permissions;
|
||||
using BITFALL;
|
||||
using BITFALL.Entities.Equipment;
|
||||
using BITFALL.Player.Equip;
|
||||
using BITKit.Entities.Melee;
|
||||
using BITKit.Entities.VFX;
|
||||
using Cinemachine;
|
||||
using Cysharp.Threading.Tasks;
|
||||
|
||||
@@ -22,7 +24,9 @@ namespace BITKit.Entities
|
||||
[SerializeField] protected AssetableItem item;
|
||||
|
||||
[Header(Constant.Header.Components)]
|
||||
public UnityAnimator animator;
|
||||
[SerializeField] public UnityAnimator animator;
|
||||
[SerializeField] protected EntityVFXPlayer vfxPlayer;
|
||||
[SerializeField] protected EntityAnimator entityAnimator;
|
||||
[SerializeField] private Renderer[] renderers;
|
||||
[SerializeField] protected Transform cameraTransform;
|
||||
|
||||
@@ -30,6 +34,7 @@ namespace BITKit.Entities
|
||||
[SerializeReference,SubclassSelector] protected IMeleeService meleeService;
|
||||
|
||||
public Core.Entites.IEntity Entity { get; set; }
|
||||
public Entity UnityEntity=>Entity as Entity;
|
||||
public IBasicItem Item { get; set; }
|
||||
|
||||
public readonly InputActionGroup inputActionGroup = new()
|
||||
@@ -46,14 +51,29 @@ namespace BITKit.Entities
|
||||
{
|
||||
AllowRendering.AddElement(this);
|
||||
inputActionGroup.allowInput.AddElement(this);
|
||||
|
||||
if (entityAnimator)
|
||||
entityAnimator.enabled = true;
|
||||
if (vfxPlayer)
|
||||
vfxPlayer.enabled = true;
|
||||
|
||||
var animName = animator.animator.GetCurrentAnimatorStateInfo(0).shortNameHash;
|
||||
animator.animator.Play(animName, -1, 0);
|
||||
}
|
||||
|
||||
public virtual UniTask EntryAsync()
|
||||
{
|
||||
|
||||
return UniTask.CompletedTask;
|
||||
}
|
||||
|
||||
public virtual void Exit()
|
||||
{
|
||||
if (entityAnimator)
|
||||
entityAnimator.enabled = false;
|
||||
if (vfxPlayer)
|
||||
vfxPlayer.enabled = false;
|
||||
|
||||
inputActionGroup.allowInput.RemoveElement(this);
|
||||
}
|
||||
public virtual UniTask ExitAsync()
|
||||
@@ -126,33 +146,54 @@ namespace BITKit.Entities
|
||||
[CustomType(typeof(IEntityEquipment))]
|
||||
public class EntityEquipment : EntityComponent,IEquipService,IEntityEquipment
|
||||
{
|
||||
public EntryGroup<IEquipBase> equips = new();
|
||||
public IOptional<float> Zoom { get; } = new Optional<float>(){Value = 1};
|
||||
|
||||
public float InitialFov;
|
||||
|
||||
[SerializeField] private CinemachineVirtualCamera virtualCamera;
|
||||
|
||||
[SerializeField] private Optional<int> overrideIndex;
|
||||
|
||||
public event Action<IBasicItem> OnEquip;
|
||||
public event Action<IBasicItem> OnDeEquip;
|
||||
|
||||
public event Action<IBasicItem> OnUnEquip;
|
||||
public event Action<string> OnEquipAddressable;
|
||||
public event Action<string> OnUnEquipAddressable;
|
||||
|
||||
private readonly EntryGroup<IEquipBase> equips = new();
|
||||
protected IEquipBase entryComplete;
|
||||
private PlayerConfig playerConfig;
|
||||
|
||||
private IBasicItem _currentItem;
|
||||
public override void OnStart()
|
||||
|
||||
[Inject(true)] private IHealth _health;
|
||||
public override void OnAwake()
|
||||
{
|
||||
base.OnStart();
|
||||
base.OnAwake();
|
||||
equips.list = GetComponentsInChildren<IEquipBase>(true).ToList();
|
||||
|
||||
equips.OnEntry += OnEntry;
|
||||
equips.OnExit += OnExit;
|
||||
|
||||
|
||||
if (_health is not null)
|
||||
{
|
||||
_health.OnSetAlive += x =>
|
||||
{
|
||||
if (x is false)
|
||||
EntryEquip(-1);
|
||||
};
|
||||
}
|
||||
|
||||
foreach (var x in equips.list)
|
||||
{
|
||||
x.Entity = entity;
|
||||
x.OnAwake();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public override void OnStart()
|
||||
{
|
||||
base.OnStart();
|
||||
foreach (var x in equips.list)
|
||||
{
|
||||
x.OnStart();
|
||||
@@ -161,14 +202,18 @@ namespace BITKit.Entities
|
||||
|
||||
private void OnExit(IEquipBase obj)
|
||||
{
|
||||
OnUnEquipAddressable?.Invoke(obj.AddressablePath);
|
||||
OnUnEquip?.Invoke(obj.Item);
|
||||
//Debug.Log($"已退出:{obj.Item.Name}");
|
||||
obj.Item = null;
|
||||
OnDeEquip?.Invoke(obj.Item);
|
||||
}
|
||||
|
||||
private void OnEntry(IEquipBase obj)
|
||||
{
|
||||
OnEquipAddressable?.Invoke(obj.AddressablePath);
|
||||
obj.Item = _currentItem;
|
||||
OnEquip?.Invoke(obj.Item);
|
||||
//Debug.Log($"已进入:{obj.Item.Name}");
|
||||
}
|
||||
|
||||
public override void OnUpdate(float deltaTime)
|
||||
@@ -185,6 +230,11 @@ namespace BITKit.Entities
|
||||
current = Mathf.Clamp(current, 10, PlayerConfig.Singleton.Fov);
|
||||
virtualCamera.m_Lens.FieldOfView = current;
|
||||
}
|
||||
|
||||
if (overrideIndex.Allow && (_health?.IsAlive ?? true))
|
||||
{
|
||||
EntryEquip(overrideIndex.Value);
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsSupportItem(IBasicItem item)=> equips.list.Any(x => x.IsSupportItem(item));
|
||||
|
Reference in New Issue
Block a user