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

@@ -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();