Машина, камера, мотор
This commit is contained in:
1 parent
b54083521f
commit
a45223d0e7
48 files changed
+5507
-3735
No files matched your search
@@ -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();
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user