Compare commits
58
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
acd9cc1a32 | ||
|
|
b7e9a26462 | ||
|
|
000985ee9b | ||
|
|
abde1d5ba9 | ||
|
|
52b18967a1 | ||
|
|
79d03528f6 | ||
|
|
4a547f1348 | ||
|
|
7130513471 | ||
|
|
ee7cf3946f | ||
|
|
175567e4dd | ||
|
|
97c60c0925 | ||
|
|
bd495a644f | ||
|
|
cea36c0cda | ||
|
|
ff8ed96138 | ||
|
|
95cb51db79 | ||
|
|
2b9fd70c85 | ||
|
|
cd384239ff | ||
|
|
f3a83eb909 | ||
|
|
35f703a8d2 | ||
|
|
e5f4f292c2 | ||
|
|
efad72b4d9 | ||
|
|
855108d88b | ||
|
|
388773129d | ||
|
|
e654a0daf4 | ||
|
|
cfe5b39cc9 | ||
|
|
c14880457d | ||
|
|
344470978d | ||
|
|
dab970737a | ||
|
|
afdd523682 | ||
|
|
575e66425a | ||
|
|
c470f63409 | ||
|
|
5da64a7b3d | ||
|
|
c4ab11488b | ||
|
|
cb968d782b | ||
|
|
522f51be3f | ||
|
|
01505de4c3 | ||
|
|
7024e1daf0 | ||
|
|
020934e07f | ||
|
|
52edef92e3 | ||
|
|
d3fbd4c5c3 | ||
|
|
5b09068b0c | ||
|
|
ddb76a5b93 | ||
|
|
c6b097a879 | ||
|
|
0f708ff4cb | ||
|
|
3bb99aaf1e | ||
|
|
a2acea39dc | ||
|
|
5c1fd1510d | ||
|
|
05449642d5 | ||
|
|
d1aad440f5 | ||
|
|
0e1c274677 | ||
|
|
dbabd847c1 | ||
|
|
a243ad53d6 | ||
|
|
874280741c | ||
|
|
177464cc09 | ||
|
|
f8448ba922 | ||
|
|
85a07065d9 | ||
|
|
7bc15cc03d | ||
|
|
0e188efe59 |
No files matched your search
@@ -15,7 +15,7 @@ MonoBehaviour:
|
|||||||
m_DefaultGroup: d447fc60305c17a17bf20948ab295a45
|
m_DefaultGroup: d447fc60305c17a17bf20948ab295a45
|
||||||
m_currentHash:
|
m_currentHash:
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
Hash: 7ed5aa0308ed28c84409cb70340524a8
|
Hash: 00000000000000000000000000000000
|
||||||
m_OptimizeCatalogSize: 0
|
m_OptimizeCatalogSize: 0
|
||||||
m_BuildRemoteCatalog: 0
|
m_BuildRemoteCatalog: 0
|
||||||
m_CatalogRequestsTimeout: 0
|
m_CatalogRequestsTimeout: 0
|
||||||
|
|||||||
+73
-20
@@ -15,21 +15,28 @@ MonoBehaviour:
|
|||||||
m_GroupName: Default Local Group
|
m_GroupName: Default Local Group
|
||||||
m_GUID: d447fc60305c17a17bf20948ab295a45
|
m_GUID: d447fc60305c17a17bf20948ab295a45
|
||||||
m_SerializeEntries:
|
m_SerializeEntries:
|
||||||
- m_GUID: 03e51c504fa7e0624ba855ec35b60bcc
|
|
||||||
m_Address: absolutely
|
|
||||||
m_ReadOnly: 0
|
|
||||||
m_SerializedLabels: []
|
|
||||||
FlaggedDuringContentUpdateRestriction: 0
|
|
||||||
- m_GUID: 111011400ce13ae859c52c757aef859e
|
|
||||||
m_Address: ahfreeman
|
|
||||||
m_ReadOnly: 0
|
|
||||||
m_SerializedLabels: []
|
|
||||||
FlaggedDuringContentUpdateRestriction: 0
|
|
||||||
- m_GUID: 144ab5188f8ad7a0a92c75703bd12e60
|
- m_GUID: 144ab5188f8ad7a0a92c75703bd12e60
|
||||||
m_Address: launch_upmenu1
|
m_Address: launch_upmenu1
|
||||||
m_ReadOnly: 0
|
m_ReadOnly: 0
|
||||||
m_SerializedLabels: []
|
m_SerializedLabels: []
|
||||||
FlaggedDuringContentUpdateRestriction: 0
|
FlaggedDuringContentUpdateRestriction: 0
|
||||||
|
- m_GUID: 16562a5c87213914cad415f10c65a3b0
|
||||||
|
m_Address: "Assets/Resources_moved/Audio/Music/LASKX3I - \u041F\u0440\u043E\u0442\u0438\u0432
|
||||||
|
\u0446\u0430\u0440\u044F (\u041A\u0430\u0440\u0430\u043E\u043A\u0435).mp3"
|
||||||
|
m_ReadOnly: 0
|
||||||
|
m_SerializedLabels: []
|
||||||
|
FlaggedDuringContentUpdateRestriction: 0
|
||||||
|
- m_GUID: 170b1a70ddee4d948abea041b9b805e4
|
||||||
|
m_Address: Assets/Resources_moved/Audio/Music/Half Life Original Soundtrack -
|
||||||
|
Track 8 - Diabolical Adrenaline Guitar.mp3
|
||||||
|
m_ReadOnly: 0
|
||||||
|
m_SerializedLabels: []
|
||||||
|
FlaggedDuringContentUpdateRestriction: 0
|
||||||
|
- m_GUID: 1d4767c722c05b5d6b96bb226d378c65
|
||||||
|
m_Address: Assets/Resources_moved/Prefabs/Player/ArmsMesh.prefab
|
||||||
|
m_ReadOnly: 0
|
||||||
|
m_SerializedLabels: []
|
||||||
|
FlaggedDuringContentUpdateRestriction: 0
|
||||||
- m_GUID: 1d7110a045075b22fa27d62bd5f2784e
|
- m_GUID: 1d7110a045075b22fa27d62bd5f2784e
|
||||||
m_Address: 357_shot1
|
m_Address: 357_shot1
|
||||||
m_ReadOnly: 0
|
m_ReadOnly: 0
|
||||||
@@ -40,13 +47,13 @@ MonoBehaviour:
|
|||||||
m_ReadOnly: 0
|
m_ReadOnly: 0
|
||||||
m_SerializedLabels: []
|
m_SerializedLabels: []
|
||||||
FlaggedDuringContentUpdateRestriction: 0
|
FlaggedDuringContentUpdateRestriction: 0
|
||||||
- m_GUID: 2301400160a23924eb27c4bdbe797739
|
- m_GUID: 23e11d2c8a4f12f4ea9a7a43d1118464
|
||||||
m_Address: 'Audio/Music/Nightmargin (Oneshot OST) - The Prophecy '
|
m_Address: Gameplay
|
||||||
m_ReadOnly: 0
|
m_ReadOnly: 0
|
||||||
m_SerializedLabels: []
|
m_SerializedLabels: []
|
||||||
FlaggedDuringContentUpdateRestriction: 0
|
FlaggedDuringContentUpdateRestriction: 0
|
||||||
- m_GUID: 23e11d2c8a4f12f4ea9a7a43d1118464
|
- m_GUID: 28a6c7a4124141341ab7c2b7dfd3e95b
|
||||||
m_Address: Gameplay
|
m_Address: Assets/Resources_moved/Prefabs/Levels/Level1 2.prefab
|
||||||
m_ReadOnly: 0
|
m_ReadOnly: 0
|
||||||
m_SerializedLabels: []
|
m_SerializedLabels: []
|
||||||
FlaggedDuringContentUpdateRestriction: 0
|
FlaggedDuringContentUpdateRestriction: 0
|
||||||
@@ -60,6 +67,11 @@ MonoBehaviour:
|
|||||||
m_ReadOnly: 0
|
m_ReadOnly: 0
|
||||||
m_SerializedLabels: []
|
m_SerializedLabels: []
|
||||||
FlaggedDuringContentUpdateRestriction: 0
|
FlaggedDuringContentUpdateRestriction: 0
|
||||||
|
- m_GUID: 2ed2d93a9f39d4edba511cb7396c7bb6
|
||||||
|
m_Address: Assets/Resources_moved/Prefabs/Enemies/Cockroach.prefab
|
||||||
|
m_ReadOnly: 0
|
||||||
|
m_SerializedLabels: []
|
||||||
|
FlaggedDuringContentUpdateRestriction: 0
|
||||||
- m_GUID: 2f6134357dc2a5641a846a7478ce4c2c
|
- m_GUID: 2f6134357dc2a5641a846a7478ce4c2c
|
||||||
m_Address: bravo!
|
m_Address: bravo!
|
||||||
m_ReadOnly: 0
|
m_ReadOnly: 0
|
||||||
@@ -75,6 +87,16 @@ MonoBehaviour:
|
|||||||
m_ReadOnly: 0
|
m_ReadOnly: 0
|
||||||
m_SerializedLabels: []
|
m_SerializedLabels: []
|
||||||
FlaggedDuringContentUpdateRestriction: 0
|
FlaggedDuringContentUpdateRestriction: 0
|
||||||
|
- m_GUID: 3d195945b1fbf114a88457cba466bc2b
|
||||||
|
m_Address: Assets/Resources_moved/Rooms/Room2.prefab
|
||||||
|
m_ReadOnly: 0
|
||||||
|
m_SerializedLabels: []
|
||||||
|
FlaggedDuringContentUpdateRestriction: 0
|
||||||
|
- m_GUID: 4472dd84628855c4085cacaec19efa29
|
||||||
|
m_Address: Assets/Resources_moved/Rooms/Room1.prefab
|
||||||
|
m_ReadOnly: 0
|
||||||
|
m_SerializedLabels: []
|
||||||
|
FlaggedDuringContentUpdateRestriction: 0
|
||||||
- m_GUID: 48aebfe8826dc0df79d047b5afbf8f5b
|
- m_GUID: 48aebfe8826dc0df79d047b5afbf8f5b
|
||||||
m_Address: Canvas
|
m_Address: Canvas
|
||||||
m_ReadOnly: 0
|
m_ReadOnly: 0
|
||||||
@@ -85,11 +107,21 @@ MonoBehaviour:
|
|||||||
m_ReadOnly: 0
|
m_ReadOnly: 0
|
||||||
m_SerializedLabels: []
|
m_SerializedLabels: []
|
||||||
FlaggedDuringContentUpdateRestriction: 0
|
FlaggedDuringContentUpdateRestriction: 0
|
||||||
|
- m_GUID: 4f660559d76c3ed42a7c34a0b16487f7
|
||||||
|
m_Address: Assets/Resources_moved/Rooms/Room3.prefab
|
||||||
|
m_ReadOnly: 0
|
||||||
|
m_SerializedLabels: []
|
||||||
|
FlaggedDuringContentUpdateRestriction: 0
|
||||||
- m_GUID: 735f38402ea347fa381408293503a24e
|
- m_GUID: 735f38402ea347fa381408293503a24e
|
||||||
m_Address: Audio/Dispatcher/receiving_an_order1
|
m_Address: Audio/Dispatcher/receiving_an_order1
|
||||||
m_ReadOnly: 0
|
m_ReadOnly: 0
|
||||||
m_SerializedLabels: []
|
m_SerializedLabels: []
|
||||||
FlaggedDuringContentUpdateRestriction: 0
|
FlaggedDuringContentUpdateRestriction: 0
|
||||||
|
- m_GUID: 751890caa1647ec6689f24933fbcb770
|
||||||
|
m_Address: "Prefabs/Furniture/\u0442\u0440\u0443\u0431\u0430"
|
||||||
|
m_ReadOnly: 0
|
||||||
|
m_SerializedLabels: []
|
||||||
|
FlaggedDuringContentUpdateRestriction: 0
|
||||||
- m_GUID: 7c5caf3ceee44f71588860c5c1fbdbe0
|
- m_GUID: 7c5caf3ceee44f71588860c5c1fbdbe0
|
||||||
m_Address: Audio/Dispatcher/take_damage3
|
m_Address: Audio/Dispatcher/take_damage3
|
||||||
m_ReadOnly: 0
|
m_ReadOnly: 0
|
||||||
@@ -100,6 +132,17 @@ MonoBehaviour:
|
|||||||
m_ReadOnly: 0
|
m_ReadOnly: 0
|
||||||
m_SerializedLabels: []
|
m_SerializedLabels: []
|
||||||
FlaggedDuringContentUpdateRestriction: 0
|
FlaggedDuringContentUpdateRestriction: 0
|
||||||
|
- m_GUID: 81844a99f5b786b41b831174f8fb6d3a
|
||||||
|
m_Address: Prefabs/Player/CharacterController
|
||||||
|
m_ReadOnly: 0
|
||||||
|
m_SerializedLabels: []
|
||||||
|
FlaggedDuringContentUpdateRestriction: 0
|
||||||
|
- m_GUID: 8187ea542d6ed824d81230966a3b7499
|
||||||
|
m_Address: Assets/Resources_moved/Audio/Music/Bauhaus - Bela Lugosi's Dead (No
|
||||||
|
Vocals Remix).mp3
|
||||||
|
m_ReadOnly: 0
|
||||||
|
m_SerializedLabels: []
|
||||||
|
FlaggedDuringContentUpdateRestriction: 0
|
||||||
- m_GUID: 82c71411174bfa86ca1f676b9d389f94
|
- m_GUID: 82c71411174bfa86ca1f676b9d389f94
|
||||||
m_Address: bastard!
|
m_Address: bastard!
|
||||||
m_ReadOnly: 0
|
m_ReadOnly: 0
|
||||||
@@ -125,13 +168,18 @@ MonoBehaviour:
|
|||||||
m_ReadOnly: 0
|
m_ReadOnly: 0
|
||||||
m_SerializedLabels: []
|
m_SerializedLabels: []
|
||||||
FlaggedDuringContentUpdateRestriction: 0
|
FlaggedDuringContentUpdateRestriction: 0
|
||||||
- m_GUID: b2c9f83c47783069aabb564f68cb0cbb
|
- m_GUID: b2e8dc2aeb0311cd8a826b51cf8e94dc
|
||||||
m_Address: absolutelynot
|
m_Address: GameOver
|
||||||
m_ReadOnly: 0
|
m_ReadOnly: 0
|
||||||
m_SerializedLabels: []
|
m_SerializedLabels: []
|
||||||
FlaggedDuringContentUpdateRestriction: 0
|
FlaggedDuringContentUpdateRestriction: 0
|
||||||
- m_GUID: b2e8dc2aeb0311cd8a826b51cf8e94dc
|
- m_GUID: b33855c694de89386a25c56cbe463a0e
|
||||||
m_Address: GameOver
|
m_Address: Assets/Resources_moved/Prefabs/Enemies/DrunkenGrandpa.prefab
|
||||||
|
m_ReadOnly: 0
|
||||||
|
m_SerializedLabels: []
|
||||||
|
FlaggedDuringContentUpdateRestriction: 0
|
||||||
|
- m_GUID: b3471d165fe389f479380f61034bea57
|
||||||
|
m_Address: Assets/Resources_moved/Prefabs/Levels/Level1 1.prefab
|
||||||
m_ReadOnly: 0
|
m_ReadOnly: 0
|
||||||
m_SerializedLabels: []
|
m_SerializedLabels: []
|
||||||
FlaggedDuringContentUpdateRestriction: 0
|
FlaggedDuringContentUpdateRestriction: 0
|
||||||
@@ -145,6 +193,11 @@ MonoBehaviour:
|
|||||||
m_ReadOnly: 0
|
m_ReadOnly: 0
|
||||||
m_SerializedLabels: []
|
m_SerializedLabels: []
|
||||||
FlaggedDuringContentUpdateRestriction: 0
|
FlaggedDuringContentUpdateRestriction: 0
|
||||||
|
- m_GUID: d4eaf1439c2788c458127b9ba67e4fbf
|
||||||
|
m_Address: Prefabs/Levels/Level1
|
||||||
|
m_ReadOnly: 0
|
||||||
|
m_SerializedLabels: []
|
||||||
|
FlaggedDuringContentUpdateRestriction: 0
|
||||||
- m_GUID: ebe18293a5ef86704b23dad3a1786476
|
- m_GUID: ebe18293a5ef86704b23dad3a1786476
|
||||||
m_Address: Half-Life01
|
m_Address: Half-Life01
|
||||||
m_ReadOnly: 0
|
m_ReadOnly: 0
|
||||||
@@ -155,8 +208,8 @@ MonoBehaviour:
|
|||||||
m_ReadOnly: 0
|
m_ReadOnly: 0
|
||||||
m_SerializedLabels: []
|
m_SerializedLabels: []
|
||||||
FlaggedDuringContentUpdateRestriction: 0
|
FlaggedDuringContentUpdateRestriction: 0
|
||||||
- m_GUID: f4b6fa54ecac6cc418f98824491aa17a
|
- m_GUID: f3d7dc64b34919ad7b50a3dd307a935b
|
||||||
m_Address: Audio/Music/SANABI - JUSTICE Is Watching You
|
m_Address: Assets/Resources_moved/Prefabs/Enemies/Fog.prefab
|
||||||
m_ReadOnly: 0
|
m_ReadOnly: 0
|
||||||
m_SerializedLabels: []
|
m_SerializedLabels: []
|
||||||
FlaggedDuringContentUpdateRestriction: 0
|
FlaggedDuringContentUpdateRestriction: 0
|
||||||
|
|||||||
@@ -1,41 +1,76 @@
|
|||||||
using Code.App.StateMachine;
|
using Code.App.StateMachine;
|
||||||
using Code.Scenes;
|
using Code.Gameplay.Player;
|
||||||
|
using Code.Input;
|
||||||
using Code.StateMachine;
|
using Code.StateMachine;
|
||||||
using Code.UI;
|
using Code.UI;
|
||||||
|
using Cysharp.Threading.Tasks;
|
||||||
|
using Reflex.Core;
|
||||||
|
using Reflex.Extensions;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using UnityEngine.InputSystem;
|
||||||
|
using UnityEngine.SceneManagement;
|
||||||
|
|
||||||
namespace Code.App.AppStates
|
namespace Code.App.AppStates
|
||||||
{
|
{
|
||||||
public class GameOverState : BaseState<AppStateMachineContext>
|
public class GameOverState : BaseState<AppStateMachineContext>
|
||||||
{
|
{
|
||||||
public GameOverState(AppStateMachineContext context) : base(context)
|
public GameOverState(AppStateMachineContext context) : base(context)
|
||||||
{ }
|
{
|
||||||
|
}
|
||||||
|
private IPlayerScore _playerScore;
|
||||||
|
|
||||||
|
private GameOverPanel _gameOverPanel;
|
||||||
|
|
||||||
private float damnTimer = 3f; // TODO Удалить при первой возможности
|
|
||||||
|
|
||||||
public override void EnterState()
|
public override void EnterState()
|
||||||
{
|
{
|
||||||
Context.UIService.SwitchPanelTo(UIPanel.GameOver);
|
Container sceneContainer = SceneManager.GetActiveScene().GetSceneContainer();
|
||||||
|
_playerScore = sceneContainer.Resolve<IPlayerScore>();
|
||||||
|
_scoreCounter = 0;
|
||||||
|
|
||||||
|
Context.InputService.EnableMap(ActionMappings.UI);
|
||||||
|
Context.InputService.DebugBindAction((int)ActionMappings.UI,(int)UIActions.Continue, TryToExit);
|
||||||
|
|
||||||
|
GameOver();
|
||||||
|
|
||||||
base.EnterState();
|
base.EnterState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void TryToExit(InputAction.CallbackContext context)
|
||||||
|
{
|
||||||
|
ToMainMenu();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async UniTaskVoid GameOver()
|
||||||
|
{
|
||||||
|
await Context.UIService.AsyncSwitchPanelTo(UIPanel.GameOver);
|
||||||
|
|
||||||
|
_gameOverPanel = (GameOverPanel)Context.UIService.CurrentPanel;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private void ToMainMenu()
|
private void ToMainMenu()
|
||||||
{
|
{
|
||||||
Context.StateMachine.SwitchState(AppState.MainMenu)
|
Context.StateMachine.SwitchState(AppState.MainMenu)
|
||||||
.AllowStateTransition(AppState.Gameplay);
|
.AllowStateTransition(AppState.Gameplay);
|
||||||
}
|
}
|
||||||
|
private float _scoreCounter;
|
||||||
public override void Tick()
|
public override void Tick()
|
||||||
{
|
{
|
||||||
damnTimer -= Time.deltaTime;
|
if (!_gameOverPanel) return;
|
||||||
if (damnTimer <= float.Epsilon) ToMainMenu();
|
|
||||||
|
_scoreCounter += Time.deltaTime * 100;
|
||||||
|
// UnityEngine.Debug.Log($"Score: {_scoreCounter}");
|
||||||
|
if((int)_scoreCounter >= _playerScore.Score)
|
||||||
|
{
|
||||||
|
_gameOverPanel.UpdateScoreText(_playerScore.Score);
|
||||||
|
}
|
||||||
|
else _gameOverPanel.UpdateScoreText((int)_scoreCounter);
|
||||||
}
|
}
|
||||||
public override void ExitState()
|
public override void ExitState()
|
||||||
{
|
{
|
||||||
damnTimer = 5f;
|
Context.InputService.DisableMap(ActionMappings.UI);
|
||||||
|
Context.InputService.DebugUnbindAction((int)ActionMappings.UI,(int)UIActions.Continue, TryToExit);
|
||||||
|
|
||||||
Context.UIService.LoadingScreen.Show();
|
|
||||||
base.ExitState();
|
base.ExitState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,19 @@
|
|||||||
|
using Code.App.Loading;
|
||||||
using Code.App.StateMachine;
|
using Code.App.StateMachine;
|
||||||
using Code.Audio;
|
using Code.Audio;
|
||||||
using Code.Gameplay.Camera;
|
using Code.Gameplay.Camera;
|
||||||
|
using Code.Gameplay.Camera.CameraStates;
|
||||||
|
using Code.Gameplay.Character.Core;
|
||||||
|
using Code.Gameplay.Orders.Order;
|
||||||
using Code.Gameplay.Player;
|
using Code.Gameplay.Player;
|
||||||
using Code.Input;
|
using Code.Input;
|
||||||
using Code.Scenes;
|
using Code.Scenes;
|
||||||
using Code.Scenes.SceneEnvironments;
|
using Code.Scenes.SceneEnvironments;
|
||||||
using Code.StateMachine;
|
using Code.StateMachine;
|
||||||
using Code.UI;
|
using Code.UI;
|
||||||
|
using Code.UI.Panels;
|
||||||
using Cysharp.Threading.Tasks;
|
using Cysharp.Threading.Tasks;
|
||||||
|
using Reflex.Core;
|
||||||
using Reflex.Extensions;
|
using Reflex.Extensions;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.InputSystem;
|
using UnityEngine.InputSystem;
|
||||||
@@ -16,14 +22,13 @@ using UnityEngine.SceneManagement;
|
|||||||
namespace Code.App.AppStates
|
namespace Code.App.AppStates
|
||||||
{
|
{
|
||||||
public class GameplayState : BaseState<AppStateMachineContext>
|
public class GameplayState : BaseState<AppStateMachineContext>
|
||||||
{
|
{
|
||||||
// DEBUG
|
|
||||||
private Transform _testSFXTransform;
|
|
||||||
// DEBUG
|
|
||||||
|
|
||||||
private PlayerHealth _playerHealth;
|
private PlayerHealth _playerHealth;
|
||||||
private PlayerMoney _playerMoney;
|
private IPlayerScore _playerScore;
|
||||||
|
|
||||||
|
private IOrderService _orderService;
|
||||||
|
|
||||||
|
private CharacterProvider _playerCharacter;
|
||||||
public GameplayState(AppStateMachineContext context) : base(context)
|
public GameplayState(AppStateMachineContext context) : base(context)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -31,83 +36,139 @@ namespace Code.App.AppStates
|
|||||||
public override void EnterState()
|
public override void EnterState()
|
||||||
{
|
{
|
||||||
Context.UIService.LoadingScreen.Show();
|
Context.UIService.LoadingScreen.Show();
|
||||||
|
|
||||||
_playerMoney = Context.PlayerFactory.CreatePlayerMoney();
|
|
||||||
_playerHealth = Context.PlayerFactory.CreatePlayerHealth();
|
|
||||||
|
|
||||||
_playerHealth.OnDeath += EndGame;
|
|
||||||
|
|
||||||
Context.AudioService.TransitToSnapshot(AudioSnapshotState.Peaceful);
|
|
||||||
|
|
||||||
Context.InputService.DebugBindAction((int)ActionMappings.Debug, (int)DebugActions.Debug1, GiveHealth);
|
|
||||||
Context.InputService.DebugBindAction((int)ActionMappings.Debug, (int)DebugActions.Debug3, GiveMoney);
|
|
||||||
Context.InputService.DebugBindAction((int)ActionMappings.Debug, (int)DebugActions.Debug2, LooseHealth);
|
|
||||||
Context.InputService.DebugBindAction((int)ActionMappings.Debug, (int)DebugActions.Debug4, LooseMoney);
|
|
||||||
Context.InputService.DebugBindAction((int)ActionMappings.Debug, (int)DebugActions.Debug5, PlayDebugSFX);
|
|
||||||
Context.InputService.DebugBindAction((int)ActionMappings.Debug, (int)DebugActions.Debug6, PlayDebugDispatcher);
|
|
||||||
|
|
||||||
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
|
Context.LoadingManager
|
||||||
WaitForSceneToLoad();
|
.RegisterLoading(LoadingWork.LoadScene)
|
||||||
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
|
.RegisterLoading(LoadingWork.LoadUI)
|
||||||
}
|
.RegisterLoading(LoadingWork.LoadModelResource)
|
||||||
|
.RegisterLoading(LoadingWork.LoadAudio);
|
||||||
|
|
||||||
|
//_playerHealth = Context.PlayerFactory.CreatePlayerHealth();
|
||||||
|
|
||||||
private async UniTaskVoid WaitForSceneToLoad()
|
//_playerHealth.OnDamage += PlayerDamageTaken;
|
||||||
{
|
//_playerHealth.OnDeath += EndGame;
|
||||||
await UniTask.WhenAll(
|
|
||||||
Context.SceneLoaderService.LoadSceneAsyncAwaitable((int)SceneIds.MovementDev),
|
|
||||||
Context.UIService.AsyncSwitchPanelTo(UIPanel.Gameplay),
|
|
||||||
Context.AudioFactory.WarmGameplayMusic(),
|
|
||||||
Context.AudioFactory.WarmSFX()
|
|
||||||
);
|
|
||||||
|
|
||||||
Context.AudioService.PlayRandomMusicUntilHumanityWillBeDestroyedForTheySins(MusicType.Peaceful);
|
Context.AudioService.TransitToSnapshot(AudioSnapshotState.None);
|
||||||
Context.AudioService.PlayRandomMusicUntilHumanityWillBeDestroyedForTheySins(MusicType.Action);
|
|
||||||
|
|
||||||
var sceneEnvironment = ((GameplaySceneEnvironment)SceneManager.GetActiveScene()
|
|
||||||
.GetSceneContainer().Resolve<CurrentSceneEnvironment>());
|
|
||||||
|
|
||||||
_testSFXTransform = sceneEnvironment.debugSfxTarget;
|
|
||||||
|
|
||||||
((GameplayPanel)Context.UIService.CurrentPanel).Initialize(_playerMoney, _playerHealth);
|
|
||||||
|
|
||||||
Context.CameraStateMachine.SwitchState(CameraMode.FirstPerson);
|
|
||||||
Context.InputService.EnableMap(ActionMappings.Gameplay);
|
Context.InputService.EnableMap(ActionMappings.Gameplay);
|
||||||
|
|
||||||
Context.UIService.LoadingScreen.Hide();
|
Context.InputService.DebugBindAction((int)ActionMappings.Debug, (int)DebugActions.Debug1, InstaKillDEBUG);
|
||||||
|
Context.InputService.DebugBindAction((int)ActionMappings.Debug, (int)DebugActions.Debug4, RoomPassedDEBUG);
|
||||||
|
|
||||||
|
Context.SceneLoaderService.LoadSceneAsyncAwaitable((int)SceneIds.DevGen);
|
||||||
|
Context.LoadingManager.OnLoadingEnded += AfterSceneLoaded;
|
||||||
|
|
||||||
|
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
|
||||||
|
WaitForLoad();
|
||||||
|
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
|
||||||
|
}
|
||||||
|
private async UniTask WaitForPlayerCharacterLoad() => _playerCharacter = await Context.PlayerFactory.CreatePlayer();
|
||||||
|
|
||||||
|
private async UniTaskVoid WaitForLoad()
|
||||||
|
{
|
||||||
|
await UniTask.WhenAll(
|
||||||
|
Context.UIService.AsyncSwitchPanelTo(UIPanel.Gameplay),
|
||||||
|
Context.AudioFactory.WarmGameplayMusic(),
|
||||||
|
Context.AudioFactory.WarmSFX(),
|
||||||
|
Context.AudioFactory.WarmDispatcher()
|
||||||
|
);
|
||||||
|
|
||||||
|
Context.LoadingManager
|
||||||
|
.UnregisterLoading(LoadingWork.LoadUI)
|
||||||
|
.UnregisterLoading(LoadingWork.LoadAudio);
|
||||||
|
|
||||||
|
InputServiceInitialize();
|
||||||
|
|
||||||
|
MusicInitialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PlayDebugSFX(InputAction.CallbackContext context)
|
private async void AfterSceneLoaded()
|
||||||
{
|
{
|
||||||
Context.AudioService.PlaySFX(SFXSounds.Crowbar, _testSFXTransform.position);
|
Context.LoadingManager
|
||||||
}
|
.RegisterLoading(LoadingWork.LoadModelResource);
|
||||||
private void PlayDebugDispatcher(InputAction.CallbackContext context)
|
|
||||||
{
|
Context.LoadingManager.OnLoadingEnded -= AfterSceneLoaded;
|
||||||
Context.AudioService.PlayDispatcher(DispatcherSounds.AhFreeman);
|
Context.LoadingManager.OnLoadingEnded += AfterPlayerLoaded;
|
||||||
}
|
|
||||||
private void GiveHealth(InputAction.CallbackContext context)
|
await UniTask.WhenAll(
|
||||||
{
|
WaitForPlayerArmsToInitialize(),
|
||||||
_playerHealth.GetDamage(-1);
|
WaitForPlayerCharacterLoad()
|
||||||
|
);
|
||||||
|
|
||||||
|
_playerHealth = Context.PlayerProvider.Health;
|
||||||
|
_playerHealth.OnDamage += PlayerDamageTaken;
|
||||||
|
_playerHealth.OnDeath += EndGame;
|
||||||
|
|
||||||
|
Context.LoadingManager
|
||||||
|
.UnregisterLoading(LoadingWork.LoadModelResource);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LooseHealth(InputAction.CallbackContext context)
|
private void AfterPlayerLoaded()
|
||||||
{
|
{
|
||||||
_playerHealth.GetDamage(1);
|
Container sceneContainer = SceneManager.GetActiveScene().GetSceneContainer();
|
||||||
|
|
||||||
|
_playerScore = sceneContainer.Resolve<IPlayerScore>();
|
||||||
|
|
||||||
|
GameplaySceneEnvironment sceneEnvironment = SceneEnvironmentVariables(sceneContainer);
|
||||||
|
|
||||||
|
PlayerInitialize(sceneEnvironment);
|
||||||
|
|
||||||
|
CameraInitialize();
|
||||||
|
|
||||||
|
GameplayServicesInitialize(sceneContainer);
|
||||||
|
|
||||||
|
UIInitialize();
|
||||||
|
|
||||||
|
Context.LoadingManager.OnLoadingEnded -= AfterPlayerLoaded;
|
||||||
|
|
||||||
|
_tickEnabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void GiveMoney(InputAction.CallbackContext context)
|
private async UniTask WaitForPlayerArmsToInitialize() => _armsMesh = await Context.PlayerFactory.CreateArms(Context.CameraStateMachine.Camera.transform);
|
||||||
|
|
||||||
|
private void OrderGiven(float time)
|
||||||
|
{
|
||||||
|
_gameplayPanel.ShowTimer();
|
||||||
|
Context.AudioService.TransitToSnapshot(AudioSnapshotState.Action);
|
||||||
|
}
|
||||||
|
private void OrderFailure()
|
||||||
{
|
{
|
||||||
_playerMoney.GiveMoney(100);
|
_playerHealth.InstaKill();
|
||||||
((GameplayPanel)(Context.UIService.CurrentPanel)).SummonDispatcher();
|
}
|
||||||
|
private void OrderRecieved(float time)
|
||||||
|
{
|
||||||
|
Context.AudioService.PlayDispatcher((DispatcherSounds)Random.Range((int)DispatcherSounds.Recieve1,(int)DispatcherSounds.Recieve2));
|
||||||
|
}
|
||||||
|
private void OrderDelivered(int score, float time)
|
||||||
|
{
|
||||||
|
_gameplayPanel.HideTimer();
|
||||||
|
|
||||||
|
if(time < 0f) Context.AudioService.PlayDispatcher((DispatcherSounds)Random.Range((int)DispatcherSounds.Late1,(int)DispatcherSounds.Late2));
|
||||||
|
_playerScore.UpdateScore(score);
|
||||||
|
|
||||||
|
Context.AudioService.TransitToSnapshot(AudioSnapshotState.Peaceful);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LooseMoney(InputAction.CallbackContext context)
|
private void PlayerDamageTaken(int damage, PlayerHealth health)
|
||||||
{
|
{
|
||||||
_playerMoney.LooseMoney(100);
|
Context.AudioService.PlayDispatcher((DispatcherSounds)Random.Range((int)DispatcherSounds.TakeDamage1,(int)DispatcherSounds.TakeDamage4));
|
||||||
((GameplayPanel)(Context.UIService.CurrentPanel)).CloseDispatcher();
|
|
||||||
}
|
}
|
||||||
// DEBUG
|
// DEBUG
|
||||||
|
private void InstaKillDEBUG(InputAction.CallbackContext context)
|
||||||
|
{
|
||||||
|
_playerHealth.InstaKill();
|
||||||
|
}
|
||||||
|
private void RoomPassedDEBUG(InputAction.CallbackContext context)
|
||||||
|
{
|
||||||
|
_orderService.RoomPassed();
|
||||||
|
}
|
||||||
|
// DEBUG
|
||||||
|
private bool _tickEnabled;
|
||||||
public override void Tick()
|
public override void Tick()
|
||||||
{
|
{
|
||||||
|
if (!_tickEnabled) return;
|
||||||
|
|
||||||
|
_orderService.DecreaseTimer(Time.deltaTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void EndGame()
|
private void EndGame()
|
||||||
@@ -119,20 +180,75 @@ namespace Code.App.AppStates
|
|||||||
public override void ExitState()
|
public override void ExitState()
|
||||||
{
|
{
|
||||||
_playerHealth = null;
|
_playerHealth = null;
|
||||||
_playerMoney = null;
|
_playerScore = null;
|
||||||
|
|
||||||
|
_tickEnabled = false;
|
||||||
|
|
||||||
|
Context.PlayerFactory.ReleasePlayer(_playerCharacter);
|
||||||
|
_playerCharacter = null;
|
||||||
|
Context.PlayerFactory.ReleaseArms(_armsMesh);
|
||||||
|
_armsMesh = null;
|
||||||
|
_orderService = null;
|
||||||
|
|
||||||
|
Context.AudioService.OnDispatcherStarted -= _gameplayPanel.SummonDispatcher;
|
||||||
|
Context.AudioService.OnDispatcherEnded -= _gameplayPanel.CloseDispatcher;
|
||||||
|
|
||||||
Context.InputService.DisableMap(ActionMappings.Gameplay);
|
Context.InputService.DisableMap(ActionMappings.Gameplay);
|
||||||
Context.AudioService.GladlyAskToStopMusic(MusicType.Action, callback: Context.AudioFactory.ReleaseActionMusic);
|
Context.AudioService.GladlyAskToStopMusic(MusicType.Action, callback: Context.AudioFactory.ReleaseActionMusic);
|
||||||
Context.AudioService.GladlyAskToStopMusic(MusicType.Peaceful, callback: Context.AudioFactory.ReleasePeacefulMusic);
|
Context.AudioService.GladlyAskToStopMusic(MusicType.Peaceful, callback: Context.AudioFactory.ReleasePeacefulMusic);
|
||||||
|
|
||||||
Context.InputService.DebugUnbindAction((int)ActionMappings.Debug, (int)DebugActions.Debug1, GiveHealth);
|
|
||||||
Context.InputService.DebugUnbindAction((int)ActionMappings.Debug, (int)DebugActions.Debug3, GiveHealth);
|
Context.InputService.DebugUnbindAction((int)ActionMappings.Debug, (int)DebugActions.Debug1, InstaKillDEBUG);
|
||||||
Context.InputService.DebugUnbindAction((int)ActionMappings.Debug, (int)DebugActions.Debug2, LooseHealth);
|
Context.InputService.DebugUnbindAction((int)ActionMappings.Debug, (int)DebugActions.Debug4, RoomPassedDEBUG);
|
||||||
Context.InputService.DebugUnbindAction((int)ActionMappings.Debug, (int)DebugActions.Debug4, LooseMoney);
|
|
||||||
Context.InputService.DebugUnbindAction((int)ActionMappings.Debug, (int)DebugActions.Debug5, PlayDebugSFX);
|
|
||||||
Context.InputService.DebugUnbindAction((int)ActionMappings.Debug, (int)DebugActions.Debug6, PlayDebugDispatcher);
|
|
||||||
|
|
||||||
base.ExitState();
|
base.ExitState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void InputServiceInitialize()
|
||||||
|
{
|
||||||
|
Context.InputService.EnableMap(ActionMappings.Gameplay);
|
||||||
|
}
|
||||||
|
private void CameraInitialize()
|
||||||
|
{
|
||||||
|
Context.CameraStateMachine.SwitchState(CameraMode.FirstPerson);
|
||||||
|
((BaseCameraState)Context.CameraStateMachine.CurrentBaseState).SetFollowTransform(_playerCharacter.GetFollowTransform());
|
||||||
|
}
|
||||||
|
|
||||||
|
private GameplayPanel _gameplayPanel;
|
||||||
|
private ArmsMeshProvider _armsMesh;
|
||||||
|
|
||||||
|
private void UIInitialize()
|
||||||
|
{
|
||||||
|
_gameplayPanel = (GameplayPanel)Context.UIService.CurrentPanel;
|
||||||
|
_gameplayPanel.Initialize(_playerScore, _playerHealth, _orderService);
|
||||||
|
Context.AudioService.OnDispatcherStarted += _gameplayPanel.SummonDispatcher;
|
||||||
|
Context.AudioService.OnDispatcherEnded += _gameplayPanel.CloseDispatcher;
|
||||||
|
}
|
||||||
|
private void MusicInitialize()
|
||||||
|
{
|
||||||
|
Context.AudioService.PlayRandomMusicUntilHumanityWillBeDestroyedForTheySins(MusicType.Peaceful);
|
||||||
|
Context.AudioService.PlayRandomMusicUntilHumanityWillBeDestroyedForTheySins(MusicType.Action);
|
||||||
|
Context.AudioService.TransitToSnapshot(AudioSnapshotState.Peaceful);
|
||||||
|
}
|
||||||
|
private void PlayerInitialize(GameplaySceneEnvironment sceneEnvironment)
|
||||||
|
{
|
||||||
|
_playerCharacter.Teleport(sceneEnvironment.playerSpawnPoint.position, sceneEnvironment.playerSpawnPoint.rotation);
|
||||||
|
_playerCharacter.PlayerAnimator.SetAnimator(_armsMesh.ArmsAnimator);
|
||||||
|
}
|
||||||
|
private void GameplayServicesInitialize(Container sceneContainer)
|
||||||
|
{
|
||||||
|
_orderService = sceneContainer.Resolve<IOrderService>();
|
||||||
|
|
||||||
|
_orderService.OnOrderGiven += OrderGiven;
|
||||||
|
_orderService.OnOrderRecieved += OrderRecieved;
|
||||||
|
_orderService.OnOrderDelivered += OrderDelivered;
|
||||||
|
_orderService.OnOrderFailure += OrderFailure;
|
||||||
|
}
|
||||||
|
private GameplaySceneEnvironment SceneEnvironmentVariables(Container sceneContainer)
|
||||||
|
{
|
||||||
|
var sceneEnvironment = (GameplaySceneEnvironment)sceneContainer.Resolve<CurrentSceneEnvironment>();
|
||||||
|
|
||||||
|
return sceneEnvironment;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,12 +1,15 @@
|
|||||||
|
using Code.App.Loading;
|
||||||
using Code.App.StateMachine;
|
using Code.App.StateMachine;
|
||||||
using Code.Audio;
|
using Code.Audio;
|
||||||
using Code.Gameplay.Camera;
|
using Code.Gameplay.Camera;
|
||||||
using Code.Gameplay.Camera.CameraStates;
|
using Code.Gameplay.Camera.CameraStates;
|
||||||
|
using Code.Gameplay.Door;
|
||||||
using Code.Input;
|
using Code.Input;
|
||||||
using Code.Scenes;
|
using Code.Scenes;
|
||||||
using Code.Scenes.SceneEnvironments;
|
using Code.Scenes.SceneEnvironments;
|
||||||
using Code.StateMachine;
|
using Code.StateMachine;
|
||||||
using Code.UI;
|
using Code.UI;
|
||||||
|
using Code.UI.Panels;
|
||||||
using Cysharp.Threading.Tasks;
|
using Cysharp.Threading.Tasks;
|
||||||
using Reflex.Extensions;
|
using Reflex.Extensions;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
@@ -22,40 +25,81 @@ namespace Code.App.AppStates
|
|||||||
|
|
||||||
public override void EnterState()
|
public override void EnterState()
|
||||||
{
|
{
|
||||||
Context.UIService.LoadingScreen.Show();
|
Context.LoadingManager
|
||||||
|
.RegisterLoading(LoadingWork.LoadScene)
|
||||||
|
.RegisterLoading(LoadingWork.LoadUI)
|
||||||
|
.RegisterLoading(LoadingWork.LoadAudio);
|
||||||
|
|
||||||
|
// Context.UIService.LoadingScreen.Show();
|
||||||
|
|
||||||
|
Context.CameraStateMachine.SwitchState(CameraMode.MainMenu);
|
||||||
|
|
||||||
|
Context.SceneLoaderService.LoadSceneAsyncAwaitable((int)SceneIds.MainMenu);
|
||||||
|
Context.LoadingManager.OnLoadingEnded += AfterSceneLoaded;
|
||||||
|
|
||||||
Context.CameraStateMachine.SwitchState(CameraMode.Static);
|
|
||||||
|
|
||||||
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
|
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
|
||||||
WaitForSceneToLoad();
|
WaitForLoad();
|
||||||
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
|
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
|
||||||
}
|
}
|
||||||
|
|
||||||
private async UniTaskVoid WaitForSceneToLoad()
|
private async UniTaskVoid WaitForLoad()
|
||||||
{
|
{
|
||||||
await UniTask.WhenAll(
|
await UniTask.WhenAll(
|
||||||
Context.SceneLoaderService.LoadSceneAsyncAwaitable((int)SceneIds.MainMenu),
|
|
||||||
Context.UIService.AsyncSwitchPanelTo(UIPanel.MainMenu),
|
Context.UIService.AsyncSwitchPanelTo(UIPanel.MainMenu),
|
||||||
Context.AudioFactory.WarmMenuMusic()
|
Context.AudioFactory.WarmMenuMusic(),
|
||||||
);
|
Context.AudioFactory.WarmAudioTestClips()
|
||||||
|
);
|
||||||
|
Context.LoadingManager
|
||||||
|
.UnregisterLoading(LoadingWork.LoadUI)
|
||||||
|
.UnregisterLoading(LoadingWork.LoadAudio);
|
||||||
|
|
||||||
|
InitializeAudio();
|
||||||
|
|
||||||
|
InitializeInput();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AfterSceneLoaded()
|
||||||
|
{
|
||||||
|
var mainMenuEnvironment = (MainMenuEnvironment)SceneManager.GetActiveScene()
|
||||||
|
.GetSceneContainer().Resolve<CurrentSceneEnvironment>();
|
||||||
|
|
||||||
|
InitializeUI(mainMenuEnvironment);
|
||||||
|
|
||||||
|
InitializeCamera(mainMenuEnvironment);
|
||||||
|
|
||||||
|
Context.LoadingManager.OnLoadingEnded -= AfterSceneLoaded;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InitializeCamera(MainMenuEnvironment mainMenuEnvironment)
|
||||||
|
{
|
||||||
|
((Gameplay.Camera.CameraStates.MainMenuState)Context.CameraStateMachine.CurrentBaseState).SetFollowTransform(mainMenuEnvironment
|
||||||
|
.cameraPosition);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InitializeInput()
|
||||||
|
{
|
||||||
|
Context.InputService.EnableMap(ActionMappings.MainMenu);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InitializeAudio()
|
||||||
|
{
|
||||||
Context.AudioService.TransitToSnapshot(AudioSnapshotState.Menu);
|
Context.AudioService.TransitToSnapshot(AudioSnapshotState.Menu);
|
||||||
Context.AudioService.PlayRandomMusicUntilHumanityWillBeDestroyedForTheySins(MusicType.Menu);
|
Context.AudioService.PlayRandomMusicUntilHumanityWillBeDestroyedForTheySins(MusicType.Menu);
|
||||||
|
}
|
||||||
|
|
||||||
((MainMenuPanel)Context.UIService.CurrentPanel).startButton.onClick.AddListener(StartGame);
|
private void InitializeUI(MainMenuEnvironment mainMenuEnvironment)
|
||||||
((MainMenuPanel)Context.UIService.CurrentPanel).exitButton.onClick.AddListener(ExitGame);
|
{
|
||||||
|
var menuPanel = (MainMenuPanel)Context.UIService.CurrentPanel;
|
||||||
|
menuPanel.Initialize(mainMenuEnvironment.uiVariables,
|
||||||
|
mainMenuEnvironment.startButton,
|
||||||
|
mainMenuEnvironment.settingButton,
|
||||||
|
mainMenuEnvironment.exitButton);
|
||||||
|
|
||||||
var hui = ((MainMenuEnvironment)SceneManager.GetActiveScene()
|
menuPanel.startButton.button.onClick.AddListener(StartGame);
|
||||||
.GetSceneContainer().Resolve<CurrentSceneEnvironment>());
|
menuPanel.exitButton.button.onClick.AddListener(ExitGame);
|
||||||
|
|
||||||
((StaticState)Context.CameraStateMachine.CurrentBaseState).LookTarget =
|
|
||||||
hui.cameraTarget;
|
|
||||||
|
|
||||||
((BaseCameraState)Context.CameraStateMachine.CurrentBaseState).SetFollowTransform(hui.cameraPosition);
|
|
||||||
|
|
||||||
Context.UIService.LoadingScreen.Hide();
|
mainMenuEnvironment.menuButtonsCanvas.worldCamera = Context.CameraStateMachine.Camera;
|
||||||
|
mainMenuEnvironment.settingsCanvas.worldCamera = Context.CameraStateMachine.Camera;
|
||||||
Context.InputService.EnableMap(ActionMappings.MainMenu);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Tick()
|
public override void Tick()
|
||||||
@@ -76,8 +120,9 @@ namespace Code.App.AppStates
|
|||||||
public override void ExitState()
|
public override void ExitState()
|
||||||
{
|
{
|
||||||
Context.InputService.DisableMap(ActionMappings.MainMenu);
|
Context.InputService.DisableMap(ActionMappings.MainMenu);
|
||||||
Context.AudioService.GladlyAskToStopMusic(MusicType.Menu, callback: Context.AudioFactory.ReleaseMenuMusic);
|
Context.AudioService.GladlyAskToStopMusic(MusicType.Menu, callback: Context.AudioFactory.ReleaseMenuMusic);
|
||||||
|
|
||||||
|
Context.AudioFactory.ReleaseAudioTestClips();
|
||||||
base.ExitState();
|
base.ExitState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,14 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using Code.App.Loading;
|
||||||
using Code.App.StateMachine;
|
using Code.App.StateMachine;
|
||||||
using Code.Audio;
|
using Code.Audio;
|
||||||
using Code.Configs;
|
using Code.Configs;
|
||||||
using Code.Constants;
|
using Code.Constants;
|
||||||
using Code.Gameplay.Camera;
|
using Code.Gameplay.Camera;
|
||||||
|
using Code.Gameplay.Enemies;
|
||||||
|
using Code.Gameplay.Orders.Order;
|
||||||
using Code.Gameplay.Player;
|
using Code.Gameplay.Player;
|
||||||
|
using Code.Generator;
|
||||||
using Code.Input;
|
using Code.Input;
|
||||||
using Code.Scenes;
|
using Code.Scenes;
|
||||||
using Code.StaticData;
|
using Code.StaticData;
|
||||||
@@ -25,10 +30,16 @@ namespace Code.App
|
|||||||
|
|
||||||
InstallInfrastructureUnit(containerBuilder, staticDataService);
|
InstallInfrastructureUnit(containerBuilder, staticDataService);
|
||||||
|
|
||||||
|
containerBuilder.AddSingleton(typeof(LoadingManager), typeof(ILoadingManager));
|
||||||
|
|
||||||
containerBuilder.AddSingleton(typeof(InputService), typeof(IInputService));
|
containerBuilder.AddSingleton(typeof(InputService), typeof(IInputService));
|
||||||
|
// Перенести нахуй в контейнер геймплея
|
||||||
containerBuilder.AddSingleton(typeof(PlayerFactory), typeof(IPlayerFactory));
|
containerBuilder.AddSingleton(typeof(PlayerFactory), typeof(IPlayerFactory));
|
||||||
|
containerBuilder.AddSingleton(typeof(EnemyFactory), typeof(IEnemyFactory));
|
||||||
|
containerBuilder.AddSingleton(typeof(PlayerProvider), typeof(IPlayerProvider));
|
||||||
|
//
|
||||||
InitializeCamera(containerBuilder, staticDataService);
|
InitializeCamera(containerBuilder, staticDataService);
|
||||||
|
|
||||||
containerBuilder.AddSingleton(typeof(UIFactory), typeof(IUIFactory));
|
containerBuilder.AddSingleton(typeof(UIFactory), typeof(IUIFactory));
|
||||||
containerBuilder.AddSingleton(typeof(UIService), typeof(IUIService));
|
containerBuilder.AddSingleton(typeof(UIService), typeof(IUIService));
|
||||||
|
|
||||||
@@ -66,17 +77,34 @@ namespace Code.App
|
|||||||
staticDataService.Load();
|
staticDataService.Load();
|
||||||
|
|
||||||
containerBuilder.AddSingleton(staticDataService, typeof(IStaticDataService));
|
containerBuilder.AddSingleton(staticDataService, typeof(IStaticDataService));
|
||||||
|
|
||||||
containerBuilder.AddSingleton(staticDataService.InputConfig.inputActionAsset, typeof(InputActionAsset));
|
containerBuilder.AddSingleton(staticDataService.InputConfig.inputActionAsset, typeof(InputActionAsset));
|
||||||
containerBuilder.AddSingleton(staticDataService.InputConfig, typeof(InputConfig));
|
containerBuilder.AddSingleton(staticDataService.InputConfig, typeof(InputConfig));
|
||||||
|
|
||||||
containerBuilder.AddSingleton(staticDataService.CameraConfig, typeof(CameraConfig));
|
containerBuilder.AddSingleton(staticDataService.CameraConfig, typeof(CameraConfig));
|
||||||
|
containerBuilder.AddSingleton(staticDataService.CameraSettingsConfigs, typeof(Dictionary<CameraMode,CameraSettingsConfig>));
|
||||||
|
|
||||||
containerBuilder.AddSingleton(staticDataService.PlayerConfig, typeof(PlayerConfig));
|
containerBuilder.AddSingleton(staticDataService.PlayerConfig, typeof(PlayerConfig));
|
||||||
containerBuilder.AddSingleton(staticDataService.CharacterConfig, typeof(CharacterConfig));
|
containerBuilder.AddSingleton(staticDataService.CharacterConfig, typeof(CharacterConfig));
|
||||||
|
|
||||||
containerBuilder.AddSingleton(staticDataService.UIConfig, typeof(UIConfig));
|
containerBuilder.AddSingleton(staticDataService.UIConfig, typeof(UIConfig));
|
||||||
|
|
||||||
|
containerBuilder.AddSingleton(staticDataService.DrunkenGrandpaConfig, typeof(DrunkenGrandpaConfig));
|
||||||
|
containerBuilder.AddSingleton(staticDataService.CockroachConfig, typeof(CockroachConfig));
|
||||||
|
containerBuilder.AddSingleton(staticDataService.FogConfig, typeof(FogConfig));
|
||||||
|
|
||||||
containerBuilder.AddSingleton(staticDataService.AudioMixerConfig, typeof(AudioMixerConfig));
|
containerBuilder.AddSingleton(staticDataService.AudioMixerConfig, typeof(AudioMixerConfig));
|
||||||
containerBuilder.AddSingleton(staticDataService.SoundtrackListConfig, typeof(SoundtrackListConfig));
|
containerBuilder.AddSingleton(staticDataService.SoundtrackListConfig, typeof(SoundtrackListConfig));
|
||||||
|
containerBuilder.AddSingleton(staticDataService.AudioTestClipsConfig, typeof(AudioTestClipsConfig));
|
||||||
containerBuilder.AddSingleton(staticDataService.SFXListConfig, typeof(SFXListConfig));
|
containerBuilder.AddSingleton(staticDataService.SFXListConfig, typeof(SFXListConfig));
|
||||||
containerBuilder.AddSingleton(staticDataService.DispatcherSoundListConfig, typeof(DispatcherSoundListConfig));
|
containerBuilder.AddSingleton(staticDataService.DispatcherSoundListConfig, typeof(DispatcherSoundListConfig));
|
||||||
containerBuilder.AddSingleton(staticDataService.EnemiesSoundListConfig, typeof(EnemiesSoundListConfig));
|
containerBuilder.AddSingleton(staticDataService.EnemiesSoundListConfig, typeof(EnemiesSoundListConfig));
|
||||||
|
containerBuilder.AddSingleton(staticDataService.AudioSourceSettingsConfigs, typeof(Dictionary<AudioSourceType, AudioSourceSettingsConfig>));
|
||||||
|
|
||||||
|
containerBuilder.AddSingleton(staticDataService.OrderServiceConfig, typeof(OrderServiceConfig));
|
||||||
|
containerBuilder.AddSingleton(staticDataService.OrderBoxConfig, typeof(OrderBoxConfig));
|
||||||
|
|
||||||
|
containerBuilder.AddSingleton(staticDataService.GeneratorConfig, typeof(GeneratorConfig));
|
||||||
}
|
}
|
||||||
|
|
||||||
private AppStateMachine _appStateMachine;
|
private AppStateMachine _appStateMachine;
|
||||||
@@ -93,19 +121,26 @@ namespace Code.App
|
|||||||
|
|
||||||
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
|
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
|
||||||
BootstrapFinish(container);
|
BootstrapFinish(container);
|
||||||
|
|
||||||
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
|
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
|
||||||
}
|
}
|
||||||
private async UniTaskVoid BootstrapFinish(Container container)
|
private async UniTaskVoid BootstrapFinish(Container container)
|
||||||
{
|
{
|
||||||
var loadingScreen = GameObject.FindWithTag(Tags.LoadingScreen);
|
var loadingScreen = GameObject.FindWithTag(Tags.LoadingScreen).GetComponent<LoadingScreen>();
|
||||||
DontDestroyOnLoad(loadingScreen);
|
DontDestroyOnLoad(loadingScreen.gameObject);
|
||||||
|
|
||||||
|
ILoadingManager loadingManager = container.Resolve<ILoadingManager>();
|
||||||
|
loadingManager.OnLoadingStarted += loadingScreen.Show;
|
||||||
|
loadingManager.OnLoadingEnded += loadingScreen.Hide;
|
||||||
|
|
||||||
|
loadingManager.RegisterLoading(LoadingWork.Bootstrap);
|
||||||
|
|
||||||
await UniTask.WhenAll(
|
await UniTask.WhenAll(
|
||||||
container.Resolve<IUIService>().Initialize(loadingScreen.GetComponent<LoadingScreen>()),
|
container.Resolve<IUIService>().Initialize(loadingScreen),
|
||||||
container.Resolve<IAudioService>().Initialize()
|
container.Resolve<IAudioService>().Initialize()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
loadingManager.UnregisterLoading(LoadingWork.Bootstrap);
|
||||||
|
|
||||||
_appStateMachine
|
_appStateMachine
|
||||||
.SwitchState(AppState.MainMenu)
|
.SwitchState(AppState.MainMenu)
|
||||||
.AllowStateTransition(AppState.Gameplay);
|
.AllowStateTransition(AppState.Gameplay);
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 08b54658296d4279b85a2bfc3cf10e62
|
||||||
|
timeCreated: 1763842256
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
using System.Collections.ObjectModel;
|
||||||
|
using Cysharp.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Code.App.Loading
|
||||||
|
{
|
||||||
|
public interface ILoadingManager
|
||||||
|
{
|
||||||
|
delegate void OnLoadingDelegate();
|
||||||
|
|
||||||
|
event OnLoadingDelegate OnLoadingStarted;
|
||||||
|
event OnLoadingDelegate OnLoadingEnded;
|
||||||
|
ReadOnlyCollection<LoadingWork> LoadingThings { get; }
|
||||||
|
LoadingManager RegisterLoading(LoadingWork loadingThingName);
|
||||||
|
LoadingManager UnregisterLoading(LoadingWork loadingThingName);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: bfb3837590d04da3b04ca8b0f0aca437
|
||||||
|
timeCreated: 1763842985
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
using Cysharp.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Code.App.Loading
|
||||||
|
{
|
||||||
|
public class LoadingManager : ILoadingManager
|
||||||
|
{
|
||||||
|
public event ILoadingManager.OnLoadingDelegate OnLoadingStarted;
|
||||||
|
public event ILoadingManager.OnLoadingDelegate OnLoadingEnded;
|
||||||
|
|
||||||
|
private List<LoadingWork> _loadingThings = new();
|
||||||
|
public ReadOnlyCollection<LoadingWork> LoadingThings => _loadingThings.AsReadOnly();
|
||||||
|
|
||||||
|
public LoadingManager RegisterLoading(LoadingWork loadingThingName)
|
||||||
|
{
|
||||||
|
if(_loadingThings.Count == 0) OnLoadingStarted?.Invoke();
|
||||||
|
|
||||||
|
_loadingThings.Add(loadingThingName);
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
public LoadingManager UnregisterLoading(LoadingWork loadingThingName)
|
||||||
|
{
|
||||||
|
_loadingThings.Remove(loadingThingName);
|
||||||
|
|
||||||
|
if(_loadingThings.Count == 0) OnLoadingEnded?.Invoke();
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// public static class LoadingManagerExtensions
|
||||||
|
// {
|
||||||
|
// public static LoadingManager AddLoading(this LoadingManager manager, LoadingWork loadingThingName)
|
||||||
|
// {
|
||||||
|
// manager.RegisterLoading(loadingThingName);
|
||||||
|
// return manager;
|
||||||
|
// }
|
||||||
|
// public static LoadingManager RemoveLoading(this LoadingManager manager, LoadingWork loadingThingName)
|
||||||
|
// {
|
||||||
|
// manager.UnregisterLoading(loadingThingName);
|
||||||
|
// return manager;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 185988ac74a24a39864238cd7f5cb626
|
||||||
|
timeCreated: 1763842268
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
namespace Code.App.Loading
|
||||||
|
{
|
||||||
|
public enum LoadingWork
|
||||||
|
{
|
||||||
|
Bootstrap,
|
||||||
|
LoadUI,
|
||||||
|
LoadAudio,
|
||||||
|
LoadScene,
|
||||||
|
LoadModelResource,
|
||||||
|
WaitingForTime
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 318d1b29b41d4b96bc09334acbf36506
|
||||||
|
timeCreated: 1763843934
|
||||||
@@ -1,7 +1,13 @@
|
|||||||
|
using Code.App.Loading;
|
||||||
|
using Code.Gameplay.Orders.Order;
|
||||||
|
using Code.Gameplay.Player;
|
||||||
|
using Code.Generator;
|
||||||
using Code.Scenes;
|
using Code.Scenes;
|
||||||
using Code.Scenes.SceneEnvironments;
|
using Code.Scenes.SceneEnvironments;
|
||||||
|
using Cysharp.Threading.Tasks;
|
||||||
using Reflex.Core;
|
using Reflex.Core;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using IPlayerScore = Code.Gameplay.Player.IPlayerScore;
|
||||||
|
|
||||||
namespace Code.App.SceneInstallers
|
namespace Code.App.SceneInstallers
|
||||||
{
|
{
|
||||||
@@ -12,15 +18,35 @@ namespace Code.App.SceneInstallers
|
|||||||
public void InstallBindings(ContainerBuilder containerBuilder)
|
public void InstallBindings(ContainerBuilder containerBuilder)
|
||||||
{
|
{
|
||||||
containerBuilder.AddScoped(typeof(GameplaySceneEnvironment), typeof(CurrentSceneEnvironment));
|
containerBuilder.AddScoped(typeof(GameplaySceneEnvironment), typeof(CurrentSceneEnvironment));
|
||||||
|
containerBuilder.AddScoped(typeof(PlayerScore), typeof(IPlayerScore));
|
||||||
|
containerBuilder.AddScoped(typeof(OrderService), typeof(IOrderService));
|
||||||
|
containerBuilder.AddScoped(typeof(RoomGeneratorFactory), typeof(IRoomGeneratorFactory));
|
||||||
|
containerBuilder.AddScoped(typeof(RoomGenerator));
|
||||||
|
|
||||||
containerBuilder.OnContainerBuilt += Initialize;
|
containerBuilder.OnContainerBuilt += Initialize;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Initialize(Container container)
|
private void Initialize(Container container)
|
||||||
{
|
{
|
||||||
GameplaySceneEnvironment env = (GameplaySceneEnvironment)container.Resolve<CurrentSceneEnvironment>();
|
ILoadingManager loadingManager = container.Resolve<ILoadingManager>();
|
||||||
|
|
||||||
|
GameplaySceneEnvironment env = (GameplaySceneEnvironment)container.Resolve<CurrentSceneEnvironment>();
|
||||||
|
|
||||||
env.TransitVariables(_gameplaySceneEnvironment);
|
env.TransitVariables(_gameplaySceneEnvironment);
|
||||||
|
|
||||||
|
loadingManager
|
||||||
|
.UnregisterLoading(LoadingWork.LoadScene);
|
||||||
|
|
||||||
|
LoadRooms(container,loadingManager);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async UniTaskVoid LoadRooms(Container container, ILoadingManager loadingManager)
|
||||||
|
{
|
||||||
|
await container.Resolve<IRoomGeneratorFactory>().PreloadRooms(container.Resolve<IOrderService>());
|
||||||
|
|
||||||
|
container.Resolve<RoomGenerator>().Initialize();
|
||||||
|
|
||||||
|
loadingManager.UnregisterLoading(LoadingWork.LoadModelResource);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
|
using Code.App.Loading;
|
||||||
using Code.Scenes;
|
using Code.Scenes;
|
||||||
using Code.Scenes.SceneEnvironments;
|
using Code.Scenes.SceneEnvironments;
|
||||||
using Reflex.Core;
|
using Reflex.Core;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Serialization;
|
|
||||||
|
|
||||||
namespace Code.App.SceneInstallers
|
namespace Code.App.SceneInstallers
|
||||||
{
|
{
|
||||||
@@ -22,6 +22,11 @@ namespace Code.App.SceneInstallers
|
|||||||
MainMenuEnvironment env = (MainMenuEnvironment)container.Resolve<CurrentSceneEnvironment>();
|
MainMenuEnvironment env = (MainMenuEnvironment)container.Resolve<CurrentSceneEnvironment>();
|
||||||
|
|
||||||
env.TransitVariables(_mainMenuEnvironment);
|
env.TransitVariables(_mainMenuEnvironment);
|
||||||
|
|
||||||
|
ILoadingManager loadingManager = container.Resolve<ILoadingManager>();
|
||||||
|
|
||||||
|
loadingManager
|
||||||
|
.UnregisterLoading(LoadingWork.LoadScene);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,9 @@
|
|||||||
|
using Code.App.Loading;
|
||||||
using Code.Audio;
|
using Code.Audio;
|
||||||
using Code.Gameplay.Camera;
|
using Code.Gameplay.Camera;
|
||||||
|
using Code.Gameplay.Enemies;
|
||||||
using Code.Gameplay.Player;
|
using Code.Gameplay.Player;
|
||||||
|
using Code.Generator;
|
||||||
using Code.Input;
|
using Code.Input;
|
||||||
using Code.Scenes;
|
using Code.Scenes;
|
||||||
using Code.UI;
|
using Code.UI;
|
||||||
@@ -10,13 +13,16 @@ namespace Code.App.StateMachine
|
|||||||
{
|
{
|
||||||
public class AppStateMachineContext
|
public class AppStateMachineContext
|
||||||
{
|
{
|
||||||
|
[Inject] public ILoadingManager LoadingManager { get; private set; }
|
||||||
[Inject] public ISceneLoaderService SceneLoaderService { get; private set; }
|
[Inject] public ISceneLoaderService SceneLoaderService { get; private set; }
|
||||||
[Inject] public IInputService InputService { get; private set; }
|
[Inject] public IInputService InputService { get; private set; }
|
||||||
[Inject] public AppStateMachine StateMachine { get; private set; }
|
[Inject] public AppStateMachine StateMachine { get; private set; }
|
||||||
[Inject] public CameraStateMachine CameraStateMachine { get; private set; }
|
[Inject] public CameraStateMachine CameraStateMachine { get; private set; }
|
||||||
[Inject] public IUIService UIService { get; private set; }
|
[Inject] public IUIService UIService { get; private set; }
|
||||||
[Inject] public IPlayerFactory PlayerFactory { get; private set; }
|
[Inject] public IPlayerFactory PlayerFactory { get; private set; }
|
||||||
|
[Inject] public IPlayerProvider PlayerProvider { get; private set; }
|
||||||
[Inject] public IAudioFactory AudioFactory { get; private set; }
|
[Inject] public IAudioFactory AudioFactory { get; private set; }
|
||||||
[Inject] public IAudioService AudioService { get; private set; }
|
[Inject] public IAudioService AudioService { get; private set; }
|
||||||
|
[Inject] public IEnemyFactory EnemyFactory { get; private set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -16,8 +16,16 @@ namespace Code.Audio
|
|||||||
}
|
}
|
||||||
public enum DispatcherSounds
|
public enum DispatcherSounds
|
||||||
{
|
{
|
||||||
Absolutely,
|
Recieve1,
|
||||||
AbsolutelyNot,
|
Recieve2,
|
||||||
AhFreeman
|
TakeDamage1,
|
||||||
|
TakeDamage2,
|
||||||
|
TakeDamage3,
|
||||||
|
TakeDamage4,
|
||||||
|
Late1,
|
||||||
|
Late2,
|
||||||
|
Late3,
|
||||||
|
Late4,
|
||||||
|
Late5
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using Code.Configs;
|
using Code.Configs;
|
||||||
using Cysharp.Threading.Tasks;
|
using Cysharp.Threading.Tasks;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
@@ -15,6 +16,7 @@ namespace Code.Audio
|
|||||||
public AudioMixer AudioMixer { get; private set; }
|
public AudioMixer AudioMixer { get; private set; }
|
||||||
private AssetReference _audioSourcePrefab;
|
private AssetReference _audioSourcePrefab;
|
||||||
|
|
||||||
|
private AssetReference[] _audioTestClipsReferences;
|
||||||
private AssetReference[] _peacefulSoundtrack;
|
private AssetReference[] _peacefulSoundtrack;
|
||||||
private AssetReference[] _actionSoundtrack;
|
private AssetReference[] _actionSoundtrack;
|
||||||
private AssetReference[] _menuSoundtrack;
|
private AssetReference[] _menuSoundtrack;
|
||||||
@@ -23,6 +25,7 @@ namespace Code.Audio
|
|||||||
private AssetReference[] _dispatcher;
|
private AssetReference[] _dispatcher;
|
||||||
private AssetReference[] _character;
|
private AssetReference[] _character;
|
||||||
|
|
||||||
|
private AsyncOperationHandle<IList<AudioClip>> _audioTestClipsHandle;
|
||||||
private AsyncOperationHandle<IList<AudioClip>> _menuMusicHandle;
|
private AsyncOperationHandle<IList<AudioClip>> _menuMusicHandle;
|
||||||
private AsyncOperationHandle<IList<AudioClip>> _actionMusicHandle;
|
private AsyncOperationHandle<IList<AudioClip>> _actionMusicHandle;
|
||||||
private AsyncOperationHandle<IList<AudioClip>> _peacefulMusicHandle;
|
private AsyncOperationHandle<IList<AudioClip>> _peacefulMusicHandle;
|
||||||
@@ -30,6 +33,7 @@ namespace Code.Audio
|
|||||||
private AsyncOperationHandle<IList<AudioClip>> _enemiesHandle;
|
private AsyncOperationHandle<IList<AudioClip>> _enemiesHandle;
|
||||||
private AsyncOperationHandle<IList<AudioClip>> _dispatcherHandle;
|
private AsyncOperationHandle<IList<AudioClip>> _dispatcherHandle;
|
||||||
|
|
||||||
|
public Dictionary<AudioType, AudioClip> AudioTestClips { get; private set; } = new();
|
||||||
public Dictionary<MusicType, List<AudioClip>> MusicDictionary { get; private set; } = new();
|
public Dictionary<MusicType, List<AudioClip>> MusicDictionary { get; private set; } = new();
|
||||||
public List<AudioClip> SFXAudios { get; private set; } = new();
|
public List<AudioClip> SFXAudios { get; private set; } = new();
|
||||||
public List<AudioClip> EnemiesAudios { get; private set; } = new();
|
public List<AudioClip> EnemiesAudios { get; private set; } = new();
|
||||||
@@ -39,7 +43,8 @@ namespace Code.Audio
|
|||||||
SoundtrackListConfig soundtrackListConfig,
|
SoundtrackListConfig soundtrackListConfig,
|
||||||
SFXListConfig sfxListConfig,
|
SFXListConfig sfxListConfig,
|
||||||
EnemiesSoundListConfig enemiesSoundListConfig,
|
EnemiesSoundListConfig enemiesSoundListConfig,
|
||||||
DispatcherSoundListConfig dispatcherSoundListConfig
|
DispatcherSoundListConfig dispatcherSoundListConfig,
|
||||||
|
AudioTestClipsConfig audioTestClipsConfig
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
AudioMixer = audioMixerConfig.audioMixerAsset;
|
AudioMixer = audioMixerConfig.audioMixerAsset;
|
||||||
@@ -51,6 +56,7 @@ namespace Code.Audio
|
|||||||
_SFX = sfxListConfig.SFX;
|
_SFX = sfxListConfig.SFX;
|
||||||
_enemies = enemiesSoundListConfig.enemies;
|
_enemies = enemiesSoundListConfig.enemies;
|
||||||
_dispatcher = dispatcherSoundListConfig.dispatcher;
|
_dispatcher = dispatcherSoundListConfig.dispatcher;
|
||||||
|
_audioTestClipsReferences = audioTestClipsConfig.audioTestClips;
|
||||||
|
|
||||||
MusicDictionary.Add(MusicType.Menu, new ());
|
MusicDictionary.Add(MusicType.Menu, new ());
|
||||||
MusicDictionary.Add(MusicType.Peaceful, new ());
|
MusicDictionary.Add(MusicType.Peaceful, new ());
|
||||||
@@ -62,8 +68,8 @@ namespace Code.Audio
|
|||||||
|
|
||||||
public async UniTask WarmGameplayMusic( )
|
public async UniTask WarmGameplayMusic( )
|
||||||
{
|
{
|
||||||
_actionMusicHandle = Addressables.LoadAssetsAsync<AudioClip>(_actionSoundtrack, OnActionTrackLoaded, Addressables.MergeMode.None);
|
_actionMusicHandle = Addressables.LoadAssetsAsync<AudioClip>(_actionSoundtrack, OnActionTrackLoaded, Addressables.MergeMode.Union);
|
||||||
_peacefulMusicHandle = Addressables.LoadAssetsAsync<AudioClip>(_peacefulSoundtrack, OnPeacefulTrackLoaded, Addressables.MergeMode.None);
|
_peacefulMusicHandle = Addressables.LoadAssetsAsync<AudioClip>(_peacefulSoundtrack, OnPeacefulTrackLoaded, Addressables.MergeMode.Union);
|
||||||
|
|
||||||
await UniTask.WhenAll(_actionMusicHandle.ToUniTask(), _peacefulMusicHandle.ToUniTask());
|
await UniTask.WhenAll(_actionMusicHandle.ToUniTask(), _peacefulMusicHandle.ToUniTask());
|
||||||
}
|
}
|
||||||
@@ -77,12 +83,28 @@ namespace Code.Audio
|
|||||||
MusicDictionary[MusicType.Peaceful].Clear();
|
MusicDictionary[MusicType.Peaceful].Clear();
|
||||||
_peacefulMusicHandle.Release();
|
_peacefulMusicHandle.Release();
|
||||||
}
|
}
|
||||||
|
public async UniTask WarmAudioTestClips( )
|
||||||
|
{
|
||||||
|
// _audioTestClipCounter = 0;
|
||||||
|
_audioTestClipsHandle = Addressables.LoadAssetsAsync<AudioClip>(_audioTestClipsReferences, OnAudioTestClipLoaded, Addressables.MergeMode.Union);
|
||||||
|
|
||||||
|
// foreach (var assetReference in _menuSoundtrack) MenuMusic.Add(await assetReference.LoadAssetAsync<AudioClip>());
|
||||||
|
var clips = (await _audioTestClipsHandle.ToUniTask()).ToList();
|
||||||
|
|
||||||
|
for (int i = 0; i < clips.Count; i++)
|
||||||
|
AudioTestClips[(AudioType)i] = clips[i];
|
||||||
|
}
|
||||||
|
public void ReleaseAudioTestClips()
|
||||||
|
{
|
||||||
|
AudioTestClips.Clear();
|
||||||
|
// foreach (var assetReference in _menuSoundtrack) assetReference.ReleaseAsset();
|
||||||
|
_audioTestClipsHandle.Release();
|
||||||
|
}
|
||||||
public async UniTask WarmMenuMusic( )
|
public async UniTask WarmMenuMusic( )
|
||||||
{
|
{
|
||||||
_menuMusicHandle = Addressables.LoadAssetsAsync<AudioClip>(_menuSoundtrack, OnMenuTrackLoaded, Addressables.MergeMode.None);
|
_menuMusicHandle = Addressables.LoadAssetsAsync<AudioClip>(_menuSoundtrack, OnMenuTrackLoaded, Addressables.MergeMode.Union);
|
||||||
// foreach (var assetReference in _menuSoundtrack) MenuMusic.Add(await assetReference.LoadAssetAsync<AudioClip>());
|
// foreach (var assetReference in _menuSoundtrack) MenuMusic.Add(await assetReference.LoadAssetAsync<AudioClip>());
|
||||||
await _menuMusicHandle.ToUniTask();
|
await _menuMusicHandle.ToUniTask();
|
||||||
|
|
||||||
}
|
}
|
||||||
public void ReleaseMenuMusic()
|
public void ReleaseMenuMusic()
|
||||||
{
|
{
|
||||||
@@ -92,7 +114,7 @@ namespace Code.Audio
|
|||||||
}
|
}
|
||||||
public async UniTask WarmSFX( )
|
public async UniTask WarmSFX( )
|
||||||
{
|
{
|
||||||
_SFXHandle = Addressables.LoadAssetsAsync<AudioClip>(_SFX, OnSFXLoaded, Addressables.MergeMode.None);
|
_SFXHandle = Addressables.LoadAssetsAsync<AudioClip>(_SFX, OnSFXLoaded, Addressables.MergeMode.Union);
|
||||||
|
|
||||||
await _SFXHandle.ToUniTask();
|
await _SFXHandle.ToUniTask();
|
||||||
|
|
||||||
@@ -104,7 +126,7 @@ namespace Code.Audio
|
|||||||
}
|
}
|
||||||
public async UniTask WarmEnemies( )
|
public async UniTask WarmEnemies( )
|
||||||
{
|
{
|
||||||
_enemiesHandle = Addressables.LoadAssetsAsync<AudioClip>(_enemies, OnEnemiesLoaded, Addressables.MergeMode.None);
|
_enemiesHandle = Addressables.LoadAssetsAsync<AudioClip>(_enemies, OnEnemiesLoaded, Addressables.MergeMode.Union);
|
||||||
|
|
||||||
await _enemiesHandle.ToUniTask();
|
await _enemiesHandle.ToUniTask();
|
||||||
|
|
||||||
@@ -118,7 +140,7 @@ namespace Code.Audio
|
|||||||
|
|
||||||
public async UniTask WarmDispatcher( )
|
public async UniTask WarmDispatcher( )
|
||||||
{
|
{
|
||||||
_dispatcherHandle = Addressables.LoadAssetsAsync<AudioClip>(_dispatcher, OnDispatcherLoaded, Addressables.MergeMode.None);
|
_dispatcherHandle = Addressables.LoadAssetsAsync<AudioClip>(_dispatcher, OnDispatcherLoaded, Addressables.MergeMode.Union);
|
||||||
|
|
||||||
await _dispatcherHandle.ToUniTask();
|
await _dispatcherHandle.ToUniTask();
|
||||||
|
|
||||||
@@ -134,6 +156,12 @@ namespace Code.Audio
|
|||||||
{
|
{
|
||||||
MusicDictionary[MusicType.Menu].Add(audioClip);
|
MusicDictionary[MusicType.Menu].Add(audioClip);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// private int _audioTestClipCounter;
|
||||||
|
private void OnAudioTestClipLoaded(AudioClip audioClip)
|
||||||
|
{
|
||||||
|
// AudioTestClips[(AudioType)_audioTestClipCounter] = audioClip;_audioTestClipCounter++;
|
||||||
|
}
|
||||||
private void OnActionTrackLoaded(AudioClip audioClip)
|
private void OnActionTrackLoaded(AudioClip audioClip)
|
||||||
{
|
{
|
||||||
MusicDictionary[MusicType.Action].Add(audioClip);
|
MusicDictionary[MusicType.Action].Add(audioClip);
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using System.Threading;
|
|||||||
using Code.Configs;
|
using Code.Configs;
|
||||||
using Code.Constants;
|
using Code.Constants;
|
||||||
using Cysharp.Threading.Tasks;
|
using Cysharp.Threading.Tasks;
|
||||||
|
using DG.Tweening;
|
||||||
using Reflex.Attributes;
|
using Reflex.Attributes;
|
||||||
using Unity.VisualScripting;
|
using Unity.VisualScripting;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
@@ -23,21 +24,93 @@ namespace Code.Audio
|
|||||||
|
|
||||||
private AudioMixerGroup _masterGroup,
|
private AudioMixerGroup _masterGroup,
|
||||||
// _musicGroup,
|
// _musicGroup,
|
||||||
// _actionMusicGroup,
|
_actionMusicGroup,
|
||||||
// _peacefulMusicGroup,
|
_menuMusicGroup,
|
||||||
|
_peacefulMusicGroup,
|
||||||
_SFXGroup,
|
_SFXGroup,
|
||||||
_creaturesGroup,
|
_creaturesGroup,
|
||||||
_dispatcherGroup,
|
_dispatcherGroup,
|
||||||
_courierGroup,
|
_courierGroup,
|
||||||
_enemiesGroup;
|
_enemiesGroup;
|
||||||
|
|
||||||
private readonly AudioSourcePool _audioSourcePool = new();
|
private readonly AudioSourcePool _audioSourcePool;
|
||||||
|
|
||||||
private Dictionary<AudioSnapshotState, AudioMixerSnapshot> _snapshots = new();
|
private Dictionary<AudioSnapshotState, AudioMixerSnapshot> _snapshots = new();
|
||||||
|
private Dictionary<AudioSourceType, AudioSourceSettingsConfig> _settings;
|
||||||
|
|
||||||
public AudioService(IAudioFactory audioFactory)
|
public AudioService(IAudioFactory audioFactory, Dictionary<AudioSourceType, AudioSourceSettingsConfig> settings)
|
||||||
{
|
{
|
||||||
_audioFactory = audioFactory;
|
_audioFactory = audioFactory;
|
||||||
|
_audioSourcePool = new(settings);
|
||||||
|
_settings = settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO Грязно, убрать снапшоты НАХУЙ
|
||||||
|
public float GetSetting(AudioType type)
|
||||||
|
{
|
||||||
|
float value;
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case AudioType.SFX:
|
||||||
|
_snapshots[AudioSnapshotState.Peaceful].audioMixer.GetFloat(_SFXGroup.name, out value);
|
||||||
|
break;
|
||||||
|
case AudioType.Master:
|
||||||
|
_snapshots[AudioSnapshotState.Menu].audioMixer.GetFloat(_masterGroup.name, out value);
|
||||||
|
break;
|
||||||
|
case AudioType.Creatures:
|
||||||
|
_snapshots[AudioSnapshotState.Peaceful].audioMixer.GetFloat(_creaturesGroup.name, out value);
|
||||||
|
break;
|
||||||
|
case AudioType.GameplayMusic:
|
||||||
|
_snapshots[AudioSnapshotState.Peaceful].audioMixer.GetFloat(_peacefulMusicGroup.name, out value);
|
||||||
|
break;
|
||||||
|
case AudioType.MenuMusic:
|
||||||
|
_snapshots[AudioSnapshotState.Menu].audioMixer.GetFloat(_menuMusicGroup.name, out value);
|
||||||
|
break;
|
||||||
|
case AudioType.DispatcherSounds:
|
||||||
|
_snapshots[AudioSnapshotState.Action].audioMixer.GetFloat(_dispatcherGroup.name, out value);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
value = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
value = Mathf.Pow(10f, value / 20);
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO Грязно, убрать снапшоты НАХУЙ
|
||||||
|
public void ChangeSetting(AudioType type, float value)
|
||||||
|
{
|
||||||
|
float volume = Mathf.Log10(value) * 20;
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case AudioType.SFX:
|
||||||
|
_snapshots[AudioSnapshotState.Peaceful].audioMixer.SetFloat(_SFXGroup.name, volume);
|
||||||
|
_snapshots[AudioSnapshotState.Action].audioMixer.SetFloat(_SFXGroup.name, volume);
|
||||||
|
break;
|
||||||
|
case AudioType.Master:
|
||||||
|
_snapshots[AudioSnapshotState.Menu].audioMixer.SetFloat(_masterGroup.name, volume);
|
||||||
|
_snapshots[AudioSnapshotState.Peaceful].audioMixer.SetFloat(_masterGroup.name, volume);
|
||||||
|
_snapshots[AudioSnapshotState.Action].audioMixer.SetFloat(_masterGroup.name, volume);
|
||||||
|
break;
|
||||||
|
case AudioType.Creatures:
|
||||||
|
_snapshots[AudioSnapshotState.Peaceful].audioMixer.SetFloat(_creaturesGroup.name, volume);
|
||||||
|
_snapshots[AudioSnapshotState.Action].audioMixer.SetFloat(_creaturesGroup.name, volume);
|
||||||
|
break;
|
||||||
|
case AudioType.GameplayMusic:
|
||||||
|
_snapshots[AudioSnapshotState.Peaceful].audioMixer.SetFloat(_peacefulMusicGroup.name, volume);
|
||||||
|
_snapshots[AudioSnapshotState.Action].audioMixer.SetFloat(_actionMusicGroup.name, volume);
|
||||||
|
break;
|
||||||
|
case AudioType.MenuMusic:
|
||||||
|
_snapshots[AudioSnapshotState.Menu].audioMixer.SetFloat(_menuMusicGroup.name, volume);
|
||||||
|
break;
|
||||||
|
case AudioType.DispatcherSounds:
|
||||||
|
_snapshots[AudioSnapshotState.Peaceful].audioMixer.SetFloat(_dispatcherGroup.name, volume);
|
||||||
|
_snapshots[AudioSnapshotState.Action].audioMixer.SetFloat(_dispatcherGroup.name, volume);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// _mixer.FindSnapshot("Action").audioMixer.SetFloat("music", volume);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async UniTask Initialize()
|
public async UniTask Initialize()
|
||||||
@@ -46,21 +119,22 @@ namespace Code.Audio
|
|||||||
_mixer = _audioFactory.AudioMixer;
|
_mixer = _audioFactory.AudioMixer;
|
||||||
|
|
||||||
_masterGroup = _mixer.FindMatchingGroups(AudioGroups.MasterGroup)[0];
|
_masterGroup = _mixer.FindMatchingGroups(AudioGroups.MasterGroup)[0];
|
||||||
// _actionMusicGroup = _mixer.FindMatchingGroups(AudioGroups.ActionMusicGroup)[0];
|
_menuMusicGroup = _mixer.FindMatchingGroups(AudioGroups.MenuMusicGroup)[0];
|
||||||
// _peacefulMusicGroup = _mixer.FindMatchingGroups(AudioGroups.PeacefulMusoup)[0];
|
_actionMusicGroup = _mixer.FindMatchingGroups(AudioGroups.ActionMusicGroup)[0];
|
||||||
|
_peacefulMusicGroup = _mixer.FindMatchingGroups(AudioGroups.PeacefulMusicGroup)[0];
|
||||||
// _musicGroup = _mixer.FindMatchingGroups(AudioGroups.MusicGroup)[0];
|
// _musicGroup = _mixer.FindMatchingGroups(AudioGroups.MusicGroup)[0];
|
||||||
_musicAudioGroups.Add(MusicType.Menu, _mixer.FindMatchingGroups(AudioGroups.MenuMusicGroup)[0]);
|
_musicAudioGroups.Add(MusicType.Menu, _mixer.FindMatchingGroups(AudioGroups.MenuMusicGroup)[0]);
|
||||||
_musicAudioGroups.Add(MusicType.Action, _mixer.FindMatchingGroups(AudioGroups.ActionMusicGroup)[0]);
|
_musicAudioGroups.Add(MusicType.Action, _mixer.FindMatchingGroups(AudioGroups.ActionMusicGroup)[0]);
|
||||||
_musicAudioGroups.Add(MusicType.Peaceful, _mixer.FindMatchingGroups(AudioGroups.PeacefulMusicGroup)[0]);
|
_musicAudioGroups.Add(MusicType.Peaceful, _mixer.FindMatchingGroups(AudioGroups.PeacefulMusicGroup)[0]);
|
||||||
|
|
||||||
_cancellationTokenSources.Add(MusicType.Menu, new());
|
_cancellationTokenSources.Add(MusicType.Menu, new());
|
||||||
_cancellationTokenSources.Add(MusicType.Action, new());
|
_cancellationTokenSources.Add(MusicType.Action, new());
|
||||||
_cancellationTokenSources.Add(MusicType.Peaceful, new());
|
_cancellationTokenSources.Add(MusicType.Peaceful, new());
|
||||||
|
|
||||||
_musicAudioSources.Add(MusicType.Menu, null);
|
_musicAudioSources.Add(MusicType.Menu, null);
|
||||||
_musicAudioSources.Add(MusicType.Action, null);
|
_musicAudioSources.Add(MusicType.Action, null);
|
||||||
_musicAudioSources.Add(MusicType.Peaceful, null);
|
_musicAudioSources.Add(MusicType.Peaceful, null);
|
||||||
|
|
||||||
_SFXGroup = _mixer.FindMatchingGroups(AudioGroups.SFXGroup)[0];
|
_SFXGroup = _mixer.FindMatchingGroups(AudioGroups.SFXGroup)[0];
|
||||||
_creaturesGroup = _mixer.FindMatchingGroups(AudioGroups.CreaturesGroup)[0];
|
_creaturesGroup = _mixer.FindMatchingGroups(AudioGroups.CreaturesGroup)[0];
|
||||||
_dispatcherGroup = _mixer.FindMatchingGroups(AudioGroups.DispatcherMusicGroup)[0];
|
_dispatcherGroup = _mixer.FindMatchingGroups(AudioGroups.DispatcherMusicGroup)[0];
|
||||||
@@ -73,7 +147,6 @@ namespace Code.Audio
|
|||||||
_snapshots[AudioSnapshotState.Menu] = _mixer.FindSnapshot(AudioGroups.MenuSnapshot);
|
_snapshots[AudioSnapshotState.Menu] = _mixer.FindSnapshot(AudioGroups.MenuSnapshot);
|
||||||
|
|
||||||
await _audioFactory.LoadAudioSourcePrefab(_audioSourcePool.Initialize);
|
await _audioFactory.LoadAudioSourcePrefab(_audioSourcePool.Initialize);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
|
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
|
||||||
@@ -83,50 +156,51 @@ namespace Code.Audio
|
|||||||
|
|
||||||
public async UniTaskVoid PlayRandomMusicUntilHumanityWillBeDestroyedForTheySins(MusicType musicType)
|
public async UniTaskVoid PlayRandomMusicUntilHumanityWillBeDestroyedForTheySins(MusicType musicType)
|
||||||
{
|
{
|
||||||
if(!_musicAudioSources[musicType])
|
if (!_musicAudioSources[musicType])
|
||||||
{
|
{
|
||||||
_musicAudioSources[musicType] = _audioSourcePool.GetSource();
|
_musicAudioSources[musicType] = _audioSourcePool.GetSource();
|
||||||
_musicAudioSources[musicType].spatialBlend = 0f;
|
_musicAudioSources[musicType].spatialBlend = _settings[AudioSourceType.NoBlend].spatialBlend;
|
||||||
_musicAudioSources[musicType].outputAudioMixerGroup = _musicAudioGroups[musicType];
|
_musicAudioSources[musicType].outputAudioMixerGroup = _musicAudioGroups[musicType];
|
||||||
}
|
}
|
||||||
|
|
||||||
_musicAudioSources[musicType].resource =
|
_musicAudioSources[musicType].resource =
|
||||||
_audioFactory.MusicDictionary[musicType][
|
_audioFactory.MusicDictionary[musicType][
|
||||||
Random.Range(0, _audioFactory.MusicDictionary[musicType].Count)];
|
Random.Range(0, _audioFactory.MusicDictionary[musicType].Count)];
|
||||||
|
|
||||||
_musicAudioSources[musicType].Play();
|
_musicAudioSources[musicType].Play();
|
||||||
|
|
||||||
// await UniTask.WaitUntilValueChanged(_musicAudioSources[musicType],
|
// await UniTask.WaitUntilValueChanged(_musicAudioSources[musicType],
|
||||||
// _ => !_musicAudioSources[musicType].isPlaying,
|
// _ => !_musicAudioSources[musicType].isPlaying,
|
||||||
// cancellationToken: _cancellationTokenSources[musicType].Token);
|
// cancellationToken: _cancellationTokenSources[musicType].Token);
|
||||||
await UniTask.NextFrame();
|
await UniTask.NextFrame();
|
||||||
// Debug.Log($"Playing {musicType}");
|
// Debug.Log($"Playing {musicType}");
|
||||||
var (isCanceled, _) = await UniTask.WaitUntilValueChanged(_musicAudioSources[musicType],
|
var (isCanceled, _) = await UniTask.WaitUntilValueChanged(_musicAudioSources[musicType],
|
||||||
_ => !_musicAudioSources[musicType].isPlaying,
|
_ => !_musicAudioSources[musicType].isPlaying,
|
||||||
cancellationToken: _cancellationTokenSources[musicType].Token).SuppressCancellationThrow();
|
cancellationToken: _cancellationTokenSources[musicType].Token).SuppressCancellationThrow();
|
||||||
// Debug.Log($"Finished {musicType}");
|
// Debug.Log($"Finished {musicType}");
|
||||||
|
|
||||||
if (isCanceled)
|
if (isCanceled)
|
||||||
{
|
{
|
||||||
// Debug.Log($"Cancelled {musicType}");
|
// Debug.Log($"Cancelled {musicType}");
|
||||||
_cancellationTokenSources[musicType].Dispose();
|
_cancellationTokenSources[musicType].Dispose();
|
||||||
_cancellationTokenSources[musicType] = new();
|
_cancellationTokenSources[musicType] = new();
|
||||||
|
|
||||||
_audioSourcePool.ReleaseSource(_musicAudioSources[musicType]);
|
_audioSourcePool.ReleaseSource(_musicAudioSources[musicType]);
|
||||||
_musicAudioSources[musicType] = null;
|
_musicAudioSources[musicType] = null;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PlayRandomMusicUntilHumanityWillBeDestroyedForTheySins(musicType);
|
PlayRandomMusicUntilHumanityWillBeDestroyedForTheySins(musicType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async UniTaskVoid GladlyAskToStopMusic(MusicType musicType, AudioSnapshotState audioSnapshotState = AudioSnapshotState.None, float time = 1f, Action callback = null)
|
public async UniTaskVoid GladlyAskToStopMusic(MusicType musicType,
|
||||||
|
AudioSnapshotState audioSnapshotState = AudioSnapshotState.None, float time = 1f, Action callback = null)
|
||||||
{
|
{
|
||||||
TransitToSnapshot(audioSnapshotState, time);
|
TransitToSnapshot(audioSnapshotState, time);
|
||||||
|
|
||||||
await UniTask.WaitForSeconds(time);
|
await UniTask.WaitForSeconds(time);
|
||||||
|
|
||||||
_cancellationTokenSources[musicType].Cancel();
|
_cancellationTokenSources[musicType].Cancel();
|
||||||
|
|
||||||
callback?.Invoke();
|
callback?.Invoke();
|
||||||
@@ -164,9 +238,115 @@ namespace Code.Audio
|
|||||||
_audioSourcePool.PlayOneShot(_audioFactory.EnemiesAudios[(int)enemySoundId], position, _enemiesGroup);
|
_audioSourcePool.PlayOneShot(_audioFactory.EnemiesAudios[(int)enemySoundId], position, _enemiesGroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Чинить долго и дорого пусть Артёмов будет много, ведь он наш друг
|
||||||
|
public event IAudioService.OnAudioPlayingDelegate OnDispatcherStarted;
|
||||||
|
public event IAudioService.OnAudioPlayingDelegate OnDispatcherEnded;
|
||||||
|
|
||||||
public void PlayDispatcher(DispatcherSounds dispatcherSoundId)
|
public void PlayDispatcher(DispatcherSounds dispatcherSoundId)
|
||||||
{
|
{
|
||||||
_audioSourcePool.PlayShizo(_audioFactory.DispatcherAudios[(int)dispatcherSoundId], _dispatcherGroup);
|
OnDispatcherStarted?.Invoke();
|
||||||
|
_audioSourcePool.PlayOneShot(_audioFactory.DispatcherAudios[(int)dispatcherSoundId], _dispatcherGroup,
|
||||||
|
AudioSourceType.NoBlend, () => OnDispatcherEnded?.Invoke());
|
||||||
|
}
|
||||||
|
|
||||||
|
private CancellationTokenSource _testClipCancellationTokenSource = new();
|
||||||
|
private void ResetCurrentTestAudioSource() => _currentTestClipAudioType = AudioType.Master;
|
||||||
|
// TODO Засунуть в словарь
|
||||||
|
public void PlayTestClip(AudioType audioType)
|
||||||
|
{
|
||||||
|
if(_currentTestClipAudioType == audioType) return;
|
||||||
|
|
||||||
|
_testClipCancellationTokenSource.Cancel();
|
||||||
|
_testClipCancellationTokenSource = new();
|
||||||
|
|
||||||
|
_currentTestClipAudioType = audioType;
|
||||||
|
|
||||||
|
switch (audioType)
|
||||||
|
{
|
||||||
|
case AudioType.SFX:
|
||||||
|
_audioSourcePool.PlayOneShot(_audioFactory.AudioTestClips[audioType],
|
||||||
|
_SFXGroup, _testClipCancellationTokenSource,
|
||||||
|
AudioSourceType.NoBlend, ResetCurrentTestAudioSource);
|
||||||
|
break;
|
||||||
|
case AudioType.Master:
|
||||||
|
_audioSourcePool.PlayOneShot(_audioFactory.AudioTestClips[audioType],
|
||||||
|
_masterGroup, _testClipCancellationTokenSource,
|
||||||
|
AudioSourceType.NoBlend, ResetCurrentTestAudioSource);
|
||||||
|
break;
|
||||||
|
case AudioType.Creatures:
|
||||||
|
_audioSourcePool.PlayOneShot( _audioFactory.AudioTestClips[audioType],
|
||||||
|
_creaturesGroup, _testClipCancellationTokenSource,
|
||||||
|
AudioSourceType.NoBlend, ResetCurrentTestAudioSource);
|
||||||
|
break;
|
||||||
|
case AudioType.GameplayMusic:
|
||||||
|
_audioSourcePool.PlayOneShot(_audioFactory.AudioTestClips[audioType],
|
||||||
|
_actionMusicGroup, _testClipCancellationTokenSource,
|
||||||
|
AudioSourceType.NoBlend, ResetCurrentTestAudioSource);
|
||||||
|
break;
|
||||||
|
case AudioType.MenuMusic:
|
||||||
|
_audioSourcePool.PlayOneShot(_audioFactory.AudioTestClips[audioType],
|
||||||
|
_menuMusicGroup, _testClipCancellationTokenSource,
|
||||||
|
AudioSourceType.NoBlend, ResetCurrentTestAudioSource);
|
||||||
|
break;
|
||||||
|
case AudioType.DispatcherSounds:
|
||||||
|
_audioSourcePool.PlayOneShot(_audioFactory.AudioTestClips[audioType],
|
||||||
|
_dispatcherGroup, _testClipCancellationTokenSource,
|
||||||
|
AudioSourceType.NoBlend, ResetCurrentTestAudioSource);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private AudioSource _testClipAudioSource;
|
||||||
|
private AudioType _currentTestClipAudioType;
|
||||||
|
|
||||||
|
// Эффективно и просто, может не так хитровыебано
|
||||||
|
private void ReleaseTestAudioClipSource()
|
||||||
|
{
|
||||||
|
_testClipAudioSource = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO Засунуть в словарь
|
||||||
|
public void PlayTestClipDeprecated(AudioType audioType)
|
||||||
|
{
|
||||||
|
if (!_testClipAudioSource) _testClipAudioSource = _audioSourcePool.GetSource();
|
||||||
|
else if (_currentTestClipAudioType != audioType) _testClipAudioSource.Stop();
|
||||||
|
else return;
|
||||||
|
|
||||||
|
_currentTestClipAudioType = audioType;
|
||||||
|
|
||||||
|
switch (audioType)
|
||||||
|
{
|
||||||
|
case AudioType.SFX:
|
||||||
|
_audioSourcePool.PlayOneShot(_testClipAudioSource, _audioFactory.AudioTestClips[audioType],
|
||||||
|
_SFXGroup,
|
||||||
|
AudioSourceType.NoBlend, ReleaseTestAudioClipSource);
|
||||||
|
break;
|
||||||
|
case AudioType.Master:
|
||||||
|
_audioSourcePool.PlayOneShot(_testClipAudioSource, _audioFactory.AudioTestClips[audioType],
|
||||||
|
_masterGroup,
|
||||||
|
AudioSourceType.NoBlend, ReleaseTestAudioClipSource);
|
||||||
|
break;
|
||||||
|
case AudioType.Creatures:
|
||||||
|
_audioSourcePool.PlayOneShot(_testClipAudioSource, _audioFactory.AudioTestClips[audioType],
|
||||||
|
_creaturesGroup,
|
||||||
|
AudioSourceType.NoBlend, ReleaseTestAudioClipSource);
|
||||||
|
break;
|
||||||
|
case AudioType.GameplayMusic:
|
||||||
|
_audioSourcePool.PlayOneShot(_testClipAudioSource, _audioFactory.AudioTestClips[audioType],
|
||||||
|
_actionMusicGroup,
|
||||||
|
AudioSourceType.NoBlend, ReleaseTestAudioClipSource);
|
||||||
|
break;
|
||||||
|
case AudioType.MenuMusic:
|
||||||
|
_audioSourcePool.PlayOneShot(_testClipAudioSource, _audioFactory.AudioTestClips[audioType],
|
||||||
|
_menuMusicGroup,
|
||||||
|
AudioSourceType.NoBlend, ReleaseTestAudioClipSource);
|
||||||
|
break;
|
||||||
|
case AudioType.DispatcherSounds:
|
||||||
|
_audioSourcePool.PlayOneShot(_testClipAudioSource, _audioFactory.AudioTestClips[audioType],
|
||||||
|
_dispatcherGroup,
|
||||||
|
AudioSourceType.NoBlend, ReleaseTestAudioClipSource);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,119 +0,0 @@
|
|||||||
using System.Collections.Generic;
|
|
||||||
using Code.Constants;
|
|
||||||
using UnityEngine;
|
|
||||||
using UnityEngine.Audio;
|
|
||||||
using UnityEngine.Serialization;
|
|
||||||
|
|
||||||
namespace Code.Audio
|
|
||||||
{
|
|
||||||
public class AudioServiceDebug : MonoBehaviour
|
|
||||||
{
|
|
||||||
[SerializeField] private AudioMixer mixer;
|
|
||||||
|
|
||||||
private AudioSource _actionMusicSource;
|
|
||||||
private AudioSource _peacefulMusicSource;
|
|
||||||
[SerializeField] private AudioSource prefab;
|
|
||||||
|
|
||||||
[SerializeField] private AudioResource[] peacefulAudio;
|
|
||||||
[SerializeField] private AudioResource[] actionAudio;
|
|
||||||
|
|
||||||
private AudioMixerGroup _masterGroup,
|
|
||||||
_musicGroup,
|
|
||||||
_actionMusicGroup,
|
|
||||||
_peacefulMusicGroup,
|
|
||||||
_SFXGroup,
|
|
||||||
_creaturesGroup,
|
|
||||||
_dispatcherGroup,
|
|
||||||
_courierGroup,
|
|
||||||
_enemiesGroup;
|
|
||||||
|
|
||||||
private readonly AudioSourcePool _audioSourcePool = new();
|
|
||||||
|
|
||||||
private Dictionary<AudioSnapshotState, AudioMixerSnapshot> _snapshots = new();
|
|
||||||
|
|
||||||
[FormerlySerializedAs("sfxAudio")] [SerializeField] private AudioClip[] sfxAudios;
|
|
||||||
[SerializeField] private AudioClip[] enemiesAudios;
|
|
||||||
[SerializeField] private AudioClip[] dispatcherAudios;
|
|
||||||
|
|
||||||
private void MixerCreated()
|
|
||||||
{
|
|
||||||
_masterGroup = mixer.FindMatchingGroups(AudioGroups.MasterGroup)[0];
|
|
||||||
_actionMusicGroup = mixer.FindMatchingGroups(AudioGroups.ActionMusicGroup)[0];
|
|
||||||
_peacefulMusicGroup = mixer.FindMatchingGroups(AudioGroups.PeacefulMusicGroup)[0];
|
|
||||||
_SFXGroup = mixer.FindMatchingGroups(AudioGroups.SFXGroup)[0];
|
|
||||||
_musicGroup = mixer.FindMatchingGroups(AudioGroups.MusicGroup)[0];
|
|
||||||
_creaturesGroup = mixer.FindMatchingGroups(AudioGroups.CreaturesGroup)[0];
|
|
||||||
_dispatcherGroup = mixer.FindMatchingGroups(AudioGroups.DispatcherMusicGroup)[0];
|
|
||||||
_courierGroup = mixer.FindMatchingGroups(AudioGroups.CourierMusicGroup)[0];
|
|
||||||
_enemiesGroup = mixer.FindMatchingGroups(AudioGroups.EnemiesMusicGroup)[0];
|
|
||||||
|
|
||||||
_snapshots[AudioSnapshotState.Peaceful] = mixer.FindSnapshot(AudioGroups.PeacefulSnapshot);
|
|
||||||
_snapshots[AudioSnapshotState.Action] = mixer.FindSnapshot(AudioGroups.ActionSnapshot);
|
|
||||||
|
|
||||||
// _audioSourcePool.Initialize(10,prefab);
|
|
||||||
|
|
||||||
InitializeMusicSources();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void InitializeMusicSources()
|
|
||||||
{
|
|
||||||
_actionMusicSource = _audioSourcePool.GetSource();
|
|
||||||
_actionMusicSource.outputAudioMixerGroup = _actionMusicGroup;
|
|
||||||
_actionMusicSource.spatialBlend = 0f;
|
|
||||||
|
|
||||||
_peacefulMusicSource = _audioSourcePool.GetSource();
|
|
||||||
_peacefulMusicSource.outputAudioMixerGroup = _peacefulMusicGroup;
|
|
||||||
_peacefulMusicSource.spatialBlend = 0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Start()
|
|
||||||
{
|
|
||||||
MixerCreated();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void PlayRandomGameplayMusic()
|
|
||||||
{
|
|
||||||
_peacefulMusicSource.resource = peacefulAudio[Random.Range(0, peacefulAudio.Length)];
|
|
||||||
_actionMusicSource.resource = actionAudio[Random.Range(0, actionAudio.Length)];
|
|
||||||
|
|
||||||
_peacefulMusicSource.Play();
|
|
||||||
_actionMusicSource.Play();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void TransitToSnapshot(AudioSnapshotState state)
|
|
||||||
{
|
|
||||||
_snapshots[state].TransitionTo(1f);
|
|
||||||
}
|
|
||||||
|
|
||||||
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
|
|
||||||
public void PlaySFX(SFXSounds sfxId, Vector3 position)
|
|
||||||
{
|
|
||||||
_audioSourcePool.PlayOneShot(sfxAudios[(int)sfxId], position, _SFXGroup);
|
|
||||||
}
|
|
||||||
public void PlayDebugSFX()
|
|
||||||
{
|
|
||||||
_audioSourcePool.PlayOneShot(sfxAudios[(int)SFXSounds.Crowbar], transform.position, _SFXGroup);
|
|
||||||
}
|
|
||||||
public void PlayEnemy(EnemiesSounds enemySoundId, Vector3 position)
|
|
||||||
{
|
|
||||||
_audioSourcePool.PlayOneShot(enemiesAudios[(int)enemySoundId], position, _enemiesGroup);
|
|
||||||
}
|
|
||||||
public void PlayDebugEnemySFX()
|
|
||||||
{
|
|
||||||
_audioSourcePool.PlayOneShot(enemiesAudios[(int)EnemiesSounds.Bastard], transform.position, _enemiesGroup);
|
|
||||||
}
|
|
||||||
public void PlayDispatcher(DispatcherSounds dispatcherSoundId)
|
|
||||||
{
|
|
||||||
_audioSourcePool.PlayShizo(dispatcherAudios[(int)dispatcherSoundId], _dispatcherGroup);
|
|
||||||
}
|
|
||||||
public void PlayDebugDispatcherSFX()
|
|
||||||
{
|
|
||||||
_audioSourcePool.PlayShizo(dispatcherAudios[(int)DispatcherSounds.AhFreeman], _dispatcherGroup);
|
|
||||||
}
|
|
||||||
|
|
||||||
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: a42cad8f28f54a53bef23d9313014abd
|
|
||||||
timeCreated: 1762805867
|
|
||||||
@@ -1,7 +1,12 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading;
|
||||||
|
using Code.Configs;
|
||||||
using Cysharp.Threading.Tasks;
|
using Cysharp.Threading.Tasks;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Audio;
|
using UnityEngine.Audio;
|
||||||
using UnityEngine.Pool;
|
using UnityEngine.Pool;
|
||||||
|
using Object = UnityEngine.Object;
|
||||||
|
|
||||||
namespace Code.Audio
|
namespace Code.Audio
|
||||||
{
|
{
|
||||||
@@ -10,7 +15,11 @@ namespace Code.Audio
|
|||||||
// The pool holds plain GameObjects (you can swap this for any component type).
|
// The pool holds plain GameObjects (you can swap this for any component type).
|
||||||
private IObjectPool<AudioSource> _pool;
|
private IObjectPool<AudioSource> _pool;
|
||||||
private GameObject _sourcePrefab;
|
private GameObject _sourcePrefab;
|
||||||
|
|
||||||
|
private Dictionary<AudioSourceType, AudioSourceSettingsConfig> _settings;
|
||||||
|
|
||||||
|
public AudioSourcePool(Dictionary<AudioSourceType, AudioSourceSettingsConfig> settings) => _settings = settings;
|
||||||
|
|
||||||
public void Initialize(GameObject sourcePrefab)
|
public void Initialize(GameObject sourcePrefab)
|
||||||
{
|
{
|
||||||
_sourcePrefab = sourcePrefab;
|
_sourcePrefab = sourcePrefab;
|
||||||
@@ -54,30 +63,58 @@ namespace Code.Audio
|
|||||||
{
|
{
|
||||||
Object.Destroy(source.gameObject);
|
Object.Destroy(source.gameObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async UniTaskVoid PlayOneShot(AudioClip clip, Vector3 position, AudioMixerGroup audioMixerGroup)
|
public async UniTaskVoid PlayOneShot(AudioClip clip, Vector3 position, AudioMixerGroup audioMixerGroup, AudioSourceType audioSourceType = AudioSourceType.NoBlend, Action onComplete = null)
|
||||||
{
|
{
|
||||||
AudioSource source = _pool.Get();
|
AudioSource source = _pool.Get();
|
||||||
source.PlayOneShot(clip);
|
source.PlayOneShot(clip);
|
||||||
source.spatialBlend = 1f;
|
source.spatialBlend = _settings[audioSourceType].spatialBlend;
|
||||||
source.transform.position = position;
|
source.transform.position = position;
|
||||||
source.outputAudioMixerGroup = audioMixerGroup;
|
source.outputAudioMixerGroup = audioMixerGroup;
|
||||||
|
|
||||||
await UniTask.WaitUntilValueChanged(source, x => x.isPlaying);
|
await UniTask.WaitUntilValueChanged(source, x => x.isPlaying);
|
||||||
|
onComplete?.Invoke();
|
||||||
_pool.Release(source);
|
_pool.Release(source);
|
||||||
}
|
}
|
||||||
public async UniTaskVoid PlayShizo(AudioClip clip, AudioMixerGroup audioMixerGroup)
|
public async UniTaskVoid PlayOneShot(AudioClip clip, AudioMixerGroup audioMixerGroup, AudioSourceType audioSourceType = AudioSourceType.NoBlend, Action onComplete = null)
|
||||||
{
|
{
|
||||||
AudioSource source = _pool.Get();
|
AudioSource source = _pool.Get();
|
||||||
source.PlayOneShot(clip);
|
source.PlayOneShot(clip);
|
||||||
source.spatialBlend = 0f;
|
source.spatialBlend = _settings[audioSourceType].spatialBlend;
|
||||||
source.outputAudioMixerGroup = audioMixerGroup;
|
source.outputAudioMixerGroup = audioMixerGroup;
|
||||||
|
|
||||||
await UniTask.WaitUntilValueChanged(source, x => x.isPlaying);
|
await UniTask.WaitUntilValueChanged(source, x => x.isPlaying);
|
||||||
|
onComplete?.Invoke();
|
||||||
|
_pool.Release(source);
|
||||||
|
}
|
||||||
|
public async UniTaskVoid PlayOneShot(AudioSource audioSource, AudioClip clip, AudioMixerGroup audioMixerGroup, AudioSourceType audioSourceType = AudioSourceType.NoBlend, Action onComplete = null)
|
||||||
|
{
|
||||||
|
audioSource.PlayOneShot(clip);
|
||||||
|
audioSource.spatialBlend = _settings[audioSourceType].spatialBlend;
|
||||||
|
audioSource.outputAudioMixerGroup = audioMixerGroup;
|
||||||
|
|
||||||
|
// TODO Потом сделать. Можно с cancellation, но сейчас лень. Ну правда
|
||||||
|
await UniTask.WaitUntilValueChanged(audioSource, x => x.isPlaying);
|
||||||
|
|
||||||
|
if (!audioSource) return;
|
||||||
|
|
||||||
|
_pool.Release(audioSource);
|
||||||
|
onComplete?.Invoke();
|
||||||
|
}
|
||||||
|
public async UniTaskVoid PlayOneShot(AudioClip clip, AudioMixerGroup audioMixerGroup, CancellationTokenSource cancellationToken, AudioSourceType audioSourceType = AudioSourceType.NoBlend, Action onComplete = null)
|
||||||
|
{
|
||||||
|
AudioSource source = _pool.Get();
|
||||||
|
source.PlayOneShot(clip);
|
||||||
|
source.spatialBlend = _settings[audioSourceType].spatialBlend;
|
||||||
|
source.outputAudioMixerGroup = audioMixerGroup;
|
||||||
|
|
||||||
|
var (isCanceled, _) = await UniTask.WaitUntilValueChanged(source, x => x.isPlaying, cancellationToken: cancellationToken.Token).SuppressCancellationThrow();
|
||||||
|
|
||||||
_pool.Release(source);
|
_pool.Release(source);
|
||||||
}
|
|
||||||
|
if(!isCanceled) onComplete?.Invoke();
|
||||||
|
else cancellationToken.Dispose();
|
||||||
|
}
|
||||||
public AudioSource GetSource() => _pool.Get();
|
public AudioSource GetSource() => _pool.Get();
|
||||||
public void ReleaseSource(AudioSource source) => _pool.Release(source);
|
public void ReleaseSource(AudioSource source) => _pool.Release(source);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
namespace Code.Audio
|
||||||
|
{
|
||||||
|
public enum AudioSourceType
|
||||||
|
{
|
||||||
|
Full3D,
|
||||||
|
NoBlend
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 260bbb19b55049928b9ab4d55b32fc3f
|
||||||
|
timeCreated: 1763849966
|
||||||
@@ -8,22 +8,25 @@ namespace Code.Audio
|
|||||||
{
|
{
|
||||||
public interface IAudioFactory
|
public interface IAudioFactory
|
||||||
{
|
{
|
||||||
|
AudioMixer AudioMixer { get; }
|
||||||
|
Dictionary<AudioType, AudioClip> AudioTestClips { get; }
|
||||||
|
Dictionary<MusicType, List<AudioClip>> MusicDictionary { get; }
|
||||||
List<AudioClip> SFXAudios { get; }
|
List<AudioClip> SFXAudios { get; }
|
||||||
List<AudioClip> EnemiesAudios { get; }
|
List<AudioClip> EnemiesAudios { get; }
|
||||||
List<AudioClip> DispatcherAudios { get; }
|
List<AudioClip> DispatcherAudios { get; }
|
||||||
AudioMixer AudioMixer { get; }
|
|
||||||
Dictionary<MusicType, List<AudioClip>> MusicDictionary { get; }
|
|
||||||
UniTask LoadAudioSourcePrefab(Action<GameObject> callback);
|
UniTask LoadAudioSourcePrefab(Action<GameObject> callback);
|
||||||
UniTask WarmGameplayMusic();
|
UniTask WarmGameplayMusic( );
|
||||||
void ReleaseActionMusic();
|
void ReleaseActionMusic();
|
||||||
UniTask WarmMenuMusic();
|
|
||||||
void ReleaseMenuMusic();
|
|
||||||
UniTask WarmSFX();
|
|
||||||
void ReleaseSFX();
|
|
||||||
UniTask WarmEnemies();
|
|
||||||
void ReleaseEnemies();
|
|
||||||
UniTask WarmDispatcher();
|
|
||||||
void ReleaseDispatcher();
|
|
||||||
void ReleasePeacefulMusic();
|
void ReleasePeacefulMusic();
|
||||||
|
UniTask WarmAudioTestClips( );
|
||||||
|
void ReleaseAudioTestClips();
|
||||||
|
UniTask WarmMenuMusic( );
|
||||||
|
void ReleaseMenuMusic();
|
||||||
|
UniTask WarmSFX( );
|
||||||
|
void ReleaseSFX();
|
||||||
|
UniTask WarmEnemies( );
|
||||||
|
void ReleaseEnemies();
|
||||||
|
UniTask WarmDispatcher( );
|
||||||
|
void ReleaseDispatcher();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -14,6 +14,14 @@ namespace Code.Audio
|
|||||||
void TransitToSnapshot(AudioSnapshotState state, float time = 1f);
|
void TransitToSnapshot(AudioSnapshotState state, float time = 1f);
|
||||||
void PlaySFX(SFXSounds sfxId, Vector3 position);
|
void PlaySFX(SFXSounds sfxId, Vector3 position);
|
||||||
void PlayEnemy(EnemiesSounds enemySoundId, Vector3 position);
|
void PlayEnemy(EnemiesSounds enemySoundId, Vector3 position);
|
||||||
|
|
||||||
|
delegate void OnAudioPlayingDelegate();
|
||||||
|
|
||||||
|
event OnAudioPlayingDelegate OnDispatcherStarted;
|
||||||
|
event OnAudioPlayingDelegate OnDispatcherEnded;
|
||||||
void PlayDispatcher(DispatcherSounds dispatcherSoundId);
|
void PlayDispatcher(DispatcherSounds dispatcherSoundId);
|
||||||
|
void ChangeSetting(AudioType type, float value);
|
||||||
|
float GetSetting(AudioType type);
|
||||||
|
void PlayTestClip(AudioType audioType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,4 +6,13 @@ namespace Code.Audio
|
|||||||
Peaceful,
|
Peaceful,
|
||||||
Action
|
Action
|
||||||
}
|
}
|
||||||
|
public enum AudioType
|
||||||
|
{
|
||||||
|
Master,
|
||||||
|
MenuMusic,
|
||||||
|
GameplayMusic,
|
||||||
|
Creatures,
|
||||||
|
DispatcherSounds,
|
||||||
|
SFX
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
using Code.Audio;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Code.Configs
|
||||||
|
{
|
||||||
|
[CreateAssetMenu(fileName = "AudioSourceSettingsConfig", menuName = "Audio/AudioSourceSettingsConfig")]
|
||||||
|
public class AudioSourceSettingsConfig : ScriptableObject
|
||||||
|
{
|
||||||
|
// Дополнять по мере необходимости
|
||||||
|
public float spatialBlend;
|
||||||
|
|
||||||
|
public AudioSourceType sourceType;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: e6406ab390b74d5ca336d7d4d0e1a732
|
||||||
|
timeCreated: 1763850008
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.AddressableAssets;
|
||||||
|
|
||||||
|
namespace Code.Configs
|
||||||
|
{
|
||||||
|
[CreateAssetMenu(menuName = "Config/Audio/AudioTestClips", fileName = "AudioTestClipsConfig")]
|
||||||
|
public class AudioTestClipsConfig : ScriptableObject
|
||||||
|
{
|
||||||
|
public AssetReference[] audioTestClips;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: f2f1c08a20a54a708336caf8ca6499e1
|
||||||
|
timeCreated: 1764263243
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
using Code.Gameplay.Camera;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Code.Configs
|
||||||
|
{
|
||||||
|
[CreateAssetMenu(fileName = "CameraSettingsConfig", menuName = "Config/CameraSettingsConfig")]
|
||||||
|
public class CameraSettingsConfig : ScriptableObject
|
||||||
|
{
|
||||||
|
// Дополнять по мере необходимости
|
||||||
|
public float fov;
|
||||||
|
|
||||||
|
public CameraMode cameraMode;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 6610b94e9823401c94533e1756a97195
|
||||||
|
timeCreated: 1763846744
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.AddressableAssets;
|
||||||
|
|
||||||
|
namespace Code.Configs
|
||||||
|
{
|
||||||
|
[CreateAssetMenu(menuName = "Config/Enemies/Cockroach", fileName = "CockroachConfig")]
|
||||||
|
public class CockroachConfig : ScriptableObject
|
||||||
|
{
|
||||||
|
public AssetReference cockroachPrefab;
|
||||||
|
|
||||||
|
public int damage = 2;
|
||||||
|
public float attackCooldown = 1.5f;
|
||||||
|
|
||||||
|
public float detectionRange = 20f;
|
||||||
|
public float attackRange = 1.3f;
|
||||||
|
|
||||||
|
public float speed = 6f;
|
||||||
|
|
||||||
|
public bool isStunnable;
|
||||||
|
public float stunDuration;
|
||||||
|
|
||||||
|
public bool usesIdleMovement = true;
|
||||||
|
public float idleWanderRadius = 3f;
|
||||||
|
public float idleMoveDurationMin = 0.3f;
|
||||||
|
public float idleMoveDurationMax = 1f;
|
||||||
|
public float idlePauseDurationMin = 0.1f;
|
||||||
|
public float idlePauseDurationMax = 0.8f;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 7bc162d3127949aa950d0738beee99a4
|
||||||
|
timeCreated: 1763571220
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.AddressableAssets;
|
||||||
|
|
||||||
|
namespace Code.Configs
|
||||||
|
{
|
||||||
|
[CreateAssetMenu(menuName = "Config/Enemies/DrunkenGrandpa", fileName = "DrunkenGrandpaConfig")]
|
||||||
|
public class DrunkenGrandpaConfig : ScriptableObject
|
||||||
|
{
|
||||||
|
public AssetReference drunkenGrandpaPrefab;
|
||||||
|
|
||||||
|
public int damage = 2;
|
||||||
|
public float attackCooldown = 5f;
|
||||||
|
|
||||||
|
public float detectionRange = 10f;
|
||||||
|
public float attackRange = 1.5f;
|
||||||
|
|
||||||
|
public float speed = 3f;
|
||||||
|
|
||||||
|
public bool isStunnable = true;
|
||||||
|
public float stunDuration = 3f;
|
||||||
|
|
||||||
|
public bool usesIdleMovement = true;
|
||||||
|
public float idleWanderRadius = 5f;
|
||||||
|
public float idleMoveDurationMin = 1f;
|
||||||
|
public float idleMoveDurationMax = 5f;
|
||||||
|
public float idlePauseDurationMin = 3f;
|
||||||
|
public float idlePauseDurationMax = 5f;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 4d157e8891074b90957a7434cff0ae71
|
||||||
|
timeCreated: 1763569096
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.AddressableAssets;
|
||||||
|
|
||||||
|
namespace Code.Configs
|
||||||
|
{
|
||||||
|
[CreateAssetMenu(menuName = "Config/Enemies/Fog", fileName = "FogConfig")]
|
||||||
|
public class FogConfig : ScriptableObject
|
||||||
|
{
|
||||||
|
public AssetReference fogPrefab;
|
||||||
|
|
||||||
|
public int damage = int.MaxValue;
|
||||||
|
public float attackCooldown;
|
||||||
|
|
||||||
|
public float detectionRange;
|
||||||
|
public float attackRange = 5f;
|
||||||
|
|
||||||
|
public float speed = 1.5f;
|
||||||
|
|
||||||
|
public bool isStunnable;
|
||||||
|
public float stunDuration;
|
||||||
|
|
||||||
|
public bool usesIdleMovement;
|
||||||
|
public float idleWanderRadius;
|
||||||
|
public float idleMoveDurationMin;
|
||||||
|
public float idleMoveDurationMax;
|
||||||
|
public float idlePauseDurationMin;
|
||||||
|
public float idlePauseDurationMax;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: aa4dd2a5cce24902a2918488b5751f2f
|
||||||
|
timeCreated: 1763581410
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Code.Configs
|
||||||
|
{
|
||||||
|
[CreateAssetMenu(menuName = "Config/Gameplay/OrderBox", fileName = "OrderBoxConfig")]
|
||||||
|
public class OrderBoxConfig : ScriptableObject
|
||||||
|
{
|
||||||
|
public float activationTime;
|
||||||
|
public AnimationCurve floatingCurve;
|
||||||
|
public float curveLength;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 6af4f53d425a41c78ef889fd7e5c3197
|
||||||
|
timeCreated: 1763735968
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Code.Configs
|
||||||
|
{
|
||||||
|
[CreateAssetMenu(fileName = "OrderServiceConfig", menuName = "Config/Gameplay/OrderServiceConfig")]
|
||||||
|
public class OrderServiceConfig : ScriptableObject
|
||||||
|
{
|
||||||
|
public Vector2 timeBounds;
|
||||||
|
public float koefRooms, koefOvertime;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: ee2550c3e4874575ac3aecadfcc42475
|
||||||
|
timeCreated: 1763559999
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using UnityEngine.AddressableAssets;
|
||||||
|
|
||||||
namespace Code.Configs
|
namespace Code.Configs
|
||||||
{
|
{
|
||||||
@@ -6,5 +7,8 @@ namespace Code.Configs
|
|||||||
public class PlayerConfig : ScriptableObject
|
public class PlayerConfig : ScriptableObject
|
||||||
{
|
{
|
||||||
public int maxHealth;
|
public int maxHealth;
|
||||||
|
|
||||||
|
public AssetReference characterPrefab;
|
||||||
|
public AssetReference armsMeshPrefab;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -10,8 +10,9 @@ namespace Code.Gameplay.Camera
|
|||||||
*/
|
*/
|
||||||
public enum CameraMode
|
public enum CameraMode
|
||||||
{
|
{
|
||||||
Bogdan,
|
None,
|
||||||
Static,
|
Static,
|
||||||
|
MainMenu,
|
||||||
FirstPerson,
|
FirstPerson,
|
||||||
ThirdPerson,
|
ThirdPerson,
|
||||||
Cinematic
|
Cinematic
|
||||||
|
|||||||
@@ -9,13 +9,16 @@ namespace Code.Gameplay.Camera
|
|||||||
// Текущий режим работы камеры
|
// Текущий режим работы камеры
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
|
States.Add(CameraMode.None, new NoneState(StateMachineContext));
|
||||||
States.Add(CameraMode.Static, new StaticState(StateMachineContext));
|
States.Add(CameraMode.Static, new StaticState(StateMachineContext));
|
||||||
|
States.Add(CameraMode.MainMenu, new MainMenuState(StateMachineContext));
|
||||||
States.Add(CameraMode.FirstPerson, new FirstPersonState(StateMachineContext));
|
States.Add(CameraMode.FirstPerson, new FirstPersonState(StateMachineContext));
|
||||||
States.Add(CameraMode.ThirdPerson, new ThirdPersonState(StateMachineContext));
|
States.Add(CameraMode.ThirdPerson, new ThirdPersonState(StateMachineContext));
|
||||||
|
|
||||||
CurrentBaseState = States[CameraMode.Static];
|
CurrentBaseState = States[CameraMode.None];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public UnityEngine.Camera Camera => StateMachineContext.Camera;
|
||||||
|
|
||||||
protected override bool CheckTransitionAllowed(CameraMode nextState) => true;
|
protected override bool CheckTransitionAllowed(CameraMode nextState) => true;
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
using Code.Configs;
|
using Code.Configs;
|
||||||
using Code.Input;
|
using Code.Input;
|
||||||
using Reflex.Attributes;
|
using Reflex.Attributes;
|
||||||
@@ -9,5 +10,6 @@ namespace Code.Gameplay.Camera
|
|||||||
[Inject] public UnityEngine.Camera Camera;
|
[Inject] public UnityEngine.Camera Camera;
|
||||||
[Inject] public CameraConfig Config;
|
[Inject] public CameraConfig Config;
|
||||||
[Inject] public IInputService InputService;
|
[Inject] public IInputService InputService;
|
||||||
|
[Inject] public Dictionary<CameraMode,CameraSettingsConfig> CameraSettingsConfigs;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -117,7 +117,7 @@ namespace Code.Gameplay.Camera.CameraStates
|
|||||||
protected virtual void HandleRotationInput(float deltaTime, Vector3 rotationInput, out Quaternion targetRotation)
|
protected virtual void HandleRotationInput(float deltaTime, Vector3 rotationInput, out Quaternion targetRotation)
|
||||||
{
|
{
|
||||||
// Вращение вокруг вертикальной оси (горизонтальный поворот)
|
// Вращение вокруг вертикальной оси (горизонтальный поворот)
|
||||||
var rotationFromInput = Quaternion.Euler(FollowTransform.up * (rotationInput.x * RotationSpeed));
|
var rotationFromInput = Quaternion.Euler(Vector3.up * (rotationInput.x * RotationSpeed));
|
||||||
PlanarDirection = rotationFromInput * PlanarDirection;
|
PlanarDirection = rotationFromInput * PlanarDirection;
|
||||||
var planarRotation = Quaternion.LookRotation(PlanarDirection, FollowTransform.up);
|
var planarRotation = Quaternion.LookRotation(PlanarDirection, FollowTransform.up);
|
||||||
|
|
||||||
|
|||||||
@@ -14,14 +14,16 @@ namespace Code.Gameplay.Camera.CameraStates
|
|||||||
|
|
||||||
public override void EnterState()
|
public override void EnterState()
|
||||||
{
|
{
|
||||||
|
base.EnterState();
|
||||||
|
|
||||||
// В FirstPerson режиме дистанция всегда равна 0
|
// В FirstPerson режиме дистанция всегда равна 0
|
||||||
MinDistance = 0f;
|
MinDistance = 0f;
|
||||||
MaxDistance = 0f;
|
MaxDistance = 0f;
|
||||||
DefaultDistance = 0f;
|
DefaultDistance = 0f;
|
||||||
TargetDistance = 0f;
|
TargetDistance = 0f;
|
||||||
CurrentDistance = 0f;
|
CurrentDistance = 0f;
|
||||||
|
|
||||||
base.EnterState();
|
Camera.fieldOfView = Context.CameraSettingsConfigs[CameraMode.FirstPerson].fov;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void HandlePosition(float deltaTime, float zoomInput, Quaternion targetRotation)
|
protected override void HandlePosition(float deltaTime, float zoomInput, Quaternion targetRotation)
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Code.Gameplay.Camera.CameraStates
|
||||||
|
{
|
||||||
|
public class MainMenuState : BaseCameraState, ICameraState
|
||||||
|
{
|
||||||
|
public MainMenuState(CameraStateMachineContext context) : base(context) { }
|
||||||
|
|
||||||
|
public override void EnterState()
|
||||||
|
{
|
||||||
|
base.EnterState();
|
||||||
|
|
||||||
|
Camera.fieldOfView = Context.CameraSettingsConfigs[CameraMode.MainMenu].fov;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void HandlePosition(float deltaTime, float zoomInput, Quaternion targetRotation)
|
||||||
|
{
|
||||||
|
Camera.transform.position = FollowTransform.position;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CameraMode GetCameraMode() => CameraMode.MainMenu;
|
||||||
|
|
||||||
|
protected override void HandleRotationInput(float deltaTime, Vector3 rotationInput,
|
||||||
|
out Quaternion targetRotation)
|
||||||
|
{
|
||||||
|
if(FollowTransform) Camera.transform.rotation = FollowTransform.rotation;
|
||||||
|
targetRotation = Camera.transform.rotation;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 8e4b2fa3af4b4ba78ab79ca154f05fb4
|
||||||
|
timeCreated: 1763547110
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Code.Gameplay.Camera.CameraStates
|
||||||
|
{
|
||||||
|
public class NoneState : BaseCameraState, ICameraState
|
||||||
|
{
|
||||||
|
public NoneState(CameraStateMachineContext context) : base(context) { }
|
||||||
|
|
||||||
|
protected override void HandlePosition(float deltaTime, float zoomInput, Quaternion targetRotation)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public CameraMode GetCameraMode() => CameraMode.None;
|
||||||
|
|
||||||
|
protected override void HandleRotationInput(float deltaTime, Vector3 rotationInput,
|
||||||
|
out Quaternion targetRotation)
|
||||||
|
{
|
||||||
|
targetRotation = Quaternion.identity;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: d8fa6119113f4f12a35365fd27387124
|
||||||
|
timeCreated: 1763847889
|
||||||
@@ -9,8 +9,9 @@ namespace Code.Gameplay.Camera.CameraStates
|
|||||||
|
|
||||||
public override void EnterState()
|
public override void EnterState()
|
||||||
{
|
{
|
||||||
Debug.Log("Static State Enter");
|
|
||||||
base.EnterState();
|
base.EnterState();
|
||||||
|
|
||||||
|
Camera.fieldOfView = Context.CameraSettingsConfigs[CameraMode.Static].fov;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void HandlePosition(float deltaTime, float zoomInput, Quaternion targetRotation)
|
protected override void HandlePosition(float deltaTime, float zoomInput, Quaternion targetRotation)
|
||||||
|
|||||||
@@ -14,13 +14,13 @@ namespace Code.Gameplay.Camera.CameraStates
|
|||||||
|
|
||||||
public override void EnterState()
|
public override void EnterState()
|
||||||
{
|
{
|
||||||
|
base.EnterState();
|
||||||
|
|
||||||
// Восстанавливаем исходные значения дистанции
|
// Восстанавливаем исходные значения дистанции
|
||||||
MinDistance = OriginalMinDistance;
|
MinDistance = OriginalMinDistance;
|
||||||
MaxDistance = OriginalMaxDistance;
|
MaxDistance = OriginalMaxDistance;
|
||||||
DefaultDistance = OriginalDefaultDistance;
|
DefaultDistance = OriginalDefaultDistance;
|
||||||
TargetDistance = DefaultDistance;
|
TargetDistance = DefaultDistance;
|
||||||
|
|
||||||
base.EnterState();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void HandlePosition(float deltaTime, float zoomInput, Quaternion targetRotation)
|
protected override void HandlePosition(float deltaTime, float zoomInput, Quaternion targetRotation)
|
||||||
|
|||||||
+40
-3
@@ -15,6 +15,12 @@ namespace Code.Gameplay.Character.Controller.Abilities
|
|||||||
private readonly float _minWallClimbSpeed;
|
private readonly float _minWallClimbSpeed;
|
||||||
// Пороговый косинус стены
|
// Пороговый косинус стены
|
||||||
public float WallNormalThreshold { get; }
|
public float WallNormalThreshold { get; }
|
||||||
|
|
||||||
|
private bool _hasClimbedThisWallSession;
|
||||||
|
private float _wallClimbCooldownTimer;
|
||||||
|
private readonly float _wallClimbCooldownDuration = 1.5f;
|
||||||
|
|
||||||
|
public bool IsClimbingActive { get; private set; }
|
||||||
|
|
||||||
// Конструктор механики залазания на стену
|
// Конструктор механики залазания на стену
|
||||||
public WallClimbMechanic(float wallClimbSpeedFactor, float minWallClimbSpeed, float wallDetectionAngleThreshold)
|
public WallClimbMechanic(float wallClimbSpeedFactor, float minWallClimbSpeed, float wallDetectionAngleThreshold)
|
||||||
@@ -26,21 +32,32 @@ namespace Code.Gameplay.Character.Controller.Abilities
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Обработка столкновения при движении (вызывается при ударе о препятствие)
|
// Обработка столкновения при движении (вызывается при ударе о препятствие)
|
||||||
public void OnMovementHit(KinematicCharacterMotor motor, Vector3 hitNormal)
|
public bool TryClimbWall(KinematicCharacterMotor motor, Vector3 hitNormal)
|
||||||
{
|
{
|
||||||
// Проверяем, что это вертикальная или почти вертикальная поверхность (стена)
|
// Проверяем, что это вертикальная или почти вертикальная поверхность (стена)
|
||||||
var dotWithUp = Vector3.Dot(hitNormal, motor.CharacterUp);
|
var dotWithUp = Vector3.Dot(hitNormal, motor.CharacterUp);
|
||||||
if (Mathf.Abs(dotWithUp) > WallNormalThreshold) return; // Не стена — это пол или потолок
|
|
||||||
|
if (Mathf.Abs(dotWithUp) > WallNormalThreshold)
|
||||||
|
{
|
||||||
|
// Сбрасываем сессию, если коснулись пола/потолка → выход из "режима стены"
|
||||||
|
_hasClimbedThisWallSession = false;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Запрещаем повторное залазание в рамках одной сессии
|
||||||
|
if (_hasClimbedThisWallSession || _wallClimbCooldownTimer > 0f)
|
||||||
|
return false;
|
||||||
|
|
||||||
// Получаем текущую скорость персонажа
|
// Получаем текущую скорость персонажа
|
||||||
var currentVelocity = motor.Velocity;
|
var currentVelocity = motor.Velocity;
|
||||||
|
|
||||||
// Проекция скорости на направление к стене (отрицательная, если летим в стену)
|
// Проекция скорости на направление к стене (отрицательная, если летим в стену)
|
||||||
var velocityIntoWall = Vector3.Dot(currentVelocity, -hitNormal);
|
var velocityIntoWall = Vector3.Dot(currentVelocity, -hitNormal);
|
||||||
|
|
||||||
// Если движемся в стену с достаточной скоростью
|
// Если движемся в стену с достаточной скоростью
|
||||||
if (velocityIntoWall > _minWallClimbSpeed)
|
if (velocityIntoWall > _minWallClimbSpeed)
|
||||||
{
|
{
|
||||||
|
_wallClimbCooldownTimer = _wallClimbCooldownDuration;
|
||||||
// Преобразуем часть горизонтальной скорости в вертикальную
|
// Преобразуем часть горизонтальной скорости в вертикальную
|
||||||
var verticalBoost = velocityIntoWall * _wallClimbSpeedFactor;
|
var verticalBoost = velocityIntoWall * _wallClimbSpeedFactor;
|
||||||
|
|
||||||
@@ -49,6 +66,26 @@ namespace Code.Gameplay.Character.Controller.Abilities
|
|||||||
|
|
||||||
// Предотвращаем заземление и повторное применение в этом кадре
|
// Предотвращаем заземление и повторное применение в этом кадре
|
||||||
motor.ForceUnground();
|
motor.ForceUnground();
|
||||||
|
_hasClimbedThisWallSession = true;
|
||||||
|
IsClimbingActive = true;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ResetWallClimbSession()
|
||||||
|
{
|
||||||
|
_hasClimbedThisWallSession = false;
|
||||||
|
IsClimbingActive = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void TickCooldown(float deltaTime)
|
||||||
|
{
|
||||||
|
if (_wallClimbCooldownTimer > 0f)
|
||||||
|
{
|
||||||
|
_wallClimbCooldownTimer -= deltaTime;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+84
-16
@@ -17,6 +17,12 @@ namespace Code.Gameplay.Character.Controller.Abilities
|
|||||||
private Vector3 _lastWallNormal;
|
private Vector3 _lastWallNormal;
|
||||||
private float _lastWallContactHeight;
|
private float _lastWallContactHeight;
|
||||||
private float _leanFactor;
|
private float _leanFactor;
|
||||||
|
private float _leanSign;
|
||||||
|
private Vector3 _leanDirection;
|
||||||
|
|
||||||
|
private Vector3 _lastWallContactPoint;
|
||||||
|
private bool _isLeaningOnWall;
|
||||||
|
private const float WallProximityThreshold = 0.6f;
|
||||||
|
|
||||||
public WallLeanMechanic(float maxLeanAngle, float leanSharpness, float heightScale)
|
public WallLeanMechanic(float maxLeanAngle, float leanSharpness, float heightScale)
|
||||||
{
|
{
|
||||||
@@ -32,29 +38,93 @@ namespace Code.Gameplay.Character.Controller.Abilities
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Вызывается из OnMovementHit
|
// Вызывается из OnMovementHit
|
||||||
public void OnWallContact(Vector3 wallNormal, float contactHeight)
|
public void OnWallContact(KinematicCharacterMotor motor, Vector3 wallNormal, float contactHeight)
|
||||||
{
|
{
|
||||||
|
// Только если это действительно стена (не пол/потолок)
|
||||||
|
var dotWithUp = Vector3.Dot(wallNormal, motor.CharacterUp);
|
||||||
|
if (Mathf.Abs(dotWithUp) > 0.7f) // ~45°, можно настроить
|
||||||
|
return;
|
||||||
|
|
||||||
_lastWallNormal = wallNormal;
|
_lastWallNormal = wallNormal;
|
||||||
_lastWallContactHeight = contactHeight; }
|
_lastWallContactHeight = contactHeight;
|
||||||
|
_lastWallContactPoint = motor.TransientPosition;
|
||||||
|
|
||||||
|
// Пересчитываем направление наклона
|
||||||
|
_leanDirection = -_lastWallNormal;
|
||||||
|
_leanDirection = Vector3.ProjectOnPlane(_leanDirection, motor.CharacterUp).normalized;
|
||||||
|
|
||||||
|
_leanSign = 1;
|
||||||
|
|
||||||
|
// what the fuck
|
||||||
|
if (_leanDirection.x != 0)
|
||||||
|
{
|
||||||
|
switch (_leanDirection.x)
|
||||||
|
{
|
||||||
|
case -1 or 1 when motor.CharacterRight.x > 0.1f:
|
||||||
|
_leanSign = -1;
|
||||||
|
break;
|
||||||
|
case -1 or 1 when Mathf.Abs(motor.CharacterRight.x) < 0.1f:
|
||||||
|
_leanDirection = new Vector3(0, 0, -1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
switch (_leanDirection.z)
|
||||||
|
{
|
||||||
|
case 1 when Mathf.Abs(motor.CharacterRight.z) < 0.1f:
|
||||||
|
_leanSign = -1;
|
||||||
|
break;
|
||||||
|
case -1 when motor.CharacterRight.z < -0.1f:
|
||||||
|
case 1 when motor.CharacterRight.z > 0.1f:
|
||||||
|
_leanDirection = new Vector3(-1, 0, 0);
|
||||||
|
break;
|
||||||
|
case -1 when motor.CharacterRight.z > 0.1f:
|
||||||
|
case 1 when motor.CharacterRight.z < -0.1f:
|
||||||
|
_leanDirection = new Vector3(1, 0, 0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_isLeaningOnWall = true;
|
||||||
|
}
|
||||||
|
|
||||||
// Обновление каждый кадр
|
// Обновление каждый кадр
|
||||||
public void UpdateLean(KinematicCharacterMotor motor, float deltaTime)
|
public void UpdateLean(KinematicCharacterMotor motor, float deltaTime)
|
||||||
{
|
{
|
||||||
if (!_characterTransform) return;
|
if (!_characterTransform) return;
|
||||||
|
|
||||||
var isGrounded = motor.GroundingStatus.IsStableOnGround;
|
|
||||||
|
|
||||||
if (!isGrounded)
|
var currentPosition = motor.TransientPosition;
|
||||||
|
|
||||||
|
var isStillNearWall = false;
|
||||||
|
if (_isLeaningOnWall && _lastWallNormal != Vector3.zero)
|
||||||
{
|
{
|
||||||
var heightDelta = motor.TransientPosition.y - _lastWallContactHeight;
|
var toWall = currentPosition - _lastWallContactPoint;
|
||||||
var targetLeanFactor = Mathf.Clamp01(heightDelta * _heightScale);
|
var distanceToWallPlane = Mathf.Abs(Vector3.Dot(toWall, _lastWallNormal));
|
||||||
_leanFactor = Mathf.Lerp(_leanFactor, targetLeanFactor, 1f - Mathf.Exp(-_leanSharpness * deltaTime));
|
isStillNearWall = distanceToWallPlane <= WallProximityThreshold;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
if (_isLeaningOnWall)
|
||||||
|
{
|
||||||
|
var isBelowContactHeight = currentPosition.y < _lastWallContactHeight;
|
||||||
|
|
||||||
|
if (!isStillNearWall || isBelowContactHeight)
|
||||||
|
{
|
||||||
|
_isLeaningOnWall = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var heightDelta = currentPosition.y - _lastWallContactHeight;
|
||||||
|
var targetLeanFactor = Mathf.Clamp01(heightDelta * _heightScale);
|
||||||
|
_leanFactor = Mathf.Lerp(_leanFactor, targetLeanFactor, 1f - Mathf.Exp(-_leanSharpness * deltaTime));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!_isLeaningOnWall)
|
||||||
{
|
{
|
||||||
_leanFactor = Mathf.Lerp(_leanFactor, 0f, 1f - Mathf.Exp(-_leanSharpness * deltaTime));
|
_leanFactor = Mathf.Lerp(_leanFactor, 0f, 1f - Mathf.Exp(-_leanSharpness * deltaTime));
|
||||||
}
|
}
|
||||||
|
|
||||||
ApplyLeanRotation(motor);
|
ApplyLeanRotation(motor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,13 +136,11 @@ namespace Code.Gameplay.Character.Controller.Abilities
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var leanDirection = -_lastWallNormal;
|
if (_leanDirection.sqrMagnitude < 0.01f) return;
|
||||||
leanDirection = Vector3.ProjectOnPlane(leanDirection, motor.CharacterUp).normalized;
|
|
||||||
|
|
||||||
if (leanDirection.sqrMagnitude < 0.01f) return;
|
var leanAngle = _leanSign * _leanFactor * _maxLeanAngle;
|
||||||
|
var leanAxis = Vector3.Cross(motor.CharacterUp, _leanDirection);
|
||||||
var leanAngle = _leanFactor * _maxLeanAngle;
|
var leanRotation = Quaternion.AngleAxis(leanAngle, leanAxis);
|
||||||
var leanRotation = Quaternion.AngleAxis(leanAngle, Vector3.Cross(motor.CharacterUp, leanDirection));
|
|
||||||
_characterTransform.localRotation = leanRotation;
|
_characterTransform.localRotation = leanRotation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+82
-19
@@ -33,9 +33,48 @@ namespace Code.Gameplay.Character.Controller
|
|||||||
private GroundMovementSystem _groundMovement;
|
private GroundMovementSystem _groundMovement;
|
||||||
private AirMovementSystem _airMovement;
|
private AirMovementSystem _airMovement;
|
||||||
|
|
||||||
|
public bool IsSliding => _slideMechanic.IsSliding;
|
||||||
|
|
||||||
|
private float abilityBlockTimer;
|
||||||
|
private bool isAbilitiesBlocked;
|
||||||
|
|
||||||
|
public void SetPosition(Vector3 position) => motor.SetPosition(position);
|
||||||
|
public void SetRotation(Quaternion rotation) => motor.SetRotation(rotation);
|
||||||
|
|
||||||
// Инициализация контроллера
|
// Инициализация контроллера
|
||||||
private void Awake()
|
// private void Awake()
|
||||||
|
// {
|
||||||
|
// // Инициализация подсистем с параметрами из конфига
|
||||||
|
// _inputHandler = new CharacterInputHandler(
|
||||||
|
// _characterConfig.sprintAngleThreshold
|
||||||
|
// );
|
||||||
|
// _slideMechanic = new SlideMechanic(
|
||||||
|
// _characterConfig.slideSpeed,
|
||||||
|
// _characterConfig.slideDuration,
|
||||||
|
// _characterConfig.slideCooldown
|
||||||
|
// );
|
||||||
|
// _wallClimbMechanic = new WallClimbMechanic(
|
||||||
|
// _characterConfig.wallClimbSpeedFactor,
|
||||||
|
// _characterConfig.minWallClimbSpeed,
|
||||||
|
// _characterConfig.wallDetectionAngleThreshold
|
||||||
|
// );
|
||||||
|
// _wallLeanMechanic = new WallLeanMechanic(
|
||||||
|
// _characterConfig.maxWallLeanAngle,
|
||||||
|
// _characterConfig.wallLeanSharpness,
|
||||||
|
// _characterConfig.wallLeanHeightScale
|
||||||
|
// );
|
||||||
|
// _groundMovement = new GroundMovementSystem(
|
||||||
|
// _characterConfig.maxStableMoveSpeed,
|
||||||
|
// _characterConfig.sprintMoveSpeed,
|
||||||
|
// _characterConfig.stableMovementSharpness,
|
||||||
|
// _characterConfig.jumpSpeed
|
||||||
|
// );
|
||||||
|
// _airMovement = new AirMovementSystem(_characterConfig.gravity);
|
||||||
|
// }
|
||||||
|
[Inject]
|
||||||
|
private void Construct(CharacterConfig characterConfig)
|
||||||
{
|
{
|
||||||
|
_characterConfig = characterConfig;
|
||||||
// Инициализация подсистем с параметрами из конфига
|
// Инициализация подсистем с параметрами из конфига
|
||||||
_inputHandler = new CharacterInputHandler(
|
_inputHandler = new CharacterInputHandler(
|
||||||
_characterConfig.sprintAngleThreshold
|
_characterConfig.sprintAngleThreshold
|
||||||
@@ -62,25 +101,31 @@ namespace Code.Gameplay.Character.Controller
|
|||||||
_characterConfig.jumpSpeed
|
_characterConfig.jumpSpeed
|
||||||
);
|
);
|
||||||
_airMovement = new AirMovementSystem(_characterConfig.gravity);
|
_airMovement = new AirMovementSystem(_characterConfig.gravity);
|
||||||
}
|
|
||||||
|
|
||||||
// Текущий режим камеры для адаптации поведения
|
|
||||||
private CameraMode _currentCameraMode = CameraMode.FirstPerson;
|
|
||||||
|
|
||||||
// Инициализация контроллера
|
|
||||||
private void Start()
|
|
||||||
{
|
|
||||||
motor.CharacterController = this; // Регистрация этого контроллера в движке
|
motor.CharacterController = this; // Регистрация этого контроллера в движке
|
||||||
_inputHandler.FirstPersonCameraRotation =
|
_inputHandler.FirstPersonCameraRotation =
|
||||||
motor.Transform.rotation; // Начальное вращение совпадает с персонажемс
|
motor.Transform.rotation; // Начальное вращение совпадает с персонажемс
|
||||||
_wallLeanMechanic.SetCharacterTransform(characterTransform);
|
_wallLeanMechanic.SetCharacterTransform(characterTransform);
|
||||||
}
|
}
|
||||||
|
// Текущий режим камеры для адаптации поведения
|
||||||
|
private CameraMode _currentCameraMode = CameraMode.FirstPerson;
|
||||||
|
|
||||||
|
// Инициализация контроллера
|
||||||
|
// private void Start()
|
||||||
|
// {
|
||||||
|
// motor.CharacterController = this; // Регистрация этого контроллера в движке
|
||||||
|
// _inputHandler.FirstPersonCameraRotation =
|
||||||
|
// motor.Transform.rotation; // Начальное вращение совпадает с персонажемс
|
||||||
|
// _wallLeanMechanic.SetCharacterTransform(characterTransform);
|
||||||
|
// }
|
||||||
|
|
||||||
// Обработка и преобразование входных данных от персонажа
|
// Обработка и преобразование входных данных от персонажа
|
||||||
public void SetInputs(ref CharacterInputs inputs)
|
public void SetInputs(ref CharacterInputs inputs)
|
||||||
{
|
{
|
||||||
// Обновляем таймер перезарядки слайда
|
// Обновляем таймер перезарядки слайда
|
||||||
_slideMechanic.TickCooldown(Time.deltaTime);
|
_slideMechanic.TickCooldown(Time.deltaTime);
|
||||||
|
_wallClimbMechanic.TickCooldown(Time.deltaTime);
|
||||||
|
|
||||||
// Если активен слайд - игнорируем весь остальной ввод
|
// Если активен слайд - игнорируем весь остальной ввод
|
||||||
if (_slideMechanic.IsSliding)
|
if (_slideMechanic.IsSliding)
|
||||||
@@ -95,6 +140,20 @@ namespace Code.Gameplay.Character.Controller
|
|||||||
|
|
||||||
// Сохраняем текущий режим камеры
|
// Сохраняем текущий режим камеры
|
||||||
_currentCameraMode = inputs.CameraMode;
|
_currentCameraMode = inputs.CameraMode;
|
||||||
|
|
||||||
|
if (isAbilitiesBlocked)
|
||||||
|
{
|
||||||
|
abilityBlockTimer -= Time.deltaTime;
|
||||||
|
if (abilityBlockTimer <= 0)
|
||||||
|
{
|
||||||
|
isAbilitiesBlocked = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
inputs.SprintPressed = false;
|
||||||
|
inputs.SlidePressed = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Обработка слайда
|
// Обработка слайда
|
||||||
_slideMechanic.RequestSlide(inputs.SlidePressed);
|
_slideMechanic.RequestSlide(inputs.SlidePressed);
|
||||||
@@ -109,8 +168,7 @@ namespace Code.Gameplay.Character.Controller
|
|||||||
// Обновление вращения персонажа на основе входных данных
|
// Обновление вращения персонажа на основе входных данных
|
||||||
public void UpdateRotation(ref Quaternion currentRotation, float deltaTime)
|
public void UpdateRotation(ref Quaternion currentRotation, float deltaTime)
|
||||||
{
|
{
|
||||||
// ВО ВРЕМЯ СЛАЙДА НЕ ОБНОВЛЯЕМ ВРАЩЕНИЕ - ПЕРСОНАЖ СМОТРИТ ПРЯМО
|
if (_slideMechanic.IsSliding || _wallClimbMechanic.IsClimbingActive) return;
|
||||||
if (_slideMechanic.IsSliding) return;
|
|
||||||
|
|
||||||
switch (_currentCameraMode)
|
switch (_currentCameraMode)
|
||||||
{
|
{
|
||||||
@@ -141,7 +199,6 @@ namespace Code.Gameplay.Character.Controller
|
|||||||
// Заготовка на будущее (если понадобится)
|
// Заготовка на будущее (если понадобится)
|
||||||
case CameraMode.Static:
|
case CameraMode.Static:
|
||||||
case CameraMode.Cinematic:
|
case CameraMode.Cinematic:
|
||||||
case CameraMode.Bogdan: // Скорее всего юзлес, но пускай будет
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -182,6 +239,12 @@ namespace Code.Gameplay.Character.Controller
|
|||||||
_groundMovement.CancelJumpRequest();
|
_groundMovement.CancelJumpRequest();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void BlockAbilities(float duration)
|
||||||
|
{
|
||||||
|
isAbilitiesBlocked = true;
|
||||||
|
abilityBlockTimer = duration;
|
||||||
|
}
|
||||||
|
|
||||||
// Метод вызывается перед обновлением персонажа (можно использовать для подготовки)
|
// Метод вызывается перед обновлением персонажа (можно использовать для подготовки)
|
||||||
public void BeforeCharacterUpdate(float deltaTime)
|
public void BeforeCharacterUpdate(float deltaTime)
|
||||||
@@ -196,6 +259,11 @@ namespace Code.Gameplay.Character.Controller
|
|||||||
{
|
{
|
||||||
_slideMechanic.EndSlide();
|
_slideMechanic.EndSlide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (motor.GroundingStatus.IsStableOnGround)
|
||||||
|
{
|
||||||
|
_wallClimbMechanic.ResetWallClimbSession();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Метод вызывается после обновления персонажа
|
// Метод вызывается после обновления персонажа
|
||||||
@@ -220,13 +288,8 @@ namespace Code.Gameplay.Character.Controller
|
|||||||
public void OnMovementHit(Collider hitCollider, Vector3 hitNormal, Vector3 hitPoint,
|
public void OnMovementHit(Collider hitCollider, Vector3 hitNormal, Vector3 hitPoint,
|
||||||
ref HitStabilityReport hitStabilityReport)
|
ref HitStabilityReport hitStabilityReport)
|
||||||
{
|
{
|
||||||
_wallClimbMechanic.OnMovementHit(motor, hitNormal);
|
if (_wallClimbMechanic.TryClimbWall(motor, hitNormal))
|
||||||
|
_wallLeanMechanic.OnWallContact(motor, hitNormal, motor.TransientPosition.y);
|
||||||
var dotWithUp = Vector3.Dot(hitNormal, motor.CharacterUp);
|
|
||||||
if (Mathf.Abs(dotWithUp) <= _wallClimbMechanic.WallNormalThreshold)
|
|
||||||
{
|
|
||||||
_wallLeanMechanic.OnWallContact(hitNormal, motor.TransientPosition.y);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Обработка отчета о стабильности столкновения
|
// Обработка отчета о стабильности столкновения
|
||||||
|
|||||||
+1
-1
@@ -113,7 +113,7 @@ namespace Code.Gameplay.Character.Controller.Input
|
|||||||
var cameraForward = cameraRotation * Vector3.forward;
|
var cameraForward = cameraRotation * Vector3.forward;
|
||||||
|
|
||||||
// Проецируем на горизонтальную плоскость
|
// Проецируем на горизонтальную плоскость
|
||||||
var horizontalForward = Vector3.ProjectOnPlane(cameraForward, motor.CharacterUp).normalized;
|
var horizontalForward = Vector3.ProjectOnPlane(cameraForward, Vector3.up).normalized;
|
||||||
|
|
||||||
// Если проекция вырождена, используем текущее направление персонажа
|
// Если проекция вырождена, используем текущее направление персонажа
|
||||||
if (horizontalForward.sqrMagnitude < 0.01f)
|
if (horizontalForward.sqrMagnitude < 0.01f)
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
using Code.Gameplay.Camera;
|
||||||
|
using Code.Gameplay.Camera.CameraStates;
|
||||||
|
using Code.Gameplay.Character.Controller;
|
||||||
|
using Code.Gameplay.Player;
|
||||||
|
using Code.Input;
|
||||||
|
using Reflex.Attributes;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Code.Gameplay.Character.Core
|
||||||
|
{
|
||||||
|
public class CharacterProvider : MonoBehaviour
|
||||||
|
{
|
||||||
|
[Inject] private CameraStateMachine _cameraStateMachine; // Стейт-машина камеры (нужна для транзакций и т.п.)
|
||||||
|
[SerializeField] private CustomCharacterController customCharacterController; // Компонент управления персонажем
|
||||||
|
public CustomCharacterController CustomCharacterController => customCharacterController;
|
||||||
|
|
||||||
|
[SerializeField] private Transform cameraFollowPoint; // Точка следования камеры (уровень глаз для FirstPerson)
|
||||||
|
public Transform GetFollowTransform() => cameraFollowPoint;
|
||||||
|
|
||||||
|
[Inject] private IInputService _inputService; // Сервис ввода через DI
|
||||||
|
|
||||||
|
[SerializeField] private PlayerAnimator _animator;
|
||||||
|
public PlayerAnimator PlayerAnimator => _animator;
|
||||||
|
|
||||||
|
public void Teleport(Vector3 position, Quaternion rotation)
|
||||||
|
{
|
||||||
|
customCharacterController.SetPosition(position);
|
||||||
|
customCharacterController.SetRotation(rotation);
|
||||||
|
}
|
||||||
|
// Обработка ввода для движения персонажа
|
||||||
|
private void HandleCharacterInput()
|
||||||
|
{
|
||||||
|
// Создаем структуру ввода с полной информацией о камере
|
||||||
|
var inputs = new CharacterInputs();
|
||||||
|
|
||||||
|
// Получаем данные движения из Input System
|
||||||
|
var moveInput = _inputService.MoveInput;
|
||||||
|
inputs.MoveAxisForward = moveInput.y; // Vertical ось (W/S или Up/Down)
|
||||||
|
inputs.MoveAxisRight = moveInput.x; // Horizontal ось (A/D или Left/Right)
|
||||||
|
inputs.JumpPressed = _inputService.JumpPressed; // Прыжки (Space)
|
||||||
|
inputs.SprintPressed = true;//_inputService.SprintPressed; // Спринт (Shift)
|
||||||
|
inputs.SlidePressed = _inputService.SlidePressed; // Слайд (Ctrl)
|
||||||
|
inputs.CameraMode = ((ICameraState)_cameraStateMachine.CurrentBaseState).GetCameraMode();
|
||||||
|
|
||||||
|
// Передаем информацию о камере для адаптивного поведения
|
||||||
|
inputs.CameraRotation = ((BaseCameraState)_cameraStateMachine.CurrentBaseState).GetCameraRotation();
|
||||||
|
inputs.CameraPlanarDirection = ((BaseCameraState)_cameraStateMachine.CurrentBaseState).GetPlanarDirection();
|
||||||
|
|
||||||
|
// Передаем ввод в контроллер персонажа
|
||||||
|
customCharacterController.SetInputs(ref inputs);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Обновление логики каждый кадр
|
||||||
|
private void Update()
|
||||||
|
{
|
||||||
|
// Обработка ввода для движения в Update (физика)
|
||||||
|
HandleCharacterInput();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: b2d4b8256c1f4b3facf6b8d0a7d5256b
|
||||||
|
timeCreated: 1763217123
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: b7ba7b62b1aa47c48dc82ac8d8e8530e
|
||||||
|
timeCreated: 1763548306
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
using DG.Tweening;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Code.Gameplay.Door
|
||||||
|
{
|
||||||
|
public class CinematicDoorOpening
|
||||||
|
{
|
||||||
|
private MainMenuDoor _mainMenuDoor;
|
||||||
|
private Light _doorLight;
|
||||||
|
|
||||||
|
public CinematicDoorOpening(MainMenuDoor mainMenuDoor, Light doorLight)
|
||||||
|
{
|
||||||
|
_mainMenuDoor = mainMenuDoor;
|
||||||
|
_doorLight = doorLight;
|
||||||
|
}
|
||||||
|
public void PreOpen(int type)
|
||||||
|
{
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
_doorLight.DOColor(Color.green, 0.2f);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
_doorLight.DOColor(Color.yellow, 0.2f);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
_doorLight.DOColor(Color.red, 0.2f);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
_mainMenuDoor.Petlya.DORotate(new Vector3(0, -10, 0), 1f);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Close()
|
||||||
|
{
|
||||||
|
_mainMenuDoor.Petlya.DORotate(new Vector3(0, 0, 0), 1f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[System.Serializable]
|
||||||
|
public class MainMenuUIVariables
|
||||||
|
{
|
||||||
|
public MainMenuDoor MainMenuDoor;
|
||||||
|
public Light DoorLight;
|
||||||
|
public Color ButtonDefaultColor;
|
||||||
|
public Color ButtonHoverColor;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: deda0339570d44609dd62eafd9c6215f
|
||||||
|
timeCreated: 1763548908
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Code.Gameplay.Door
|
||||||
|
{
|
||||||
|
public class Door : MonoBehaviour
|
||||||
|
{
|
||||||
|
[SerializeField] private Transform hingeJointAnchor;
|
||||||
|
[SerializeField] private HingeJoint hingeJoint;
|
||||||
|
[SerializeField] private Rigidbody rigidbody;
|
||||||
|
|
||||||
|
public void TranslationMode(bool on)
|
||||||
|
{
|
||||||
|
if (on)
|
||||||
|
{
|
||||||
|
rigidbody.isKinematic = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
rigidbody.isKinematic = false;
|
||||||
|
hingeJoint.autoConfigureConnectedAnchor = false;
|
||||||
|
hingeJoint.connectedAnchor = hingeJointAnchor.position;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: bc9fc6ce2cc24b68b2b330e4fd029b80
|
||||||
|
timeCreated: 1764304430
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Code.Gameplay.Door
|
||||||
|
{
|
||||||
|
public class MainMenuDoor : MonoBehaviour
|
||||||
|
{
|
||||||
|
[SerializeField] Rigidbody rigidbody;
|
||||||
|
[SerializeField] private Transform petlya;
|
||||||
|
public Transform Petlya => petlya;
|
||||||
|
|
||||||
|
public void SetPhysics(bool active)
|
||||||
|
{
|
||||||
|
rigidbody.isKinematic = active;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 50a6b5e332704611b19f5a209d4dbffe
|
||||||
|
timeCreated: 1763548314
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 3b36108558824d748620db29707cd2b1
|
||||||
|
timeCreated: 1763228467
|
||||||
@@ -0,0 +1,203 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.AI;
|
||||||
|
using Code.Gameplay.Player;
|
||||||
|
using Code.Gameplay.Character.Controller;
|
||||||
|
using Code.Gameplay.Character.Core;
|
||||||
|
using Reflex.Attributes;
|
||||||
|
using Reflex.Core;
|
||||||
|
using Reflex.Injectors;
|
||||||
|
|
||||||
|
namespace Code.Gameplay.Enemies
|
||||||
|
{
|
||||||
|
public abstract class BaseEnemy : MonoBehaviour
|
||||||
|
{
|
||||||
|
[SerializeField] protected NavMeshAgent agent;
|
||||||
|
[SerializeField] protected Collider enemyCollider;
|
||||||
|
|
||||||
|
protected int Damage;
|
||||||
|
protected float AttackCooldown;
|
||||||
|
|
||||||
|
protected float DetectionRange;
|
||||||
|
protected float AttackRange;
|
||||||
|
|
||||||
|
protected float Speed;
|
||||||
|
|
||||||
|
protected bool IsStunnable;
|
||||||
|
protected float StunDuration;
|
||||||
|
|
||||||
|
protected bool UsesIdleMovement;
|
||||||
|
protected float IdleWanderRadius;
|
||||||
|
protected float IdleMoveDurationMin;
|
||||||
|
protected float IdleMoveDurationMax;
|
||||||
|
protected float IdlePauseDurationMin;
|
||||||
|
protected float IdlePauseDurationMax;
|
||||||
|
|
||||||
|
private bool _isStunned;
|
||||||
|
private float _currentStunTimer;
|
||||||
|
|
||||||
|
private bool _canAttack = true;
|
||||||
|
private float _attackCooldownTimer;
|
||||||
|
|
||||||
|
private enum IdleState { Moving, Paused }
|
||||||
|
private IdleState _currentIdleState = IdleState.Paused;
|
||||||
|
private float _idleTimer;
|
||||||
|
private Vector3 _idleTargetPosition;
|
||||||
|
|
||||||
|
[Inject] private IPlayerProvider _playerProvider;
|
||||||
|
protected CharacterProvider Player => _playerProvider?.Character;
|
||||||
|
protected PlayerHealth PlayerHealth => _playerProvider?.Health;
|
||||||
|
protected CustomCharacterController PlayerController => Player?.CustomCharacterController;
|
||||||
|
|
||||||
|
protected virtual void Awake()
|
||||||
|
{
|
||||||
|
if (_playerProvider == null)
|
||||||
|
{
|
||||||
|
AttributeInjector.Inject(this, Container.ProjectContainer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void Update()
|
||||||
|
{
|
||||||
|
if (!Player) return;
|
||||||
|
|
||||||
|
HandleStun();
|
||||||
|
HandleAttackCooldown();
|
||||||
|
if (_isStunned) return;
|
||||||
|
|
||||||
|
HandleMovement();
|
||||||
|
HandleAttack();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void HandleMovement()
|
||||||
|
{
|
||||||
|
if (!Player || !agent) return;
|
||||||
|
|
||||||
|
var distanceToPlayer = Vector3.Distance(transform.position, Player.transform.position);
|
||||||
|
|
||||||
|
if (distanceToPlayer <= DetectionRange)
|
||||||
|
{
|
||||||
|
agent.isStopped = false;
|
||||||
|
agent.SetDestination(Player.transform.position);
|
||||||
|
}
|
||||||
|
else if (UsesIdleMovement)
|
||||||
|
{
|
||||||
|
HandleIdleMovement();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
agent.isStopped = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void HandleIdleMovement()
|
||||||
|
{
|
||||||
|
_idleTimer -= Time.deltaTime;
|
||||||
|
|
||||||
|
switch (_currentIdleState)
|
||||||
|
{
|
||||||
|
case IdleState.Paused:
|
||||||
|
if (_idleTimer <= 0f)
|
||||||
|
{
|
||||||
|
// Start moving to a new random point
|
||||||
|
_currentIdleState = IdleState.Moving;
|
||||||
|
SetNewIdleDestination();
|
||||||
|
_idleTimer = Random.Range(IdleMoveDurationMin, IdleMoveDurationMax);
|
||||||
|
agent.isStopped = false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case IdleState.Moving:
|
||||||
|
if (_idleTimer <= 0f || HasReachedIdleDestination())
|
||||||
|
{
|
||||||
|
// Stop and pause
|
||||||
|
_currentIdleState = IdleState.Paused;
|
||||||
|
_idleTimer = Random.Range(IdlePauseDurationMin, IdlePauseDurationMax);
|
||||||
|
agent.isStopped = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetNewIdleDestination()
|
||||||
|
{
|
||||||
|
Vector3 randomPoint = transform.position + Random.insideUnitSphere * IdleWanderRadius;
|
||||||
|
NavMeshHit hit;
|
||||||
|
if (NavMesh.SamplePosition(randomPoint, out hit, 3f, agent.areaMask))
|
||||||
|
{
|
||||||
|
_idleTargetPosition = hit.position;
|
||||||
|
agent.SetDestination(_idleTargetPosition);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Fallback: stay
|
||||||
|
_idleTargetPosition = transform.position;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool HasReachedIdleDestination()
|
||||||
|
{
|
||||||
|
return agent.remainingDistance <= agent.stoppingDistance;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void HandleAttack() { }
|
||||||
|
|
||||||
|
protected virtual void HandleStun()
|
||||||
|
{
|
||||||
|
if (!_isStunned || !IsStunnable) return;
|
||||||
|
|
||||||
|
_currentStunTimer -= Time.deltaTime;
|
||||||
|
|
||||||
|
if (!(_currentStunTimer <= 0)) return;
|
||||||
|
|
||||||
|
_isStunned = false;
|
||||||
|
agent.isStopped = false;
|
||||||
|
enemyCollider.enabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void ApplyStun()
|
||||||
|
{
|
||||||
|
_isStunned = true;
|
||||||
|
_currentStunTimer = StunDuration;
|
||||||
|
agent.isStopped = true;
|
||||||
|
enemyCollider.enabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void HandleAttackCooldown()
|
||||||
|
{
|
||||||
|
if (!_canAttack)
|
||||||
|
{
|
||||||
|
_attackCooldownTimer -= Time.deltaTime;
|
||||||
|
if (_attackCooldownTimer <= 0)
|
||||||
|
{
|
||||||
|
_canAttack = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void DealDamage()
|
||||||
|
{
|
||||||
|
if (!_canAttack || PlayerHealth == null) return;
|
||||||
|
|
||||||
|
PlayerHealth.GetDamage(Damage);
|
||||||
|
ApplyEffectsToPlayer();
|
||||||
|
|
||||||
|
_canAttack = false;
|
||||||
|
_attackCooldownTimer = AttackCooldown;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void ApplyEffectsToPlayer()
|
||||||
|
{
|
||||||
|
if (PlayerController)
|
||||||
|
PlayerController.BlockAbilities(3f);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnDrawGizmosSelected()
|
||||||
|
{
|
||||||
|
Gizmos.color = Color.yellow;
|
||||||
|
Gizmos.DrawWireSphere(transform.position, DetectionRange);
|
||||||
|
|
||||||
|
Gizmos.color = new Color(0.3f, 0.3f, 0.8f, 0.4f);
|
||||||
|
Gizmos.DrawSphere(transform.position, AttackRange);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 691006ba0f69448787db8f350ecf32f4
|
||||||
|
timeCreated: 1763228480
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
using Code.Configs;
|
||||||
|
using Reflex.Attributes;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.AI;
|
||||||
|
|
||||||
|
namespace Code.Gameplay.Enemies
|
||||||
|
{
|
||||||
|
public class Cockroach : BaseEnemy
|
||||||
|
{
|
||||||
|
[Inject]
|
||||||
|
private void Construct(CockroachConfig cockroachConfig)
|
||||||
|
{
|
||||||
|
Damage = cockroachConfig.damage;
|
||||||
|
AttackCooldown = cockroachConfig.attackCooldown;
|
||||||
|
|
||||||
|
DetectionRange = cockroachConfig.detectionRange;
|
||||||
|
AttackRange = cockroachConfig.attackRange;
|
||||||
|
|
||||||
|
Speed = cockroachConfig.speed;
|
||||||
|
|
||||||
|
IsStunnable = cockroachConfig.isStunnable;
|
||||||
|
StunDuration = cockroachConfig.stunDuration;
|
||||||
|
|
||||||
|
UsesIdleMovement = cockroachConfig.usesIdleMovement;
|
||||||
|
IdleWanderRadius = cockroachConfig.idleWanderRadius;
|
||||||
|
IdleMoveDurationMin = cockroachConfig.idleMoveDurationMin;
|
||||||
|
IdleMoveDurationMax = cockroachConfig.idleMoveDurationMax;
|
||||||
|
IdleMoveDurationMin = cockroachConfig.idleMoveDurationMin;
|
||||||
|
IdleMoveDurationMax = cockroachConfig.idleMoveDurationMax;
|
||||||
|
IdlePauseDurationMin = cockroachConfig.idlePauseDurationMin;
|
||||||
|
IdlePauseDurationMax = cockroachConfig.idlePauseDurationMax;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Awake()
|
||||||
|
{
|
||||||
|
base.Awake();
|
||||||
|
|
||||||
|
if (agent == null) return;
|
||||||
|
|
||||||
|
var walkableArea = NavMesh.GetAreaFromName("Cockroach");
|
||||||
|
agent.areaMask = 1 << walkableArea;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void HandleAttack()
|
||||||
|
{
|
||||||
|
if (!Player) return;
|
||||||
|
|
||||||
|
var distance = Vector3.Distance(transform.position, Player.transform.position);
|
||||||
|
|
||||||
|
if (!(distance <= AttackRange)) return;
|
||||||
|
|
||||||
|
DealDamage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 119c0b675c944ed7ada6cdc8db4b04aa
|
||||||
|
timeCreated: 1763228933
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
using Code.Configs;
|
||||||
|
using Reflex.Attributes;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.AI;
|
||||||
|
|
||||||
|
namespace Code.Gameplay.Enemies
|
||||||
|
{
|
||||||
|
public class DrunkenGrandpa : BaseEnemy
|
||||||
|
{
|
||||||
|
[Inject]
|
||||||
|
private void Construct(DrunkenGrandpaConfig drunkenGrandpaConfig)
|
||||||
|
{
|
||||||
|
Damage = drunkenGrandpaConfig.damage;
|
||||||
|
AttackCooldown = drunkenGrandpaConfig.attackCooldown;
|
||||||
|
|
||||||
|
DetectionRange = drunkenGrandpaConfig.detectionRange;
|
||||||
|
AttackRange = drunkenGrandpaConfig.attackRange;
|
||||||
|
|
||||||
|
Speed = drunkenGrandpaConfig.speed;
|
||||||
|
|
||||||
|
IsStunnable = drunkenGrandpaConfig.isStunnable;
|
||||||
|
StunDuration = drunkenGrandpaConfig.stunDuration;
|
||||||
|
|
||||||
|
UsesIdleMovement = drunkenGrandpaConfig.usesIdleMovement;
|
||||||
|
IdleWanderRadius = drunkenGrandpaConfig.idleWanderRadius;
|
||||||
|
IdleMoveDurationMin = drunkenGrandpaConfig.idleMoveDurationMin;
|
||||||
|
IdleMoveDurationMax = drunkenGrandpaConfig.idleMoveDurationMax;
|
||||||
|
IdleMoveDurationMin = drunkenGrandpaConfig.idleMoveDurationMin;
|
||||||
|
IdleMoveDurationMax = drunkenGrandpaConfig.idleMoveDurationMax;
|
||||||
|
IdlePauseDurationMin = drunkenGrandpaConfig.idlePauseDurationMin;
|
||||||
|
IdlePauseDurationMax = drunkenGrandpaConfig.idlePauseDurationMax;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Awake()
|
||||||
|
{
|
||||||
|
base.Awake();
|
||||||
|
|
||||||
|
if (agent == null) return;
|
||||||
|
|
||||||
|
var walkableArea = NavMesh.GetAreaFromName("Walkable");
|
||||||
|
agent.areaMask = 1 << walkableArea;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void HandleAttack()
|
||||||
|
{
|
||||||
|
if (!Player) return;
|
||||||
|
|
||||||
|
var distance = Vector3.Distance(transform.position, Player.transform.position);
|
||||||
|
|
||||||
|
if (!(distance <= AttackRange)) return;
|
||||||
|
|
||||||
|
if (Player.CustomCharacterController.IsSliding)
|
||||||
|
ApplyStun();
|
||||||
|
else
|
||||||
|
DealDamage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 5e77164596e249bca15e09cdfc9ddac2
|
||||||
|
timeCreated: 1763228910
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
using System;
|
||||||
|
using Code.Configs;
|
||||||
|
using Cysharp.Threading.Tasks;
|
||||||
|
using Reflex.Attributes;
|
||||||
|
using Reflex.Core;
|
||||||
|
using Reflex.Injectors;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.AddressableAssets;
|
||||||
|
|
||||||
|
namespace Code.Gameplay.Enemies
|
||||||
|
{
|
||||||
|
public class EnemyFactory : IEnemyFactory
|
||||||
|
{
|
||||||
|
[Inject] private FogConfig _fogConfig;
|
||||||
|
[Inject] private DrunkenGrandpaConfig _drunkenGrandpaConfig;
|
||||||
|
[Inject] private CockroachConfig _cockroachConfig;
|
||||||
|
|
||||||
|
public async UniTask<BaseEnemy> CreateEnemy(EnemyType type, Vector3? position = null, Quaternion? rotation = null)
|
||||||
|
{
|
||||||
|
var prefabRef = GetEnemyPrefab(type);
|
||||||
|
|
||||||
|
var enemyObj = await Addressables
|
||||||
|
.InstantiateAsync(
|
||||||
|
prefabRef,
|
||||||
|
position: position ?? Vector3.zero,
|
||||||
|
rotation: rotation ?? Quaternion.identity
|
||||||
|
)
|
||||||
|
.ToUniTask();
|
||||||
|
|
||||||
|
AttributeInjector.Inject(enemyObj, Container.ProjectContainer);
|
||||||
|
|
||||||
|
return enemyObj.GetComponent<BaseEnemy>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ReleaseEnemy(BaseEnemy enemy)
|
||||||
|
{
|
||||||
|
if (enemy == null) return;
|
||||||
|
|
||||||
|
enemy.gameObject.SetActive(false);
|
||||||
|
|
||||||
|
Addressables.ReleaseInstance(enemy.gameObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
private AssetReference GetEnemyPrefab(EnemyType type)
|
||||||
|
{
|
||||||
|
return type switch
|
||||||
|
{
|
||||||
|
EnemyType.Fog => _fogConfig.fogPrefab,
|
||||||
|
EnemyType.DrunkenGrandpa => _drunkenGrandpaConfig.drunkenGrandpaPrefab,
|
||||||
|
EnemyType.Cockroach => _cockroachConfig.cockroachPrefab,
|
||||||
|
_ => throw new ArgumentOutOfRangeException(nameof(type), type, null)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 2f9328c54d334b0c85ce44b0aa7add44
|
||||||
|
timeCreated: 1764168610
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
using Code.Gameplay.Player;
|
||||||
|
using Cysharp.Threading.Tasks;
|
||||||
|
using Reflex.Attributes;
|
||||||
|
using Reflex.Core;
|
||||||
|
using Reflex.Injectors;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Code.Gameplay.Enemies
|
||||||
|
{
|
||||||
|
public class EnemySpawner : MonoBehaviour
|
||||||
|
{
|
||||||
|
[SerializeField] private EnemyType spawnerType;
|
||||||
|
[SerializeField] private float spawnRadius = 40f;
|
||||||
|
[SerializeField] private float despawnRadius = 50f;
|
||||||
|
|
||||||
|
[Inject] private IPlayerProvider _playerProvider;
|
||||||
|
[Inject] private IEnemyFactory _enemyFactory;
|
||||||
|
|
||||||
|
private BaseEnemy _spawnedEnemy;
|
||||||
|
private bool _isSpawning;
|
||||||
|
private bool _isPlayerInRange;
|
||||||
|
|
||||||
|
private void Awake()
|
||||||
|
{
|
||||||
|
if (_playerProvider == null || _enemyFactory == null)
|
||||||
|
{
|
||||||
|
AttributeInjector.Inject(this, Container.ProjectContainer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Update()
|
||||||
|
{
|
||||||
|
if (!_playerProvider?.Character)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var distanceToPlayer = Vector3.Distance(transform.position, _playerProvider.Character.transform.position);
|
||||||
|
|
||||||
|
var wasInRange = _isPlayerInRange;
|
||||||
|
_isPlayerInRange = distanceToPlayer <= spawnRadius;
|
||||||
|
|
||||||
|
switch (_isPlayerInRange)
|
||||||
|
{
|
||||||
|
case true when !_spawnedEnemy && !_isSpawning && !wasInRange:
|
||||||
|
Spawn().Forget();
|
||||||
|
break;
|
||||||
|
case false when _spawnedEnemy && distanceToPlayer > despawnRadius:
|
||||||
|
Despawn();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async UniTask Spawn()
|
||||||
|
{
|
||||||
|
if (_spawnedEnemy || _isSpawning) return;
|
||||||
|
|
||||||
|
_isSpawning = true;
|
||||||
|
var enemy = await _enemyFactory.CreateEnemy(
|
||||||
|
spawnerType,
|
||||||
|
transform.position,
|
||||||
|
transform.rotation
|
||||||
|
);
|
||||||
|
|
||||||
|
_spawnedEnemy = enemy;
|
||||||
|
_isSpawning = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Despawn()
|
||||||
|
{
|
||||||
|
if (_spawnedEnemy == null) return;
|
||||||
|
|
||||||
|
_enemyFactory.ReleaseEnemy(_spawnedEnemy);
|
||||||
|
_spawnedEnemy = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnDrawGizmosSelected()
|
||||||
|
{
|
||||||
|
Gizmos.color = new Color(0, 1, 0, 0.5f);
|
||||||
|
Gizmos.DrawSphere(transform.position, spawnRadius);
|
||||||
|
|
||||||
|
Gizmos.color = new Color(1, 0, 0, 0.2f);
|
||||||
|
Gizmos.DrawSphere(transform.position, despawnRadius);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: e87d9529de45409781ec5bfc356518c7
|
||||||
|
timeCreated: 1764225519
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
namespace Code.Gameplay.Enemies
|
||||||
|
{
|
||||||
|
public enum EnemyType
|
||||||
|
{
|
||||||
|
Fog,
|
||||||
|
DrunkenGrandpa,
|
||||||
|
Cockroach
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 5430cad1a8c44516944259a428de641e
|
||||||
|
timeCreated: 1764168839
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
using Code.Configs;
|
||||||
|
using Reflex.Attributes;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Code.Gameplay.Enemies
|
||||||
|
{
|
||||||
|
public class Fog : BaseEnemy
|
||||||
|
{
|
||||||
|
[Inject]
|
||||||
|
private void Construct(FogConfig fogConfig)
|
||||||
|
{
|
||||||
|
Damage = fogConfig.damage;
|
||||||
|
AttackCooldown = fogConfig.attackCooldown;
|
||||||
|
|
||||||
|
DetectionRange = fogConfig.detectionRange;
|
||||||
|
AttackRange = fogConfig.attackRange;
|
||||||
|
|
||||||
|
Speed = fogConfig.speed;
|
||||||
|
|
||||||
|
IsStunnable = fogConfig.isStunnable;
|
||||||
|
StunDuration = fogConfig.stunDuration;
|
||||||
|
|
||||||
|
UsesIdleMovement = fogConfig.usesIdleMovement;
|
||||||
|
IdleWanderRadius = fogConfig.idleWanderRadius;
|
||||||
|
IdleMoveDurationMin = fogConfig.idleMoveDurationMin;
|
||||||
|
IdleMoveDurationMax = fogConfig.idleMoveDurationMax;
|
||||||
|
IdleMoveDurationMin = fogConfig.idleMoveDurationMin;
|
||||||
|
IdleMoveDurationMax = fogConfig.idleMoveDurationMax;
|
||||||
|
IdlePauseDurationMin = fogConfig.idlePauseDurationMin;
|
||||||
|
IdlePauseDurationMax = fogConfig.idlePauseDurationMax;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Awake()
|
||||||
|
{
|
||||||
|
base.Awake();
|
||||||
|
|
||||||
|
if (agent == null) return;
|
||||||
|
agent.enabled = false;
|
||||||
|
Destroy(agent);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void HandleMovement()
|
||||||
|
{
|
||||||
|
if (!Player) return;
|
||||||
|
|
||||||
|
var direction = (Player.transform.position - transform.position).normalized;
|
||||||
|
transform.position += direction * (Speed * Time.deltaTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void HandleAttack()
|
||||||
|
{
|
||||||
|
if (!Player || PlayerHealth == null) return;
|
||||||
|
|
||||||
|
var distance = Vector3.Distance(transform.position, Player.transform.position);
|
||||||
|
|
||||||
|
if (!(distance < AttackRange)) return;
|
||||||
|
|
||||||
|
PlayerHealth.GetDamage(PlayerHealth.MaxHealthPoints);
|
||||||
|
base.ApplyEffectsToPlayer();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnDrawGizmosSelected()
|
||||||
|
{
|
||||||
|
Gizmos.color = new Color(0.3f, 0.3f, 0.8f, 0.4f);
|
||||||
|
Gizmos.DrawSphere(transform.position, AttackRange);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 4c70370426e4457aa9a56c77689158ff
|
||||||
|
timeCreated: 1763228955
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
using Cysharp.Threading.Tasks;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Code.Gameplay.Enemies
|
||||||
|
{
|
||||||
|
public interface IEnemyFactory
|
||||||
|
{
|
||||||
|
UniTask<BaseEnemy> CreateEnemy(EnemyType type, Vector3? position, Quaternion? rotation);
|
||||||
|
void ReleaseEnemy(BaseEnemy enemy);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 68eb3027a07042b991aa1893ddd14368
|
||||||
|
timeCreated: 1764168497
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: e41c28f7828a44b7bc26d87886064d99
|
||||||
|
timeCreated: 1763556651
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 4911436131e345ada949f2418595bbd8
|
||||||
|
timeCreated: 1763559099
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
namespace Code.Gameplay.Orders.Order
|
||||||
|
{
|
||||||
|
public interface IOrderService
|
||||||
|
{
|
||||||
|
delegate void OrderFailureDelegate();
|
||||||
|
|
||||||
|
delegate void OrderProgressDelegate(float time);
|
||||||
|
|
||||||
|
event OrderProgressDelegate OnOrderGiven;
|
||||||
|
event OrderProgressDelegate OnOrderRecieved;
|
||||||
|
event OrderFailureDelegate OnOrderFailure;
|
||||||
|
|
||||||
|
delegate void OrderDeliveredDelegate(int score, float time);
|
||||||
|
|
||||||
|
event OrderDeliveredDelegate OnOrderDelivered;
|
||||||
|
OrderState OrderState { get; }
|
||||||
|
float DeliveryTimer { get; }
|
||||||
|
void RoomPassed();
|
||||||
|
void DecreaseTimer(float delta);
|
||||||
|
void OrderGive();
|
||||||
|
void OrderRecieved();
|
||||||
|
void OrderDelivered();
|
||||||
|
void OrderFailed();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 8b4467951c884c8dafeb633020696c24
|
||||||
|
timeCreated: 1763561686
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
using System;
|
||||||
|
using Code.Configs;
|
||||||
|
using Code.Gameplay.Orders.Order;
|
||||||
|
using Cysharp.Threading.Tasks;
|
||||||
|
using Reflex.Attributes;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Code.Gameplay.Orders.Order
|
||||||
|
{
|
||||||
|
public class OrderBox : MonoBehaviour
|
||||||
|
{
|
||||||
|
[Inject] private IOrderService _orderService;
|
||||||
|
public Rigidbody rigidbody;
|
||||||
|
private bool _pickupMode;
|
||||||
|
// [SerializeField] private AnimationCurve debugCurve;
|
||||||
|
|
||||||
|
//DEBUG
|
||||||
|
// private void Start()
|
||||||
|
// {
|
||||||
|
// _capturedPosition = transform.position;
|
||||||
|
// _floatingCurve = debugCurve;
|
||||||
|
// _curveLength = 1f;
|
||||||
|
// }
|
||||||
|
// DEBUG
|
||||||
|
|
||||||
|
private float _activationTime;
|
||||||
|
[Inject]
|
||||||
|
private void Construct(OrderBoxConfig config)
|
||||||
|
{
|
||||||
|
_floatingCurve = config.floatingCurve;
|
||||||
|
_activationTime = config.activationTime;
|
||||||
|
_curveLength = config.curveLength;
|
||||||
|
}
|
||||||
|
public void OnTriggerEnter(Collider other)
|
||||||
|
{
|
||||||
|
if (!_pickupMode || !other.CompareTag("Player")) return;
|
||||||
|
|
||||||
|
_orderService.OrderRecieved();
|
||||||
|
Destroy(gameObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async UniTaskVoid SwitchMode()
|
||||||
|
{
|
||||||
|
await UniTask.WaitForSeconds(_activationTime);
|
||||||
|
_pickupMode = true;
|
||||||
|
rigidbody.isKinematic = true;
|
||||||
|
_capturedPosition = transform.position;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Vector3 _capturedPosition;
|
||||||
|
private float _timeForMoving;
|
||||||
|
private AnimationCurve _floatingCurve;
|
||||||
|
private float _curveLength;
|
||||||
|
|
||||||
|
private void FixedUpdate()
|
||||||
|
{
|
||||||
|
if (!_pickupMode) return;
|
||||||
|
_timeForMoving += Time.fixedDeltaTime;
|
||||||
|
|
||||||
|
if (_timeForMoving > _curveLength) _timeForMoving = 0;
|
||||||
|
|
||||||
|
transform.position = _capturedPosition + new Vector3(0, _floatingCurve.Evaluate(_timeForMoving), 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 067bc72af86a4fb8ac44d0c1fcfd25d5
|
||||||
|
timeCreated: 1763573681
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
using System;
|
||||||
|
using Reflex.Attributes;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Code.Gameplay.Orders.Order
|
||||||
|
{
|
||||||
|
public class OrderDeliveryTrigger : MonoBehaviour
|
||||||
|
{
|
||||||
|
[Inject] private IOrderService _orderService;
|
||||||
|
private bool _playerEntered;
|
||||||
|
private void OnTriggerEnter(Collider other)
|
||||||
|
{
|
||||||
|
if (_playerEntered) return;
|
||||||
|
|
||||||
|
_playerEntered = true;
|
||||||
|
_orderService.OrderDelivered();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 47fbefab729047e5a11d8761e26f75a6
|
||||||
|
timeCreated: 1763737623
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
using DG.Tweening;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Code.Gameplay.Orders.Order
|
||||||
|
{
|
||||||
|
public class OrderDispenser : MonoBehaviour
|
||||||
|
{
|
||||||
|
[SerializeField] private Transform hatch;
|
||||||
|
[SerializeField] private OrderBox order;
|
||||||
|
|
||||||
|
private bool _activated;
|
||||||
|
public void ThrowOrder()
|
||||||
|
{
|
||||||
|
hatch.DORotate(new Vector3(-130f, 0, 0), 0.2f);
|
||||||
|
|
||||||
|
order.rigidbody.isKinematic = false;
|
||||||
|
order.rigidbody.AddForce(-transform.forward * 1f, ForceMode.Impulse);
|
||||||
|
|
||||||
|
order.SwitchMode();
|
||||||
|
}
|
||||||
|
|
||||||
|
// DEBUG TODO ДИМКА УДАЛИ И ПРОПИШИ В СВОЕЙ ЛОГИКЕ
|
||||||
|
// public void OnTriggerEnter(Collider other)
|
||||||
|
// {
|
||||||
|
// if(_activated) return;
|
||||||
|
// _activated = true;
|
||||||
|
//
|
||||||
|
// ThrowOrder();
|
||||||
|
// order.SwitchMode();
|
||||||
|
// }
|
||||||
|
// DEBUG
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: e50e3c42f5ee45e0b1087e0dbf7dd0f4
|
||||||
|
timeCreated: 1763556675
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
using Reflex.Attributes;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Code.Gameplay.Orders.Order
|
||||||
|
{
|
||||||
|
public class OrderGiveTrigger : MonoBehaviour
|
||||||
|
{
|
||||||
|
[Inject] private IOrderService _orderService;
|
||||||
|
private bool _playerEntered;
|
||||||
|
private void OnTriggerEnter(Collider other)
|
||||||
|
{
|
||||||
|
if (_playerEntered) return;
|
||||||
|
|
||||||
|
_playerEntered = true;
|
||||||
|
_orderService.OrderGive();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: d3966e4798d243abba9d85b9ad8aef33
|
||||||
|
timeCreated: 1763742374
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
using Code.Configs;
|
||||||
|
using UnityEngine;
|
||||||
|
using Random = UnityEngine.Random;
|
||||||
|
|
||||||
|
namespace Code.Gameplay.Orders.Order
|
||||||
|
{
|
||||||
|
public class OrderService : IOrderService
|
||||||
|
{
|
||||||
|
public event IOrderService.OrderProgressDelegate OnOrderGiven;
|
||||||
|
public event IOrderService.OrderProgressDelegate OnOrderRecieved;
|
||||||
|
public event IOrderService.OrderDeliveredDelegate OnOrderDelivered;
|
||||||
|
public event IOrderService.OrderFailureDelegate OnOrderFailure;
|
||||||
|
|
||||||
|
private OrderState _orderState;
|
||||||
|
public OrderState OrderState => _orderState;
|
||||||
|
|
||||||
|
private float _deliveryTimer;
|
||||||
|
public float DeliveryTimer => _deliveryTimer;
|
||||||
|
|
||||||
|
private Vector2 _timeBounds;
|
||||||
|
private float _koefRooms, _koefOvertime;
|
||||||
|
|
||||||
|
private int _roomsPassed;
|
||||||
|
|
||||||
|
public OrderService(OrderServiceConfig config)
|
||||||
|
{
|
||||||
|
_orderState = OrderState.Delivered;
|
||||||
|
|
||||||
|
_timeBounds = config.timeBounds;
|
||||||
|
_koefRooms = config.koefRooms;
|
||||||
|
_koefOvertime = config.koefOvertime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RoomPassed() => _roomsPassed++;
|
||||||
|
public void DecreaseTimer(float delta) => _deliveryTimer -= delta;
|
||||||
|
|
||||||
|
// Вызываются триггерами
|
||||||
|
public void OrderGive()
|
||||||
|
{
|
||||||
|
_orderState = OrderState.Given;
|
||||||
|
_roomsPassed = 0;
|
||||||
|
|
||||||
|
_deliveryTimer = Random.Range(_timeBounds.x, _timeBounds.y);
|
||||||
|
OnOrderGiven?.Invoke(_deliveryTimer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OrderRecieved()
|
||||||
|
{
|
||||||
|
_orderState = OrderState.Recieved;
|
||||||
|
OnOrderRecieved?.Invoke(_deliveryTimer);
|
||||||
|
}
|
||||||
|
public void OrderFailed() => OnOrderFailure?.Invoke();
|
||||||
|
|
||||||
|
public void OrderDelivered()
|
||||||
|
{
|
||||||
|
if (_orderState != OrderState.Recieved)
|
||||||
|
{
|
||||||
|
OnOrderFailure?.Invoke();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_orderState = OrderState.Delivered;
|
||||||
|
|
||||||
|
int score = (int)(_koefRooms * _roomsPassed + _deliveryTimer * _koefOvertime);
|
||||||
|
OnOrderDelivered?.Invoke(score, _deliveryTimer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: b324c2a1be1546868cddf779445b286a
|
||||||
|
timeCreated: 1763559110
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
namespace Code.Gameplay.Orders.Order
|
||||||
|
{
|
||||||
|
public enum OrderState
|
||||||
|
{
|
||||||
|
Delivered,
|
||||||
|
Given,
|
||||||
|
Recieved,
|
||||||
|
}
|
||||||
|
}
|
||||||
Loaded 100 of 627 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user