1
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "BITFALL.Entities.Animation",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:14fe60d984bf9f84eac55c6ea033a8f4",
|
||||
"GUID:709caf8d7fb6ef24bbba0ab9962a3ad0",
|
||||
"GUID:84d565da37ad40546a118cfb3c3509f3",
|
||||
"GUID:d525ad6bd40672747bde77962f1c401e",
|
||||
"GUID:49b49c76ee64f6b41bf28ef951cb0e50",
|
||||
"GUID:677cd05ca06c46b4395470200b1acdad"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
@@ -1,18 +1,48 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using AYellowpaper.SerializedCollections;
|
||||
using BITFALL.Entities.Equipment;
|
||||
using BITKit.Animations;
|
||||
using UnityEngine;
|
||||
|
||||
public class EntitiesAnimationController : MonoBehaviour
|
||||
namespace BITKit.Entities.Animation
|
||||
{
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
public sealed class EntitiesAnimationController : EntityComponent
|
||||
{
|
||||
[SerializeField] private UnityAnimator unityAnimator;
|
||||
[SerializeField] private SerializedDictionary<string, RuntimeAnimatorController> animatorControllers;
|
||||
[Inject]
|
||||
private IEntityEquipment _entityEquipment;
|
||||
|
||||
private RuntimeAnimatorController _initialRuntimeAnimatorController;
|
||||
|
||||
private readonly DoubleBuffer<RuntimeAnimatorController> _runtimeAnimatorControllerBuffer = new();
|
||||
public override void OnAwake()
|
||||
{
|
||||
base.OnAwake();
|
||||
_entityEquipment.OnEquip += OnEquip;
|
||||
_initialRuntimeAnimatorController = unityAnimator.animator.runtimeAnimatorController;
|
||||
}
|
||||
|
||||
public override void OnLateUpdate(float deltaTime)
|
||||
{
|
||||
if(_runtimeAnimatorControllerBuffer.TryGetRelease(out var controller))
|
||||
{
|
||||
unityAnimator.animator.runtimeAnimatorController = controller;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEquip(IBasicItem obj)
|
||||
{
|
||||
if(animatorControllers.TryGetValue(obj.AddressablePath, out var controller))
|
||||
{
|
||||
_runtimeAnimatorControllerBuffer.Release(controller);
|
||||
}
|
||||
else
|
||||
{
|
||||
_runtimeAnimatorControllerBuffer.Release(_initialRuntimeAnimatorController);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -278,6 +278,7 @@ namespace BITFALL.Entities.Equipment
|
||||
|
||||
private void Equip(IBasicItem item)
|
||||
{
|
||||
|
||||
_equipment.EntryEquip(item);
|
||||
currentEquip = item;
|
||||
}
|
||||
@@ -296,6 +297,7 @@ namespace BITFALL.Entities.Equipment
|
||||
{
|
||||
if (!_equipmentContainer.Equipment.TryGetAny(x => x.Key is T, out var item)) return false;
|
||||
//if (!_inventory.TryUseItem(item.Value)) return false;
|
||||
_improvisedService.TryUnEquipImprovised(out _);
|
||||
Equip(item.Value);
|
||||
return true;
|
||||
}
|
||||
|
@@ -16,7 +16,9 @@
|
||||
"GUID:30cdc242b1ac6a944a460f4ab0b77b88",
|
||||
"GUID:7efac18f239530141802fb139776f333",
|
||||
"GUID:ef0bb553b58b90b488bdbe8672e3be0b",
|
||||
"GUID:48ef04d98836e2640bf90b524bdff904"
|
||||
"GUID:48ef04d98836e2640bf90b524bdff904",
|
||||
"GUID:1eb13dc7c3cb5a444877a995967ed591",
|
||||
"GUID:ea5474181b324dd49a5976cd68f44f18"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
|
@@ -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));
|
||||
|
@@ -53,6 +53,10 @@ namespace BITFALL.Entities.Improvised
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (TryGetImprovisedItem(out var current))
|
||||
{
|
||||
TryUnEquipImprovised(out _);
|
||||
}
|
||||
_improvisedItem = weapon;
|
||||
OnEquipImprovisedItem?.Invoke(weapon);
|
||||
return true;
|
||||
|
@@ -16,7 +16,7 @@ namespace BITFALL
|
||||
{
|
||||
[CustomType(typeof(IEntityInventory))]
|
||||
[CustomType(typeof(IBasicItemContainer))]
|
||||
public abstract class EntityInventory : EntityComponent, IEntityInventory,IBasicItemContainer
|
||||
public class EntityInventory : EntityComponent, IEntityInventory
|
||||
{
|
||||
/// <summary>
|
||||
/// 数据字典
|
||||
|
@@ -41,7 +41,7 @@ namespace BITFALL
|
||||
{
|
||||
if (!obj.Transform.TryGetComponentAny<WorldItem>(out var item)) return;
|
||||
var _item = item.Pick();
|
||||
if(item.GetAssetable().TryGetProperty<Improvisable>(out _))
|
||||
if(item.GetAssetable().IsImprovised)
|
||||
{
|
||||
if (_knockdown is not null && _knockdown.IsKnockdown)
|
||||
{
|
||||
|
@@ -9,72 +9,104 @@ namespace BITFALL
|
||||
{
|
||||
public class EntityPropsDisplay : EntityComponent
|
||||
{
|
||||
[SerializeField] private SerializedDictionary<string, GameObject> equipments = new();
|
||||
[SerializeField] private SerializedDictionary<string, GameObject> unEquipDictionary = new();
|
||||
[SerializeField] private SerializedDictionary<string, GameObject> equipDictionary = new();
|
||||
[SerializeField] private SerializedDictionary<string, GameObject> equipped = new();
|
||||
[SerializeField] private SerializedDictionary<string, GameObject> bodyEquips = new();
|
||||
[SerializeField] private SerializedDictionary<string, GameObject> holsteredEquips = new();
|
||||
|
||||
[Inject] private IEntityEquipment _entityEquipment;
|
||||
[Inject] private IEntityEquipmentContainer _playerEquipContainer;
|
||||
[Inject] private IPlayerEquipSelector _playerEquipSelector;
|
||||
[Inject(true)] private IEntityEquipment _entityEquipment;
|
||||
[Inject(true)] private IEntityEquipmentContainer _playerEquipContainer;
|
||||
[Inject(true)] private IPlayerEquipSelector _playerEquipSelector;
|
||||
|
||||
public override void OnStart()
|
||||
{
|
||||
_playerEquipContainer.OnEquip += OnEquip;
|
||||
_playerEquipContainer.OnDeEquip += OnDeEquip;
|
||||
if (_entityEquipment is not null)
|
||||
{
|
||||
_entityEquipment.OnEquip += OnEquippedEquip;
|
||||
_entityEquipment.OnUnEquip += OnEquippedUnEquip;
|
||||
_entityEquipment.OnEquipAddressable+=OnEquippedEquipAddressable;
|
||||
_entityEquipment.OnUnEquipAddressable+=OnUnEquippedEquipAddressable;
|
||||
}
|
||||
|
||||
if (_playerEquipSelector is not null)
|
||||
{
|
||||
_playerEquipSelector.OnUpdateEquip += OnUpdateHolsteredEquip;
|
||||
}
|
||||
|
||||
_entityEquipment.OnEquip += OnEquip;
|
||||
_entityEquipment.OnDeEquip += OnDeEquip;
|
||||
_playerEquipSelector.OnUpdateEquip += OnUpdateEquip;
|
||||
if (_playerEquipContainer is not null)
|
||||
{
|
||||
_playerEquipContainer.OnEquip += OnEquipBodyEquip;
|
||||
_playerEquipContainer.OnDeEquip += OnUnEquipBodyEquip;
|
||||
}
|
||||
|
||||
foreach (var x in equipments)
|
||||
foreach (var x in equipped)
|
||||
{
|
||||
x.Value.SetActive(false);
|
||||
}
|
||||
foreach (var x in unEquipDictionary)
|
||||
foreach (var x in bodyEquips)
|
||||
{
|
||||
x.Value.SetActive(false);
|
||||
}
|
||||
foreach (var x in equipDictionary)
|
||||
foreach (var x in holsteredEquips)
|
||||
{
|
||||
x.Value.SetActive(false);
|
||||
}
|
||||
}
|
||||
private void OnDeEquip(IEquipmentSlot slot, IBasicItem item)
|
||||
|
||||
private void OnUnEquippedEquipAddressable(string obj)
|
||||
{
|
||||
var asset = item.GetAssetable();
|
||||
if (equipments.TryGetValue(asset.AddressablePath, out GameObject prop))
|
||||
if (string.IsNullOrEmpty(obj) is false && equipped.TryGetValue(obj, out var go))
|
||||
{
|
||||
prop.SetActive(false);
|
||||
go.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEquip(IEquipmentSlot slot, IBasicItem item)
|
||||
private void OnEquippedEquipAddressable(string obj)
|
||||
{
|
||||
var asset = item.GetAssetable();
|
||||
if(equipments.TryGetValue(asset.AddressablePath, out GameObject prop)) {
|
||||
prop.SetActive(true);
|
||||
if (string.IsNullOrEmpty(obj) is false && equipped.TryGetValue(obj, out var go))
|
||||
{
|
||||
go.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEquip(IBasicItem item)
|
||||
private void OnUnEquipBodyEquip(IEquipmentSlot arg1, IBasicItem arg2)
|
||||
{
|
||||
if(item is null) return;
|
||||
if (equipDictionary.TryGetValue(item.AddressablePath, out var model))
|
||||
if (bodyEquips.TryGetValue(arg2.AddressablePath, out var go))
|
||||
{
|
||||
model.SetActive(true);
|
||||
go.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDeEquip(IBasicItem item)
|
||||
private void OnEquipBodyEquip(IEquipmentSlot arg1, IBasicItem arg2)
|
||||
{
|
||||
foreach (var x in equipDictionary)
|
||||
if (bodyEquips.TryGetValue(arg2.AddressablePath, out var go))
|
||||
{
|
||||
x.Value.gameObject.SetActive(false);
|
||||
go.SetActive(true);
|
||||
}
|
||||
}
|
||||
private void OnUpdateEquip(IDictionary<int, IBasicItem> maps)
|
||||
|
||||
private void OnUpdateHolsteredEquip(IDictionary<int, IBasicItem> obj)
|
||||
{
|
||||
|
||||
foreach (var x in holsteredEquips)
|
||||
{
|
||||
x.Value.SetActive(false);
|
||||
}
|
||||
foreach (var x in obj)
|
||||
{
|
||||
if (holsteredEquips.TryGetValue(x.Value.AddressablePath, out var go))
|
||||
{
|
||||
go.SetActive(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEquippedUnEquip(IBasicItem obj)
|
||||
{
|
||||
OnUnEquippedEquipAddressable(obj?.AddressablePath);
|
||||
}
|
||||
|
||||
private void OnEquippedEquip(IBasicItem obj)
|
||||
{
|
||||
OnEquippedEquipAddressable(obj?.AddressablePath);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user