Развитие системы растений

This commit is contained in:
ThomasCharester committed 2026-03-02 18:25:46 +03:00
1 parent 1b578067f3
commit ba49ef5015
218 files changed
+70415 -1519

No files matched your search

@@ -7,10 +7,7 @@ namespace Code.Infrastructure.App
{
public enum AppStates
{
Bootstrap,
Gameplay,
MainMenu,
Platformer
Bootstrap
}
public class AppStateMachineContext
+46 -13
View File
@@ -1,3 +1,5 @@
using Code.Calendar.Constants;
using Code.Calendar.DataStructures;
using Code.Infrastructure.Audio;
using Code.Infrastructure.Configs;
using Code.Infrastructure.Input;
@@ -8,7 +10,6 @@ using Reflex.Core;
using Reflex.Enums;
using Reflex.Injectors;
using UnityEngine;
using UnityEngine.Rendering.Universal;
using Resolution = Reflex.Enums.Resolution;
namespace Code.Infrastructure.App
@@ -20,7 +21,10 @@ namespace Code.Infrastructure.App
IUIPanelLoaded,
IAudioSourcePoolInitializedHandle,
IAudioConfigsLoadedHandle,
ILayerMasksInitializedHandle
ILayerMasksInitializedHandle,
ITaskServiceHandle,
IPlantsServiceInitHandle,
IConstantImagesServiceHandle
{
public void InstallBindings(ContainerBuilder containerBuilder)
{
@@ -50,18 +54,29 @@ namespace Code.Infrastructure.App
Resolution.Eager);
containerBuilder.RegisterType(typeof(AudioService), new[] { typeof(IAudioService) }, Lifetime.Singleton,
Resolution.Eager);
containerBuilder.RegisterType(typeof(TaskService), new[] { typeof(ITaskService) }, Lifetime.Singleton,
Resolution.Eager);
containerBuilder.RegisterType(typeof(PlantService), new[] { typeof(IPlantService) }, Lifetime.Singleton,
Resolution.Eager);
containerBuilder.RegisterType(typeof(ConstantImagesService), Lifetime.Singleton,
Resolution.Eager);
}
private void InitLoadings()
{
// UIFactory
// UIFactory =
// Logo
// Scene configs
// Input service
// Audio Factory
// Audio Pool
// Scene configs =
// Input service
// Audio Factory =
// Audio Pool =
// Layer masks
_initialLoading = new Loading(7, () => EssentialLoadEnded(_thatRightContainer));
// Tasks =
// Plants =
// CIS =
_initialLoading = new Loading(10, () => EssentialLoadEnded(_thatRightContainer));
}
@@ -81,9 +96,7 @@ namespace Code.Infrastructure.App
private void EssentialLoadEnded(Container container)
{
container.Resolve<EventBus.EventBus>().Unsubscribe(this);
container.Resolve<AppStateMachine>().SwitchState(AppStates.Bootstrap)
.AllowStateTransition(AppStates.Gameplay)
.AllowStateTransition(AppStates.Platformer);
container.Resolve<AppStateMachine>().SwitchState(AppStates.Bootstrap);
container.Resolve<AppStateMachineContext>().StateMachine = container.Resolve<AppStateMachine>();
}
@@ -96,8 +109,7 @@ namespace Code.Infrastructure.App
{
_initialLoading.DoProgress();
}
public void UIInitialized()
{
_initialLoading.DoProgress();
@@ -138,5 +150,26 @@ namespace Code.Infrastructure.App
{
_initialLoading.DoProgress();
}
public void TasksLoaded()
{
_initialLoading.DoProgress();
}
public void TasksSaved()
{ }
public void PlantsLoaded()
{
_initialLoading.DoProgress();
}
public void PlantsSaved()
{ }
public void ImagesLoaded()
{
_initialLoading.DoProgress();
}
}
}
@@ -21,7 +21,8 @@ namespace Code.Infrastructure.App.States
_eventBus.Subscribe(this);
Context.UIService.TryRemovePanel(UIPanelType.Logo);
Context.UIService.TryRemovePanel(UIPanelType.Loading);
Context.UIService.TryLoadPanel(UIPanelType.PlantAdd);
// Context.AudioFactory.LoadAudioClips(AudioNames.UISounds);
}
@@ -33,9 +34,9 @@ namespace Code.Infrastructure.App.States
public void UILoaded(UIPanelType uiPanelType)
{
// if (uiPanelType != UIPanelType.DebugSceneChooser) return;
//
// Context.UIService.OpenPanel(uiPanelType);
if (uiPanelType != UIPanelType.PlantAdd) return;
Context.UIService.OpenPanel(uiPanelType);
}
public void OnReadyToPlay(AudioNames groupName)
{
@@ -29,7 +29,7 @@ namespace Code.Infrastructure.Audio
{
_eventBus = eventBus;
_label = configLocator.TryGetManyConfigAssetReferences<AudioInfoConfig>();
for (var i = 0; i < typeof(AudioNames).GetEnumValues().Length; i++)
{
_audioInfos.Add((AudioNames)i, new Dictionary<int, AssetReference>());
@@ -38,15 +38,17 @@ namespace Code.Infrastructure.Audio
LoadConfigs().Forget();
}
private async UniTaskVoid LoadConfigs()
{
_configsHandle = Addressables.LoadAssetsAsync<AudioInfoConfig>(_label);
if ((await Addressables.LoadResourceLocationsAsync(_label).Task).Count != 0)
{
_configsHandle = Addressables.LoadAssetsAsync<AudioInfoConfig>(_label);
await _configsHandle.ToUniTask();
await _configsHandle.ToUniTask();
foreach (AudioInfoConfig config in _configsHandle.Result)
_audioInfos[config.GroupName].Add(config.id, config.fileReference);
foreach (var config in _configsHandle.Result)
_audioInfos[config.GroupName].Add(config.id, config.fileReference);
}
_eventBus.RaiseEvent<IAudioConfigsLoadedHandle>(ui => ui.AudioConfigsLoaded());
}
@@ -54,14 +56,15 @@ namespace Code.Infrastructure.Audio
public async UniTaskVoid LoadAudioClips(AudioNames groupName)
{
UnityEngine.Debug.LogWarning($"Audios loaded {groupName}");
foreach (var audioInfo in _audioInfos[groupName])
if (!_clipsHandles[groupName].ContainsKey(audioInfo.Key))
_clipsHandles[groupName].Add(audioInfo.Key, Addressables.LoadAssetAsync<AudioClip>(audioInfo.Value));
_clipsHandles[groupName]
.Add(audioInfo.Key, Addressables.LoadAssetAsync<AudioClip>(audioInfo.Value));
else
_clipsHandles[groupName][audioInfo.Key] = Addressables.LoadAssetAsync<AudioClip>(audioInfo.Value);
foreach (var handle in _clipsHandles[groupName])
foreach (var handle in _clipsHandles[groupName])
await handle.Value.ToUniTask();
_eventBus.RaiseEvent<IAudioClipsEventHandle>(ui =>
@@ -73,11 +76,12 @@ namespace Code.Infrastructure.Audio
public void ReleaseAudios(AudioNames groupName)
{
UnityEngine.Debug.LogWarning($"Audios unloaded {groupName}");
_eventBus.RaiseEvent<IAudioClipsEventHandle>(x=> x.AudioClipsUnLoaded(groupName));
foreach (var handle in _clipsHandles)
_eventBus.RaiseEvent<IAudioClipsEventHandle>(x => x.AudioClipsUnLoaded(groupName));
foreach (var handle in _clipsHandles)
Addressables.Release(handle.Value);
}
public void Dispose()
{
foreach (var handles in _clipsHandles)
@@ -88,7 +92,8 @@ namespace Code.Infrastructure.Audio
}
}
_configsHandle.Release();
if (_configsHandle.IsValid())
_configsHandle.Release();
}
}
@@ -118,7 +118,7 @@ namespace Code.Infrastructure.Audio
{
Addressables.Release(_handles);
Addressables.Release(_prefabConfigHandle);
Addressables.Release(_sourcePrefab);
if(_sourcePrefab) Addressables.Release(_sourcePrefab);
}
}
@@ -32,15 +32,21 @@ namespace Code.Infrastructure.Configs
}
private async UniTaskVoid SetupMasks(IConfigLocator configLocator, EventBus.EventBus eventBus)
{
var handle =
Addressables.LoadAssetsAsync<LayerMasksConfigConfig>(
configLocator.TryGetManyConfigAssetReferences<LayerMasksConfigConfig>(), null, Addressables.MergeMode.Union);
var label = configLocator.TryGetManyConfigAssetReferences<LayerMasksConfigConfig>();
if ((await Addressables.LoadResourceLocationsAsync(label).Task).Count != 0)
{
await handle.ToUniTask();
var handle =
Addressables.LoadAssetsAsync<LayerMasksConfigConfig>(
label, null, Addressables.MergeMode.Union);
SetMasks(handle.Result);
await handle.ToUniTask();
Addressables.Release(handle);
SetMasks(handle.Result);
Addressables.Release(handle);
}
eventBus.RaiseEvent<ILayerMasksInitializedHandle>(x => x.LayerMasksInitialized());
}
+3
View File
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 7b23da77f3794e41b162b2ba2e392936
timeCreated: 1772114910
@@ -0,0 +1,7 @@
namespace Code.Infrastructure.JSON
{
public class JsonService
{
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 0c0d29a568964f799b9fda906d71323f
timeCreated: 1772115192
@@ -5,6 +5,7 @@ using Code.Infrastructure.Configs;
using Code.Infrastructure.EventBus;
using Code.Infrastructure.Generators;
using Cysharp.Threading.Tasks;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
using UnityEngine.ResourceManagement.ResourceProviders;
@@ -12,23 +13,24 @@ using UnityEngine.SceneManagement;
namespace Code.Infrastructure.SceneLoader
{
[Config("Configs/SceneConfig",true)]
[Config("Configs/SceneConfig", true)]
public class SceneInfo
{
[ToConfig] public AssetReference SceneAsset;
[ToConfig] public SceneId SceneId;
[ToConfig] public SceneId SceneId;
}
public partial class SceneLoader : IDisposable
{
private Dictionary<SceneId, SceneInfo> _sceneInfos = new();
private Dictionary<SceneId, Action> _scenesActions = new();
private EventBus.EventBus _eventBus;
partial void SetupScenesInfo();
private AsyncOperationHandle<IList<SceneInfoConfig>> _loadHandle;
public SceneLoader(EventBus.EventBus eventBus, IConfigLocator configLocator)
{
_eventBus = eventBus;
@@ -41,16 +43,17 @@ namespace Code.Infrastructure.SceneLoader
if (loadMode == LoadSceneMode.Single)
for (var i = 0; i < _loadedScenes.Count; i++)
UnloadSceneAsync(_loadedScenes.Keys.ToList()[i]).Forget();
_loadedScenes.Add(id,Addressables.LoadSceneAsync(_sceneInfos[id].SceneAsset, loadMode));
_loadedScenes.Add(id, Addressables.LoadSceneAsync(_sceneInfos[id].SceneAsset, loadMode));
await _loadedScenes[id];
_scenesActions[id]();
_scenesActions[id]();
}
private Dictionary<SceneId, AsyncOperationHandle<SceneInstance>> _loadedScenes = new();
public Scene GetScene(SceneId id) => _loadedScenes[id].Result.Scene;
public async UniTaskVoid UnloadSceneAsync(SceneId id)
{
await Addressables.UnloadSceneAsync(_loadedScenes[id]);
@@ -61,35 +64,41 @@ namespace Code.Infrastructure.SceneLoader
private async UniTaskVoid LoadConfigs(string configReferences)
{
_configHandle = Addressables.LoadAssetsAsync<SceneInfoConfig>(configReferences, OnSceneConfigLoaded, Addressables.MergeMode.Union);
await _configHandle.ToUniTask();
SetupScenesInfo();
_eventBus.RaiseEvent<ISceneConfigsLoadedHandle>(h => h.SceneConfigsLoaded());
if ((await Addressables.LoadResourceLocationsAsync(configReferences).Task).Count != 0)
{
_configHandle = Addressables.LoadAssetsAsync<SceneInfoConfig>(configReferences, OnSceneConfigLoaded,
Addressables.MergeMode.Union);
await _configHandle.ToUniTask();
SetupScenesInfo();
}
_eventBus.RaiseEvent<ISceneConfigsLoadedHandle>(h => h.SceneConfigsLoaded());
}
private void OnSceneConfigLoaded(SceneInfoConfig sceneInfoConfig)
{
SceneInfo sceneInfo = new();
sceneInfo.SceneId = sceneInfoConfig.SceneId;
sceneInfo.SceneAsset = sceneInfoConfig.SceneAsset;
_sceneInfos.Add(sceneInfoConfig.SceneId, sceneInfo);
}
public void Dispose()
{
Addressables.Release(_configHandle);
if(_configHandle.IsValid()) _configHandle.Release();
}
}
public interface ISceneConfigsLoadedHandle : IGlobalSubscriber
{
void SceneConfigsLoaded();
}
public interface ILoadedSceneHandle : IGlobalSubscriber
{
void SceneLoaded(SceneId sceneId);
+5 -1
View File
@@ -3,6 +3,10 @@ namespace Code.Infrastructure.UI
public enum UIPanelType
{
Logo,
Loading
Loading,
Calendar,
Tasks,
Plants,
PlantAdd
}
}