1
This commit is contained in:
@@ -30,20 +30,30 @@ namespace BITFALL.Guns
|
||||
public BITGun root;
|
||||
[Inject]
|
||||
protected IEntityMovement _entityMovement;
|
||||
|
||||
[Inject] protected IEquipService equipService;
|
||||
protected AnimancerComponent animancerComponent=>root.AnimancerComponent;
|
||||
public bool Enabled { get;set; }
|
||||
protected AnimancerState currentState;
|
||||
|
||||
protected string[] AnimationKey;
|
||||
protected bool PlayAnimation(params string[] args)
|
||||
{
|
||||
if (root.MotionMatchingService.TryMatch(out var obj,args) is false) return false;
|
||||
if (root.MotionMatchingService.TryMatch(out var obj,root.SearchKey.Union(args).ToArray()) is false) return false;
|
||||
switch (obj)
|
||||
{
|
||||
case IMotionMatchingClip clip:
|
||||
animancerComponent.Play(clip.Clip,0.1f);
|
||||
currentState = animancerComponent.Play(clip.Clip,0.1f);
|
||||
return true;
|
||||
case IMotionMatchingSequence sequence:
|
||||
//animancerComponent.Play(sequence.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;
|
||||
@@ -55,20 +65,28 @@ namespace BITFALL.Guns
|
||||
switch (obj)
|
||||
{
|
||||
case IMotionMatchingClip clip:
|
||||
var state = animancerComponent.Play(clip.Clip, 0.1f);
|
||||
state.Events.OnEnd=OnEnd is null ? null : () =>
|
||||
currentState = animancerComponent.Play(clip.Clip, 0.1f);
|
||||
currentState.Events.OnEnd=OnEnd is null ? null : () =>
|
||||
{
|
||||
state.Events.OnEnd = 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.Events.OnEnd = null;
|
||||
this.OnEnd();
|
||||
};
|
||||
break;
|
||||
}
|
||||
}
|
||||
public virtual void Initialize()
|
||||
{
|
||||
root.Entity.Inject(this);
|
||||
_entityMovement.OnStateChanged += OnMovementStateChanged;
|
||||
// AnimationKey = new []{BITGun.C_Weapon,GetType().Name,root._gun.Name};
|
||||
AnimationKey = root.SearchKey.Append(GetType().Name).ToArray();
|
||||
}
|
||||
|
||||
@@ -424,13 +442,14 @@ namespace BITFALL.Guns
|
||||
expectFiring.shouldBe = fireAction.action.WasPressedThisFrame();
|
||||
if(burstFireInterval.AllowUpdate)
|
||||
{
|
||||
switch (AnimationProperties.TryGetValue(BITConstant.Player.AllowFire, out var allowFire))
|
||||
{
|
||||
case false:
|
||||
case true when allowFire >0.9f:
|
||||
Fire();
|
||||
break;
|
||||
}
|
||||
// switch (AnimationProperties.TryGetValue(BITConstant.Player.AllowFire, out var allowFire))
|
||||
// {
|
||||
// case false:
|
||||
// case true when allowFire >0.9f:
|
||||
// Fire();
|
||||
// break;
|
||||
// }
|
||||
Fire();
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -440,18 +459,8 @@ namespace BITFALL.Guns
|
||||
Focus = recoilSpring.value.GetLength() > 0.1f,
|
||||
Sender = this
|
||||
});
|
||||
|
||||
if(AnimationProperties.TryGetValue(BITConstant.Player.Aim, out var __aim))
|
||||
{
|
||||
//animator.animator.SetFloat((int)BITHash.Player.Aim,__aim);
|
||||
}
|
||||
|
||||
var length = _movement.GroundVelocity.GetLength();
|
||||
// animator.animator.SetFloat(BITConstant.Player.SqrMagnitude,
|
||||
// Mathf.Clamp(
|
||||
// length / _movement.ReferenceSpeed,0.1f,1
|
||||
// )
|
||||
// );
|
||||
|
||||
if (walkState is not null)
|
||||
{
|
||||
@@ -473,10 +482,9 @@ namespace BITFALL.Guns
|
||||
if (selfViewAdditive)
|
||||
{
|
||||
var positionWeight = recoilPositionWeight;
|
||||
if (AnimationProperties.TryGetValue(BITConstant.Player.Aim, out var aim))
|
||||
{
|
||||
|
||||
var aim = _equipService.Aim;
|
||||
positionWeight *= Mathf.Lerp(2, 1, aim);
|
||||
}
|
||||
//selfViewAdditive.AddEuler(recoilSpring.value);
|
||||
selfViewAdditive.AddRotation(Quaternion.Euler(recoilSpring.value));
|
||||
selfViewAdditive.AddPosition(
|
||||
@@ -489,8 +497,9 @@ namespace BITFALL.Guns
|
||||
);
|
||||
}
|
||||
|
||||
if(AnimationProperties.TryGetValue(BITConstant.Player.Aim, out var _aim))
|
||||
{
|
||||
var _aim = _equipService.Aim;
|
||||
|
||||
_equipService.Zoom.Allow = CurrentState is Aim;
|
||||
_equipService.Zoom.Value =Mathf.Lerp(1,_gun.InitialAimZoom, _aim);
|
||||
_equipService.AllowScope = _aim > 0.5f && _gun.IsScopeAim;
|
||||
@@ -542,15 +551,15 @@ namespace BITFALL.Guns
|
||||
}
|
||||
}
|
||||
|
||||
if (AnimationProperties.TryGetValue(BITConstant.Player.Stable, out var stable))
|
||||
{
|
||||
_equipService.Stable = stable;
|
||||
}
|
||||
|
||||
if(AnimationProperties.TryGetValue(BITConstant.Player.AllowFire, out var _allowFire))
|
||||
{
|
||||
_equipService.AllowAttack = _allowFire > 0.9f;
|
||||
}
|
||||
// if (AnimationProperties.TryGetValue(BITConstant.Player.Stable, out var stable))
|
||||
// {
|
||||
// _equipService.Stable = stable;
|
||||
// }
|
||||
//
|
||||
// if(AnimationProperties.TryGetValue(BITConstant.Player.AllowFire, out var _allowFire))
|
||||
// {
|
||||
// _equipService.AllowAttack = _allowFire > 0.9f;
|
||||
// }
|
||||
|
||||
//AllowRendering.SetDisableElements(64564,_equipService.AllowScope);
|
||||
|
||||
@@ -670,10 +679,6 @@ namespace BITFALL.Guns
|
||||
{
|
||||
InternalAddRecoil();
|
||||
InternalFire(_gun.BuckShot.Value);
|
||||
// for (int i = 0; i < _gun.BuckShot.Value; i++)
|
||||
// {
|
||||
//
|
||||
// }
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -710,6 +715,7 @@ namespace BITFALL.Guns
|
||||
|
||||
private void InternalFire(int count = 1)
|
||||
{
|
||||
var aim = _equipService.Aim;
|
||||
//调用BulletManager生成子弹
|
||||
var _transform = transform;
|
||||
var rotation =_movement.ViewRotation;
|
||||
@@ -720,10 +726,7 @@ namespace BITFALL.Guns
|
||||
{
|
||||
fireRecoil *= spread.Spread;
|
||||
}
|
||||
if(AnimationProperties.TryGetValue(BITConstant.Player.Aim, out var aim))
|
||||
{
|
||||
fireRecoil *= Mathf.Lerp(_gun.InitialHipFireSpread,1,aim);
|
||||
}
|
||||
fireRecoil *= recoilSpring.value.GetLength();
|
||||
var length = fireRecoil.GetLength();
|
||||
for (var i = 0; i < count; i++)
|
||||
|
@@ -39,10 +39,13 @@ namespace BITFALL.Guns.States
|
||||
case Equip:
|
||||
break;
|
||||
default:
|
||||
PlayAnimation();
|
||||
OnMovementStateChanged(null, _entityMovement.CurrentState);
|
||||
if (_entityMovement.CurrentState is IPlayerWalkState)
|
||||
PlayAnimation();
|
||||
else
|
||||
OnMovementStateChanged(null, _entityMovement.CurrentState);
|
||||
break;
|
||||
}
|
||||
|
||||
_selector.OnActive += OnActive;
|
||||
boltActionImmediately = root.RequireBolt;
|
||||
|
||||
@@ -123,13 +126,18 @@ namespace BITFALL.Guns.States
|
||||
_expectRun = newState is IPlayerRunState or IPlayerSprintState;
|
||||
if (newState is IPlayerSlideState)
|
||||
{
|
||||
root.TransitionState<Movement>();
|
||||
PlayAnimation(root.SearchKey.Append(nameof(BITConstant.Player.Slide)).ToArray());
|
||||
if (root.CurrentState != this)
|
||||
root.TransitionState<Movement>();
|
||||
PlayAnimation(BITConstant.Player.Slide);
|
||||
//root.animator.CrossFade(BITConstant.Player.Slide, 0.32f);
|
||||
}else if (newState is IPlayerDodgeState)
|
||||
}
|
||||
else if (newState is IPlayerDodgeState)
|
||||
{
|
||||
PlayAnimation(root.SearchKey.Append(nameof(BITConstant.Player.Dodge)).ToArray());
|
||||
}else if (Enabled)
|
||||
if (root.CurrentState != this)
|
||||
root.TransitionState<Movement>();
|
||||
PlayAnimation(BITConstant.Player.Dodge);
|
||||
}
|
||||
else if (Enabled)
|
||||
{
|
||||
switch (newState)
|
||||
{
|
||||
@@ -172,7 +180,11 @@ namespace BITFALL.Guns.States
|
||||
else if(_expectRun == false)
|
||||
{
|
||||
root.TransitionState<Movement>();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
currentState.Speed = _entityMovement.LocomotionBasedVelocity.GetLength() / _entityMovement.ReferenceSpeed;
|
||||
}
|
||||
}
|
||||
private void OnAim(InputAction.CallbackContext context)
|
||||
{
|
||||
@@ -194,8 +206,9 @@ namespace BITFALL.Guns.States
|
||||
private ExpectState<bool> _expectSprint;
|
||||
public override void OnStateEntry(IState old)
|
||||
{
|
||||
base.OnStateEntry(old);
|
||||
//root.animator.CrossFade(BITConstant.Player.Sprint, 0.32f);
|
||||
PlayAnimation(root.SearchKey.Append(nameof(BITConstant.Player.Sprint)).ToArray());
|
||||
//PlayAnimation(root.SearchKey.Append(nameof(BITConstant.Player.Sprint)).ToArray());
|
||||
|
||||
root.inputActionGroup.RegisterCallback(root.aimAction, OnAim);
|
||||
}
|
||||
@@ -209,6 +222,10 @@ namespace BITFALL.Guns.States
|
||||
{
|
||||
root.TransitionState<Movement>();
|
||||
}
|
||||
else
|
||||
{
|
||||
currentState.Speed = _entityMovement.LocomotionBasedVelocity.GetLength() / _entityMovement.ReferenceSpeed;
|
||||
}
|
||||
}
|
||||
private void OnAim(InputAction.CallbackContext context)
|
||||
{
|
||||
@@ -227,17 +244,19 @@ namespace BITFALL.Guns.States
|
||||
{
|
||||
public override void OnStateEntry(IState old)
|
||||
{
|
||||
switch (old)
|
||||
{
|
||||
case IPlayerRunState:
|
||||
case IPlayerSprintState:
|
||||
//root.animator.CrossFade(BITConstant.Player.Aim, 0.32f);
|
||||
PlayAnimation(root.SearchKey.Append(nameof(BITConstant.Player.Aim)).ToArray());
|
||||
break;
|
||||
default:
|
||||
PlayAnimation(root.SearchKey.Append(nameof(BITConstant.Player.Aim)).ToArray());
|
||||
break;
|
||||
}
|
||||
// switch (old)
|
||||
// {
|
||||
// case IPlayerRunState:
|
||||
// case IPlayerSprintState:
|
||||
// //root.animator.CrossFade(BITConstant.Player.Aim, 0.32f);
|
||||
// PlayAnimation(root.SearchKey.Append(nameof(BITConstant.Player.Aim)).ToArray());
|
||||
// break;
|
||||
// default:
|
||||
// PlayAnimation(root.SearchKey.Append(nameof(BITConstant.Player.Aim)).ToArray());
|
||||
// break;
|
||||
// }
|
||||
base.OnStateEntry(old);
|
||||
|
||||
_entityMovement.ExecuteCommand<PlayerPauseRunCommand>(new(this,true));
|
||||
|
||||
_entityMovement.ExecuteCommand(new PlayerLimitMoveSpeedCommand()
|
||||
@@ -267,6 +286,8 @@ namespace BITFALL.Guns.States
|
||||
root.Fire();
|
||||
}
|
||||
|
||||
equipService.Aim = currentState.Weight;
|
||||
|
||||
if (BITAppForUnity.AllowCursor)
|
||||
{
|
||||
root.TransitionState<Movement>();
|
||||
@@ -351,7 +372,7 @@ namespace BITFALL.Guns.States
|
||||
public override void OnStateEntry(IState old)
|
||||
{
|
||||
base.OnStateEntry(old);
|
||||
|
||||
|
||||
_entityMovement.ExecuteCommand<PlayerPauseRunCommand>(new(this,true));
|
||||
|
||||
if (root.RequireBolt)
|
||||
|
Reference in New Issue
Block a user