Essentials + extra crap
Loadings Startups Movement Camera
This commit is contained in:
1 parent
662f4a1d05
commit
5f5ace1b52
734 files changed
+107323
-1713
No files matched your search
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Code.Infrastructure.Configs;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace Code.Infrastructure.Camera
|
||||
{
|
||||
public class CameraFactory : IDisposable
|
||||
{
|
||||
private AsyncOperationHandle<GameCameraConfig> _configHandle;
|
||||
private GameCameraConfig _config;
|
||||
private AssetReference _gameCameraConfigReference;
|
||||
|
||||
private AsyncOperationHandle<IList<CameraSettingsConfig>> _settingsConfigsHandle;
|
||||
private Dictionary<CameraMode, CameraSettingsConfig> _settingsConfigs;
|
||||
private string _cameraConfigsLabel;
|
||||
|
||||
private EventBus.EventBus _eventBus;
|
||||
private UnityEngine.Camera _camera;
|
||||
private IDisposable _disposableImplementation;
|
||||
|
||||
public CameraFactory(IConfigLocator configLocator, EventBus.EventBus eventBus)
|
||||
{
|
||||
_gameCameraConfigReference = configLocator.TryGetConfigAssetReference<GameCameraConfig>();
|
||||
_cameraConfigsLabel = configLocator.TryGetManyConfigAssetReferences<CameraSettingsConfig>();
|
||||
|
||||
_eventBus = eventBus;
|
||||
}
|
||||
|
||||
public async UniTaskVoid CreateCameraStateMachine(CameraStateMachine stateMachine)
|
||||
{
|
||||
_settingsConfigsHandle = Addressables
|
||||
.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 void Dispose()
|
||||
{
|
||||
Addressables.Release(_configHandle);
|
||||
Addressables.Release(_settingsConfigsHandle);
|
||||
Addressables.ReleaseInstance(_camera.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user