1
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Animancer;
|
||||
using BITFALL.Entities.Equipment;
|
||||
using BITFALL.Guns.Modify;
|
||||
using BITFALL.Guns.States;
|
||||
using BITFALL.Player.Equip;
|
||||
@@ -37,64 +38,58 @@ namespace BITFALL.Guns
|
||||
protected AnimancerState currentState;
|
||||
|
||||
protected string[] AnimationKey;
|
||||
protected bool PlayAnimation(params string[] args)
|
||||
{
|
||||
if (root.MotionMatchingService.TryMatch(out var obj,root.SearchKey.Union(args).ToArray()) is false) return false;
|
||||
switch (obj)
|
||||
{
|
||||
case IMotionMatchingClip clip:
|
||||
currentState = animancerComponent.Play(clip.Clip,0.1f);
|
||||
return true;
|
||||
case IMotionMatchingSequence sequence:
|
||||
return true;
|
||||
case IMotionMatchingDualClip dualClip:
|
||||
currentState = animancerComponent.Play(dualClip.Clip1,0.1f);
|
||||
if (root.AdditionalAnimancerComponent)
|
||||
{
|
||||
root.AdditionalAnimancerComponent.Stop();
|
||||
var state2 = root.AdditionalAnimancerComponent.Play(dualClip.Clip2,0.1f);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void PlayAnimation(Action OnEnd = null)
|
||||
protected AnimancerState PlayAnimation(params string[] args)
|
||||
{
|
||||
if (root.MotionMatchingService.TryMatch(out var obj,AnimationKey) is false) return;
|
||||
return PlayAnimation(0,null, args);
|
||||
}
|
||||
protected AnimancerState PlayAnimation(int layer,Action OnEnd,params string[] args)
|
||||
{
|
||||
if (root.MotionMatchingService.TryMatch(out var obj, root.SearchKey.Union(args).ToArray()) is false)
|
||||
return null;
|
||||
switch (obj)
|
||||
{
|
||||
case IMotionMatchingClip clip:
|
||||
currentState = animancerComponent.Play(clip.Clip, 0.1f);
|
||||
currentState.Events.OnEnd=OnEnd is null ? null : () =>
|
||||
{
|
||||
currentState.Events.OnEnd = null;
|
||||
this.OnEnd();
|
||||
};
|
||||
break;
|
||||
case IMotionMatchingDualClip dualClip:
|
||||
currentState = animancerComponent.Play(dualClip.Clip1, 0.1f);
|
||||
root.AdditionalAnimancerComponent.Stop();
|
||||
var state2 = root.AdditionalAnimancerComponent.Play(dualClip.Clip2, 0.1f);
|
||||
currentState.Events.OnEnd = OnEnd is null ? null : () =>
|
||||
currentState = animancerComponent.Layers[layer].Play(clip.Clip, 0.1f);
|
||||
currentState.Events.OnEnd =OnEnd ?? (() =>
|
||||
{
|
||||
currentState.Events.OnEnd = null;
|
||||
this.OnEnd();
|
||||
};
|
||||
});
|
||||
break;
|
||||
case IMotionMatchingSequence sequence:
|
||||
break;
|
||||
case IMotionMatchingDualClip dualClip:
|
||||
currentState = animancerComponent.Layers[layer].Play(dualClip.Clip1, 0.1f);
|
||||
currentState.Events.OnEnd =OnEnd ?? (() =>
|
||||
{
|
||||
currentState.Events.OnEnd = null;
|
||||
this.OnEnd();
|
||||
});
|
||||
if (root.AdditionalAnimancerComponent)
|
||||
{
|
||||
root.AdditionalAnimancerComponent.Stop();
|
||||
var state2 = root.AdditionalAnimancerComponent.Play(dualClip.Clip2, 0.1f);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
return currentState;
|
||||
}
|
||||
protected void PlayAnimationVoid()=>PlayAnimation();
|
||||
protected AnimancerState PlayAnimation()
|
||||
{
|
||||
return PlayAnimation(0,null,GetType().Name);
|
||||
}
|
||||
public virtual void Initialize()
|
||||
{
|
||||
root.Entity.Inject(this);
|
||||
AnimationKey = root.SearchKey.Append(GetType().Name).ToArray();
|
||||
}
|
||||
|
||||
public virtual void OnStateEntry(IState old)
|
||||
{
|
||||
PlayAnimation(OnEnd);
|
||||
PlayAnimation();
|
||||
}
|
||||
|
||||
public virtual void OnStateExit(IState old, IState newState)
|
||||
{
|
||||
}
|
||||
@@ -146,6 +141,7 @@ namespace BITFALL.Guns
|
||||
[SerializeField] internal InputActionReference reloadAction;
|
||||
[SerializeField] internal InputActionReference meleeAction;
|
||||
[SerializeField] internal InputActionReference steadyAimAction;
|
||||
[SerializeField] internal InputActionReference tacticsAction;
|
||||
[SerializeField] internal InputActionReference inspectAction;
|
||||
|
||||
[Header(Constant.Header.HotFix)]
|
||||
@@ -172,6 +168,7 @@ namespace BITFALL.Guns
|
||||
private IHealth _health;
|
||||
|
||||
[Inject] private IEquipService _equipService;
|
||||
[Inject] private IEntityEquipmentContainer _equipmentContainer;
|
||||
|
||||
internal AssetableGun _gun=>item as AssetableGun;
|
||||
private bool isSteadyAim;
|
||||
@@ -193,9 +190,7 @@ namespace BITFALL.Guns
|
||||
{
|
||||
base.OnAwake();
|
||||
|
||||
AnimancerComponent.Layers[3].IsAdditive = true;
|
||||
AnimancerComponent.Layers[2].IsAdditive = true;
|
||||
AnimancerComponent.Layers[4].IsAdditive = true;
|
||||
|
||||
|
||||
if (breathingAdditive.Allow)
|
||||
inputActionGroup.RegisterCallback(steadyAimAction, OnSteadyAim);
|
||||
@@ -230,22 +225,24 @@ namespace BITFALL.Guns
|
||||
switch (obj)
|
||||
{
|
||||
case OnPlayerJumpCommand when
|
||||
MotionMatchingService.TryMatch(out var jump ,SearchKey.Append("Jump").ToArray())
|
||||
MotionMatchingService.TryMatch(out var jump, SearchKey.Append("Jump").ToArray())
|
||||
&& jump is IMotionMatchingClip jumpMotion
|
||||
:
|
||||
jumpState?.Stop();
|
||||
if (jumpState is { IsValid: true })
|
||||
jumpState?.Stop();
|
||||
jumpState = AnimancerComponent.Layers[4].Play(jumpMotion.Clip);
|
||||
break;
|
||||
case OnPlayerLandCommand when
|
||||
MotionMatchingService.TryMatch(out var land ,SearchKey.Append("Land").ToArray())
|
||||
MotionMatchingService.TryMatch(out var land, SearchKey.Append("Land").ToArray())
|
||||
&& land is IMotionMatchingClip landMotion
|
||||
:
|
||||
jumpState?.Stop();
|
||||
jumpState = AnimancerComponent.Layers[4].Play(landMotion.Clip,0.1f);
|
||||
if (jumpState is { IsValid: true })
|
||||
jumpState?.Stop();
|
||||
jumpState = AnimancerComponent.Layers[4].Play(landMotion.Clip, 0.1f);
|
||||
jumpState.Events.OnEnd = () =>
|
||||
{
|
||||
jumpState.Events.OnEnd = null;
|
||||
jumpState.StartFade(0);
|
||||
jumpState.StartFade(0);
|
||||
};
|
||||
break;
|
||||
}
|
||||
@@ -255,7 +252,7 @@ namespace BITFALL.Guns
|
||||
{
|
||||
switch (CurrentState)
|
||||
{
|
||||
case Equip:
|
||||
case Draw:
|
||||
case Melee:
|
||||
return;
|
||||
}
|
||||
@@ -267,7 +264,7 @@ namespace BITFALL.Guns
|
||||
if (obj.JustPressed() is false) return;
|
||||
switch (CurrentState)
|
||||
{
|
||||
case Equip:
|
||||
case Draw:
|
||||
case Melee:
|
||||
return;
|
||||
}
|
||||
@@ -299,12 +296,13 @@ namespace BITFALL.Guns
|
||||
inputActionGroup.RegisterCallback(aimAction, OnAim);
|
||||
inputActionGroup.RegisterCallback(reloadAction, OnReload);
|
||||
inputActionGroup.RegisterCallback(meleeAction, OnMelee);
|
||||
inputActionGroup.RegisterCallback(tacticsAction, OnTactics);
|
||||
|
||||
TransitionState<Equip>();
|
||||
TransitionState<Draw>();
|
||||
|
||||
if (MotionMatchingService.TryMatch(out var walkMotion, SearchKey.Append(BITConstant.Player.Walk).ToArray())
|
||||
&&
|
||||
MotionMatchingService.TryMatch(out var movementMotion, SearchKey.Append(BITConstant.Player.Movement).ToArray()))
|
||||
MotionMatchingService.TryMatch(out var movementMotion, SearchKey.Append(BITConstant.Player.Idle).ToArray()))
|
||||
{
|
||||
if (walkMotion is IMotionMatchingClip walkClip && movementMotion is IMotionMatchingClip movementClip)
|
||||
{
|
||||
@@ -320,6 +318,17 @@ namespace BITFALL.Guns
|
||||
|
||||
_movement.OnStateChanged += OnMovementStateChanged;
|
||||
_movement.OnCommand += OnMovementCommand;
|
||||
|
||||
AnimancerComponent.Layers[3].IsAdditive = true;
|
||||
AnimancerComponent.Layers[2].IsAdditive = true;
|
||||
AnimancerComponent.Layers[4].IsAdditive = true;
|
||||
}
|
||||
|
||||
private void OnTactics(InputAction.CallbackContext obj)
|
||||
{
|
||||
if(obj is not {interaction:TapInteraction, performed: true}) return;
|
||||
if (_equipmentContainer.Equipment.TryGetValue(new EquipmentAsTactics(), out _) is false) return;
|
||||
TransitionState<Tactics>();
|
||||
}
|
||||
|
||||
private bool IsClipReady(IBasicItem clip)
|
||||
@@ -351,6 +360,7 @@ namespace BITFALL.Guns
|
||||
inputActionGroup.UnRegisterCallback(aimAction, OnAim);
|
||||
inputActionGroup.UnRegisterCallback(reloadAction, OnReload);
|
||||
inputActionGroup.UnRegisterCallback(meleeAction, OnMelee);
|
||||
inputActionGroup.UnRegisterCallback(tacticsAction, OnTactics);
|
||||
|
||||
_movement.OnStateChanged -= OnMovementStateChanged;
|
||||
_movement.OnCommand -= OnMovementCommand;
|
||||
@@ -372,7 +382,7 @@ namespace BITFALL.Guns
|
||||
burstFireInterval.Reset();
|
||||
}
|
||||
|
||||
TransitionState<Equip>();
|
||||
TransitionState<Draw>();
|
||||
|
||||
return UniTask.CompletedTask;
|
||||
}
|
||||
@@ -396,21 +406,15 @@ namespace BITFALL.Guns
|
||||
|
||||
try
|
||||
{
|
||||
while (_health.IsAlive && AnimancerComponent.IsPlaying())
|
||||
{
|
||||
destroyCancellationToken.ThrowIfCancellationRequested();
|
||||
_equipService.Zoom.Value = Mathf.MoveTowards(_equipService.Zoom.Value,0,Time.deltaTime);
|
||||
await UniTask.NextFrame();
|
||||
}
|
||||
await base.ExitAsync();
|
||||
|
||||
_equipService.Zoom.Value = Mathf.MoveTowards(_equipService.Zoom.Value, 0, Time.deltaTime);
|
||||
|
||||
_equipService.Zoom.Allow = false;
|
||||
|
||||
destroyCancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
_equipService.Stable = 1;
|
||||
|
||||
|
||||
await base.ExitAsync();
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
@@ -462,13 +466,24 @@ namespace BITFALL.Guns
|
||||
|
||||
var length = _movement.GroundVelocity.GetLength();
|
||||
|
||||
if (walkState is not null)
|
||||
if (walkState is {IsValid:true})
|
||||
{
|
||||
var value = Mathf.Clamp(
|
||||
length / _movement.ReferenceSpeed, 0, 1
|
||||
);
|
||||
walkState.Parameter = value;
|
||||
|
||||
switch (CurrentState,_movement.CurrentState)
|
||||
{
|
||||
case (Movement,IPlayerWalkState):
|
||||
walkState.SetWeight(1 - _equipService.Aim);
|
||||
break;
|
||||
default:
|
||||
walkState.SetWeight(0);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
recoilSpring.Update(deltaTime,default);
|
||||
@@ -542,8 +557,6 @@ namespace BITFALL.Guns
|
||||
if (newSight.Allow)
|
||||
{
|
||||
transform.localPosition = Vector3.Lerp(default, _fixAimPosition.Value, _aim);
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -643,6 +656,13 @@ namespace BITFALL.Guns
|
||||
public void Fire()
|
||||
{
|
||||
if (RequireBolt) return;
|
||||
switch (CurrentState)
|
||||
{
|
||||
case States.Reload:
|
||||
case Draw:
|
||||
return;
|
||||
}
|
||||
|
||||
var infiniteAmmo = Data.Get<int>(BITConstant.Environment.sv_infinite_ammo) is 1;
|
||||
switch (Item.TryGetProperty<IClip>(out var clip))
|
||||
{
|
||||
@@ -774,6 +794,14 @@ namespace BITFALL.Guns
|
||||
expectFiring.Reset();
|
||||
return;
|
||||
}
|
||||
|
||||
if (Item.TryGetProperty<IClip>(out var clip))
|
||||
{
|
||||
if (clip.Remaining is 0)
|
||||
{
|
||||
expectFiring.Reset();return;
|
||||
}
|
||||
}
|
||||
switch (_gun.FireMode)
|
||||
{
|
||||
case AutoFireMode :
|
||||
|
Reference in New Issue
Block a user