Danro-Jump/Assets/Scripts/Runtime/Settings/Installers/ServiceSettingsSceneInjector.cs
Danil Iarosh 77186697f8 Prepare v0.1 gameplay and hardware foundation
Подробные изменения:

- Расширен основной gameplay loop: джетпак, новые платформы, оборудование, враги, прогрессия сложности и ограничения взаимодействий игрока.

- Добавлены Bootstrap-сервисы запуска приложения, защита, фокус окна, управление курсором и настройки сервисов через DI.

- Добавлена COM-интеграция с технической схемой Input System, обработкой кнопок/ADC, подсветкой и консольной диагностикой.

- Добавлен отдельный debug/logging модуль с каналами, обработчиками консоли и файловым выводом.

- Добавлены asmdef, link.xml, EditMode/PlayMode тесты и обновлена дорожная карта проекта.

Проверки:

- dotnet build .\\DanroJump.Runtime.csproj --no-restore

- dotnet build .\\DanroJump.Tests.EditMode.csproj --no-restore

- dotnet build .\\DanroJump.Tests.PlayMode.csproj --no-restore
2026-06-08 14:22:48 +03:00

95 lines
2.7 KiB
C#

using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using Zenject;
namespace DanroJump.Settings
{
/// <summary>
/// Инжектит сценовые ServiceSettingsActions из ProjectContext без прямого глобального поиска объектов.
/// </summary>
public sealed class ServiceSettingsSceneInjector : IInitializable, IDisposable
{
private readonly DiContainer container;
private readonly bool injectActionsInScene;
private readonly List<GameObject> rootObjects = new();
private readonly List<ServiceSettingsActions> actions = new();
private readonly HashSet<EntityId> injectedEntityIds = new();
public ServiceSettingsSceneInjector(DiContainer container, bool injectActionsInScene)
{
this.container = container;
this.injectActionsInScene = injectActionsInScene;
}
public void Initialize()
{
if (!injectActionsInScene)
{
return;
}
InjectLoadedScenes();
SceneManager.sceneLoaded += OnSceneLoaded;
}
public void Dispose()
{
SceneManager.sceneLoaded -= OnSceneLoaded;
rootObjects.Clear();
actions.Clear();
injectedEntityIds.Clear();
}
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
InjectScene(scene);
}
private void InjectLoadedScenes()
{
for (var index = 0; index < SceneManager.sceneCount; index++)
{
InjectScene(SceneManager.GetSceneAt(index));
}
}
private void InjectScene(Scene scene)
{
if (!scene.IsValid() || !scene.isLoaded)
{
return;
}
rootObjects.Clear();
scene.GetRootGameObjects(rootObjects);
for (var rootIndex = 0; rootIndex < rootObjects.Count; rootIndex++)
{
actions.Clear();
rootObjects[rootIndex].GetComponentsInChildren(true, actions);
for (var actionIndex = 0; actionIndex < actions.Count; actionIndex++)
{
var sceneActions = actions[actionIndex];
if (sceneActions == null)
{
continue;
}
if (!injectedEntityIds.Add(sceneActions.GetEntityId()))
{
continue;
}
container.Inject(sceneActions);
}
}
actions.Clear();
rootObjects.Clear();
}
}
}