Переполох в камере, насрано
This commit is contained in:
1 parent
623b152690
commit
724161c455
15 files changed
+48
-75
No files matched your search
@@ -10,7 +10,7 @@ namespace Code.App.AppStates
|
|||||||
{
|
{
|
||||||
public class GameplayState : BaseState<AppStateMachineContext>
|
public class GameplayState : BaseState<AppStateMachineContext>
|
||||||
{
|
{
|
||||||
private PlayerHealthPoints _playerHealthPoints;
|
private PlayerHealth _playerHealthPoints;
|
||||||
|
|
||||||
public GameplayState(AppStateMachineContext context) : base(context)
|
public GameplayState(AppStateMachineContext context) : base(context)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Code.App.StateMachine;
|
using Code.App.StateMachine;
|
||||||
|
using Code.Configs;
|
||||||
using Code.Input;
|
using Code.Input;
|
||||||
using Code.Scenes;
|
using Code.Scenes;
|
||||||
using Code.StaticData;
|
using Code.StaticData;
|
||||||
@@ -45,6 +46,7 @@ namespace Code.App
|
|||||||
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.UIConfig.canvasPrefab, typeof(Canvas));
|
containerBuilder.AddSingleton(staticDataService.UIConfig.canvasPrefab, typeof(Canvas));
|
||||||
|
containerBuilder.AddSingleton(staticDataService.CameraConfig, typeof(CameraConfig));
|
||||||
containerBuilder.AddSingleton(staticDataService.UIConfig.uiElementsPrefabs, typeof(UIElement[]));
|
containerBuilder.AddSingleton(staticDataService.UIConfig.uiElementsPrefabs, typeof(UIElement[]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,10 +7,4 @@ namespace Code.Configs
|
|||||||
{
|
{
|
||||||
public GameObject infrastructureUnitPrefab;
|
public GameObject infrastructureUnitPrefab;
|
||||||
}
|
}
|
||||||
[CreateAssetMenu(menuName = "Config/Player", fileName = "PlayerConfig")]
|
|
||||||
public class PlayerConfig : ScriptableObject
|
|
||||||
{
|
|
||||||
public Player playerPrefab;
|
|
||||||
public int maxHealth;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
+2
-2
@@ -4,7 +4,7 @@ using UnityEngine;
|
|||||||
namespace Code.Configs
|
namespace Code.Configs
|
||||||
{
|
{
|
||||||
[CreateAssetMenu(fileName = "CharacterCameraConfig", menuName = "Config/CharacterCameraConfig")]
|
[CreateAssetMenu(fileName = "CharacterCameraConfig", menuName = "Config/CharacterCameraConfig")]
|
||||||
public class CharacterCameraConfig : ScriptableObject
|
public class CameraConfig : ScriptableObject
|
||||||
{
|
{
|
||||||
public float
|
public float
|
||||||
// Расстояния от персонажа до камеры
|
// Расстояния от персонажа до камеры
|
||||||
@@ -30,7 +30,7 @@ namespace Code.Configs
|
|||||||
defaultVerticalAngle = 10f; // Стандартный угол наклона камеры
|
defaultVerticalAngle = 10f; // Стандартный угол наклона камеры
|
||||||
|
|
||||||
// Текущий режим камеры
|
// Текущий режим камеры
|
||||||
public CameraMode defaultCameraMode = CameraMode.MainMenu;
|
public CameraMode defaultCameraMode = CameraMode.Bogdan;
|
||||||
|
|
||||||
// Позиция следования по умолчанию (для меню)
|
// Позиция следования по умолчанию (для меню)
|
||||||
public Vector3 defaultFollowPosition = Vector3.zero;
|
public Vector3 defaultFollowPosition = Vector3.zero;
|
||||||
File renamed without changes.
+26
-20
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using Code.Configs;
|
||||||
using Code.Gameplay.Character.Core;
|
using Code.Gameplay.Character.Core;
|
||||||
using Code.StaticData;
|
using Code.StaticData;
|
||||||
using Reflex.Attributes;
|
using Reflex.Attributes;
|
||||||
@@ -13,9 +14,9 @@ namespace Code.Gameplay.Character.Camera
|
|||||||
*
|
*
|
||||||
* Источник: Tvtig, https://www.youtube.com/watch?v=9ibpY64wBYM
|
* Источник: Tvtig, https://www.youtube.com/watch?v=9ibpY64wBYM
|
||||||
*/
|
*/
|
||||||
public class CharacterCamera : MonoBehaviour
|
public class CameraService : MonoBehaviour
|
||||||
{
|
{
|
||||||
// Параметры загружаются из CharacterCameraConfig
|
// Параметры загружаются из CameraConfig
|
||||||
private float
|
private float
|
||||||
_defaultDistance,
|
_defaultDistance,
|
||||||
_minDistance,
|
_minDistance,
|
||||||
@@ -52,27 +53,26 @@ namespace Code.Gameplay.Character.Camera
|
|||||||
// Текущий режим работы камеры
|
// Текущий режим работы камеры
|
||||||
public CameraMode CurrentMode { get; private set; }
|
public CameraMode CurrentMode { get; private set; }
|
||||||
|
|
||||||
// DI для загрузки конфига
|
// Конфиг из DI
|
||||||
[Inject] private IStaticDataService _staticDataService;
|
[Inject] private CameraConfig _config;
|
||||||
|
|
||||||
// Загрузка конфига для камеры
|
// Загрузка конфига для камеры
|
||||||
private void LoadConfig()
|
private void LoadConfig()
|
||||||
{
|
{
|
||||||
// Загрузка значений из конфигов
|
// Загрузка значений из конфига
|
||||||
var config = _staticDataService.CharacterCameraConfig;
|
|
||||||
|
|
||||||
_defaultDistance = config.defaultDistance;
|
_defaultDistance = _config.defaultDistance;
|
||||||
_minDistance = config.minDistance;
|
_minDistance = _config.minDistance;
|
||||||
_maxDistance = config.maxDistance;
|
_maxDistance = _config.maxDistance;
|
||||||
_distanceMovementSpeed = config.distanceMovementSpeed;
|
_distanceMovementSpeed = _config.distanceMovementSpeed;
|
||||||
_rotationSpeed = config.rotationSpeed;
|
_rotationSpeed = _config.rotationSpeed;
|
||||||
_rotationSharpness = config.rotationSharpness;
|
_rotationSharpness = _config.rotationSharpness;
|
||||||
_followSharpness = config.followSharpness;
|
_followSharpness = _config.followSharpness;
|
||||||
_minVerticalAngle = config.minVerticalAngle;
|
_minVerticalAngle = _config.minVerticalAngle;
|
||||||
_maxVerticalAngle = config.maxVerticalAngle;
|
_maxVerticalAngle = _config.maxVerticalAngle;
|
||||||
_defaultVerticalAngle = config.defaultVerticalAngle;
|
_defaultVerticalAngle = _config.defaultVerticalAngle;
|
||||||
CurrentMode = config.defaultCameraMode;
|
CurrentMode = _config.defaultCameraMode;
|
||||||
_defaultFollowPosition = config.defaultFollowPosition;
|
_defaultFollowPosition = _config.defaultFollowPosition;
|
||||||
|
|
||||||
// Валидация значений (на случай ручного редактирования конфига)
|
// Валидация значений (на случай ручного редактирования конфига)
|
||||||
_defaultDistance = Mathf.Clamp(_defaultDistance, _minDistance, _maxDistance);
|
_defaultDistance = Mathf.Clamp(_defaultDistance, _minDistance, _maxDistance);
|
||||||
@@ -166,7 +166,7 @@ namespace Code.Gameplay.Character.Camera
|
|||||||
public void UpdateWithInput(float deltaTime, float zoomInput, Vector3 rotationInput)
|
public void UpdateWithInput(float deltaTime, float zoomInput, Vector3 rotationInput)
|
||||||
{
|
{
|
||||||
// Проверка наличия цели для следования и проверка на режим главного меню
|
// Проверка наличия цели для следования и проверка на режим главного меню
|
||||||
if (!_followTransform || CurrentMode == CameraMode.MainMenu) return;
|
if (!_followTransform || CurrentMode == CameraMode.Bogdan) return;
|
||||||
|
|
||||||
// Обработка ввода и позиционирования
|
// Обработка ввода и позиционирования
|
||||||
HandleRotationInput(deltaTime, rotationInput, out var targetRotation);
|
HandleRotationInput(deltaTime, rotationInput, out var targetRotation);
|
||||||
@@ -204,7 +204,13 @@ namespace Code.Gameplay.Character.Camera
|
|||||||
_targetDistance = _defaultDistance;
|
_targetDistance = _defaultDistance;
|
||||||
break;
|
break;
|
||||||
// Заготовка на будущее (если понадобится)
|
// Заготовка на будущее (если понадобится)
|
||||||
case CameraMode.MainMenu:
|
case CameraMode.Bogdan:
|
||||||
|
_minDistance = 0f;
|
||||||
|
_maxDistance = 0f;
|
||||||
|
_defaultDistance = 0f;
|
||||||
|
_targetDistance = 0f;
|
||||||
|
_currentDistance = 0f;
|
||||||
|
break;
|
||||||
case CameraMode.Static:
|
case CameraMode.Static:
|
||||||
case CameraMode.Cinematic:
|
case CameraMode.Cinematic:
|
||||||
default:
|
default:
|
||||||
File renamed without changes.
+1
-1
@@ -127,7 +127,7 @@ namespace Code.Gameplay.Character.Controller
|
|||||||
// Заготовка на будущее (если понадобится)
|
// Заготовка на будущее (если понадобится)
|
||||||
case CameraMode.Static:
|
case CameraMode.Static:
|
||||||
case CameraMode.Cinematic:
|
case CameraMode.Cinematic:
|
||||||
case CameraMode.MainMenu: // Скорее всего юзлес, но пускай будет
|
case CameraMode.Bogdan: // Скорее всего юзлес, но пускай будет
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ namespace Code.Gameplay.Character.Core
|
|||||||
*/
|
*/
|
||||||
public enum CameraMode
|
public enum CameraMode
|
||||||
{
|
{
|
||||||
MainMenu,
|
Bogdan,
|
||||||
Static,
|
Static,
|
||||||
FirstPerson,
|
FirstPerson,
|
||||||
ThirdPerson,
|
ThirdPerson,
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using Code.Gameplay.Character.Controller;
|
|||||||
using Code.Input;
|
using Code.Input;
|
||||||
using Reflex.Attributes;
|
using Reflex.Attributes;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using UnityEngine.Serialization;
|
||||||
|
|
||||||
namespace Code.Gameplay.Character.Core
|
namespace Code.Gameplay.Character.Core
|
||||||
{
|
{
|
||||||
@@ -14,7 +15,7 @@ namespace Code.Gameplay.Character.Core
|
|||||||
*/
|
*/
|
||||||
public class Character : MonoBehaviour
|
public class Character : MonoBehaviour
|
||||||
{
|
{
|
||||||
[SerializeField] private CharacterCamera characterCamera; // Компонент камеры персонажа
|
[FormerlySerializedAs("characterCamera")] [SerializeField] private CameraService cameraService; // Компонент камеры персонажа
|
||||||
[SerializeField] private CustomCharacterController customCharacterController; // Компонент управления персонажем
|
[SerializeField] private CustomCharacterController customCharacterController; // Компонент управления персонажем
|
||||||
[SerializeField] private Transform cameraFollowPoint; // Точка следования камеры (уровень глаз для FirstPerson)
|
[SerializeField] private Transform cameraFollowPoint; // Точка следования камеры (уровень глаз для FirstPerson)
|
||||||
|
|
||||||
@@ -27,8 +28,8 @@ namespace Code.Gameplay.Character.Core
|
|||||||
private void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
// Настройка камеры для следования за точкой камеры
|
// Настройка камеры для следования за точкой камеры
|
||||||
characterCamera.SetFollowTransform(cameraFollowPoint);
|
cameraService.SetFollowTransform(cameraFollowPoint);
|
||||||
characterCamera.SetCameraMode(CameraMode.FirstPerson);
|
cameraService.SetCameraMode(CameraMode.FirstPerson);
|
||||||
|
|
||||||
// Включение Gameplay мапа ввода
|
// Включение Gameplay мапа ввода
|
||||||
_inputService.EnableMap(ActionMappings.Gameplay);
|
_inputService.EnableMap(ActionMappings.Gameplay);
|
||||||
@@ -42,7 +43,7 @@ namespace Code.Gameplay.Character.Core
|
|||||||
var scrollInput = _inputService.ZoomInput;
|
var scrollInput = _inputService.ZoomInput;
|
||||||
|
|
||||||
// Передаем данные в камеру
|
// Передаем данные в камеру
|
||||||
characterCamera.UpdateWithInput(Time.deltaTime, scrollInput,
|
cameraService.UpdateWithInput(Time.deltaTime, scrollInput,
|
||||||
new Vector3(lookInput.x, lookInput.y, 0));
|
new Vector3(lookInput.x, lookInput.y, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,9 +62,9 @@ namespace Code.Gameplay.Character.Core
|
|||||||
inputs.SlidePressed = _inputService.SlidePressed; // Слайд (Ctrl)
|
inputs.SlidePressed = _inputService.SlidePressed; // Слайд (Ctrl)
|
||||||
|
|
||||||
// Передаем информацию о камере для адаптивного поведения
|
// Передаем информацию о камере для адаптивного поведения
|
||||||
inputs.CameraRotation = characterCamera.transform.rotation;
|
inputs.CameraRotation = cameraService.transform.rotation;
|
||||||
inputs.CameraMode = characterCamera.CurrentMode;
|
inputs.CameraMode = cameraService.CurrentMode;
|
||||||
inputs.CameraPlanarDirection = characterCamera.PlanarDirection;
|
inputs.CameraPlanarDirection = cameraService.PlanarDirection;
|
||||||
|
|
||||||
// Передаем ввод в контроллер персонажа
|
// Передаем ввод в контроллер персонажа
|
||||||
customCharacterController.SetInputs(ref inputs);
|
customCharacterController.SetInputs(ref inputs);
|
||||||
@@ -92,10 +93,10 @@ namespace Code.Gameplay.Character.Core
|
|||||||
// Метод для переключения режимов камеры
|
// Метод для переключения режимов камеры
|
||||||
private void ToggleCameraMode()
|
private void ToggleCameraMode()
|
||||||
{
|
{
|
||||||
var currentMode = characterCamera.CurrentMode;
|
var currentMode = cameraService.CurrentMode;
|
||||||
var newMode = currentMode == CameraMode.FirstPerson ? CameraMode.ThirdPerson : CameraMode.FirstPerson;
|
var newMode = currentMode == CameraMode.FirstPerson ? CameraMode.ThirdPerson : CameraMode.FirstPerson;
|
||||||
|
|
||||||
characterCamera.SetCameraMode(newMode);
|
cameraService.SetCameraMode(newMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Обновление логики каждый кадр
|
// Обновление логики каждый кадр
|
||||||
|
|||||||
@@ -8,11 +8,11 @@ namespace Code.Gameplay.Player
|
|||||||
{
|
{
|
||||||
[Inject] PlayerConfig _playerConfig;
|
[Inject] PlayerConfig _playerConfig;
|
||||||
|
|
||||||
public PlayerHealthPoints CreatePlayerHP(int count = -1)
|
public PlayerHealth CreatePlayerHP(int count = -1)
|
||||||
{
|
{
|
||||||
if (count < 0) count = _playerConfig.maxHealth;
|
if (count < 0) count = _playerConfig.maxHealth;
|
||||||
|
|
||||||
return new PlayerHealthPoints(count);
|
return new PlayerHealth(count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
namespace Code.Gameplay.Player
|
|
||||||
{
|
|
||||||
public class PlayerHealthPoints
|
|
||||||
{
|
|
||||||
public delegate void OnDeathDelegate();
|
|
||||||
|
|
||||||
public event OnDeathDelegate OnDeath;
|
|
||||||
|
|
||||||
public delegate void OnDamageDelegate(int damage);
|
|
||||||
|
|
||||||
public event OnDamageDelegate OnDamage;
|
|
||||||
|
|
||||||
private int _healthPoints;
|
|
||||||
|
|
||||||
public int HealthPoints => _healthPoints;
|
|
||||||
|
|
||||||
public void GetDamage(int count)
|
|
||||||
{
|
|
||||||
_healthPoints -= count;
|
|
||||||
OnDamage?.Invoke(count);
|
|
||||||
|
|
||||||
if (_healthPoints <= 0) OnDeath?.Invoke();
|
|
||||||
}
|
|
||||||
|
|
||||||
public PlayerHealthPoints(int healthPoints = 1) => _healthPoints = healthPoints;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 105512e4d3af4b36932a0d569b87c68e
|
|
||||||
timeCreated: 1761059874
|
|
||||||
@@ -9,6 +9,6 @@ namespace Code.StaticData
|
|||||||
InputConfig InputConfig { get; }
|
InputConfig InputConfig { get; }
|
||||||
AppConfig AppConfig { get; }
|
AppConfig AppConfig { get; }
|
||||||
UIConfig UIConfig { get; }
|
UIConfig UIConfig { get; }
|
||||||
CharacterCameraConfig CharacterCameraConfig { get; }
|
CameraConfig CameraConfig { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9,13 +9,13 @@ namespace Code.StaticData
|
|||||||
public AppConfig AppConfig { get; private set; }
|
public AppConfig AppConfig { get; private set; }
|
||||||
public InputConfig InputConfig { get; private set; }
|
public InputConfig InputConfig { get; private set; }
|
||||||
public UIConfig UIConfig { get; private set; }
|
public UIConfig UIConfig { get; private set; }
|
||||||
public CharacterCameraConfig CharacterCameraConfig { get; private set; }
|
public CameraConfig CameraConfig { get; private set; }
|
||||||
|
|
||||||
public void Load()
|
public void Load()
|
||||||
{
|
{
|
||||||
InputConfig = Resources.Load<InputConfig>(string.Format(StringPaths.ConfigSingle, "App", "InputConfig"));
|
InputConfig = Resources.Load<InputConfig>(string.Format(StringPaths.ConfigSingle, "App", "InputConfig"));
|
||||||
AppConfig = Resources.Load<AppConfig>(string.Format(StringPaths.ConfigSingle, "App", "AppConfig"));
|
AppConfig = Resources.Load<AppConfig>(string.Format(StringPaths.ConfigSingle, "App", "AppConfig"));
|
||||||
CharacterCameraConfig = Resources.Load<CharacterCameraConfig>(string.Format(StringPaths.ConfigSingle, "App", "CharacterCameraConfig"));
|
CameraConfig = Resources.Load<CameraConfig>(string.Format(StringPaths.ConfigSingle, "App", "CharacterCameraConfig"));
|
||||||
UIConfig = Resources.Load<UIConfig>(string.Format(StringPaths.ConfigSingle, "App", "UIConfig"));
|
UIConfig = Resources.Load<UIConfig>(string.Format(StringPaths.ConfigSingle, "App", "UIConfig"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user