1
This commit is contained in:
@@ -30,7 +30,8 @@
|
||||
"GUID:1eb13dc7c3cb5a444877a995967ed591",
|
||||
"GUID:a83bfc00a1ad8e74981b456e6c50ed4e",
|
||||
"GUID:de309aeb0cb045044a5b9cd0a72f471b",
|
||||
"GUID:508392158bd966c4d9c21e19661a441d"
|
||||
"GUID:508392158bd966c4d9c21e19661a441d",
|
||||
"GUID:fd0a768fe19798b48a5e0fe3568c874f"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
|
@@ -76,6 +76,7 @@ namespace BITFALL.Guns
|
||||
[SerializeField] internal InputActionReference reloadAction;
|
||||
[SerializeField] internal InputActionReference meleeAction;
|
||||
[SerializeField] internal InputActionReference steadyAimAction;
|
||||
[SerializeField] internal InputActionReference inspectAction;
|
||||
|
||||
[Header(Constant.Header.HotFix)]
|
||||
[SerializeField] private Transform cameraView;
|
||||
@@ -101,11 +102,12 @@ namespace BITFALL.Guns
|
||||
private IHealth _health;
|
||||
|
||||
[Inject] private IEquipService _equipService;
|
||||
private static readonly int IsGrounded = Animator.StringToHash(BITConstant.Player.IsGrounded);
|
||||
private static readonly int IsCrouched = Animator.StringToHash(BITConstant.Player.IsCrouched);
|
||||
|
||||
internal AssetableGun _gun=>item as AssetableGun;
|
||||
private bool isHolstered;
|
||||
private bool isSteadyAim;
|
||||
|
||||
private readonly DoubleBuffer<int> cacheRounds = new();
|
||||
|
||||
public bool RequireBolt { get; set; }
|
||||
|
||||
@@ -120,19 +122,29 @@ namespace BITFALL.Guns
|
||||
inputActionGroup.RegisterCallback(aimAction, OnAim);
|
||||
inputActionGroup.RegisterCallback(reloadAction, OnReload);
|
||||
inputActionGroup.RegisterCallback(meleeAction, OnMelee);
|
||||
|
||||
|
||||
if (inspectAction is not null)
|
||||
inputActionGroup.RegisterCallback(inspectAction, OnInspect);
|
||||
|
||||
if (breathingAdditive.Allow)
|
||||
inputActionGroup.RegisterCallback(steadyAimAction, OnSteadyAim);
|
||||
_movement.OnStateChanged += OnMovementStateChanged;
|
||||
//_movement.OnCommand += OnMovementCommand;
|
||||
|
||||
animator[0].onStateExit += (state) => { isHolstered = state is BITConstant.Player.Holster; };
|
||||
|
||||
|
||||
BITAppForUnity.AllowCursor.AddListener(OnAllowCursor);
|
||||
destroyCancellationToken.Register(() =>
|
||||
destroyCancellationToken.Register(() => { BITAppForUnity.AllowCursor.RemoveListener(OnAllowCursor); });
|
||||
}
|
||||
|
||||
private void OnInspect(InputAction.CallbackContext obj)
|
||||
{
|
||||
switch (obj)
|
||||
{
|
||||
BITAppForUnity.AllowCursor.RemoveListener(OnAllowCursor);
|
||||
});
|
||||
case {interaction:PressInteraction, performed: true} when CurrentState is Movement:
|
||||
animator.Play(BITConstant.Player.Inspect);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnAllowCursor(bool allow)
|
||||
@@ -185,6 +197,17 @@ namespace BITFALL.Guns
|
||||
case Melee:
|
||||
return;
|
||||
}
|
||||
|
||||
if (Item?.TryGetProperty<IClip>(out var clip) is false)
|
||||
{
|
||||
_uxPopup?.Popup("<color=yellow>机匣损坏或不存在</color>");
|
||||
return;
|
||||
}
|
||||
if (_inventory.TryGetItem(IsClipReady, out var clipItem) is false)
|
||||
{
|
||||
_uxPopup?.Popup("<color=yellow>没有兼容的弹夹</color>");
|
||||
return;
|
||||
}
|
||||
TransitionState<Reload>();
|
||||
}
|
||||
|
||||
@@ -199,6 +222,13 @@ namespace BITFALL.Guns
|
||||
});
|
||||
}
|
||||
|
||||
private bool IsClipReady(IBasicItem clip)
|
||||
{
|
||||
if(Item.TryGetProperty<IClip>(out var _clip) is false) return false;
|
||||
if(clip.AddressablePath != _clip.AddressablePath) return false;
|
||||
if(clip.TryGetProperty<IClip>(out var _clipItem) is false) return false;
|
||||
return _clipItem.Remaining > 0;
|
||||
}
|
||||
private void OnMovementStateChanged(IEntityMovementState arg1, IEntityMovementState arg2)
|
||||
{
|
||||
if (IsEntered is false) return;
|
||||
@@ -207,6 +237,17 @@ namespace BITFALL.Guns
|
||||
x.OnMovementStateChanged(arg1,arg2);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Exit()
|
||||
{
|
||||
base.Exit();
|
||||
if (Item.TryGetProperty<IClip>(out var clip) && cacheRounds.TryGetRelease(out var rounds))
|
||||
{
|
||||
clip.Remaining = rounds;
|
||||
}
|
||||
cacheRounds.Clear();
|
||||
}
|
||||
|
||||
public override UniTask EntryAsync()
|
||||
{
|
||||
base.EntryAsync();
|
||||
@@ -311,8 +352,10 @@ namespace BITFALL.Guns
|
||||
Sender = this
|
||||
});
|
||||
|
||||
animator.animator.SetBool(IsGrounded,_movement.IsGrounded);
|
||||
animator.animator.SetBool(IsCrouched,_movement.CurrentState is IPlayerCrouchState or IPlayerSlideState);
|
||||
animator.animator.SetBool((int)BITHash.Player.IsGrounded,_movement.IsGrounded);
|
||||
animator.animator.SetBool((int)BITHash.Player.IsCrouched,_movement.CurrentState is IPlayerCrouchState or IPlayerSlideState);
|
||||
animator.animator.SetBool((int)BITHash.Player.Cancel,
|
||||
recoilSpring.value.GetLength()>0.1f);
|
||||
animator.animator.SetFloat((int)BITHash.Player.Aim,_equipService.Zoom.Value);
|
||||
animator.animator.SetFloat(BITConstant.Player.SqrMagnitude,_movement.LocomotionBasedVelocity.sqrMagnitude);
|
||||
|
||||
@@ -404,30 +447,95 @@ namespace BITFALL.Guns
|
||||
|
||||
expectAiming.shouldBe = inputActionGroup.GetAction(aimAction).IsPressed();
|
||||
}
|
||||
|
||||
|
||||
public override void AnimationEvent(string eventName)
|
||||
{
|
||||
if(IsEntered is false) return;
|
||||
if (IsEntered is false) return;
|
||||
base.AnimationEvent(eventName);
|
||||
CurrentState?.AnimationEvent(eventName);
|
||||
// switch (eventName)
|
||||
// {
|
||||
// case "Melee":
|
||||
// meleeService.Melee(new MeleeCommand
|
||||
// {
|
||||
// PlayerId = Entity.Id,
|
||||
// Position = Transform.position,
|
||||
// Force = Transform.forward * 128,
|
||||
// Range = 1
|
||||
// });
|
||||
// break;
|
||||
// }
|
||||
|
||||
|
||||
|
||||
if (Item.TryGetProperty<IClip>(out var clip)
|
||||
&& _inventory.TryGetItem(IsClipReady, out var clipItem)
|
||||
&& clipItem.TryGetProperty<IClip>(out var nextClip)
|
||||
)
|
||||
switch (eventName)
|
||||
{
|
||||
case BITConstant.Player.EjectClip:
|
||||
if(clip.Remaining <= 0) break;
|
||||
cacheRounds.Release(clip.Remaining);
|
||||
clip.Remaining = 0;
|
||||
break;
|
||||
case BITConstant.Player.InsertClip:
|
||||
cacheRounds.TryGetRelease(out var current);
|
||||
|
||||
var newRound = nextClip.Remaining;
|
||||
var swapClipClone = nextClip.Clone().As<IClip>();
|
||||
|
||||
var swapClip = clipItem.Clone().As<IBasicItem>();
|
||||
swapClipClone.Remaining = current;
|
||||
if (swapClip.TrySetProperty(swapClipClone) is false || _inventory.TrySetItem(swapClip) is false)
|
||||
{
|
||||
_uxPopup?.Popup("<color=yellow>弹匣回收失败</color>");
|
||||
clip.Remaining = current;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
clip.Remaining = newRound;
|
||||
}
|
||||
// var newRound = Mathf.Clamp(current + nextClip.Remaining, 0,int.MaxValue);
|
||||
//
|
||||
// newRound = nextClip.Remaining;
|
||||
//
|
||||
// var newClipItem = clipItem.Clone() as IBasicItem;
|
||||
// nextClip = nextClip.Clone().As<IClip>();
|
||||
//
|
||||
// if(newRound>clip.Capacity)
|
||||
// {
|
||||
// newRound = clip.Capacity;
|
||||
// nextClip.Remaining = current + nextClip.Remaining - clip.Capacity;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// nextClip.Remaining = 0;
|
||||
// }
|
||||
// if(newRound == 0)
|
||||
// {
|
||||
// _uxPopup?.Popup("<color=yellow>空弹匣</color>");
|
||||
// break;
|
||||
// }
|
||||
//
|
||||
// newClipItem!.TrySetProperty(nextClip);
|
||||
//
|
||||
// if (_inventory.TrySetItem(newClipItem))
|
||||
// {
|
||||
// clip.Remaining = newRound;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// clip.Remaining = current;
|
||||
// _uxPopup?.Popup("<color=yellow>弹匣回收失败</color>");
|
||||
// }
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void Fire()
|
||||
{
|
||||
if (RequireBolt) return;
|
||||
|
||||
|
||||
if (Item.TryGetProperty<IClip>(out var clip))
|
||||
{
|
||||
if (clip.Remaining <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
clip.Remaining--;
|
||||
}
|
||||
}
|
||||
//播放射击动画
|
||||
UnityEntity.Invoke(Constant.Animation.Play, BITConstant.Player.Fire);
|
||||
|
||||
|
@@ -18,7 +18,7 @@ namespace BITFALL.Player.Equip
|
||||
{
|
||||
[SerializeField] private Material material;
|
||||
[SerializeField] private LayerMask layerMask;
|
||||
|
||||
|
||||
[Header(Constant.Header.Input)] [SerializeField]
|
||||
private InputActionReference craftAction;
|
||||
|
||||
|
47
Assets/Artists/Scripts/Equip/PlacingController.cs
Normal file
47
Assets/Artists/Scripts/Equip/PlacingController.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using BITFALL.Entities.Inventory;
|
||||
using BITFALL.Placement;
|
||||
using BITKit;
|
||||
using BITKit.Entities;
|
||||
using BITKit.StateMachine;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BITFALL.Player.Equip
|
||||
{
|
||||
public interface IPlacingState:IState{}
|
||||
public class PlacingController : BITEquipBase<IPlacingState>
|
||||
{
|
||||
internal AssetablePlacement _placement => item as AssetablePlacement;
|
||||
|
||||
[SerializeField] private Vector3 offset;
|
||||
|
||||
[Inject] private IEntityInventory _inventory;
|
||||
[Inject] private IEntityMovement _movement;
|
||||
[Inject] private IPlayerEquipSelector _equipSelector;
|
||||
|
||||
public override void OnAwake()
|
||||
{
|
||||
base.OnAwake();
|
||||
animator[0].onStateExit += OnStateExit;
|
||||
}
|
||||
|
||||
private void OnStateExit(string obj)
|
||||
{
|
||||
if (IsEntered is false || obj is not BITConstant.Player.Use) return;
|
||||
if (!_inventory.Remove(Item)) return;
|
||||
var instance = _placement.CreateInstance() as MonoBehaviour;
|
||||
instance!.transform.SetPositionAndRotation(_movement.Position + _movement.Rotation * offset, _movement.Rotation);
|
||||
|
||||
_equipSelector.Cancel();
|
||||
}
|
||||
|
||||
public override void Entry()
|
||||
{
|
||||
base.Entry();
|
||||
animator.Play(BITConstant.Player.Draw);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user