Машина, камера, мотор
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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user