Машина, камера, мотор
This commit is contained in:
1 parent
b54083521f
commit
a45223d0e7
48 files changed
+5507
-3735
No files matched your search
@@ -17,6 +17,7 @@ namespace Code.Infrastructure.App
|
||||
{
|
||||
[Inject] public SceneLoader.SceneLoader SceneLoader { get; set; }
|
||||
[Inject] public CameraStateMachine Camera { get; set; }
|
||||
[Inject] public CameraFactory CameraFactory { get; set; }
|
||||
[Inject] public IUIService UIService { get; set; }
|
||||
[Inject] public IAudioFactory AudioFactory { get; set; }
|
||||
[Inject] public IAudioService AudioService { get; set; }
|
||||
|
||||
@@ -9,6 +9,7 @@ using Code.Infrastructure.UI;
|
||||
using Code.Infrastructure.Volume;
|
||||
using Reflex.Core;
|
||||
using Reflex.Enums;
|
||||
using Unity.Cinemachine;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering.Universal;
|
||||
using Resolution = Reflex.Enums.Resolution;
|
||||
@@ -24,10 +25,13 @@ namespace Code.Infrastructure.App
|
||||
IVolumesInitializedHandle,
|
||||
IVolumeLoaded,
|
||||
IAudioSourcePoolInitializedHandle,
|
||||
IAudioConfigsLoadedHandle
|
||||
IAudioConfigsLoadedHandle,
|
||||
ICinematicMachineHandle
|
||||
{
|
||||
public void InstallBindings(ContainerBuilder containerBuilder)
|
||||
{
|
||||
InitLoadings();
|
||||
|
||||
containerBuilder.RegisterType(typeof(EventBus.EventBus), Lifetime.Singleton, Resolution.Eager);
|
||||
containerBuilder.RegisterType(typeof(ConfigLocator), new[] { typeof(IConfigLocator) }, Lifetime.Singleton,
|
||||
Resolution.Eager);
|
||||
@@ -61,6 +65,10 @@ namespace Code.Infrastructure.App
|
||||
containerBuilder.RegisterType(typeof(AudioService), new[] { typeof(IAudioService) }, Lifetime.Singleton,
|
||||
Resolution.Eager);
|
||||
|
||||
}
|
||||
|
||||
private void InitLoadings()
|
||||
{
|
||||
// UIFactory
|
||||
// Logo
|
||||
// Scene configs
|
||||
@@ -70,7 +78,9 @@ namespace Code.Infrastructure.App
|
||||
// Loading volume
|
||||
// Audio Factory
|
||||
// Audio Pool
|
||||
_initialLoading = new Loading(9, () => EssentialLoadEnded(_thatRightContainer));
|
||||
// Cinemachine Camera
|
||||
_initialLoading = new Loading(10, () => EssentialLoadEnded(_thatRightContainer));
|
||||
|
||||
_ui2CamLoading = new Loading(2,
|
||||
() =>
|
||||
{
|
||||
@@ -90,7 +100,8 @@ namespace Code.Infrastructure.App
|
||||
|
||||
container.Resolve<EventBus.EventBus>().Subscribe(this);
|
||||
|
||||
container.Resolve<CameraFactory>().CreateCameraStateMachine(container.Resolve<CameraStateMachine>())
|
||||
var cameraFactory = container.Resolve<CameraFactory>();
|
||||
cameraFactory.CreateCameraStateMachine(container.Resolve<CameraStateMachine>())
|
||||
.Forget();
|
||||
}
|
||||
|
||||
@@ -121,6 +132,8 @@ namespace Code.Infrastructure.App
|
||||
|
||||
_ui2CamLoading.DoProgress();
|
||||
_initialLoading.DoProgress();
|
||||
|
||||
_thatRightContainer.Resolve<CameraFactory>().LoadCinemachineCamera(CameraMode.None).Forget();
|
||||
}
|
||||
|
||||
public void UIInitialized()
|
||||
@@ -179,5 +192,10 @@ namespace Code.Infrastructure.App
|
||||
{
|
||||
_initialLoading.DoProgress();
|
||||
}
|
||||
|
||||
public void CinemachineLoaded(CinemachineCamera cinemachineCamera)
|
||||
{
|
||||
_initialLoading.DoProgress();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,7 @@
|
||||
using System.Threading;
|
||||
using Code.Example.Race.Racer;
|
||||
using Code.Example.Race.Track;
|
||||
using System.Threading;
|
||||
using Code.Infrastructure.Audio;
|
||||
using Code.Infrastructure.Generators;
|
||||
using Code.Infrastructure.SceneLoader;
|
||||
using Code.Infrastructure.UI;
|
||||
using Reflex.Core;
|
||||
using UnityEngine.SceneManagement;
|
||||
using Code.Infrastructure.Generators;
|
||||
using Code.Infrastructure.UI;
|
||||
|
||||
namespace Code.Infrastructure.App.States
|
||||
{
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Code.Example.Race;
|
||||
using Code.Example.Race.Racer;
|
||||
using Code.Example.Race.Racer.AI;
|
||||
using Code.Example.Race.Track;
|
||||
using Code.Infrastructure.Camera;
|
||||
using Code.Infrastructure.Camera.CameraStates;
|
||||
@@ -10,13 +11,19 @@ using Code.Infrastructure.SceneLoader;
|
||||
using Code.Infrastructure.UI;
|
||||
using Reflex.Core;
|
||||
using Reflex.Injectors;
|
||||
using Unity.Cinemachine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace Code.Infrastructure.App.States
|
||||
{
|
||||
[State(typeof(AppStates), typeof(AppStateMachineContext))]
|
||||
[StateRaisingEvent]
|
||||
public partial class GameplayState : IOnGameplaySceneLoadedHandler, IRaceGameInitializedHandle, IRacerFactoryInitializedHandle, IUIPanelLoaded
|
||||
public partial class GameplayState :
|
||||
IOnGameplaySceneLoadedHandler,
|
||||
IRaceGameInitializedHandle,
|
||||
IRacerFactoryInitializedHandle,
|
||||
IUIPanelLoaded,
|
||||
ICinematicMachineHandle
|
||||
{
|
||||
public GameplayState(AppStateMachineContext context, EventBus.EventBus eventBus) : base(context, eventBus)
|
||||
{
|
||||
@@ -35,10 +42,13 @@ namespace Code.Infrastructure.App.States
|
||||
// RaceGame
|
||||
// Factory
|
||||
// PlayerCounter
|
||||
_gameplayLoading = new Loading(4, GameplayLoadingCompleted);
|
||||
// CinemachineCamera
|
||||
_gameplayLoading = new Loading(5, GameplayLoadingCompleted);
|
||||
|
||||
Context.UIService.TryLoadPanel(UIPanelType.PlayerScoreCounter);
|
||||
Context.SceneLoader.LoadSceneAsync(SceneId.Gameplay, LoadSceneMode.Single).Forget();
|
||||
Context.InputService.EnableMap(ActionMappings.Gameplay);
|
||||
Context.CameraFactory.LoadCinemachineCamera(CameraMode.ThirdPerson).Forget();
|
||||
}
|
||||
|
||||
private void GameplayLoadingCompleted()
|
||||
@@ -46,7 +56,12 @@ namespace Code.Infrastructure.App.States
|
||||
_raceGame.PlaceRacers();
|
||||
|
||||
Context.Camera.SwitchState(CameraMode.ThirdPerson).AllowStateTransition(CameraMode.None);
|
||||
((ThirdPersonState)Context.Camera.CurrentBaseState).SetFollowTarget(_raceGame.PlacedRacers[0].gameObject.transform, _raceGame.PlacedRacers[0].CarRigidbody);
|
||||
// ((ThirdPersonState)Context.Camera.CurrentBaseState).SetFollowTarget(_raceGame.PlacedRacers[0].gameObject.transform, _raceGame.PlacedRacers[0].CarRigidbody);
|
||||
Context.CameraFactory.GetCinematicCamera(CameraMode.ThirdPerson).transform.position = ((PlayerRacer)_raceGame.PlacedRacers[0]).CameraPosition.position;
|
||||
Context.CameraFactory.GetCinematicCamera(CameraMode.ThirdPerson).transform.rotation = ((PlayerRacer)_raceGame.PlacedRacers[0]).CameraPosition.rotation;
|
||||
|
||||
Context.CameraFactory.GetCinematicCamera(CameraMode.ThirdPerson).Follow =
|
||||
_raceGame.PlacedRacers[0].gameObject.transform;
|
||||
|
||||
Context.UIService.ClosePanel(UIPanelType.Loading);
|
||||
_raceGame.StartRacers();
|
||||
@@ -56,6 +71,7 @@ namespace Code.Infrastructure.App.States
|
||||
{
|
||||
Context.InputService.DisableMap(ActionMappings.Gameplay);
|
||||
Context.UIService.TryRemovePanel(UIPanelType.PlayerScoreCounter);
|
||||
Context.CameraFactory.ReleaseCinemachineCamera(CameraMode.ThirdPerson);
|
||||
EventBus.Unsubscribe(this);
|
||||
}
|
||||
|
||||
@@ -68,12 +84,13 @@ namespace Code.Infrastructure.App.States
|
||||
private Container UNTILTHEYFIXCONTAINERS;
|
||||
public void OnGameplaySceneInitialized(Container container)
|
||||
{
|
||||
_raceTrackData = container.Resolve<RaceTrackData>();
|
||||
|
||||
Context.Camera.Camera.transform.position = _raceTrackData.CameraPosition.transform.position;
|
||||
Context.Camera.Camera.transform.rotation = _raceTrackData.CameraPosition.transform.rotation;
|
||||
|
||||
UNTILTHEYFIXCONTAINERS = container;
|
||||
|
||||
_raceTrackData = container.Resolve<RaceTrackData>();
|
||||
|
||||
Context.CameraFactory.GetCinematicCamera(CameraMode.None).transform.position = _raceTrackData.CameraPosition.transform.position;
|
||||
Context.CameraFactory.GetCinematicCamera(CameraMode.None).transform.rotation = _raceTrackData.CameraPosition.transform.rotation;
|
||||
|
||||
_gameplayLoading.DoProgress();
|
||||
|
||||
container.Resolve<IRacerFactory>();
|
||||
@@ -98,5 +115,7 @@ namespace Code.Infrastructure.App.States
|
||||
Context.UIService.OpenPanel(UIPanelType.PlayerScoreCounter);
|
||||
_gameplayLoading.DoProgress();
|
||||
}
|
||||
|
||||
public void CinemachineLoaded(CinemachineCamera cinemachineCamera) => _gameplayLoading.DoProgress();
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,10 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Code.Infrastructure.Configs;
|
||||
using Code.Infrastructure.EventBus;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using Unity.Cinemachine;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||
using Object = UnityEngine.Object;
|
||||
@@ -20,7 +23,9 @@ namespace Code.Infrastructure.Camera
|
||||
private string _cameraConfigsLabel;
|
||||
|
||||
private EventBus.EventBus _eventBus;
|
||||
private UnityEngine.Camera _camera;
|
||||
private UnityEngine.Camera _camera;
|
||||
|
||||
private Dictionary<CameraMode, CinemachineCamera> _cinemachines = new();
|
||||
|
||||
public CameraFactory(IConfigLocator configLocator, EventBus.EventBus eventBus)
|
||||
{
|
||||
@@ -36,20 +41,34 @@ namespace Code.Infrastructure.Camera
|
||||
.LoadAssetsAsync<CameraSettingsConfig>(_cameraConfigsLabel, null, Addressables.MergeMode.Union);
|
||||
await _settingsConfigsHandle.ToUniTask();
|
||||
_settingsConfigs = _settingsConfigsHandle.Result.ToDictionary(x => x.cameraMode);
|
||||
|
||||
|
||||
_configHandle = Addressables.LoadAssetAsync<GameCameraConfig>(_gameCameraConfigReference);
|
||||
await _configHandle.ToUniTask();
|
||||
_config = _configHandle.Result;
|
||||
|
||||
var cameraObject = await Addressables.InstantiateAsync(_config.Camera).ToUniTask();
|
||||
_camera = cameraObject.GetComponent<UnityEngine.Camera>();
|
||||
|
||||
|
||||
cameraObject.GetComponent<CameraStateMachineRunner>().StateMachine = stateMachine;
|
||||
Object.DontDestroyOnLoad(cameraObject);
|
||||
|
||||
|
||||
_eventBus.RaiseEvent<ICameraInitializedHandle>(x => x.CameraInitialized(new(_camera, _settingsConfigs)));
|
||||
}
|
||||
|
||||
public async UniTaskVoid LoadCinemachineCamera(CameraMode cameraMode)
|
||||
{
|
||||
var cinemachine = await Addressables.InstantiateAsync(_settingsConfigs[cameraMode].cinemachineCamera);
|
||||
Object.DontDestroyOnLoad(cinemachine);
|
||||
_cinemachines[cameraMode] = cinemachine.GetComponent<CinemachineCamera>();
|
||||
_eventBus.RaiseEvent<ICinematicMachineHandle>(x=> x.CinemachineLoaded(_cinemachines[cameraMode]));
|
||||
}
|
||||
|
||||
public CinemachineCamera GetCinematicCamera(CameraMode cameraMode) => _cinemachines[cameraMode];
|
||||
|
||||
public void ReleaseCinemachineCamera(CameraMode cameraMode)
|
||||
{
|
||||
Addressables.Release(_cinemachines[cameraMode].gameObject);
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
Addressables.Release(_configHandle);
|
||||
@@ -57,4 +76,9 @@ namespace Code.Infrastructure.Camera
|
||||
Addressables.ReleaseInstance(_camera.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
public interface ICinematicMachineHandle : IGlobalSubscriber
|
||||
{
|
||||
void CinemachineLoaded(CinemachineCamera cinemachineCamera);
|
||||
}
|
||||
}
|
||||
@@ -1,34 +1,15 @@
|
||||
using Code.Infrastructure.Generators;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
|
||||
namespace Code.Infrastructure.Camera
|
||||
{
|
||||
[Config("Configs/Camera/CameraSettings", true)]
|
||||
public class CameraSettings
|
||||
{
|
||||
// Расстояния от персонажа до камеры
|
||||
[ToConfig] public float defaultDistance = 6f; // Стандартное расстояние камеры от цели
|
||||
|
||||
[ToConfig] public float minDistance = 3f; // Минимальное расстояние при зуме
|
||||
|
||||
[ToConfig] public float maxDistance = 10f; // Максимальное расстояние при зуме
|
||||
|
||||
[ToConfig] public float distanceMovementSpeed = 5f; // Множитель скорости изменения дистанции при зуме
|
||||
|
||||
// Скорость поворота камеры
|
||||
[ToConfig] public float rotationSpeed = 0.3f;
|
||||
|
||||
[ToConfig] public float rotationSharpness = 100f; // Коэффициент плавности вращения камеры (чем выше - тем резче)
|
||||
|
||||
[ToConfig] public float followSharpness = 100f; // Коэффициент плавности следования за движущейся целью (чем выше - тем резче)
|
||||
|
||||
[ToConfig] public float minVerticalAngle = -70f; // Минимальный угол наклона камеры (вниз)
|
||||
|
||||
[ToConfig] public float maxVerticalAngle = 70f; // Максимальный угол наклона камеры (вверх)
|
||||
|
||||
[ToConfig] public float defaultVerticalAngle = 10f; // Стандартный угол наклона камеры
|
||||
|
||||
[ToConfig] public float fov = 60; // Комментарии оставляет только нейросеть и долбаёбы, никому и так не будет понятно, что ты высрал
|
||||
|
||||
[ToConfig] public AssetReference cinemachineCamera;
|
||||
|
||||
[ToConfig] public CameraMode cameraMode;
|
||||
|
||||
|
||||
@@ -37,9 +37,8 @@ namespace Code.Infrastructure.Camera
|
||||
SettingsConfigs = settingsConfigs;
|
||||
}
|
||||
}
|
||||
|
||||
public CameraLoadedData cameraLoadedData;
|
||||
|
||||
|
||||
[Inject] public IInputService InputService;
|
||||
[Inject] public EventBus.EventBus EventBus;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using Code.Infrastructure.Generators;
|
||||
using DG.Tweening;
|
||||
using Code.Infrastructure.Generators;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Code.Infrastructure.Camera.CameraStates
|
||||
@@ -23,70 +22,21 @@ namespace Code.Infrastructure.Camera.CameraStates
|
||||
protected override void HandleRotationInput(float deltaTime, Vector3 rotationInput, out Quaternion q)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
private Transform _carTarget;
|
||||
private Rigidbody _carRigidbody;
|
||||
|
||||
public void SetFollowTarget(Transform carTarget, Rigidbody carRigidbody)
|
||||
{
|
||||
_carTarget = carTarget;
|
||||
_carRigidbody = carRigidbody;
|
||||
}
|
||||
|
||||
private Vector3 _lookAtOffset = new Vector3(0, 1.5f, 0);
|
||||
}
|
||||
|
||||
protected override void HandlePosition(float deltaTime, object targetRotation)
|
||||
{
|
||||
Fuck();
|
||||
}
|
||||
|
||||
private void Fuck()
|
||||
{
|
||||
// Автоматическое вращение вокруг машины
|
||||
Vector3 targetPosition = CalculateFollowPosition();
|
||||
|
||||
// Плавное перемещение
|
||||
{
|
||||
|
||||
Vector3 velocity = _carRigidbody ? _carRigidbody.linearVelocity : new Vector3();
|
||||
// Context.cameraLoadedData.Camera.transform.DOMove(targetPosition,
|
||||
// Context.cameraLoadedData.SettingsConfigs[CameraMode.ThirdPerson].followSharpness);
|
||||
Context.cameraLoadedData.Camera.transform.position = Vector3.SmoothDamp(
|
||||
Context.cameraLoadedData.Camera.transform.position,
|
||||
targetPosition,
|
||||
ref velocity,
|
||||
Context.cameraLoadedData.SettingsConfigs[CameraMode.ThirdPerson].followSharpness
|
||||
);
|
||||
|
||||
// Направление взгляда с опережением
|
||||
Vector3 lookTarget = _carTarget.position +
|
||||
_carTarget.forward * Context.cameraLoadedData.SettingsConfigs[CameraMode.ThirdPerson].defaultDistance +
|
||||
_lookAtOffset;
|
||||
|
||||
Context.cameraLoadedData.Camera.transform.LookAt(lookTarget);
|
||||
}
|
||||
|
||||
private Vector3 _followOffset = new Vector3(0, 3, -8);
|
||||
|
||||
private Vector3 CalculateFollowPosition()
|
||||
{
|
||||
Vector3 basePosition = _carTarget.position +
|
||||
_carTarget.TransformDirection(_followOffset);
|
||||
|
||||
// Динамическое смещение на основе скорости
|
||||
if (!_carRigidbody) return basePosition;
|
||||
|
||||
var speedFactor = Mathf.Clamp01(_carRigidbody.linearVelocity.magnitude / 50f);
|
||||
var speedOffset = _carTarget.forward * (speedFactor * -3f);
|
||||
basePosition += speedOffset;
|
||||
|
||||
return basePosition;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void LateUpdate()
|
||||
{
|
||||
Fuck();
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,9 +9,7 @@ namespace Code.Infrastructure.Input
|
||||
public enum GameplayActions
|
||||
{
|
||||
Move,
|
||||
Crouch,
|
||||
Look,
|
||||
Zoom
|
||||
Brake,
|
||||
}
|
||||
public enum DebugActions
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user