This commit is contained in:
CortexCore
2024-03-24 02:05:16 +08:00
parent bfc869d19e
commit 65d90d1bfa
48 changed files with 7433 additions and 7600 deletions

View File

@@ -29,6 +29,8 @@ namespace BITKit.Entities
{
public const string C_Weapon = "c_weapon";
public string[] SearchKey { get; set; }
[Header(Constant.Header.Settings)]
[SerializeField] protected AssetableItem item;
@@ -77,6 +79,13 @@ namespace BITKit.Entities
[Inject] protected IEntityOverride _entityOverride;
[Inject(true)] protected IEntityInventory _inventory;
[Inject(true)] protected IUXPopup _uxPopup;
public override void Initialize()
{
SearchKey = new []{C_Weapon,item.Name};
base.Initialize();
}
public virtual void Entry()
{
if (animancerComponent)
@@ -125,6 +134,8 @@ namespace BITKit.Entities
public virtual void OnAwake()
{
AnimationProperties= animationProperties.ToDictionary(x=>x.Key,x=>x.Value.Value);
foreach (var x in StateDictionary.Values)

View File

@@ -33,7 +33,6 @@ namespace BITFALL.Guns
protected AnimancerComponent animancerComponent=>root.AnimancerComponent;
public bool Enabled { get;set; }
protected string[] SearchKey;
protected string[] AnimationKey;
protected bool PlayAnimation(params string[] args)
{
@@ -69,8 +68,8 @@ namespace BITFALL.Guns
{
root.Entity.Inject(this);
_entityMovement.OnStateChanged += OnMovementStateChanged;
AnimationKey = new []{BITGun.C_Weapon,GetType().Name,root._gun.Name};
SearchKey = new []{BITGun.C_Weapon,GetType().Name};
// AnimationKey = new []{BITGun.C_Weapon,GetType().Name,root._gun.Name};
AnimationKey = root.SearchKey.Append(GetType().Name).ToArray();
}
public virtual void OnStateEntry(IState old)
@@ -169,13 +168,20 @@ namespace BITFALL.Guns
public override string AddressablePath => _gun.AddressablePath;
#endregion
private LinearMixerState walkState;
private AnimancerState jumpState;
public override void OnAwake()
{
base.OnAwake();
AnimancerComponent.Layers[3].IsAdditive = true;
AnimancerComponent.Layers[2].IsAdditive = true;
AnimancerComponent.Layers[4].IsAdditive = true;
if (breathingAdditive.Allow)
inputActionGroup.RegisterCallback(steadyAimAction, OnSteadyAim);
_movement.OnStateChanged += OnMovementStateChanged;
BITAppForUnity.AllowCursor.AddListener(OnAllowCursor);
destroyCancellationToken.Register(() => { BITAppForUnity.AllowCursor.RemoveListener(OnAllowCursor); });
@@ -201,15 +207,31 @@ namespace BITFALL.Guns
}
}
// private void OnMovementCommand(object obj)
// {
// switch (obj)
// {
// case OnPlayerJumpCommand:
// animator.Play("Jump");
// break;
// }
// }
private void OnMovementCommand(object obj)
{
switch (obj)
{
case OnPlayerJumpCommand when
MotionMatchingService.TryMatch(out var jump ,SearchKey.Append("Jump").ToArray())
&& jump is IMotionMatchingClip jumpMotion
:
jumpState?.Stop();
jumpState = AnimancerComponent.Layers[4].Play(jumpMotion.Clip);
break;
case OnPlayerLandCommand when
MotionMatchingService.TryMatch(out var land ,SearchKey.Append("Land").ToArray())
&& land is IMotionMatchingClip landMotion
:
jumpState?.Stop();
jumpState = AnimancerComponent.Layers[4].Play(landMotion.Clip,0.1f);
jumpState.Events.OnEnd = () =>
{
jumpState.Events.OnEnd = null;
jumpState.StartFade(0);
};
break;
}
}
private void OnMelee(InputAction.CallbackContext obj)
{
@@ -261,6 +283,25 @@ namespace BITFALL.Guns
inputActionGroup.RegisterCallback(meleeAction, OnMelee);
TransitionState<Equip>();
if (MotionMatchingService.TryMatch(out var walkMotion, SearchKey.Append(BITConstant.Player.Walk).ToArray())
&&
MotionMatchingService.TryMatch(out var movementMotion, SearchKey.Append(BITConstant.Player.Movement).ToArray()))
{
if (walkMotion is IMotionMatchingClip walkClip && movementMotion is IMotionMatchingClip movementClip)
{
walkState = new LinearMixerState
{
{ movementClip.Clip, 0 },
{ walkClip.Clip, 1 }
};
AnimancerComponent.Layers[2].Play(walkState);
//walkState = AnimancerComponent.Layers[2].Play(walkClip.Clip);
}
}
_movement.OnStateChanged += OnMovementStateChanged;
_movement.OnCommand += OnMovementCommand;
}
private bool IsClipReady(IBasicItem clip)
@@ -292,6 +333,9 @@ namespace BITFALL.Guns
inputActionGroup.UnRegisterCallback(aimAction, OnAim);
inputActionGroup.UnRegisterCallback(reloadAction, OnReload);
inputActionGroup.UnRegisterCallback(meleeAction, OnMelee);
_movement.OnStateChanged -= OnMovementStateChanged;
_movement.OnCommand -= OnMovementCommand;
}
public override UniTask EntryAsync()
@@ -408,11 +452,19 @@ namespace BITFALL.Guns
// length / _movement.ReferenceSpeed,0.1f,1
// )
// );
if (walkState is not null)
{
var value = Mathf.Clamp(
length / _movement.ReferenceSpeed, 0, 1
);
walkState.Parameter = value;
}
recoilSpring.Update(deltaTime,default);
if (_gun.TryGetProperty<IRecoil>(out var recoil))
if (_gun.TryGetProperty<IRecoil>(out var recoil) && locationAdditive)
{
//locationAdditive.AddEuler(Vector3.Scale(recoilSpring.value,recoil.ViewRecoilScale) );
locationAdditive.AddRotation(Quaternion.Euler(Vector3.Scale(recoilSpring.value,recoil.ViewRecoilScale)));
@@ -598,6 +650,22 @@ namespace BITFALL.Guns
//播放射击动画
//UnityEntity.Invoke(Constant.Animation.Play, BITConstant.Player.Fire);
if (MotionMatchingService.TryMatch(out var motion, SearchKey.Append(
CurrentState is Aim ? BITConstant.Player.AimFire : BITConstant.Player.Fire
).ToArray()))
{
if (motion is IMotionMatchingClip fireClip)
{
AnimancerComponent.Layers[3].Stop();
var state =AnimancerComponent.Layers[3].Play(fireClip.Clip);
state.Events.OnEnd = () =>
{
state.Events.OnEnd = null;
};
}
}
if (_gun.BuckShot.Allow)
{
InternalAddRecoil();

View File

@@ -29,6 +29,8 @@ namespace BITFALL.Guns.States
private bool boltActionImmediately;
private AnimancerState inspectState;
private AnimancerState crouchState;
public override void OnStateEntry(IState old)
{
switch (old)
@@ -38,6 +40,7 @@ namespace BITFALL.Guns.States
break;
default:
PlayAnimation();
OnMovementStateChanged(null, _entityMovement.CurrentState);
break;
}
_selector.OnActive += OnActive;
@@ -113,7 +116,7 @@ namespace BITFALL.Guns.States
public void OnActive(ISelectable selectable)
{
//root.animator.Play(BITConstant.Player.Interactive);
PlayAnimation(SearchKey.Append(nameof(BITConstant.Player.Interactive)).ToArray());
PlayAnimation(root.SearchKey.Append(nameof(BITConstant.Player.Interactive)).ToArray());
}
public override void OnMovementStateChanged(IEntityMovementState old, IEntityMovementState newState)
{
@@ -121,11 +124,22 @@ namespace BITFALL.Guns.States
if (newState is IPlayerSlideState)
{
root.TransitionState<Movement>();
PlayAnimation(SearchKey.Append(nameof(BITConstant.Player.Slide)).ToArray());
PlayAnimation(root.SearchKey.Append(nameof(BITConstant.Player.Slide)).ToArray());
//root.animator.CrossFade(BITConstant.Player.Slide, 0.32f);
}else if (Enabled && newState is IPlayerDodgeState)
}else if (newState is IPlayerDodgeState)
{
PlayAnimation(SearchKey.Append(nameof(BITConstant.Player.Dodge)).ToArray());
PlayAnimation(root.SearchKey.Append(nameof(BITConstant.Player.Dodge)).ToArray());
}else if (Enabled)
{
switch (newState)
{
case IPlayerCrouchState:
PlayAnimation(root.SearchKey.Append(nameof(BITConstant.Player.Crouch)).ToArray());
break;
case IPlayerMovementState:
PlayAnimation();
break;
}
}
}
}
@@ -136,7 +150,7 @@ namespace BITFALL.Guns.States
private ExpectState<bool> _expectSprint;
public override void OnStateEntry(IState old)
{
PlayAnimation(SearchKey.Append(nameof(BITConstant.Player.Run)).ToArray());
PlayAnimation(root.SearchKey.Append(nameof(BITConstant.Player.Run)).ToArray());
root.inputActionGroup.RegisterCallback(root.aimAction, OnAim);
}
@@ -181,7 +195,7 @@ namespace BITFALL.Guns.States
public override void OnStateEntry(IState old)
{
//root.animator.CrossFade(BITConstant.Player.Sprint, 0.32f);
PlayAnimation(SearchKey.Append(nameof(BITConstant.Player.Sprint)).ToArray());
PlayAnimation(root.SearchKey.Append(nameof(BITConstant.Player.Sprint)).ToArray());
root.inputActionGroup.RegisterCallback(root.aimAction, OnAim);
}
@@ -218,10 +232,10 @@ namespace BITFALL.Guns.States
case IPlayerRunState:
case IPlayerSprintState:
//root.animator.CrossFade(BITConstant.Player.Aim, 0.32f);
PlayAnimation(SearchKey.Append(nameof(BITConstant.Player.Aim)).ToArray());
PlayAnimation(root.SearchKey.Append(nameof(BITConstant.Player.Aim)).ToArray());
break;
default:
PlayAnimation(SearchKey.Append(nameof(BITConstant.Player.Aim)).ToArray());
PlayAnimation(root.SearchKey.Append(nameof(BITConstant.Player.Aim)).ToArray());
break;
}
_entityMovement.ExecuteCommand<PlayerPauseRunCommand>(new(this,true));

View File

@@ -585,6 +585,7 @@ namespace BITFALL.Entities.Player.Movement
var value = currentGravity.y;
//Debug.Log($"Vector:{currentVelocity}\tMagnitude:{value}\tGravity:{currentGravity}");
//Debug.Log(value);
OnCommand?.Invoke(new OnPlayerLandCommand());
switch (value)
{
case > 0:
@@ -609,6 +610,7 @@ namespace BITFALL.Entities.Player.Movement
if (actor.IsGrounded is false && actor.IsStable is false)
{
landFreeze.Reset();
}
}