Multiple entities

This commit is contained in:
ThomasCharester committed 2026-10-23 20:09:32 +03:00
1 parent ccc4c04234
commit 1de0e93ae0
5677 files changed
+364912 -919855

No files matched your search

+37 -25
View File
@@ -1,3 +1,4 @@
using System.Linq;
using Code.Game.Cleaning.Player;
using Code.Game.Gameplay.Player;
using Code.Game.Gameplay.Player.Factory;
@@ -8,6 +9,7 @@ using Code.Infrastructure.Input;
using Code.Infrastructure.SceneLoader;
using Code.Infrastructure.UI;
using Code.Infrastructure.Utils;
using Code.OfficeGame.BattleMode.Actions;
using Code.OfficeGame.BattleMode.Actions.Player;
using Code.OfficeGame.BattleMode.UI;
using Code.OfficeGame.Player;
@@ -16,6 +18,7 @@ using KinematicCharacterController;
using ObservableCollections;
using R3;
using Reflex.Core;
using Reflex.Injectors;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.SceneManagement;
@@ -35,21 +38,22 @@ namespace Code.Game.TestingLevel
{
Cursor.lockState = CursorLockMode.Locked;
#if UNITY_EDITOR
#if UNITY_EDITOR
Context.InputService.EnableMap(ActionMappings.Debug);
Context.InputService.BindActionPerformed((int)ActionMappings.Debug, (int)DebugActions.ToggleBattleMode, ToggleBattleMode);
#endif
Context.InputService.BindActionPerformed((int)ActionMappings.Debug, (int)DebugActions.ToggleBattleMode,
ToggleBattleMode);
#endif
Context.InputService.EnableMap(ActionMappings.OpenMovement);
Context.InputService.EnableMap(ActionMappings.UI); //
await Context.Camera.SwitchState(CameraMode.OpenMovement);
if (Context.StateMachine.CurrentState == AppStates.BattleState) return;
Context.AudioService.SetAudioListener(Context.Camera.Camera.GetComponent<AudioListener>());
var waitForContainer =
Context.SceneContainerManager.ScenesContainers
.ObserveDictionaryAdd()
@@ -65,44 +69,44 @@ namespace Code.Game.TestingLevel
var factory = new PlayerFactory(factoryConfig);
var player = await factory.CreatePlayer();
var playerKinematicCharacterMotor = player.GetComponent<KinematicCharacterMotor>();
var playerMovementController = player.GetComponent<PlayerMovementController>();
var playerMovementController = player.GetComponent<MovementController>();
var playerControlsProvider = player.GetComponent<PlayerControlsProvider>();
var playerAnimatorProvider = player.GetComponent<PlayerAnimator>();
var playerTimelineActor = player.GetComponent<PlayerTimelineActor>();
var playerTimelineActor = player.GetComponent<PlayerControlledTimelineActor>();
playerMovementController.Freeze = true;
BattleActionDecisionPanel battleActionDecisionPanel =
(BattleActionDecisionPanel) await Context.UIFactory
.LoadPanel(UIPanelType.BattleActionDecision,false);
BattleActionDecisionPanel battleActionDecisionPanel =
(BattleActionDecisionPanel)await Context.UIFactory
.LoadPanel(UIPanelType.BattleActionDecision, false);
// ((OpenMovementCameraState)Context.Camera.CurrentBaseState).SetTarget(player.transform);
void InstallExtra(Scene scene, ContainerBuilder builder)
{
builder.RegisterValue(factoryConfig);
builder.RegisterValue(factory, new []{typeof(IPlayerFactory)});
builder.RegisterValue(factory, new[] { typeof(IPlayerFactory) });
builder.RegisterValue(playerKinematicCharacterMotor);
builder.RegisterValue(playerMovementController);
builder.RegisterValue(playerControlsProvider);
builder.RegisterValue(playerAnimatorProvider);
builder.RegisterValue(playerTimelineActor);
builder.RegisterValue(battleActionDecisionPanel);
}
await UniTask.WhenAll(
Context.SceneLoader
.LoadSceneAsync(
SceneId.Testing,
LoadSceneMode.Single,
true,
InstallExtra),
InstallExtra),
Context.SceneLoader
.LoadSceneAsync(
SceneId.FirstTestingSegment,
LoadSceneMode.Additive,
false),
false),
Context.SceneLoader
.LoadSceneAsync(
SceneId.SecondTestingSegment,
@@ -110,14 +114,21 @@ namespace Code.Game.TestingLevel
false),
waitForContainer
);
var container = Context.SceneContainerManager.ScenesContainers[SceneId.Testing];
container.Resolve<KinematicCharacterMotor>()
.SetPositionAndRotation(
container.Resolve<TestingLevelData>().playerSpawnPoint.position,
container.Resolve<TestingLevelData>().playerSpawnPoint.rotation);
var entities =
Object.FindObjectsByType<EntityTimelineActor>()
.Select(x => x.gameObject)
.ToList();
GameObjectInjector.InjectRecursiveMany(entities, container);
playerMovementController.Freeze = false;
}
@@ -130,12 +141,13 @@ namespace Code.Game.TestingLevel
{
#if UNITY_EDITOR
Context.InputService.DisableMap(ActionMappings.Debug);
Context.InputService.UnbindActionPerformed((int)ActionMappings.Debug, (int)DebugActions.ToggleBattleMode, ToggleBattleMode);
Context.InputService.UnbindActionPerformed((int)ActionMappings.Debug, (int)DebugActions.ToggleBattleMode,
ToggleBattleMode);
#endif
Context.InputService.DisableMap(ActionMappings.OpenMovement);
if (Context.StateMachine.NextState == AppStates.BattleState) return;
await Context.SceneLoader.UnloadSceneAsync(SceneId.Testing);
await Context.SceneLoader.UnloadSceneAsync(SceneId.FirstTestingSegment);
await Context.SceneLoader.UnloadSceneAsync(SceneId.SecondTestingSegment);
@@ -1,11 +1,13 @@
using Cysharp.Threading.Tasks;
using UnityEngine;
namespace Code.OfficeGame.BattleMode.Actions
{
public abstract class BattleAction
public abstract class BattleAction : MonoBehaviour
{
public bool Finished { get; protected set; }
public abstract void Tick(float tickDelta);
public abstract UniTask<BattleActionDecisionResultCode> DecideAction();
public abstract BattleActionType ActionType { get; }
}
}
@@ -4,6 +4,7 @@ using Code.Infrastructure.Camera;
using Code.Infrastructure.Input;
using Cysharp.Threading.Tasks;
using KinematicCharacterController;
using Reflex.Attributes;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.InputSystem;
@@ -14,9 +15,9 @@ namespace Code.OfficeGame.BattleMode.Actions
{
private CameraStateMachine _cameraStateMachine;
private IInputService _inputService;
private PlayerMovementController _playerMovementController;
private MovementController _movementController;
private readonly NavMeshPath _path = new();
private NavMeshPath _path;
private Vector3[] _corners;
private int _currentCornerIndex;
@@ -25,14 +26,14 @@ namespace Code.OfficeGame.BattleMode.Actions
private const float StoppingDistance = 0.15f;
public BattleActionMove(
[Inject]
public void Construct(
CameraStateMachine cameraStateMachine,
IInputService inputService,
PlayerMovementController playerMovementController)
IInputService inputService)
{
_cameraStateMachine = cameraStateMachine;
_inputService = inputService;
_playerMovementController = playerMovementController;
_movementController = GetComponent<MovementController>();
_navMeshMask = LayerMask.GetMask("Environment");
}
@@ -46,7 +47,7 @@ namespace Code.OfficeGame.BattleMode.Actions
return;
}
Vector3 currentPos = _playerMovementController.Motor.TransientPosition;
Vector3 currentPos = _movementController.Motor.TransientPosition;
while (_currentCornerIndex < _corners.Length)
{
@@ -81,7 +82,7 @@ namespace Code.OfficeGame.BattleMode.Actions
float distance = moveDirection.magnitude;
Vector3 moveNormal = distance > 0.0001f ? moveDirection / distance : Vector3.zero;
float maxStep = _playerMovementController.MaxStableMoveSpeed * tickDelta;
float maxStep = _movementController.MaxStableMoveSpeed * tickDelta;
float inputMagnitude = (_currentCornerIndex == _corners.Length - 1 && distance < maxStep && maxStep > 0f)
? distance / maxStep
: 1f;
@@ -90,11 +91,11 @@ namespace Code.OfficeGame.BattleMode.Actions
{
MoveVector = moveNormal * inputMagnitude,
Look = moveNormal.sqrMagnitude > 0.0001f
? Quaternion.LookRotation(moveNormal, _playerMovementController.Motor.CharacterUp)
: _playerMovementController.Motor.TransientRotation
? Quaternion.LookRotation(moveNormal, _movementController.Motor.CharacterUp)
: _movementController.Motor.TransientRotation
};
_playerMovementController.SetInputs(ref aiInputs);
_movementController.SetInputs(ref aiInputs);
KinematicCharacterSystem.Simulate(
tickDelta,
@@ -102,7 +103,7 @@ namespace Code.OfficeGame.BattleMode.Actions
KinematicCharacterSystem.PhysicsMovers
);
Vector3 postMovePos = _playerMovementController.Motor.TransientPosition;
Vector3 postMovePos = _movementController.Motor.TransientPosition;
Vector3 toFinal = _corners[^1] - postMovePos;
toFinal.y = 0f;
@@ -117,10 +118,10 @@ namespace Code.OfficeGame.BattleMode.Actions
var emptyInputs = new AICharacterInputs
{
MoveVector = Vector3.zero,
Look = _playerMovementController.Motor.TransientRotation
Look = _movementController.Motor.TransientRotation
};
_playerMovementController.SetInputs(ref emptyInputs);
_playerMovementController.Motor.BaseVelocity = Vector3.zero;
_movementController.SetInputs(ref emptyInputs);
_movementController.Motor.BaseVelocity = Vector3.zero;
Finished = true;
}
@@ -132,7 +133,7 @@ namespace Code.OfficeGame.BattleMode.Actions
{
_waitForEnterTokenSource = new CancellationTokenSource();
_decisionResultCode = BattleActionDecisionResultCode.CancelDecision;
_targetPosition = _playerMovementController.transform.position;
_targetPosition = _movementController.transform.position;
_inputService.BindActionPerformed((int)ActionMappings.BattleMode, (int)BattleModeActions.Select,
SelectPosition);
@@ -158,6 +159,8 @@ namespace Code.OfficeGame.BattleMode.Actions
return _decisionResultCode;
}
public override BattleActionType ActionType => BattleActionType.Move;
private void CancelPosition(InputAction.CallbackContext obj)
{
_decisionResultCode = BattleActionDecisionResultCode.CancelDecision;
@@ -166,8 +169,10 @@ namespace Code.OfficeGame.BattleMode.Actions
private void ConfirmPosition(InputAction.CallbackContext input)
{
Vector3 startPos = _playerMovementController.Motor.TransientPosition;
Vector3 startPos = _movementController.Motor.TransientPosition;
_path = new();
if ((_targetPosition - startPos).sqrMagnitude > StoppingDistance * StoppingDistance
&& NavMesh.CalculatePath(startPos, _targetPosition, NavMesh.AllAreas, _path)
&& _path.corners.Length > 0)
@@ -19,5 +19,7 @@ namespace Code.OfficeGame.BattleMode.Actions
return BattleActionDecisionResultCode.Decided;
}
public override BattleActionType ActionType => BattleActionType.Wait;
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 8a301d248b3d4b3b8218e5e6d0bcb10a
timeCreated: 1792768701
@@ -0,0 +1,11 @@
using TinyGoose.Tremble;
using UnityEngine;
namespace Code.OfficeGame.BattleMode.Actions.Companions
{
[PrefabEntity()]
public class OnMapCompanion : MonoBehaviour
{
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 86667e70b64146cda8e1a79a88fb8d6d
timeCreated: 1792774265
@@ -15,5 +15,13 @@ namespace Code.OfficeGame.BattleMode.Actions
public Animator animator;
protected readonly Dictionary<BattleActionType, BattleAction> BattleActions = new();
private void Awake()
{
foreach (var action in GetComponents<BattleAction>())
{
BattleActions.Add(action.ActionType, action);
}
}
}
}
@@ -1,7 +1,4 @@
using System.Threading;
using Code.Game.Gameplay.Player;
using Code.Infrastructure.Camera;
using Code.Infrastructure.Input;
using Code.OfficeGame.BattleMode.UI;
using Cysharp.Threading.Tasks;
using Reflex.Attributes;
@@ -9,21 +6,10 @@ using UnityEngine;
namespace Code.OfficeGame.BattleMode.Actions.Player
{
public class PlayerTimelineActor : EntityTimelineActor
public class PlayerControlledTimelineActor : EntityTimelineActor
{
[Inject] private BattleActionDecisionPanel _battleActionDecisionPanel;
[Inject]
private void Construct(
CameraStateMachine cameraStateMachine,
IInputService inputService,
PlayerMovementController playerMovementController)
{
BattleActions.Add(BattleActionType.Wait, new BattleActionWait());
BattleActions.Add(BattleActionType.Move,
new BattleActionMove(cameraStateMachine, inputService, playerMovementController));
}
public override async UniTask DecideAction(CancellationToken ctx)
{
BattleActionDecisionResultCode decision = BattleActionDecisionResultCode.Deciding;
@@ -35,7 +21,7 @@ namespace Code.OfficeGame.BattleMode.Actions.Player
while (decidedAction == BattleActionType.None || ctx.IsCancellationRequested)
{
Cursor.lockState = CursorLockMode.Confined;
await _battleActionDecisionPanel.Open(ctx);
decidedAction = await _battleActionDecisionPanel.GetDecision(ctx);
@@ -45,10 +31,8 @@ namespace Code.OfficeGame.BattleMode.Actions.Player
&& !ctx.IsCancellationRequested)
{
Cursor.lockState = CursorLockMode.Locked;
await _battleActionDecisionPanel.Close(ctx);
// Панель UI здесь
await _battleActionDecisionPanel.Close(ctx);
decision = await BattleActions[decidedAction].DecideAction();
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using Code.Game.Cleaning.Player;
using Code.Infrastructure.App;
@@ -43,6 +44,10 @@ namespace Code.Game.OfficeGame.GameStates
var container = Context.SceneContainerManager.ScenesContainers[SceneId.Testing];
// T
var entities =
Object.FindObjectsByType<EntityTimelineActor>().ToList();
if (Context.StateMachine.CurrentState == AppStates.Testing)
{
_battleTokenSource = new();
@@ -53,11 +58,14 @@ namespace Code.Game.OfficeGame.GameStates
KinematicCharacterSystem.Settings.Interpolate = false;
TogglePlayerBattleMode(container, false);
await Context.Camera.SwitchState(CameraMode.BattleMode);
}
List<EntityTimelineActor> entities = new List<EntityTimelineActor>(){container.Resolve<PlayerTimelineActor>()};
await Context.Camera.SwitchState(CameraMode.BattleMode);
foreach (var entity in entities)
{
entity.animator.enabled = false;
}
}
_battleTimeline.RunBattleLoopAsync(entities,_battleTokenSource.Token).Forget();
}
@@ -87,6 +95,15 @@ namespace Code.Game.OfficeGame.GameStates
var container = Context.SceneContainerManager.ScenesContainers[SceneId.Testing];
TogglePlayerBattleMode(container, true);
// T
var entities =
Object.FindObjectsByType<EntityTimelineActor>().ToList();
foreach (var entity in entities)
{
entity.animator.enabled = false;
}
}
#if UNITY_EDITOR
@@ -1,7 +1,10 @@
namespace Code.OfficeGame.BattleMode.Souls
{
/// <summary>
/// Идея такая, ты делаешь отдельные классы скиллов и накидываешь их на сущность в фабрике. Параметры скиллов можно прочитать из jsona, ActionMaker проходится по каждому компоненту скилла и читает для него параметры из конфига сущности.
/// Идея такая,
/// ты делаешь отдельные классы скиллов и накидываешь их на сущность в фабрике.
/// Параметры скиллов можно прочитать из jsona,
/// ActionMaker проходится по каждому компоненту скилла и читает для него параметры из конфига сущности.
/// </summary>
public interface IBattleActionCharacteristics
{
@@ -0,0 +1,12 @@
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace Code.OfficeGame.BattleMode.UI
{
public class BattleActionDecisionButton : MonoBehaviour
{
public TMP_Text text;
public Button button;
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 9bf452c1274f4e78b36e619ddd26f0ae
timeCreated: 1792771940
@@ -14,9 +14,9 @@ namespace Code.OfficeGame.BattleMode.UI
public class BattleActionDecisionPanel : UIPanel
{
[SerializeField] private float duration = 0.35f;
[SerializeField] private Button actionButtonPrefab;
[SerializeField] private BattleActionDecisionButton actionButtonPrefab;
private List<Button> _actionButtons = new();
private List<BattleActionDecisionButton> _actionButtons = new();
private UniTaskCompletionSource<BattleActionType> _decisionCompletionSource;
private MotionHandle _motionHandle;
@@ -35,9 +35,9 @@ namespace Code.OfficeGame.BattleMode.UI
_actionButtons.Add(button);
button.onClick.AddListener(() => _decisionCompletionSource.TrySetResult(action));
button.button.onClick.AddListener(() => _decisionCompletionSource.TrySetResult(action));
//button.GetComponentInChildren<Text>().text = action.ToString();
button.text.text = action.ToString();
}
}
@@ -35,7 +35,7 @@ namespace Code.Game.Gameplay.Player
TowardsGroundSlopeAndGravity,
}
public class PlayerMovementController : MonoBehaviour, ICharacterController
public class MovementController : MonoBehaviour, ICharacterController
{
public KinematicCharacterMotor Motor;
@@ -9,7 +9,7 @@ namespace Code.Game.Cleaning.Player
{
public class PlayerControlsProvider : MonoBehaviour
{
[SerializeField] private PlayerMovementController playerMovementController;
[SerializeField] private MovementController movementController;
private IInputService _inputService;
@@ -43,7 +43,7 @@ namespace Code.Game.Cleaning.Player
CameraRotation = _cameraTransform.rotation
};
playerMovementController.SetInputs(ref inputs);
movementController.SetInputs(ref inputs);
}
private void OnDestroy()