This commit is contained in:
CortexCore
2023-11-15 23:54:54 +08:00
parent ee3ecec6cb
commit 3c837a4a33
356 changed files with 73756 additions and 26493 deletions

View File

@@ -1,7 +1,12 @@
using System;
using System.Collections;
using System.Collections.Generic;using BITFALL.Entities.Equipment;
using System.Collections.Generic;
using BITFALL.Combat;
using BITFALL.Entities.Equipment;
using BITKit;
using BITKit.Entities;
using BITKit.Entities.Melee;
using BITKit.Sensors;
using Cysharp.Threading.Tasks;
using UnityEngine;
using IEntity = BITKit.Entities.IEntity;
@@ -10,25 +15,31 @@ namespace BITFALL.Entities.Equipment
{
public class AIEquipController : MonoBehaviour,IEquipBase
{
[SerializeField] protected Optional<int> overrideDamage;
[SerializeField] protected AssetableItem assetableItem;
[SerializeField] protected Optional<Tag> ignoreTag;
[SerializeReference,SubclassSelector] protected ISensor targetSensor;
[SerializeReference, SubclassSelector] protected IMeleeService meleeService;
protected AssetableEquip equip => assetableItem as AssetableEquip;
protected Transform Transform { get; private set; }
public bool IsEntered { get; set; }
protected readonly IntervalUpdate meleeInterval = new(1);
[Inject] public IHealth _health;
public virtual void Entry()
{
UnityEntity.AddListener<string>(Constant.Animation.OnEvent, OnAnimationEvent);
}
protected virtual void OnAnimationEvent(string animationEventName)
{
}
public virtual UniTask EntryAsync()
{
return UniTask.CompletedTask;
}
public virtual void Entered()
{
UnityEntity.AddListener<string>(Constant.Animation.OnEvent, OnAnimationEvent);
}
public virtual void Exit()
{
UnityEntity.RemoveListener<string>(Constant.Animation.OnEvent, OnAnimationEvent);
}
public virtual UniTask ExitAsync()
@@ -36,8 +47,37 @@ namespace BITFALL.Entities.Equipment
return UniTask.CompletedTask;
}
public virtual void Exited()
{
UnityEntity.RemoveListener<string>(Constant.Animation.OnEvent, OnAnimationEvent);
}
protected virtual void OnAnimationEvent(string animationEventName)
{
switch (animationEventName)
{
case BITConstant.Player.Attack:
case BITConstant.Player.Melee:
meleeService.Melee(new MeleeCommand()
{
Damage = equip.MeleeDamage,
Force = equip.MeleeForce,
PlayerId = Entity.Id,
Position = transform.position,
Range = equip.MeleeRange,
Forward = UnityEntity.transform.forward,
IgnoreTags = ignoreTag.Allow ?ignoreTag.Value.GetTags():Array.Empty<string>(),
ForceHitStun = true,
Limit = 1,
});
break;
}
}
public virtual void OnAwake()
{
Transform = transform;
}
public virtual void OnStart()
@@ -58,6 +98,11 @@ namespace BITFALL.Entities.Equipment
public void PlayAudio(string name)
{
}
protected void RequestMelee()
{
if (meleeInterval.AllowUpdate is false) return;
UnityEntity.Invoke(Constant.Animation.Play, BITConstant.Player.Melee);
}
}
}

View File

@@ -2,6 +2,7 @@ using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Security.Cryptography;
using BITFALL.Bullet;
using BITFALL.Entities.Equipment;
using BITKit;
@@ -17,37 +18,73 @@ namespace BITFALL.Guns
[SerializeField] private Transform firePoint;
[SerializeReference,SubclassSelector] private IBulletService bulletService;
[SerializeField] private bool forceFire;
[SerializeField] private Optional<int> customFireRate;
[SerializeField] private Optional<int> customBurstCount;
[SerializeField] private Optional<IntervalUpdate> customFireInterval;
[SerializeField] private Optional<float> overrideRecoil;
private AssetableGun _gun=>assetableItem as AssetableGun;
private readonly IntervalUpdate fireInterval = new();
private readonly LimitTimes fireLimitTimes=new()
{
max = 3
};
public override void Entry()
{
base.Entry();
fireInterval.Interval = _gun.FireMode.FireRate is 0 ? 1 : 1f/_gun.FireMode.FireRate;
if (customFireRate.Allow)
{
fireInterval.Interval =customFireRate.Value is 0 ? 1 : 1f / customFireRate.Value;
}
UnityEntity.AddListener<BITConstant.Command.AttackCommand>(OnAttack);
fireLimitTimes.max = customBurstCount.IfNotAllow(1);
fireLimitTimes.Reset();
UnityEntity.AddListener<string>(OnCommand);
}
private void OnCommand(string obj)
{
switch (obj)
{
case BITConstant.Player.Fire:
RequestFire();
break;
case BITConstant.Player.Melee:
RequestMelee();
fireInterval.AddDelay(1);
break;
}
}
public override void Exit()
{
base.Exit();
UnityEntity.RemoveListener<BITConstant.Command.AttackCommand>(OnAttack);
UnityEntity.RemoveListener<string>(OnCommand);
}
public override void OnUpdate(float deltaTime)
{
if (forceFire && fireInterval.AllowUpdate)
if (forceFire)
{
if(customFireInterval.Allow)
RequestFire();
}
}
private void RequestFire()
{
if (fireInterval.AllowUpdate)
{
if (customFireInterval.Allow)
{
if (customFireInterval.Value.AllowUpdate)
{
OnAttack(new BITConstant.Command.AttackCommand());
//OnAttack(new BITConstant.Command.AttackCommand());
fireLimitTimes.Reset();
}
else
{
if (fireLimitTimes.Allow)
OnAttack(new BITConstant.Command.AttackCommand());
}
}
else
@@ -59,17 +96,46 @@ namespace BITFALL.Guns
private void OnAttack(BITConstant.Command.AttackCommand obj)
{
for (var i = 0; i < _gun.BuckShot.IfNotAllow(1); i++)
{
InternalFire();
}
UnityEntity.Invoke(Constant.Animation.Play, BITConstant.Player.Fire);
}
private void InternalFire()
{
var random = UnityEngine.Random.insideUnitCircle;
if (_gun.TryGetProperty<ISpread>(out var spread))
{
random *= spread.Spread;
}
if (overrideRecoil.Allow)
{
random *= overrideRecoil.Value;
}
var rotation = firePoint.rotation;
if(targetSensor is not null && targetSensor.Get().TryGetFirstOrDefault(out var target))
{
if (target.TryGetComponent<IEntityMovement>(out var targetMovement))
{
rotation = Quaternion.LookRotation(targetMovement.ViewCenter - firePoint.position);
}
else
{
rotation = Quaternion.LookRotation(target.position - firePoint.position);
}
}
bulletService.Spawn(new SpawnBullet()
{
forward = firePoint.forward,
initialDamage = _gun.InitialDamage,
initiator = Entity.Id,
pos = firePoint.position,
rot = firePoint.rotation,
startSpeed = _gun.InitialBulletSpeed,
Forward = rotation * (Vector3.forward + Vector3.up * random.y + Vector3.right * random.x),
InitialDamage =overrideDamage.IfNotAllow( _gun.InitialDamage),
Initiator = Entity.Id,
Position = firePoint.position,
Rotation = rotation,
StartSpeed = _gun.InitialBulletSpeed,
InitialForce = _gun.InitialBulletForce,
});
UnityEntity.Invoke(Constant.Animation.Play, BITConstant.Player.Fire);
}
}

View File

@@ -12,7 +12,6 @@ namespace BITFALL.Entities.Equipment
{
public class AIMeleeController : AIEquipController
{
[SerializeReference,SubclassSelector] private IMeleeService meleeService;
[SerializeField] private bool forceAttack;
private readonly IntervalUpdate interval = new(1);
@@ -35,30 +34,10 @@ namespace BITFALL.Entities.Equipment
OnAttack(new BITConstant.Command.AttackCommand());
}
}
private void OnAttack(BITConstant.Command.AttackCommand obj)
{
UnityEntity.Invoke(Constant.Animation.Play, BITConstant.Player.Melee);
}
protected override void OnAnimationEvent(string animationEventName)
{
switch (animationEventName)
{
case BITConstant.Player.Attack:
case BITConstant.Player.Melee:
meleeService.Melee(new MeleeCommand()
{
Damage = assetableMelee.MeleeDamage,
Force = assetableMelee.MeleeForce,
PlayerId = Entity.Id,
Position = transform.position,
Range = assetableMelee.MeleeRange,
Forward = UnityEntity.transform.forward,
});
break;
}
}
}
}

View File

@@ -27,7 +27,10 @@
"GUID:87bea3a21c744b1478660b70494160ba",
"GUID:ef0bb553b58b90b488bdbe8672e3be0b",
"GUID:48ef04d98836e2640bf90b524bdff904",
"GUID:1eb13dc7c3cb5a444877a995967ed591"
"GUID:1eb13dc7c3cb5a444877a995967ed591",
"GUID:a83bfc00a1ad8e74981b456e6c50ed4e",
"GUID:de309aeb0cb045044a5b9cd0a72f471b",
"GUID:508392158bd966c4d9c21e19661a441d"
],
"includePlatforms": [],
"excludePlatforms": [],

View File

@@ -11,10 +11,8 @@ using UnityEngine.InputSystem;
using BITKit.StateMachine;
using Cysharp.Threading.Tasks;
using Unity.Mathematics;
using UnityEditorInternal;
using UnityEngine.InputSystem.Interactions;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace BITFALL.Guns
@@ -62,6 +60,7 @@ namespace BITFALL.Guns
[Header(Constant.Header.Settings)]
[SerializeField] private Vector3 bulletInitialOffset;
[SerializeField] private SpringEulerAngle recoilSpring=new();
[SerializeField] private float recoilPositionWeight=1;
[Header(Constant.Header.Gameobjects)]
[SerializeField] private Transform initialSight;
@@ -83,6 +82,7 @@ namespace BITFALL.Guns
// 引用组件
[Header(Constant.Header.Components)]
[SerializeField] private LocationAdditive locationAdditive;
[SerializeField] private LocationAdditive selfViewAdditive;
// 引用预制体
[Header(Constant.Header.Prefabs)]
@@ -111,7 +111,7 @@ namespace BITFALL.Guns
#region
public override string AddressablePath => _gun.AddressablePath;
#endregion
public override void OnAwake()
{
base.OnAwake();
@@ -119,14 +119,26 @@ namespace BITFALL.Guns
inputActionGroup.RegisterCallback(aimAction, OnAim);
inputActionGroup.RegisterCallback(reloadAction, OnReload);
inputActionGroup.RegisterCallback(meleeAction, OnMelee);
inputActionGroup.RegisterCallback(steadyAimAction, OnSteadyAim);
if (breathingAdditive.Allow)
inputActionGroup.RegisterCallback(steadyAimAction, OnSteadyAim);
_movement.OnStateChanged += OnMovementStateChanged;
_movement.OnCommand += OnMovementCommand;
animator[0].onStateExit += (state) => { isHolstered = state is BITConstant.Player.Holster; };
animator[0].onStateExit += (state) =>
BITAppForUnity.AllowCursor.AddListener(OnAllowCursor);
destroyCancellationToken.Register(() =>
{
isHolstered = state is BITConstant.Player.Holster;
};
BITAppForUnity.AllowCursor.RemoveListener(OnAllowCursor);
});
}
private void OnAllowCursor(bool allow)
{
if (!allow) return;
expectFiring.Reset();
expectAiming.Reset();
}
private void OnSteadyAim(InputAction.CallbackContext obj)
@@ -262,15 +274,25 @@ namespace BITFALL.Guns
break;
}
animator.animator.SetBool(IsGrounded,_movement.IsGrounded);
animator.animator.SetFloat(BITConstant.Player.SqrMagnitude,_movement.LocomotionBasedVelocity.sqrMagnitude);
recoilSpring.Update(deltaTime,default);
locationAdditive.AddEuler(recoilSpring.value);
if (selfViewAdditive)
{
selfViewAdditive.AddEuler(recoilSpring.value);
selfViewAdditive.AddPosition(
new Vector3(
recoilSpring.value.y,
-recoilSpring.value.x,
recoilSpring.value.z
) *
recoilPositionWeight
);
}
if(AnimationProperties.TryGetValue(BITConstant.Player.Aim, out var _aim))
{
_equipService.Zoom.Allow = CurrentState is Aim;
@@ -331,6 +353,8 @@ namespace BITFALL.Guns
}
AllowRendering.SetDisableElements(64564,_equipService.AllowScope);
expectAiming.shouldBe = inputActionGroup.GetAction(aimAction).IsPressed();
}
public override void AnimationEvent(string eventName)
@@ -353,28 +377,25 @@ namespace BITFALL.Guns
public void Fire()
{
if (RequireBolt) return;
//如果启用了指针则不开火
if(BITAppForUnity.AllowCursor)
{
return;
}
//播放射击动画
UnityEntity.Invoke(Constant.Animation.Play, BITConstant.Player.Fire);
//调用BulletManager生成子弹
var _transform = transform;
var rotation = _transform.rotation;
BulletService.Spawn(new SpawnBullet
if (_gun.BuckShot.Allow)
{
initiator = Entity.Id,
pos = (_transform.position+rotation * bulletInitialOffset),
rot = rotation,
forward = _transform.forward,
initialDamage = _gun.InitialDamage,
startSpeed = _gun.InitialBulletSpeed,
InitialForce = _gun.InitialBulletForce,
});
InternalAddRecoil();
for (int i = 0; i < _gun.BuckShot.Value; i++)
{
InternalFire();
}
}
else
{
InternalFire();
InternalAddRecoil();
}
//开火模式逻辑判断
switch (_gun.FireMode)
@@ -395,6 +416,38 @@ namespace BITFALL.Guns
}
break;
}
if (_gun.FireMode is SemiFireMode {RequireBoltAction:true})
{
RequireBolt = true;
}
}
private void InternalFire()
{
//调用BulletManager生成子弹
var _transform = transform;
var rotation = _transform.rotation;
var random = UnityEngine.Random.insideUnitCircle;
if (_gun.TryGetProperty<ISpread>(out var spread))
{
random *= spread.Spread;
}
random *= recoilSpring.value.GetLength();
BulletService.Spawn(new SpawnBullet
{
Initiator = Entity.Id,
Position = (_transform.position+rotation * bulletInitialOffset),
Rotation = rotation,
Forward = rotation * (Vector3.forward + Vector3.up * random.y + Vector3.right * random.x),
InitialDamage = _gun.InitialDamage,
StartSpeed = _gun.InitialBulletSpeed,
InitialForce = _gun.InitialBulletForce,
});
}
private void InternalAddRecoil()
{
if (_gun.TryGetProperty<IRecoil>(out var _recoil))
{
var _newRecoil = new Vector3
@@ -406,14 +459,15 @@ namespace BITFALL.Guns
recoilSpring.value = _newRecoil;
_playerMovement.AddViewEuler(new float2(_newRecoil.x,_newRecoil.y));
}
if (_gun.FireMode is SemiFireMode {RequireBoltAction:true})
{
RequireBolt = true;
}
}
private void OnFire(InputAction.CallbackContext context)
{
//如果启用了指针则不开火
if(BITAppForUnity.AllowCursor)
{
expectFiring.Reset();
return;
}
switch (_gun.FireMode)
{
case AutoFireMode :
@@ -439,11 +493,17 @@ namespace BITFALL.Guns
}
private void OnAim(InputAction.CallbackContext context)
{
expectAiming.shouldBe = context.ReadValueAsButton();
//如果启用了指针则不开火
if(BITAppForUnity.AllowCursor)
{
expectAiming.Reset();
return;
}
//expectAiming.shouldBe = context.ReadValueAsButton();
}
}
#if UNITY_EDITOR
[CustomEditor(typeof(BITGun))]
public class BITGunInspector:BITInspector<BITGun>{}
#endif
// #if UNITY_EDITOR
// [CustomEditor(typeof(BITGun))]
// public class BITGunInspector:BITInspector<BITGun>{}
// #endif
}

View File

@@ -20,12 +20,15 @@ namespace BITFALL.Guns.States
{
[SerializeField] private ExpectState<bool> _expectRun;
[Inject] protected ISelector _selector;
private float elapsedTime;
private float requestBoltActionElapsedTime;
private bool boltActionImmediately;
public override void OnStateEntry(IState old)
{
switch (old)
{
case Movement:
case Equip:
break;
case Aim:
root.animator.CrossFade(BITConstant.Player.Movement, 0.32f);
break;
@@ -38,13 +41,15 @@ namespace BITFALL.Guns.States
}
public override void OnStateExit(IState old, IState newState)
{
elapsedTime = 0;
requestBoltActionElapsedTime = 0;
base.OnStateExit(old, newState);
_selector.OnActive -= OnActive;
}
public override void OnStateUpdate(float deltaTime)
{
elapsedTime += deltaTime;
if (root.RequireBolt)
requestBoltActionElapsedTime += deltaTime;
if (root.animator[0].stateName is not BITConstant.Player.Movement) return;
if (root.expectFiring.shouldBe && root.fireInterval.AllowUpdate)
{
@@ -53,14 +58,24 @@ namespace BITFALL.Guns.States
if (root.expectAiming.shouldBe && BITAppForUnity.AllowCursor == false)
{
root.TransitionState<Aim>();
}else if (_expectRun)
return;
}
if (_expectRun)
{
root.TransitionState<Run>();
}else if (root.RequireBolt && elapsedTime > 0.5f || boltActionImmediately)
return;
}
switch (root.RequireBolt)
{
root.TransitionState<Reload>();
case var _ when boltActionImmediately:
case var _ when requestBoltActionElapsedTime > 1f:
case var _ when root.animator[4].stateName == BITConstant.Player.Empty && requestBoltActionElapsedTime>0.32f:
root.TransitionState<Reload>();
break;
}
}
public void OnActive(ISelectable selectable)
{
root.animator.Play(BITConstant.Player.Interactive);
@@ -167,13 +182,12 @@ namespace BITFALL.Guns.States
root.animator.CrossFade(BITConstant.Player.Aim, 0.16f);
break;
}
_entityMovement.ExecuteCommand<PlayerDisableRunCommand>(new(this));
_entityMovement.ExecuteCommand<PlayerPauseRunCommand>(new(this,true));
}
public override void OnStateExit(IState old, IState newState)
{
base.OnStateExit(old, newState);
_entityMovement.ExecuteCommand<PlayerEnableRunCommand>(new(this));
_entityMovement.ExecuteCommand<PlayerPauseRunCommand>(new(this,false));
}
public override void OnStateUpdate(float deltaTime)
@@ -214,8 +228,6 @@ namespace BITFALL.Guns.States
base.Initialize();
root.animator[0].onStateExit += OnAnimationStateExit;
}
private void OnAnimationStateExit(string obj)
{
if (obj is BITConstant.Player.Equip) completed = true;
@@ -225,22 +237,26 @@ namespace BITFALL.Guns.States
{
completed = false;
root.animator.Play(BITConstant.Player.Equip,-1,0);
root.animator.animator.Update(0);
_entityMovement.ExecuteCommand<PlayerPauseRunCommand>(new(this,true));
}
public override void OnStateExit(IState old, IState newState)
{
base.OnStateExit(old, newState);
_entityMovement.ExecuteCommand<PlayerPauseRunCommand>(new(this,false));
}
public override void OnStateUpdate(float deltaTime)
{
var state = root.animator[0];
if (state.stateName == BITConstant.Player.Equip)
//var state = root.animator[0];
if (completed)
{
if (completed)
{
root.TransitionState<Movement>();
}
}
else
{
root.animator.Play(BITConstant.Player.Equip);
root.TransitionState<Movement>();
}
// else
// {
// root.animator.Play(BITConstant.Player.Equip);
// }
}
}
@@ -264,7 +280,7 @@ namespace BITFALL.Guns.States
{
base.OnStateEntry(old);
_entityMovement.ExecuteCommand<PlayerCancelRunCommand>();
_entityMovement.ExecuteCommand<PlayerPauseRunCommand>(new(this,true));
if (root.RequireBolt)
{
@@ -289,6 +305,7 @@ namespace BITFALL.Guns.States
{
root.RequireBolt = false;
base.OnStateExit(old, newState);
_entityMovement.ExecuteCommand<PlayerPauseRunCommand>(new(this,false));
}
}
[System.Serializable]
@@ -310,13 +327,15 @@ namespace BITFALL.Guns.States
}
public override void OnStateEntry(IState old)
{
base.OnStateEntry(old);
root.UnityEntity.Invoke(Constant.Animation.Play, BITConstant.Player.Melee);
_entityMovement.ExecuteCommand(new PlayerDisableRunCommand(this));
_entityMovement.ExecuteCommand<PlayerPauseRunCommand>(new(this,true));
}
public override void OnStateExit(IState old, IState newState)
{
_entityMovement.ExecuteCommand(new PlayerEnableRunCommand(this));
base.OnStateExit(old,newState);
_entityMovement.ExecuteCommand<PlayerPauseRunCommand>(new(this,false));
}
public override void OnStateUpdate(float deltaTime)
@@ -338,7 +357,15 @@ namespace BITFALL.Guns.States
{
public override void OnStateEntry(IState old)
{
base.OnStateEntry(old);
root.animator.Play(BITConstant.Player.Climb);
_entityMovement.ExecuteCommand<PlayerPauseRunCommand>(new(this,true));
}
public override void OnStateExit(IState old, IState newState)
{
base.OnStateExit(old, newState);
_entityMovement.ExecuteCommand<PlayerPauseRunCommand>(new(this,false));
}
public override void OnMovementStateChanged(IEntityMovementState old, IEntityMovementState newState)

View File

@@ -29,6 +29,11 @@ namespace BITFALL.Guns
return UniTask.CompletedTask;
}
public void Entered()
{
}
public void Exit()
{
}
@@ -38,6 +43,10 @@ namespace BITFALL.Guns
return UniTask.CompletedTask;
}
public void Exited()
{
}
public void OnAwake()
{
Entity.Inject(this);

View File

@@ -40,8 +40,8 @@ namespace BITFALL.Player.Movement
}
currentPosition = Vector3.Lerp(currentPosition,velocity * posValue,posDelta * deltaTime);
currentRotation = Quaternion.Lerp(currentRotation,Quaternion.Euler(angularVelocity * rotValue),rotDelta * deltaTime);
currentRotation = Quaternion.Slerp(currentRotation,Quaternion.Euler(angularVelocity * rotValue),rotDelta * deltaTime);
locationAdditive.AddEuler(currentRotation.eulerAngles);
locationAdditive.AddPosition(currentPosition);
}

View File

@@ -133,6 +133,12 @@ namespace BITFALL.Entities.Equipment.Melee
TransitionState<Draw>();
}
public override void Exited()
{
base.Exited();
_movement.ExecuteCommand<PlayerPauseRunCommand>(new(this,false));
}
public override void OnUpdate(float deltaTime)
{
base.OnUpdate(deltaTime);
@@ -144,6 +150,8 @@ namespace BITFALL.Entities.Equipment.Melee
var sqr = _movement.LocomotionBasedVelocity.sqrMagnitude;
animator.animator.SetFloat(BITConstant.Player.SqrMagnitude,sqr);
_movement.ExecuteCommand<PlayerPauseRunCommand>(new(this,CurrentState is not Idle));
}
private void OnBlock(InputAction.CallbackContext obj)
{
@@ -170,7 +178,7 @@ namespace BITFALL.Entities.Equipment.Melee
case {interaction: TapInteraction,performed:true} when CurrentState is not (Attack or HeavyAttack or Draw or Blocking):
TransitionState<Attack>();
break;
case {interaction: HoldInteraction,started:true} when CurrentState is not (Charging or Attack or HeavyAttack or Draw or Blocking):
case {interaction: PressInteraction,performed:true} when CurrentState is not (Attack or HeavyAttack or Draw or Blocking):
TransitionState<Charging>();
break;
case {interaction: HoldInteraction,canceled:true} when CurrentState is not (Attack or Idle or Draw or Blocking):

View File

@@ -48,7 +48,8 @@ namespace BITFALL.Entities.Equipment.Melee
public override void OnStateUpdate(float deltaTime)
{
base.OnStateUpdate(deltaTime);
meleeController.animator.animator.SetBool(BITConstant.Player.IsRunning,_movement.CurrentState is IPlayerRunState or IPlayerSprintState);
meleeController.animator.animator.SetBool(BITConstant.Player.IsRunning,_movement.CurrentState is IPlayerRunState);
meleeController.animator.animator.SetBool(BITConstant.Player.IsSprint,_movement.CurrentState is IPlayerSprintState);
meleeController.animator.animator.SetBool(BITConstant.Player.IsGrounded,_movement.IsGrounded);
meleeController.animator.animator.SetBool(BITConstant.Player.IsCrouched,_movement.CurrentState is IPlayerCrouchState);
}

View File

@@ -0,0 +1,83 @@
using System;
using System.Collections;
using System.Collections.Generic;
using BITFALL.Placement;
using BITFALL.Player.Movement;
using BITKit;
using BITKit.Entities;
using BITKit.StateMachine;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Interactions;
namespace BITFALL.Player.Equip
{
public interface IPlacementState:IState{}
public sealed class PlacementController : BITEquipBase<IPlacementState>
{
[SerializeField] private Material material;
[SerializeField] private LayerMask layerMask;
[Header(Constant.Header.Input)] [SerializeField]
private InputActionReference craftAction;
[Inject] private IEntityMovement _movement;
private readonly Optional<Location> allowCraft = new();
private AssetablePlacement _assetablePlacement=>Item.GetAssetable() as AssetablePlacement;
public override bool IsSupportItem(IBasicItem item)
{
if (item is null) return false;
var assetable = item.GetAssetable();
return assetable is IPlacementObject;
}
public override void OnAwake()
{
base.OnAwake();
inputActionGroup.RegisterCallback(craftAction, OnCraft);
}
private void OnCraft(InputAction.CallbackContext obj)
{
if (BITAppForUnity.AllowCursor.Allow) return;
if (obj is not { interaction: PressInteraction, performed: true }) return;
if (!allowCraft.Allow) return;
var instance = _assetablePlacement.CreateInstance() as MonoBehaviour;
instance!.transform.SetPositionAndRotation(allowCraft.Value, allowCraft.Value);
}
public override void OnUpdate(float deltaTime)
{
var startPosition = Camera.main.transform.position;
var direction = Camera.main.transform.forward;
var distance = 3.2f;
var position = _movement.Position;
var rotation = _movement.Rotation;
// ReSharper disable once AssignmentInConditionalExpression
if (allowCraft.Allow = Physics.Raycast(startPosition, direction, out var hit, distance, layerMask))
{
position = hit.point + hit.normal * 0.32f;
Debug.DrawLine(hit.point, hit.point + hit.normal, Color.magenta);
rotation = _movement.Rotation;
position = MathV.AlignToGrid(position, _assetablePlacement.PositionIncrement);
rotation = MathQ.AlignRotation(rotation, _assetablePlacement.RotationIncrement);
foreach (var x in _assetablePlacement.Object.As<MonoBehaviour>().GetComponentsInChildren<MeshFilter>())
{
Graphics.DrawMesh(x.sharedMesh,position+rotation*x.transform.localPosition,rotation * x.transform.localRotation,material,LayerMask.NameToLayer("Default"));
}
allowCraft.Value = new Location(position, rotation);
}
else
{
Debug.DrawLine(startPosition, startPosition + direction * distance, Color.red);
}
}
}
}

View File

@@ -50,6 +50,11 @@ namespace BITFALL.Player.Equip
return UniTask.CompletedTask;
}
public void Entered()
{
}
public void Exit()
{
spriteRenderer.enabled = false;
@@ -58,6 +63,11 @@ namespace BITFALL.Player.Equip
{
return UniTask.CompletedTask;
}
public void Exited()
{
}
private void OnUnEquip(IBasicItem obj)
{
foreach (var x in modelDictionary.Values)