Better action system

This commit is contained in:
ThomasCharester committed 2026-10-30 02:58:51 +03:00
1 parent 2bd71f8dc5
commit 71bb4c3b5b
110 files changed
+73523 -86288

No files matched your search

@@ -0,0 +1,24 @@
using Cysharp.Threading.Tasks;
namespace Code.OfficeGame.BattleMode.Actions.Deciders
{
public class AsIsBattleActionDecider : BattleActionDecider
{
public override DeciderType DeciderType => DeciderType.AsIs;
public override async UniTask<BattleActionDecisionResult> GetDecision()
{
await UniTask.Yield();
return new AsIsBattleActionDeciderResult()
{
ResultCode = BattleActionDecisionResultCode.Decided
};
}
public override void UnmountDecider()
{ }
public override void MountDecider()
{ }
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 2034bb40c0ea462baeac67d89aef0429
timeCreated: 1793316764
@@ -0,0 +1,15 @@
using Cysharp.Threading.Tasks;
namespace Code.OfficeGame.BattleMode.Actions.Deciders
{
public abstract class BattleActionDecider
{
public abstract DeciderType DeciderType { get; }
protected bool IsMounted;
public abstract UniTask<BattleActionDecisionResult> GetDecision();
public abstract void UnmountDecider();
public abstract void MountDecider();
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 8b6762673a7f4e40979aa0bd6532f836
timeCreated: 1793278644
@@ -0,0 +1,22 @@
using UnityEngine;
namespace Code.OfficeGame.BattleMode.Actions
{
public abstract class BattleActionDecisionResult
{
public BattleActionType ActionType;
public BattleActionDecisionResultCode ResultCode;
}
public class PositionBattleActionDeciderResult : BattleActionDecisionResult
{
public Vector3 Position;
public Quaternion Rotation;
}
public class FrameBattleActionDeciderResult : BattleActionDecisionResult
{
public int FrameCount;
}
public class AsIsBattleActionDeciderResult : BattleActionDecisionResult
{
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 392d78f7e24c4a4bbceea3776e00272c
timeCreated: 1793113452
@@ -0,0 +1,9 @@
namespace Code.OfficeGame.BattleMode.Actions
{
public enum BattleActionDecisionResultCode
{
Decided,
Deciding,
CancelDecision
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 6aa25f1eaf09411a875619aca0a36a3e
timeCreated: 1792758849
@@ -0,0 +1,142 @@
using System;
using System.Threading;
using Code.Infrastructure.Camera;
using Code.Infrastructure.Input;
using Code.OfficeGame.BattleMode.Actions.Player;
using Code.OfficeGame.BattleMode.Marker;
using Cysharp.Threading.Tasks;
using UnityEngine;
using UnityEngine.InputSystem;
namespace Code.OfficeGame.BattleMode.Actions.Deciders
{
public class BattleActionPositionDecider : BattleActionDecider
{
private CameraStateMachine _cameraStateMachine;
private IInputService _inputService;
private Vector3 _targetPosition;
private LayerMask _navMeshMask;
private const float StoppingDistance = 0.15f;
public BattleActionPositionDecider(
CameraStateMachine cameraStateMachine,
IInputService inputService,
MarkerManager markerManager)
{
_markerManager = markerManager;
_cameraStateMachine = cameraStateMachine;
_inputService = inputService;
_navMeshMask = LayerMask.GetMask("Environment");
}
private CancellationTokenSource _waitForEnterTokenSource;
private BattleActionDecisionResultCode _decisionResultCode;
public override DeciderType DeciderType => DeciderType.Position;
public override async UniTask<BattleActionDecisionResult> GetDecision()
{
if (!IsMounted) throw new Exception("Decider is not mounted"); // А почему бы и нет?
_waitForEnterTokenSource = new CancellationTokenSource();
_decisionResultCode = BattleActionDecisionResultCode.CancelDecision;
await UniTask.WaitUntilCanceled(_waitForEnterTokenSource.Token).SuppressCancellationThrow();
_waitForEnterTokenSource.Dispose();
_waitForEnterTokenSource = null;
return new PositionBattleActionDeciderResult()
{
ResultCode = _decisionResultCode,
Position = _targetPosition,
};
}
public override void UnmountDecider()
{
if (!IsMounted) return;
_playerDecisionMarker.Toggle(false);
_markerManager.ReleaseMarkerInstance(_playerDecisionMarker);
_markerManager.ReleaseMarkerInstance(_playerLockedDecisionMarker);
_inputService.UnbindActionPerformed((int)ActionMappings.BattleMode, (int)BattleModeActions.Select,
SelectPosition);
_inputService.UnbindActionPerformed((int)ActionMappings.BattleMode, (int)BattleModeActions.Confirm,
ConfirmPosition);
_inputService.UnbindActionPerformed((int)ActionMappings.BattleMode, (int)BattleModeActions.Cancel,
CancelPosition);
_inputService.UnbindActionPerformed((int)ActionMappings.BattleMode, (int)BattleModeActions.Watchment,
MarkPosition);
IsMounted = false;
}
public override void MountDecider()
{
if (IsMounted) return;
_inputService.BindActionPerformed((int)ActionMappings.BattleMode, (int)BattleModeActions.Select,
SelectPosition);
_inputService.BindActionPerformed((int)ActionMappings.BattleMode, (int)BattleModeActions.Confirm,
ConfirmPosition);
_inputService.BindActionPerformed((int)ActionMappings.BattleMode, (int)BattleModeActions.Cancel,
CancelPosition);
_inputService.BindActionPerformed((int)ActionMappings.BattleMode, (int)BattleModeActions.Watchment,
MarkPosition);
_playerLockedDecisionMarker = _markerManager.GetMarkerInstance();
_playerDecisionMarker = _markerManager.GetMarkerInstance();
_playerDecisionMarker.Toggle(true);
IsMounted = true;
}
private MarkerManager _markerManager;
private void CancelPosition(InputAction.CallbackContext obj)
{
_decisionResultCode = BattleActionDecisionResultCode.CancelDecision;
_waitForEnterTokenSource?.Cancel();
}
private void ConfirmPosition(InputAction.CallbackContext input)
{
_decisionResultCode = BattleActionDecisionResultCode.Decided;
_waitForEnterTokenSource?.Cancel();
}
private RaycastHit[] _hitBuffer = new RaycastHit[1];
private Vector3 _lastViewedPosition;
private PlayerDecisionMarker _playerDecisionMarker;
private PlayerDecisionMarker _playerLockedDecisionMarker;
private void MarkPosition(InputAction.CallbackContext input)
{
var position = _cameraStateMachine.Camera.transform.position;
var direction = _cameraStateMachine.Camera.transform.forward;
var hitCount = Physics.RaycastNonAlloc(position, direction, _hitBuffer, Mathf.Infinity, _navMeshMask);
if (hitCount == 0) return;
var hit = _hitBuffer[0];
_playerDecisionMarker.MoveMarker(hit.point);
_lastViewedPosition = hit.point;
}
private void SelectPosition(InputAction.CallbackContext input)
{
_targetPosition = _lastViewedPosition;
_playerLockedDecisionMarker.MoveMarker(_targetPosition);
_playerLockedDecisionMarker.Toggle(true);
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 220462a568ce470482b264d105953329
timeCreated: 1793278626
@@ -0,0 +1,8 @@
namespace Code.OfficeGame.BattleMode.Actions.Deciders
{
public enum DeciderType
{
AsIs,
Position
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 534386b84312450f997b33343b402f74
timeCreated: 1793278491