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 :
|
||||
|
@@ -11,6 +11,7 @@ using BITKit.Entities;
|
||||
using BITKit.Selection;
|
||||
using UnityEngine.InputSystem;
|
||||
using BITKit.StateMachine;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
// ReSharper disable UnassignedField.Local
|
||||
|
||||
@@ -36,7 +37,6 @@ namespace BITFALL.Guns.States
|
||||
switch (old)
|
||||
{
|
||||
case Movement:
|
||||
case Equip:
|
||||
break;
|
||||
default:
|
||||
if (_entityMovement.CurrentState is IPlayerWalkState)
|
||||
@@ -54,20 +54,7 @@ namespace BITFALL.Guns.States
|
||||
|
||||
private void OnInspect(InputAction.CallbackContext obj)
|
||||
{
|
||||
PlayAnimation("Inspect");
|
||||
// if (root.MotionMatchingService.TryMatch(out var value, SearchKey.Append(BITConstant.Player.Inspect).ToArray()) is false)
|
||||
// {
|
||||
// Debug.LogWarning("No inspect animation found");
|
||||
// return;
|
||||
// }
|
||||
// Debug.Log(value);
|
||||
// switch (value)
|
||||
// {
|
||||
// case IMotionMatchingClip clip:
|
||||
// inspectState = animancerComponent.Layers[1].Play(clip.Clip);
|
||||
// inspectState.Events.OnEnd = () => { animancerComponent.Layers[1].Stop(); };
|
||||
// break;
|
||||
// }
|
||||
PlayAnimation(0,PlayAnimationVoid,nameof(BITConstant.Player.Inspect));
|
||||
}
|
||||
|
||||
public override void OnStateExit(IState old, IState newState)
|
||||
@@ -116,11 +103,14 @@ namespace BITFALL.Guns.States
|
||||
}
|
||||
}
|
||||
|
||||
public void OnActive(ISelectable selectable)
|
||||
public async void OnActive(ISelectable selectable)
|
||||
{
|
||||
//root.animator.Play(BITConstant.Player.Interactive);
|
||||
PlayAnimation(root.SearchKey.Append(nameof(BITConstant.Player.Interactive)).ToArray());
|
||||
await UniTask.DelayFrame(8);
|
||||
if (root.destroyCancellationToken.IsCancellationRequested) return;
|
||||
if (root.IsEntered && Enabled)
|
||||
PlayAnimation(0, PlayAnimationVoid,BITConstant.Player.Interactive);
|
||||
}
|
||||
|
||||
public override void OnMovementStateChanged(IEntityMovementState old, IEntityMovementState newState)
|
||||
{
|
||||
_expectRun = newState is IPlayerRunState or IPlayerSprintState;
|
||||
@@ -277,6 +267,8 @@ namespace BITFALL.Guns.States
|
||||
Limit =false,
|
||||
Speed = root._gun.InitialAimMovementSpeed,
|
||||
});
|
||||
|
||||
equipService.Aim = 0;
|
||||
}
|
||||
|
||||
public override void OnStateUpdate(float deltaTime)
|
||||
@@ -311,7 +303,7 @@ namespace BITFALL.Guns.States
|
||||
}
|
||||
}
|
||||
[System.Serializable]
|
||||
public sealed class Equip : GunState
|
||||
public sealed class Draw : GunState
|
||||
{
|
||||
[Inject]
|
||||
private IPlayerEquipSelector _equipSelector;
|
||||
@@ -319,8 +311,6 @@ namespace BITFALL.Guns.States
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
//root.animator[0].onStateExit += OnAnimationStateExit;
|
||||
|
||||
_equipSelector.OnUpdateEquip += OnUpdateEquip;
|
||||
}
|
||||
private readonly List<int> _drawed = new();
|
||||
@@ -345,13 +335,13 @@ namespace BITFALL.Guns.States
|
||||
base.OnStateEntry(old);
|
||||
if (_drawed.TryAdd(root.Item.Id))
|
||||
{
|
||||
PlayAnimation(nameof(BITConstant.Player.Draw));
|
||||
root.UnityEntity.Invoke(Constant.Animation.Play, BITConstant.Player.Draw);
|
||||
//root.animator.Play(BITConstant.Player.Draw, -1, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
PlayAnimation(nameof(BITConstant.Player.QuickDraw));
|
||||
root.UnityEntity.Invoke(Constant.Animation.Play, BITConstant.Player.QuickDraw);
|
||||
//root.animator.Play(BITConstant.Player.QuickDraw,-1,0);
|
||||
}
|
||||
_entityMovement.ExecuteCommand<PlayerPauseRunCommand>(new(this,true));
|
||||
}
|
||||
@@ -419,23 +409,32 @@ namespace BITFALL.Guns.States
|
||||
Focus = true,
|
||||
Sender = this
|
||||
});
|
||||
|
||||
root.inputActionGroup.RegisterCallback(root.meleeAction, OnMelee);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public override void OnStateExit(IState old, IState newState)
|
||||
{
|
||||
base.OnStateExit(old,newState);
|
||||
_entityMovement.ExecuteCommand<PlayerPauseRunCommand>(new(this,false));
|
||||
|
||||
root.inputActionGroup.UnRegisterCallback(root.meleeAction, OnMelee);
|
||||
|
||||
_entityMovement.ExecuteCommand(new PlayerFocusCommand()
|
||||
{
|
||||
Focus = false,
|
||||
Sender = this
|
||||
});
|
||||
}
|
||||
|
||||
public override void OnStateUpdate(float deltaTime)
|
||||
private void OnMelee(InputAction.CallbackContext obj)
|
||||
{
|
||||
_entityMovement.ExecuteCommand<PlayerCancelRunCommand>();
|
||||
if (obj.performed is false) return;
|
||||
if (!(currentState.NormalizedTime > 0.5f)) return;
|
||||
currentState.Events.OnEnd = null;
|
||||
currentState.Stop();
|
||||
PlayAnimation();
|
||||
}
|
||||
public override void OnMovementStateChanged(IEntityMovementState old, IEntityMovementState newState)
|
||||
{
|
||||
@@ -469,7 +468,15 @@ namespace BITFALL.Guns.States
|
||||
case IPlayerClimbState:
|
||||
case IPlayerLinkState { LinkArea: 44 }:
|
||||
case IPlayerVaultState:
|
||||
root.TransitionState<Climb>();
|
||||
if (Enabled)
|
||||
{
|
||||
currentState.Stop();
|
||||
PlayAnimation();
|
||||
}
|
||||
else
|
||||
{
|
||||
root.TransitionState<Climb>();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (Enabled)
|
||||
@@ -491,4 +498,23 @@ namespace BITFALL.Guns.States
|
||||
animancerComponent.Stop();
|
||||
}
|
||||
}
|
||||
[Serializable]
|
||||
public sealed class Tactics : GunState
|
||||
{
|
||||
public override void OnStateEntry(IState old)
|
||||
{
|
||||
base.OnStateEntry(old);
|
||||
_entityMovement.ExecuteCommand<PlayerPauseRunCommand>(new(this,true));
|
||||
}
|
||||
public override void OnStateExit(IState old, IState newState)
|
||||
{
|
||||
base.OnStateExit(old, newState);
|
||||
_entityMovement.ExecuteCommand<PlayerPauseRunCommand>(new(this,false));
|
||||
}
|
||||
protected override void OnEnd()
|
||||
{
|
||||
base.OnEnd();
|
||||
root.TransitionState<Movement>();
|
||||
}
|
||||
}
|
||||
}
|
@@ -43,24 +43,24 @@ namespace BITFALL.Player.Movement
|
||||
}
|
||||
|
||||
//Debug.Log(MathV.TransientRotationAxis(_movement.ViewRotation.eulerAngles) );
|
||||
|
||||
currentPosition = Vector3.Lerp(currentPosition, velocity * posValue, posDelta * deltaTime);
|
||||
currentRotation = Quaternion.Slerp(currentRotation, Quaternion.Euler((angularVelocity -
|
||||
new Vector3()
|
||||
{
|
||||
x =
|
||||
_equipService.Zoom.Allow ? 0 :
|
||||
MathV.TransientRotationAxis(_movement.ViewRotation.eulerAngles).x * 0.05f
|
||||
} * rotValue
|
||||
)
|
||||
), rotDelta * deltaTime);
|
||||
|
||||
|
||||
currentPosition += new Vector3(
|
||||
angularVelocity.y,
|
||||
angularVelocity.x,
|
||||
angularVelocity.z
|
||||
) * (posValue * deltaTime * 8);
|
||||
|
||||
if (_equipService.Zoom.Allow)
|
||||
{
|
||||
currentPosition = Vector3.MoveTowards(currentPosition,default, posDelta * deltaTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
currentPosition = Vector3.Lerp(currentPosition, velocity * posValue, posDelta * deltaTime);
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (_health.HealthPoint <= 50)
|
||||
{
|
||||
var t = math.sin(Time.time*5) * 0.001f;
|
||||
|
29
Assets/Artists/Scripts/Equip/TacticsController.cs
Normal file
29
Assets/Artists/Scripts/Equip/TacticsController.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using BITFALL.Entities.Equipment;
|
||||
using BITFALL.Items;
|
||||
using BITKit;
|
||||
using BITKit.Entities;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BITFALL.Player.Equip
|
||||
{
|
||||
public class TacticsController : EntityBehavior
|
||||
{
|
||||
[Inject] private IEntityEquipmentContainer _equipmentContainer;
|
||||
[SerializeField] private Transform throwPoint;
|
||||
[SerializeField] private int throwForce;
|
||||
public override void OnStart()
|
||||
{
|
||||
base.OnStart();
|
||||
UnityEntity.AddListener<string>(Constant.Animation.OnEvent, OnAnimationEvent);
|
||||
}
|
||||
private void OnAnimationEvent(string value)
|
||||
{
|
||||
if (value is not BITConstant.Player.Tactics) return;
|
||||
if (_equipmentContainer.Equipment.TryGetValue(new EquipmentAsTactics(), out var item) is false) return;
|
||||
if (_equipmentContainer.TryUseEquip<EquipmentAsTactics>() is false) return;
|
||||
ThrowController.Throw(throwPoint,throwForce,item);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,5 +1,6 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Animancer;
|
||||
using BITFALL.Entities.Equipment;
|
||||
using BITFALL.Entities.Inventory;
|
||||
using BITFALL.Items;
|
||||
@@ -10,74 +11,83 @@ using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.InputSystem.Interactions;
|
||||
|
||||
namespace BITFALL.Throws
|
||||
namespace BITFALL.Player.Equip
|
||||
{
|
||||
public interface IThrowState:IState{}
|
||||
public class ThrowController : BITEquipBase<IThrowState>
|
||||
{
|
||||
[Header(nameof(throwPoint))]
|
||||
[SerializeField] private Transform throwPoint;
|
||||
[SerializeField] private float throwForce;
|
||||
[SerializeField] private InputActionReference throwAction;
|
||||
private AssetableThrow _assetableThrow=>(AssetableThrow)item;
|
||||
[Inject] private IPlayerEquipSelector _equipSelector;
|
||||
[Inject] private IEntityEquipmentContainer _equipmentContainer;
|
||||
private bool isHolding;
|
||||
public override void OnAwake()
|
||||
public static void Throw(Transform throwPoint,int throwForce, IBasicItem item)
|
||||
{
|
||||
inputActionGroup.RegisterCallback(throwAction, OnThrow);
|
||||
base.OnAwake();
|
||||
//animator[0].onStateExit += OnStateExit;
|
||||
}
|
||||
private void OnStateExit(string obj)
|
||||
{
|
||||
if (IsEntered is false) return;
|
||||
switch (obj)
|
||||
{
|
||||
case BITConstant.Player.Draw:
|
||||
if (isHolding is false)
|
||||
{
|
||||
//animator.Play(BITConstant.Player.Throw);
|
||||
}
|
||||
break;
|
||||
case BITConstant.Player.Throw:
|
||||
_equipSelector.Cancel();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Entry()
|
||||
{
|
||||
isHolding = false;
|
||||
base.Entry();
|
||||
//animator.Play(BITConstant.Player.Draw);
|
||||
}
|
||||
|
||||
private void OnThrow(InputAction.CallbackContext obj)
|
||||
{
|
||||
switch (obj)
|
||||
{
|
||||
case { interaction: HoldInteraction, performed: true }:
|
||||
isHolding = true;
|
||||
break;
|
||||
case { interaction: HoldInteraction, canceled: true }:
|
||||
// if (animator[0].stateName == BITConstant.Player.Idle)
|
||||
// animator.Play(BITConstant.Player.Throw);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public override void AnimationEvent(string eventName)
|
||||
{
|
||||
if (IsEntered is false) return;
|
||||
if (eventName is not BITConstant.Player.Throw) return;
|
||||
|
||||
if (!_equipmentContainer.TryUseEquip<EquipmentAsThrow>() && !_equipmentContainer.TryUseEquip<EquipmentAsTactics>()) return;
|
||||
var instance =Instantiate(_assetableThrow.Prefab,
|
||||
if (item.GetAssetable() is not AssetableThrow assetableThrow) return;
|
||||
var instance =Instantiate(assetableThrow.Prefab,
|
||||
throwPoint.position + throwPoint.forward * 0.016f,
|
||||
throwPoint.rotation) ;
|
||||
if (!instance.TryGetComponent<Rigidbody>(out var _rigidbody)) return;
|
||||
_rigidbody.AddForce(throwPoint.forward * throwForce, ForceMode.VelocityChange);
|
||||
var forward = throwPoint.forward;
|
||||
_rigidbody.AddForce(forward * throwForce, ForceMode.VelocityChange);
|
||||
_rigidbody.AddTorque(forward * throwForce, ForceMode.VelocityChange);
|
||||
}
|
||||
[Header(nameof(throwPoint))]
|
||||
[SerializeField] private Transform throwPoint;
|
||||
[SerializeField] private int throwForce;
|
||||
[SerializeField] private InputActionReference throwAction;
|
||||
[Inject] private IPlayerEquipSelector _equipSelector;
|
||||
[Inject] private IEntityEquipmentContainer _equipmentContainer;
|
||||
|
||||
[Header(Constant.Header.Animations)]
|
||||
[SerializeField] private AnimationClip drawClip;
|
||||
[SerializeField] private AnimationClip throwClip;
|
||||
private AnimancerState currentState;
|
||||
private bool isThrowing;
|
||||
public override void Entry()
|
||||
{
|
||||
base.Entry();
|
||||
isThrowing = false;
|
||||
inputActionGroup.RegisterCallback(throwAction, OnThrow);
|
||||
currentState = AnimancerComponent.Play(drawClip);
|
||||
currentState.Events.OnEnd = () =>
|
||||
{
|
||||
currentState.Events.OnEnd = null;
|
||||
if (inputActionGroup.GetAction(throwAction).IsPressed())
|
||||
{
|
||||
currentState.Events.OnEnd = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
isThrowing = true;
|
||||
currentState = AnimancerComponent.Play(throwClip);
|
||||
currentState.Events.OnEnd =()=>
|
||||
{
|
||||
currentState.Events.OnEnd = null;
|
||||
_equipSelector.Cancel();
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
private void OnThrow(InputAction.CallbackContext obj)
|
||||
{
|
||||
if (obj is not { interaction: HoldInteraction, canceled: true } || isThrowing) return;
|
||||
isThrowing = true;
|
||||
currentState = AnimancerComponent.Play(throwClip);
|
||||
currentState.Events.OnEnd =()=>
|
||||
{
|
||||
currentState.Events.OnEnd = null;
|
||||
_equipSelector.Cancel();
|
||||
};
|
||||
}
|
||||
|
||||
public override void Exit()
|
||||
{
|
||||
base.Exit();
|
||||
inputActionGroup.UnRegisterCallback(throwAction, OnThrow);
|
||||
AnimancerComponent.Stop();
|
||||
}
|
||||
public override void AnimationEvent(string eventName)
|
||||
{
|
||||
if (eventName is not BITConstant.Player.Throw) return;
|
||||
if(item.GetAssetable().TryGetProperty<EquipmentAsSlot>(out var slot) is false)return;
|
||||
if(_equipmentContainer.TryUseEquip(slot.slot) is false) return;
|
||||
Throw(throwPoint, throwForce, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -25,36 +25,49 @@ namespace BITFALL.Entities.Equipment.Universal
|
||||
[SerializeField] protected AnimancerComponent animancerComponent;
|
||||
[SerializeField] protected AnimationClip[] clips;
|
||||
public virtual bool Enabled { get; set; }
|
||||
protected AnimancerState currentState;
|
||||
|
||||
public virtual void Initialize()
|
||||
{
|
||||
|
||||
}
|
||||
public virtual void OnStateEntry(IState old)
|
||||
{
|
||||
PlayAnimation();
|
||||
}
|
||||
public virtual void PlayAnimation()
|
||||
{
|
||||
if (clips?.Length is 0) return;
|
||||
var clip = clips.Random();
|
||||
animancerComponent.Play(clip).Events.OnEnd=OnPlayEnd;
|
||||
currentState = animancerComponent.Play(clip);
|
||||
currentState.Events.OnEnd = OnPlayEnd;
|
||||
}
|
||||
|
||||
public virtual void OnStateUpdate(float deltaTime)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void OnStateExit(IState old, IState newState)
|
||||
{
|
||||
}
|
||||
|
||||
protected virtual void OnPlayEnd()
|
||||
{
|
||||
if (currentState is { IsValid: true })
|
||||
currentState.Events.OnEnd = null;
|
||||
}
|
||||
}
|
||||
|
||||
public class UniversalUseController : BITEquipBase<IUseState>
|
||||
{
|
||||
public struct Used:IProperty{}
|
||||
/// <summary>
|
||||
/// 是使用完就释放,还是连续使用
|
||||
/// </summary>
|
||||
[SerializeField] private bool release;
|
||||
[Inject] internal IPlayerInventory _playerInventory;
|
||||
[Inject] internal IPlayerEquipSelector _playerEquipSelector;
|
||||
[Inject] internal IEntityEquipmentContainer _equipmentContainer;
|
||||
public bool IClosed { get; set; }
|
||||
public bool Release => release;
|
||||
public override void Entry()
|
||||
{
|
||||
base.Entry();
|
||||
@@ -72,6 +85,7 @@ namespace BITFALL.Entities.Equipment.Universal
|
||||
switch (eventName)
|
||||
{
|
||||
case BITConstant.Player.Use when CurrentState is Use:
|
||||
var current = Item;
|
||||
if (item.TryGetProperty<EquipmentAsSlot>(out var asSlot))
|
||||
{
|
||||
_equipmentContainer.TryUseEquip(asSlot.slot);
|
||||
@@ -80,6 +94,8 @@ namespace BITFALL.Entities.Equipment.Universal
|
||||
{
|
||||
_inventory.UseItem(Item);
|
||||
}
|
||||
if (current?.Id == Item?.Id)
|
||||
Item = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@@ -3,6 +3,7 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using BITKit;
|
||||
using BITKit.StateMachine;
|
||||
using BITKit.UX;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BITFALL.Entities.Equipment.Universal.States
|
||||
@@ -19,10 +20,53 @@ namespace BITFALL.Entities.Equipment.Universal.States
|
||||
[Serializable]
|
||||
public sealed class Use:UseState
|
||||
{
|
||||
public override void OnStateEntry(IState old)
|
||||
{
|
||||
base.OnStateEntry(old);
|
||||
useController._equipmentContainer.OnEquip+=OnEquip;
|
||||
}
|
||||
|
||||
public override void OnStateExit(IState old, IState newState)
|
||||
{
|
||||
base.OnStateExit(old, newState);
|
||||
useController._equipmentContainer.OnEquip-=OnEquip;
|
||||
}
|
||||
|
||||
protected override void OnPlayEnd()
|
||||
{
|
||||
base.OnPlayEnd();
|
||||
useController.TransitionState<Exit>();
|
||||
//useController.TransitionState<Exit>();
|
||||
if (useController.Release)
|
||||
useController._playerEquipSelector.Cancel();
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
if (useController.Item is not null
|
||||
&& useController.Inventory.AllowUseItem(useController.Item)
|
||||
)
|
||||
{
|
||||
currentState.Events.OnEnd = null;
|
||||
currentState.Stop();
|
||||
PlayAnimation();
|
||||
//animancerComponent.States.Current.Time = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
useController._playerEquipSelector.Cancel();
|
||||
}
|
||||
}
|
||||
catch (InGameException e)
|
||||
{
|
||||
useController.UXPopup.Popup(e.Message);
|
||||
useController._playerEquipSelector.Cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
private void OnEquip(IEquipmentSlot arg1, IBasicItem arg2)
|
||||
{
|
||||
if (useController.ScriptableItem.AddressablePath != arg2?.AddressablePath) return;
|
||||
useController.Item = arg2;
|
||||
}
|
||||
}
|
||||
[Serializable]
|
||||
@@ -32,7 +76,6 @@ namespace BITFALL.Entities.Equipment.Universal.States
|
||||
{
|
||||
base.OnPlayEnd();
|
||||
animancerComponent.Stop();
|
||||
useController._playerEquipSelector.Cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user